靴
靴子
Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi+mapx做了一个查找地图上的名字后让他闪烁的程序,但是这样只能查到只有一个单独的地名的字段,如果有两个名字一样,则就查不出来。请问一下,如何改一下呢啊?下面是代码。
procedure TForm1.tmFlashSelectTimer(Sender: TObject);
var
ft: MapXLib_TLB.FindFeature;//查找的图元
lyr: MapXLib_TLB.Layer;
//图层
bExist: Boolean;
i: Integer;
str: String;
ds: MapXLib_TLB.Dataset;
//数据
begin
bExist := False;
//查找所有的图层,如果存在就退出图层的搜索
for i := 1 to mapCity.Layers.Countdo
begin
if mapCity.Layers.Item(i).Name = m_strSelLyr then
begin
bExist := True;
break;
end;
end;
if not bExist then
//如果要查找的图层不存在
begin
tmFlashSelect.Enabled := False;
MsgFrm := TMsgFrm.Create(Self);
MsgFrm.m_strMsg.Caption := Format('图层[%s]信息不存在!',[m_strSelLyr]);
MsgFrm.ShowModal;
MsgFrm.Free;
Exit;
end;
//如果查找的图层存在
lyr := mapCity.Layers.Item(m_strSelLyr);//把查找的图层的值给一个图层
ds := mapCity.Datasets.Add(miDataSetLayer, lyr ,EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
//向地图的数据集中加入查找到的图层
lyr.Find.FindDataset := ds;
//字段数据集
lyr.Find.FindField := ds.Fields.Item(1);//数据集字段
str := Format('%s',[m_nSelID]);
//要查找的名字
ft := lyr.Find.Search(str,EmptyParam);//找到的图元 (如果找到两个的话就有问题)
//showmessage(inttostr(ft.FindRC));
查看搜索的结果
if ft.FindRC mod 10 <> 1 then
begin
tmFlashSelect.Enabled := False;
MsgFrm := TMsgFrm.Create(Self);
MsgFrm.m_strMsg.Caption := Format('单位点[%s]信息不存在!',[m_strCorpName]);
MsgFrm.ShowModal;
MsgFrm.Free;
Exit;
end;
case ft.type_ of
miFeatureTypeLine:
begin
if ft.Style.LineColor = miColorWhite then
ft.Style.LineColor := miColorRed
else
ft.Style.LineColor := miColorWhite;
end;
miFeatureTypeRegion:
begin
if ft.Style.RegionColor = miColorGreen then
ft.Style.RegionColor := miColorRed
else
ft.Style.RegionColor := miColorGreen;
end;
miFeatureTypeSymbol:
begin
if not m_bFlashSel then
lyr.Selection.Replace(ft)
else
lyr.Selection.ClearSelection;
m_bFlashSel := not m_bFlashSel;
end;
end;
ft.Update(EmptyParam, EmptyParam);
if not m_bCenter then
begin
m_bCenter := True;
mapCity.CenterX := ft.CenterX;
mapCity.CenterY := ft.CenterY;
mapCity.Refresh;
end;
end;
private
m_strSelLyr,m_strCorpName : string
m_nSelID : string;
m_bFlashSel ,m_bCenter :Boolean;
procedure TForm1.tmFlashSelectTimer(Sender: TObject);
var
ft: MapXLib_TLB.FindFeature;//查找的图元
lyr: MapXLib_TLB.Layer;
//图层
bExist: Boolean;
i: Integer;
str: String;
ds: MapXLib_TLB.Dataset;
//数据
begin
bExist := False;
//查找所有的图层,如果存在就退出图层的搜索
for i := 1 to mapCity.Layers.Countdo
begin
if mapCity.Layers.Item(i).Name = m_strSelLyr then
begin
bExist := True;
break;
end;
end;
if not bExist then
//如果要查找的图层不存在
begin
tmFlashSelect.Enabled := False;
MsgFrm := TMsgFrm.Create(Self);
MsgFrm.m_strMsg.Caption := Format('图层[%s]信息不存在!',[m_strSelLyr]);
MsgFrm.ShowModal;
MsgFrm.Free;
Exit;
end;
//如果查找的图层存在
lyr := mapCity.Layers.Item(m_strSelLyr);//把查找的图层的值给一个图层
ds := mapCity.Datasets.Add(miDataSetLayer, lyr ,EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
//向地图的数据集中加入查找到的图层
lyr.Find.FindDataset := ds;
//字段数据集
lyr.Find.FindField := ds.Fields.Item(1);//数据集字段
str := Format('%s',[m_nSelID]);
//要查找的名字
ft := lyr.Find.Search(str,EmptyParam);//找到的图元 (如果找到两个的话就有问题)
//showmessage(inttostr(ft.FindRC));
查看搜索的结果
if ft.FindRC mod 10 <> 1 then
begin
tmFlashSelect.Enabled := False;
MsgFrm := TMsgFrm.Create(Self);
MsgFrm.m_strMsg.Caption := Format('单位点[%s]信息不存在!',[m_strCorpName]);
MsgFrm.ShowModal;
MsgFrm.Free;
Exit;
end;
case ft.type_ of
miFeatureTypeLine:
begin
if ft.Style.LineColor = miColorWhite then
ft.Style.LineColor := miColorRed
else
ft.Style.LineColor := miColorWhite;
end;
miFeatureTypeRegion:
begin
if ft.Style.RegionColor = miColorGreen then
ft.Style.RegionColor := miColorRed
else
ft.Style.RegionColor := miColorGreen;
end;
miFeatureTypeSymbol:
begin
if not m_bFlashSel then
lyr.Selection.Replace(ft)
else
lyr.Selection.ClearSelection;
m_bFlashSel := not m_bFlashSel;
end;
end;
ft.Update(EmptyParam, EmptyParam);
if not m_bCenter then
begin
m_bCenter := True;
mapCity.CenterX := ft.CenterX;
mapCity.CenterY := ft.CenterY;
mapCity.Refresh;
end;
end;
private
m_strSelLyr,m_strCorpName : string
m_nSelID : string;
m_bFlashSel ,m_bCenter :Boolean;