昨天試了一天的Feature,現在還存在的問題有:
1)無法將CMapX***Disp 轉換成 tagVariant, 例如例子中,創建線及區域時, 無論你寫成下面的任何一種,都創建不成功,
Map1->Layers->_Item(Variant(1))->CreateRegion(points, EmptyParam);//編譯失敗
Map1->Layers->_Item(Variant(1))->CreateRegion(Variant((IUnknown *)points), EmptyParam);//運行創建不成功
應該寫爲:
Map1->Layers->_Item(Variant(1))->CreateRegion(Variant((CMapXPoints*)points), EmptyParam);//運行創建不成功
而只好改用下面的兩行代碼:
feature = Map1->FeatureFactory->CreateRegion(EmptyParam, EmptyParam);
feature->Parts->Add(points);
2)下面的示例中保留了一個錯誤,就是用 下面的代碼創建Feature時,程序退出會拋出異常。現在還沒找到解決的方法,也只好改用其它的方法,如 CreateRegion中使用的方法
CMapXFeatureDisp line;
line.Bind(StringToOleStr("MapX.Feature.5"));
line.Attach(Map1->OleObject);
3)文本顯示不能顯示在層上(已解決):.
將原來的Variant("文本圖元")改爲Variant(WideString("文本圖元"))就可以了,但如果有中文,則沒了後面的四個字節,只顯示“文本”。
示例代碼:
void __fastcall TfrmFeature::Map1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{ //只向 動畫層中加圖元
if((Button != mbLeft) || (placeFeatureId == -1)) return;
if(Map1->Layers->Count == 0 ){
log("日誌", "沒有圖層或動畫圖層, 不能完成添加Feature的工作");
placeFeatureId = -1;
return;
}
//動作名稱
String strFeature;
CMapXPointDisp point;
//生成的圖元
CMapXFeature * feature = NULL;
point.Bind(StringToOleStr("MapX.Point.5"));
point = Map1->ConvertCoordP(Variant(X), Variant(Y), miScreenToMap);
switch (placeFeatureId)
{
case 0:{
CMapXPointDisp p1;
CMapXPointDisp p2;
p1.Bind(StringToOleStr("MapX.Point.5"));
p2.Bind(StringToOleStr("MapX.Point.5"));
p1.Set_(point.get_X() -1.0, point.get_Y() + 0.2);
p2.Set_(point.get_X() + 0.4, point.get_Y() -0.4);
feature = Map1->FeatureFactory->CreateArc(p1, p2, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
strFeature = "形似弧的線圖元";}
break;
case 1:{
feature = Map1->FeatureFactory->CreateCircularRegion(miCircleTypeMap, point, Variant(30), EmptyParam, Variant(99), EmptyParam);
Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
strFeature = "似圓的區域";}
break;
case 2: {
//這樣做, 在退出程序時,會報異常
CMapXFeatureDisp line;
line.Bind(StringToOleStr("MapX.Feature.5"));
line.Attach(Map1->OleObject);
line.Type = miFeatureTypeLine;
line.Style = Map1->DefaultStyle;
CMapXPointsDisp points;
points.Bind(StringToOleStr("MapX.Points.5"));
double x = point.get_X();
double y = point.get_Y();
points.AddXY(x - 1, y - 0.5);
points.AddXY(x - 0.5, y + 0.5);
points.AddXY(x, y);
points.AddXY(x + 0.5, y - 0.5);
points.AddXY(x + 1, y + 0.5);
line.Parts->Add(points);
//feature = Map1->FeatureFactory->CreateLine(EmptyParam, EmptyParam);
Map1->Layers->_Item(Variant(1))->AddFeature(line, EmptyParam);
line->Attach(NULL);
strFeature = "線, 退出會異常,請用添加區域的方法";}
break;
case 3: {
CMapXPointsDisp points;
points.Bind(StringToOleStr("MapX.Points.5"));
double x = point.get_X();
double y = point.get_Y();
points.AddXY(x - 1, y - 0.5);
points.AddXY(x - 0.2, y + 0.7);
points.AddXY(x + 0.3, y - 0.1);
points.AddXY(x + 0.8, y + 0.6);
feature = Map1->FeatureFactory->CreateRegion(EmptyParam, EmptyParam);
feature->Parts->Add(points);
Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
strFeature = "區域圖元";}
break;
case 4: {
feature = Map1->FeatureFactory->CreateSymbol(EmptyParam, EmptyParam);
feature->set_Point(point);
Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
strFeature = "點圖元";}
break;
case 5: {
Variant caption = "文本圖元abcdefg";
caption.ChangeType(0x8);
feature = Map1->FeatureFactory->CreateText(EmptyParam, caption, EmptyParam, EmptyParam);
feature->set_Point(point);
Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
strFeature = "文本圖元";}
break;
default:
;
}
placeFeatureId = -1;
log("日誌", strFeature + "位置 x:" + String(point.get_X()) + " y:" + String(point.get_Y()) +( feature == NULL ?" faile":" secc"));