Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using MapInfo;
Using MapInfo. Data. Find;
Using MapInfo. Data;
Using MapInfo. geometry;
Using MapInfo. styles;
Using MapInfo. Mapping. thematics;
Using MapInfo. Mapping;
Using MapInfo. Mapping. Legends;
Using MapInfo. webcontrols;
Using applicationstatemanager;
Namespace
// Bind the country name to the menu
Private Static string _ findlayername = "worldcap ";
Private Static string _ findcolumnname = "country ";
Protected override void onprerender (eventargs E)
{
If (! Ispostback)
{
Filldropdown (_ findlayername, _ findcolumnname );
}
}
Private void filldropdown (string tablename, string colname)
{
MapInfo. Mapping. Map map = NULL;
// Get the map
If (MapInfo. Engine. session. Current. mapfactory. Count = 0 |
(MAP = MapInfo. Engine. session. Current. mapfactory [mapcontrol1.mapalias]) = NULL)
{
Return;
}
Ddlcity. Items. Clear ();
MapInfo. mapping. featurelayer FL = (MapInfo. mapping. featurelayer) map. layers [tablename];
MapInfo. data. table T = FL. table;
midatareader TR;
miconnection con = new miconnection ();
micommand Tc = con. createcommand ();
TC. commandtext = "select" + colname + "from" + T. alias;
// convert. todatetime ("AFDS");
con. open ();
TR = tc. executereader ();
while (TR. read ()
{< br> ddlcity. items. add (TR. getstring (0);
}
TC. Cancel ();
TC. Dispose ();
Tr. Close ();
Con. Close ();
}
// Search for a country on the map
Private Static string _ workinglayername = "workinglayer ";
Protected void butfind_click (Object sender, eventargs E)
{
Find find = NULL;
Try
{
MapInfo. Mapping. Map map = NULL;
// get the map
If (MapInfo. engine. session. current. mapfactory. count = 0 |
(MAP = MapInfo. engine. session. current. mapfactory [mapcontrol1.mapalias]) = NULL)
{< br> return;
}
// do the find
MapInfo. mapping. featurelayer findlayer = (MapInfo. mapping. featurelayer) map. layers [_ findlayername];
Find = new find (findlayer. table, findlayer. table. tableinfo. columns [_ findcolumnname]);
findresult result = find. search (ddlcity. selecteditem. text);
If (result. exactmatch)
{< br> // create a feature (point) for the location we found
coordsys csys = findlayer. coordsys;
featuregeometry G = new MapInfo. geometry. point (csys, result. foundpoint. x, result. foundpoint. y);
feature F = new feature (G, new MapInfo. styles. simplevectorpointstyle (52, system. drawing. color. darkgreen, 32);
// Delete the existing find object and add the new one
MapInfo. mapping. featurelayer workinglayer = (MapInfo. mapping. featurelayer) map. layers [_ workinglayername];
If (workinglayer! = NULL)
{< br> (workinglayer. table as itablefeaturecollection ). clear ();
workinglayer. table. insertfeature (f);
}
// Set the map's center and zooom
Map. Center = new dpoint (result. foundpoint. X, result. foundpoint. y );
MapInfo. Geometry. distance d = new MapInfo. Geometry. Distance (1, map. Zoom. Unit );
Map. Zoom = D;
}
Else
{
Response. Write ("nothing ");
}
Find. Dispose ();
}
Catch (exception)
{
If (find! = NULL) find. Dispose ();
}
}