procedure TMapBaseForm.MapTopoMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
FCurXCoord: Double; // Current X coordination on map
FCurYCoord: Double; // Current Y coordination on map
ScreenX, ScreenY: Single;
FeatureKey: String;
begin
ScreenX := X;
ScreenY := Y;
{ Save current mouse position for add new rolly point. }
MapTopo.ConvertCoord(ScreenX, ScreenY, FCurXCoord, FCurYCoord, miScreenToMap);
FeatureKey := GetFeatureKey(FCurXCoord, FCurYCoord);
if FeatureKey <> EmptyStr then
根据FeatureKey就可以做你要做的事情了,MapX的Demo中有;
end;
function TMapBaseForm.GetFeatureKey(AMapX, AMapY: Double): String;
var
Point: CMapXPoint;
Features: Variant;
InfoFeature: Variant;
begin
Result := EmptyStr;
Point := CoPoint.Create;
Point.Set_(AMapX, AMapY);
Features := FFeatureLayer.SearchAtPoint(Point);
if Features.Count > 0 then
begin
InfoFeature := Features.Item(1);
Result := InfoFeature.FeatureKey;
end; {if}
end;
case ToolNum of
CUSTOM_INFO_TOOL : //信息工具Info
begin
pt := CoPoint.Create;
pt.Set_(X1,Y1);
lyr:=GetLayer(pt,mArea);
mlyr:= lyr;
AddtoSelection(lyr,pt,X1,Y1,Ctrl);
// pt._Release;
end;
end;
procedure TMDIChild.AddToSelection(lyr:CMapXLayer; pt:CMapXPoint;X1,Y1:Double;Ctrl:WordBool);
var
ft:CMapXFeature;
fts:CMapXFeatures;
begin
fts:= lyr.SearchAtPoint(pt);
if fts.Count = 0 then
begin
end
else
begin
ft := fts.Item(1);
if not Ctrl then
lyr.Selection.Replace(ft)
else
lyr.Selection.Add(ft);
displayobjinfo(lyr);
end;{if}
end;
procedure displayobjinfo(lyr: CMapXLayer);
begin
with Child do
begin
if not frmInformation.Showing then
frmInformation.Show
else
begin
with frmInformation do
begin
UpdateTreeView(lyr);
end;
end;
end;
end;
procedure TfrmInformation.UpdateTreeView(lyr: CMapXLayer);
var
i,j,L,M: integer;
ftr: CMapXFeature;
ds: CMapXDataset;
fld: CMapXField;
lyrNode, ftrNode: TTreeNode;
RootNode: TTreeNode;
multitag: Boolean;
singleX,singleY: Double;
value: Variant;
strValue, NDName: string;
begin
frmInfoShowed := True;
if tvwInformation.HasParent then
multitag:=true
else
multitag:=false;
with Child do
begin
// RootNode:= tvwInformation.Items.Add( nil,lyr.Name );
// for i:=0 to Map1.Layers.count-1 do
// begin
if lyr.Selection.Count>0 then
lyr.BeginAccess(miAccessRead);
lyrNode := tvwInformation.Items.AddChild(nil , lyr.Name);
lyrNode.Expanded := True;
for j:=0 to lyr.Selection.Count-1 do
begin
if multitag then
begin
ftrNode.Expanded := True;
multitag := not multitag;
end;
for L:= 0 to lyr.Datasets.Count-1 do
begin
ds:= lyr.Datasets.Item(L+1);
for M:=0 to ds.Fields.Count-1 do
begin
// if fld =ds.Fields.Item(M+1) then
// begin
fld :=ds.Fields.Item(M+1);
if (ds.Value[ftr, fld.Name] <> Null) and (Trim(fld.Name) <> 'NAME') then
begin
value := ds.Value[ftr, fld] ;
if(TVarData(value).vType = varOleStr) then
strValue := value
else
strValue:=ds.Value[ftr, fld];
if fld.Name ='MobileNodes' then
NDName:='移动营业厅数量'
else
NDName:='联通营业厅数量';
try
FID := FieldByName('地图结点号').AsInteger;
LrName := FieldByName('地图层名称').AsString;
lr := Map1.Layers.Item(lrName);
if lr <> nil then
begin
try
f := lr.GetFeatureByID(FID);
except
end;
if f <> nil then
lr.AddFeature(f);
end;
finally
Next;
end;