C#进行MapX二次开发之图层操作
2009-06-27 07:07:57 来源:WEB开发网在得到了Recordset对象后,如何解决第一个问题。步骤如下:
1. 创建CMapXFields对象,并对应数据库中字段添加字段;
2. 创建CMapXBindLayer对象,指定其坐标值字段的序号;
3. 向map.DataSets中添加数据集,从而生成新的图层;
4. 指定新图层中要素的显示风格,本文采用显示位图的方式,为此需要将要显示的位图放入MapX安装目录的CUSTSYMB文件夹下。
具体的操作代码如下所示:
/// <summary>
/// 删除所有的图层数据
/// </summary>
/// <param name="layerName"></param>
private void DeleteLayerByName(string layerName)
{
//Layer的序号是从1开始
int count = axMap1.Layers.Count;
for (int i = 1; i < count; i++)
{
if (axMap1.Layers[i].Name == layerName)
{
axMap1.Layers.Remove(i);
}
}
}
/// <summary>
/// 创建新的图层信息
/// </summary>
/// <param name="layerName"></param>
/// <param name="rsNoPass"></param>
private void CreatNewLayerfromDB(string layerName, ADODB.Recordset rsNoPass)
{
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 = axMap1.DataSets.Add(DatasetTypeConstants.miDataSetADO, rsNoPass, layerName, "stationid", "address", bindLayerObject, flds, false);
CMapXLayer layer = axMap1.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;
}
}
文章来源:http://www.iqidi.com
更多精彩
赞助商链接