10 examples of mapxtreme practical skills and source code

Source: Internet
Author: User
1. Set the optional layer status.
/**////
/// Change the selectable status of the layer
///

///

///
Public bool layerselectablestatusupdate (string tablealias, bool selectablestatus)
{
If (mapcontrol1.map. Layers [tablealias] = NULL)
Return false;

MapInfo. Mapping. layerhelper. setselectable (mapcontrol1.map. Layers [tablealias], selectablestatu

S );
Return true;
}

2. Set the available status of the layer

/**////

/// Change the available status of the layer to status
///

///

///

Public void layerenablestatusupdate (string layername, bool status)
{
If (mapcontrol1.map. Layers [layername]! = NULL & mapcontrol1.map. Layers [layername]. enabled!

= Status)
{
Mapcontrol1.map. Layers [layername]. Enabled = status;
}
}
Center the three layers to see the full Graph

/**////

/// Make all specified layers appear in the visible range of the map
///

///
Layer alias

Public void layercenter (string layername)
{
MapInfo. Data. Table [] tables = new MapInfo. Data. Table [1];
Tables [0] = MapInfo. Engine. session. Current. Catalog. gettable (layername );
If (tables [0] = NULL)
Return;
If (mapcontrol1.map. Layers [layername] = NULL)
Return;

If (mapcontrol1.map. Layers [layername]. Enabled = false)
Mapcontrol1.map. Layers [layername]. Enabled = true;

MapInfo. Mapping. imaplayerfilter =

MapInfo. Mapping. maplayerfilterfactory. filterbytable (tables );
MapInfo. Mapping. maplayerenumerator =

Mapcontrol1.map. layers. getmaplayerenumerator (imaplayerfilter );
Mapcontrol1.map. setview (maplayerenumerator );
Onfeatureunclick ();
}

4. Zoom in and out the map

/**////

/// Enlarge the map
///

///
Magnification, valid value: 1-10

Public void zoomin (uint times)
{
If (Times <1 | times> 10) return;
MapInfo. Geometry. Distance previuszoom = This. mapcontrol1.map. Zoom;
Mapcontrol1.map. Zoom = new MapInfo. Geometry. Distance (previuszoom. Value/

(2 * times), previuszoom. Unit );
}
/**////

/// Zoom out the map
///

///
Zoom in multiple, valid value: 1-10

Public void zoomout (uint times)
{
If (Times <1 | times> 10) return;
MapInfo. Geometry. Distance previuszoom = This. mapcontrol1.map. Zoom;
Mapcontrol1.map. Zoom = new MapInfo. Geometry. Distance (previuszoom. Value *

(2 * times), previuszoom. Unit );
}

5. Sequence of moving Layers
Mapcontrol1.map. layers. Move (index1, index2 );

6. Opacity of elements/Layers

/**////

/// Set whether the layer is transparent or not
///

///
Layer name

///
Opacity type all opacity border only has the border opacity (internal transparency)

None all transparent

///
If the border is not transparent, set the border color here.

Public void layertransparent (string layername, opaquetype, system. Drawing. Color

Bordercolor)
{

MapInfo. Styles. compositestyle = getopaquestyle (opaquetype, bordercolor );

// Create a connection and command to update table data
MapInfo. Data. miconnection connection = new MapInfo. Data. miconnection ();
Connection. open ();
MapInfo. Data. micommand command = connection. createcommand ();
Command. commandtext = "Update" + layername + "set OBJ = OBJ, mi_style = @ style ";
Command. Parameters. Add ("@ style", compositestyle );
Command. Prepare ();
Command. executenonquery ();

// Close the connection
Command. Cancel ();
Command. Dispose ();
Connection. Close ();
Connection. Dispose ();
}
/**////

/// Create a style
///

///
Opacity type: All is not transparent (white solid); border boundary is not transparent (fill part

Transparent); none transparent

///
If opaquetype = border, set the border color here.

/// Combination Style
Private MapInfo. Styles. compositestyle getopaquestyle (opaquetype

Opaquetype, system. Drawing. Color bordercolor)
{
MapInfo. Styles. simpleinterior;
If (opaquetype = opaquetype. All)
Simpleinterior = new MapInfo. Styles. simpleinterior (); // The default constructor is white and solid.
Else
Simpleinterior = new MapInfo. Styles. simpleinterior (1); // 0 is wire transparent, 1 is surface transparent

MapInfo. Styles. linewidth = new

MapInfo. Styles. linewidth (1, MapInfo. Styles. linewidthunit. Point );

MapInfo. Styles. simplelinestyle;
If (opaquetype = opaquetype. All)
Simplelinestyle = new MapInfo. Styles. simplelinestyle (linewidth );
Else if (opaquetype = opaquetype. Border)
Simplelinestyle = new MapInfo. Styles. simplelinestyle (linewidth, 2, bordercolor); // 2 indicates Filling

Transparent to display the outline
Else
Simplelinestyle = new MapInfo. Styles. simplelinestyle (linewidth, 0); // 0 indicates that all are transparent, that is, continuous Wheel

Invisible to profile

MapInfo. Styles. areastyle = new

MapInfo. Styles. areastyle (simplelinestyle, simpleinterior );

MapInfo. Styles. compositestyle = new

MapInfo. Styles. compositestyle (areastyle, null, null );

Return compositestyle;
}

7. Select all elements

MapInfo. Engine. session. Current. Catalog. Search (
Table,
MapInfo. Data. searchinfofactory. searchall (),
MapInfo. Engine. session. Current. Selections. defaultselection,
MapInfo. Data. resultsetcombinemode. Replace );

8. Set Coordinate System
By default, the coordsys used by mapxtreme is the longitude and latitude projection (longlat) and WGS84. I want to modify the projection type

Coordsystype. transversemercator, with the reference value datumid. pulkovo1942
MapInfo. Geometry. coordsysfactory

Coordsysfactory = MapInfo. Engine. session. Current. coordsysfactory;
Mapcontrol1.map. setdisplaycoordsys (coordsysfactory. createcoordsys ("MapInfo: coordsys

7,117, 20500000,0 "));

Coordsysfactory. createcoordsys ("MapInfo: coordsys 7,117, 20500000,0") default Origin

Yes (B = 0, L = 117). How should I write this string if I want to set the origin point to (23,117?
Coordsysfactory. createcoordsys ("MapInfo: coordsys 8, 7,114 ")

9 Save the new painting as a tab File
The source code below is to create a permanent table, add a feature to the table, and save it as a tab file on the hard disk.

Private MapInfo. Data. Table createnewmapdatatable (string tablename)
{
// The followingCodeIs to create a permanent table
MapInfo. Data. tableinfonative

Tableinfonative = newmapinfo. Data. tableinfonative (tablename );
Tableinfonative. tablepath = @ "D: \ data \" + tablename + ". tab ";
Tableinfonative. Columns. Add (MapInfo. Data. columnfactory. createintcolumn ("ID "));
Tableinfonative. Columns. Add (MapInfo. Data. columnfactory. createstylecolumn ());
MapInfo. Geometry. coordsys = mapcontrol1.map. getdisplaycoordsys ();

Tableinfonative. Columns. Add (MapInfo. Data. columnfactory. createfeaturegeometrycolumn (coordsys)

);
MapInfo. Data. Table

= MapInfo. Engine. session. Current. Catalog. createtable (tableinfonative );

// The following Code creates a temporary table
// MapInfo. Data. tableinfo

= MapInfo. Data. tableinfofactory. createtemp (tablename );
// Tableinfo. Columns. Add (MapInfo. Data. columnfactory. createintcolumn ("ID "));
// MapInfo. Data. Table

= MapInfo. Engine. session. Current. Catalog. createtable (tableinfo );

MapInfo. Mapping. featurelayer =

Newmapinfo. Mapping. featurelayer (table );
This. mapcontrol1.map. layers. Add (featurelayer );
Return table;
}

Private void addfeaturesandsave ()
{
MapInfo. Styles. simplelinestyle =

Newmapinfo. Styles. simplelinestyle (New

MapInfo. Styles. linewidth (1, MapInfo. Styles. linewidthunit. Point ));
MapInfo. Styles. compositestyle =

Newmapinfo. Styles. compositestyle (null, simplelinestyle, null, null );
MapInfo. Geometry. coordsys = mapcontrol1.map. getdisplaycoordsys ();

MapInfo. Data. Table = createnewmapdatatable ("newtable ");
MapInfo. Data. tableinfo = table. tableinfo;
While (......)
{
MapInfo. Data. Feature feature = newmapinfo. Data. feature (tableinfo. columns );

Feature. Geometry = ......
Feature. Style = ......
Feature ["ID"] = ......
Table. insertfeature (feature );
}
Tableinfo. writetabfile (); // Save As A. Tab File

Mapcontrol1.refresh ();
}

10. Calculate the scaling ratio.

/**////

/// Calculate the zoom ratio when you redraw the widget
///

///

///

protected void mapcontrol1_paint (Object sender, painteventargs e)
{< br> MapInfo. geometry. distance zoomdistance = This. mapcontrol1.map. zoom;
double zoom = convert. todouble (convert. toint32 (zoomdistance. value * 16.09)/10;
This. statusbar1.text = "zoom ratio:" + zoom. tostring () + "km";
}

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.