0

我在 Windows 10 64 位开发机器上使用 Delphi Berlin 和 GMLib v3 Google Map Components。在使用 GMMarker 组件的 LoadFromDataSet 函数时,我希望能够在单击标记或网格时为位置设置动画。我不知道该怎么做。

我的 ERP 应用程序尝试通过对输入的地址进行地理编码并获取返回的纬度和经度来验证输入的地址,然后将这些值存储在数据库中。当地理编码返回多个值时,我会显示一个带有网格的屏幕和一张显示地理编码结果位置的地图。

在此处输入图像描述

为此,我首先将所有结果添加到 Listview 组件,然后处理每个 Listview 项目并为每次出现添加一个 GMMarker,如下所示:

for I := 0 to ListView.Items.Count-1 do
begin
 GMMarker1.Add(StrToFloat(ListView.Items[I].SubItems[2]),StrToFloat(ListView.Items[I].SubItems[1]),ListView.Items[I].Caption);
end;

然后,我可以在单击标记时使用 GMMarker 的索引访问弹跳动画方法并定位 Listview,如下所示:

procedure TfrmGeoCodeAdd.GMMarker1Click(Sender: TObject; LatLng: TLatLng;Index: Integer; LinkedComponent: TLinkedComponent);
begin
  inherited;

  if ListView.ItemIndex = Index then
     HandleAnimation(Index)
  else
     ListView.ItemIndex := Index;
end;

procedure TfrmGeoCodeAdd.HandleAnimation(Index: integer);
begin
  inherited;

  if  (AnimationIndex >= 0) then
  begin
    GMMarker1[AnimationIndex].Animation.Bounce := False;
  end;

  if (AnimationIndex = index) then
      AnimationIndex := -1
  else
  begin
    if GMMarker1[Index].Animation.Bounce then
       GMMarker1[Index].Animation.Bounce := False
    else
       GMMarker1[Index].Animation.Bounce := True;

    AnimationIndex := Index;
  end;
end;

当我将位置加载到单独的 GMMarker 中时,这非常有效。但是,一旦数据库更新,我想通过在谷歌地图上显示某一天的所有送货地点来完成类似的事情。为此,我使用 GMMarker 的 LoadfromDataset 函数,如下所示:

GMMarker1.LoadFromDataSet(cdsDeliveries, 'Latitude', 'Longitude', 'SO_NO', 'Marker', True);
GMMarker1.ZoomToPoints;

这也很有效,并产生以下地图:

在此处输入图像描述

我遇到的问题是,当使用 LoadFromDataSet 时,即使地图上有许多标记,GMMarker.Count 也是 1。因此,我假设我必须使用 GMMarker 的 VisualObjects 属性。但是,GMMarker.VisualObjects.Count 也是 1。

我的问题是:

使用 GMMarkers.LoadFromDataset 函数时,如何访问屏幕上标记的 Animation.Bounce 属性?

任何帮助是极大的赞赏。

伦纳德

4

1 回答 1

0

我解决了我的问题,但不知道为什么在提出问题之前我没有尝试这个。不过,也许我的回答会对其他人有所帮助。

为了解决这个问题,我将 OnClick 事件中的 Marker 传递给了 HandleAnimation 函数,并使用传递的参数来访问动画方法,如下所示:

procedure TfrmDeliveryMap.GMMarker1Click(Sender: TObject; LatLng: TLatLng;  Index: Integer; LinkedComponent: TLinkedComponent);
begin
  inherited;

  if cdsDeliveries.RecNo = Index then
     HandleAnimation((Sender as TGMMarker), Index)
  else
     cdsDeliveries.RecNo := Index;
end;

procedure TfrmDeliveryMap.HandleAnimation(Marker: TGMMarker; Index: integer);
begin
  inherited;

  if  (AnimationIndex >= 0) then
    Marker[AnimationIndex].Animation.Bounce := False;

  if (AnimationIndex = index) then
      AnimationIndex := -1
  else
  begin
    if Marker[Index].Animation.Bounce then
       Marker[Index].Animation.Bounce := False
    else
      Marker[Index].Animation.Bounce := True;

    AnimationIndex := Index;
  end;
end;
于 2016-11-15T20:46:08.377 回答