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