mapx标注之详解

以前做gis的时候,没怎么用到标记,今天终于接触到标记这方面的东西,做了个demo测试了一下:

 

首先写了个操作mapx的单元,其中有个函数:

function TMapModule.CreateTempAnimationLayer(var currentMap: TMap;
  layerName: string): CMapXLayer;
var
  layerInfo:CMapXLayerInfo;
  flds : CMapXFields;
  ANewLayer : CMapXLayer;
begin
  try
    flds := CoFields.Create;
    flds.AddIntegerField('ID',EmptyParam);
    flds.AddStringField('captiontoshow',254,EmptyParam);
    flds.AddStringField('name',254,EmptyParam);

    layerInfo := CoLayerInfo.Create;
    layerInfo.type_ := miLayerInfoTypeTemp;
    layerInfo.AddParameter('FileSpec',layerName);
    layerInfo.AddParameter('Name',layerName);
    layerInfo.AddParameter('Fields',flds);

    ANewLayer := currentMap.Layers.Add(layerInfo,1);

    currentMap.DataSets.Add( miDataSetLayer , ANewLayer , 'ds_'+layerName , EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);

    currentMap.Layers.AnimationLayer := ANewLayer;

    result := ANewLayer;
  except
    result := nil;
  end;
end;

 

 

2.新窗体中拖一个tmapx控件,设置了加载的geoset,

窗体创建的时候,创建一个临时图层:

procedure TForm1.FormCreate(Sender: TObject);
var
  AMapModule:TMapModule;
  ALayer:CMapXLayer;
begin
  AMapModule := TMapModule.Create;
  ALayer := AMapModule.CreateTempAnimationLayer(MainMap,'temp_layer');
  ALayer.AutoLabel := True;

end;

3.窗体上拖一个按钮,onclick事件如下:

procedure TForm1.Button1Click(Sender: TObject);
var
  APoint:CMapXPoint;
  ACreatePoint,ANewPoint:CMapXFeature;
  ALayer:CMapXLayer;
  AMapXDateset:CMapXDataset;
  ARowValue:CMapXRowValues;
begin
  APoint := CoPoint.Create;
  APoint.Set_(114.337552895699,30.5367033707355);
  ALayer := MainMap.Layers['temp_layer'];

  ACreatePoint := MainMap.FeatureFactory.CreateSymbol(APoint,EmptyParam);

  ANewPoint := ALayer.AddFeature(ACreatePoint,EmptyParam);

  ALayer.KeyField := 'captiontoshow';
  ANewPoint.KeyValue := 'this is caption' + #13#10 + 'hello! i am peirenlei';
  ANewPoint.Update(EmptyParam,EmptyParam);

  ALayer.KeyField := 'name';
  ANewPoint.KeyValue := 'this is name';
  ANewPoint.Update(EmptyParam,EmptyParam);

  ALayer.KeyField := 'ID';
  ANewPoint.KeyValue := IntToStr(1);
  ANewPoint.Update(EmptyParam,EmptyParam);

  ALayer.KeyField := 'name';
  ShowMessage(ANewPoint.KeyValue);

  ANewPoint.Update(EmptyParam,EmptyParam);

  AMapXDateset := MainMap.DataSets.Item['ds_temp_layer'] ;
  ARowValue := AMapXDateset.RowValues[ANewPoint];

  ShowMessage(ARowValue.Item['id'].Value);
end;

 

经过上面的代码,得出一个结论,mapx的lable只能显示创建的字段中的第一个字符型的字段的值,而且必须手工指定,如:  ALayer.KeyField := 'captiontoshow'; 如果指定为id,或者name,label 是不会显示的,这一点要切记。

你可能感兴趣的:(单元测试)