mapx从数据库读取数据形成新图层(c#)
代码如下: private void creatnewlayerfromdb(string layername, adodb.recordset rsnopass) { this.deletelayerbyname(layername); //将原有层删除
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("longitude", "longitude", aggregationfunctionconstants.miaggregationsum, fieldtypeconstants.mitypenumeric); //经度 flds.add("latitude", "latitude", aggregationfunctionconstants.miaggregationsum, fieldtypeconstants.mitypenumeric); //纬度
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; i++) { if(map.layers._item(i).name==layername) map.layers.remove(i); } }
说明: mapx控件中的序号是从1开始的,这一点可从上面的代码中layers集合与fields集合的序号使用上可以看出。
新闻热点
疑难解答