Reputation: 199
I am using Delphi Berlin with the GMLib v3 Google Map Components on a Windows 10 64bit development machine. I would like to be able to animate the locations when clicking on the marker or grid when using the LoadFromDataSet function of the GMMarker component. I am not sure how to go about this.
My ERP application tries to validate an inputted address by geocoding the entered address and grabbing the returned latitude and longitude and then store those values in the database. When the geocoding returns multiple values I display a screen with a grid and a map showing the locations of the geocoding results.
I accomplish this by first adding all the results to a Listview component and then processing each Listview Item and add a GMMarker for each occurrence as follows:
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;
I am then able to access the bounce animation method and position the Listview by using the index of the GMMarker when the marker is Clicked as follows:
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;
This works very well when I load the locations into individual GMMarkers. However, once the database has been updated, I want to accomplish a similar thing by showing all the delivery locations for a certain day on a google map. To do this I use the LoadfromDataset function of the GMMarker as follows:
GMMarker1.LoadFromDataSet(cdsDeliveries, 'Latitude', 'Longitude', 'SO_NO', 'Marker', True);
GMMarker1.ZoomToPoints;
This also works very well and produces the following map:
The problem I have is that when LoadFromDataSet is used, GMMarker.Count is 1 even though there are numerous markers on the Map. Therefore, I assume I have to use the VisualObjects property of the GMMarker. However, GMMarker.VisualObjects.Count is also 1.
My question is:
How can I get access to the Animation.Bounce property of the markers on the screen when I use the GMMarkers.LoadFromDataset function?
Any help is greatly appreciated.
Leonard
Upvotes: 0
Views: 762
Reputation: 199
I solved my problem but don't know why I didn't try this before asking the question. Maybe my answer will help someone else, though.
To solve the problem I passed the Marker from the OnClick event to my HandleAnimation function and used the passed parameter to access the animation methods as follows:
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;
Upvotes: 0