How to add and delete tags in mapxtreme

Source: Internet
Author: User

How does mapxtreme add and delete tags?

Two pointselectiontools are added,

Set clientcommand to mapcommand and clientinteraction to clickinteraction,

Set "command" to "addpinpointcommand" and "clearpinpointcommand" to "command,

Add page_load

Controlmodel. commands. Add (New addpinpointcommand ());
Controlmodel. commands. Add (New clearpinpointcommand ());

MapInfo. Mapping. Map mymap = getmapobj ();

If (mymap! = NULL)
{
If (mymap. Layers [sampleconstants. templayeralias]! = NULL)
{
Mymap. layers. Remove (sampleconstants. templayeralias );
}
}
// Need to clean up "dirty" Temp table left by other customer requests.
MapInfo. Engine. session. Current. Catalog. CloseTable (sampleconstants. temptablealias );
// Need to clear the defautlselection.
MapInfo. Engine. session. Current. Selections. defaultselection. Clear ();

// Creat a temp table and addpintpointcommand will add features into it.
MapInfo. Data. tableinfomemtable Ti = new MapInfo. Data. tableinfomemtable (sampleconstants. temptablealias );
// Make the table mappable
Ti. Columns. Add (MapInfo. Data. columnfactory. createfeaturegeometrycolumn (mymap. getdisplaycoordsys ()));
Ti. Columns. Add (MapInfo. Data. columnfactory. createstylecolumn ());

MapInfo. Data. Table = MapInfo. Engine. session. Current. Catalog. createtable (Ti );
// Create a new featurelayer Based on the temp table, so we can see the temp table on the map.
Mymap. layers. insert (0, new featurelayer (table, "templayer", sampleconstants. templayeralias ));

Add a method:

Private MapInfo. Mapping. Map getmapobj ()
{
// Get the map
MapInfo. Mapping. Map mymap = MapInfo. Engine. session. Current. mapfactory [mapcontrol1.mapalias];
If (mymap = NULL)
{
Mymap = MapInfo. Engine. session. Current. mapfactory [0];
}
Return mymap;
}

Add it to customizedcommands. CS (this class is added when info is obtained, and the following code is added)

/// <Summary>
/// Summary description for pinpointcommand.
/// </Summary>
[Serializable]
Public class addpinpointcommand: MapInfo. webcontrols. mapbasecommand
{
/// <Summary>
/// Constructor for this command, sets the name of the command
/// </Summary>
/// <Remarks> none </remarks>
Public addpinpointcommand ()
{
Name = "addpinpointcommand ";
}

/// <Summary>
/// This method gets the map object out of the mapfactory with given mapalias and
/// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
/// </Summary>
/// <Remarks> none </remarks>
Public override void process ()
{
// Extract points from the string
System. Drawing. Point [] points = This. extractpoints (this. datastring );

Mapcontrolmodel model = mapcontrolmodel. getmodelfromsession ();
Model. setmapsize (mapalias, mapwidth, mapheight );

MapInfo. Mapping. Map map = model. getmapobj (mapalias );
If (MAP = NULL) return;

// There will be only one point, convert it to spatial
MapInfo. Geometry. dpoint point;
Map. displaytransform. fromdisplay (points [0], Out Point );

Imaplayer lyr = map. Layers [sampleconstants. templayeralias];
If (lyr = NULL)
{
Tableinfomemtable Ti = new tableinfomemtable (sampleconstants. temptablealias );
// Make the table mappable
Ti. Columns. Add (columnfactory. createfeaturegeometrycolumn (Map. getdisplaycoordsys ()));
Ti. Columns. Add (columnfactory. createstylecolumn ());

MapInfo. Data. Table = MapInfo. Engine. session. Current. Catalog. createtable (Ti );
Map. layers. insert (0, new featurelayer (table, "templayer", sampleconstants. templayeralias ));
}
Lyr = map. Layers [sampleconstants. templayeralias];
If (lyr = NULL) return;
Featurelayer flyr = lyr as featurelayer;

MapInfo. Geometry. Point geopoint = new MapInfo. Geometry. Point (Map. getdisplaycoordsys (), point );
// Create a point style which is a red pin point.
Simplevectorpointstyle Vs = new simplevectorpointstyle ();
Vs. Code = 67;
Vs. Color = color. Red;
Vs. pointsize = convert. toint16 (24 );
Vs. Attributes = styleattributes. pointattributes. baseall;
Vs. setapplyall ();

// Bitmappointstyle Vs = new bitmappointstyle ();
// Vs. Name = @ "C: \ Documents and Settings \ Dong Jing \ Desktop \ GIS \ sample \ images \ star.gif ";
// Vs. pointsize = convert. toint16 (24 );
// Vs. Attributes = styleattributes. pointattributes. baseall;
// Vs. setapplyall ();

// Create a feature which contains a point geometry and insert it into temp table.
Feature pntfeature = new feature (geopoint, );
MapInfo. Data. Key key = flyr. Table. insertfeature (pntfeature );

// Send contents back to client.
Memorystream MS = model. getmap (mapalias, mapwidth, mapheight, exportformat );
Streamimagetoclient (MS );
}
}
/// <Summary>
/// Summary description for pinpointcommand.
/// </Summary>
[Serializable]
Public class clearpinpointcommand: MapInfo. webcontrols. mapbasecommand
{
/// <Summary>
/// Constructor for this command, sets the name of the command
/// </Summary>
/// <Remarks> none </remarks>
Public clearpinpointcommand ()
{
Name = "clearpinpointcommand ";
}

/// <Summary>
/// This method gets the map object out of the mapfactory with given mapalias
/// And this method Delete the pin point features added by addpinpointcommand in a given point
/// And then streams the image back to client.
/// </Summary>
/// <Remarks> none </remarks>
Public override void process ()
{
System. Drawing. Point [] points = extractpoints (datastring );
Mapcontrolmodel model = mapcontrolmodel. getmodelfromsession ();
Model. setmapsize (mapalias, mapwidth, mapheight );
MapInfo. Mapping. Map map = model. getmapobj (mapalias );
If (MAP = NULL) return;
Pointdeletion (MAP, points [0]);
Memorystream MS = model. getmap (mapalias, mapwidth, mapheight, exportformat );
Streamimagetoclient (MS );
}
/// <Summary>
/// Delete a feature in the temporary layer.
/// </Summary>
/// <Param name = "mapalias"> mapalias of the Map </param>
/// <Param name = "point"> point in pixels </param>
Private void pointdeletion (MAP map, system. Drawing. Point point)
{
// Do the search and show selections
Searchinfo Si = MapInfo. Mapping. searchinfofactory. searchnearest (MAP, point, 10 );
(Si. searchresultprocessor as closestsearchresultprocessor). Options = closestsearchoptions. stopatfirstmatch;

MapInfo. Data. Table = MapInfo. Engine. session. Current. Catalog [sampleconstants. temptablealias];
If (table! = NULL)
{
Iresultsetfeaturecollection IFC = session. Current. Catalog. Search (table, Si );
Foreach (feature F in IFC)
{
Table. deletefeature (f );
}
IFC. Close ();
}
}
}

/// <Summary>
/// Summary description for sampleconstants.
/// </Summary>
Public class sampleconstants
{
Public static string templayeralias = "pinpointlayer ";
Public static string temptablealias = "pinpointtable ";

Private sampleconstants (){}
}

 

The system prompts that the class referenced by simplevectorpointstyle cannot be found. This is the referenced MapInfo. styles.

If you run the command again, you will be prompted that the session is not found. This is the referenced MapInfo. Engine.

OK! This article is excerpted on the Internet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.