数据|数据库
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.Override 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集合的序号使用上可以看出。