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集合的序號使用上可以看出。
新聞熱點
疑難解答