MapX reads data from the database to form a new layer [reprinted]
Address: http://www.pin5i.com/showtopic-9729.html
In C #, MapX reads data from the database to form a new layer. There are two problems::
1. MapX reads data from the database to form a new layer;
2. Convert the datatable to the recordset of ADO.
The second problem is caused by the first problem, because MapX is a COM control and only supports the data access method of ADO, C # generally uses ADO for programming.. (Of course, you can also use the ADO method in C #, but this is a lagging method after all. For more information about this solution, see "using ADO to access a database in Visual Basic. Net".
For the solution to the second problem, see the author's another article converting a able object to A recordset object (http://blog.csdn.net/allentao/archive/2005/05/11/373634.aspx), this article only describes after obtaining a recordset object, how to solve the first problem.
The procedure is as follows::
1. Create a cmapxfields object and add fields to fields in the database;
2. Create a cmapxbindlayer object and specify the serial number of its coordinate value field;
3. Add a dataset to map. datasets to generate a new layer;
4. Specify the display style of the elements in the new layer. This article uses the display bitmap method. Therefore, you need to place the bitmap to the custsymb folder in the installation directory of MapX.
The Code is as follows::
Private void creatnewlayerfromdb (string layername, ADODB. recordset rsnopass)
{
This. deletelayerbyname (layername); // Delete the original layer
Cmapxfields FLDS = new fieldsclass ();
// Describe the structure of the unbound Dataset
FLDS. Add ("stationid", "theid", aggregationfunctionconstants. miaggregationindividual, fieldtypeconstants. mitypestring );
FLDS. Add ("Address", "Address", aggregationfunctionconstants. miaggregationindividual, fieldtypeconstants. mitypestring );
FLDS. Add ("longpolling", "longpolling", aggregationfunctionconstants. miaggregationsum, fieldtypeconstants. mitypenumeric); // longitude
FLDS. Add ("latitude", "latitude", aggregationfunctionconstants. miaggregationsum, fieldtypeconstants. mitypenumeric); // latitude
Cmapxbindlayer bindlayerobject = new bindlayerclass ();
Bindlayerobject. layername = layername;
Bindlayerobject. refcolumn1 = 3;
Bindlayerobject. refcolumn2 = 4;
Bindlayerobject. layertype = bindlayertypeconstants. mibindlayertypexy;
Cmapxdataset dataset = map. datasets. Add (datasettypeconstants. midatasetado, rsnopass, layername, "stationid", "Address", bindlayerobject, FLDS, false );
Cmapxlayer layer = map. layers. _ item (layername );
Layer. overridestyle = true;
String picname = "icon. BMP ";
If (layer. style. supportsbitmapsymbols = true)
{
Layer. style. symboltype = symboltypeconstants. misymboltypebitmap;
Layer. style. symbolbitmapsize = 60;
Layer. style. symbolbitmaptransparent = true;
Layer. style. symbolbitmapname = picname;
}
}
Private void deletelayerbyname (string layername)
{
Int COUNT = map. layers. count;
For (INT I = 1; I <count; Div I ++ ){
If (Map. layers. _ item (I). Name = layername)
Map. layers. Remove (I );
}
}
Description:
The serial number in the MapX control starts from 1, which can be seen from the code above.