程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#進行MapX二次開發之圖層操作(2)

C#進行MapX二次開發之圖層操作(2)

編輯:關於C語言

在得到了 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;
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved