Map slow to respond to clearing and drawing markers

In my app I clear a list of markers (custom icons) from a TMSFNCGoogleMaps instance and plot another list of markers at a different location. There are only about 10 markers in the list to clear and plot. It works, but the map can take anything up to 5 seconds to respond (move, possibly zoo, erase markers and plot the new ones). Is this normal behaviour? I enclose my map code within BeginUpdate and EndUpdate as recommended. If it is normal, then I would like to at least have a busy indicator for the user, but I also don't know what event I can hook into when the map has finished redrawing. I tried OnAfterDraw but the map continues to update well after that event fires. So my second question is, is there a suitable event I can use?
My code to draw my list of icons is as follows;

procedure PlotEvents(aMap: TTMSFNCGoogleMaps; aEvents: TEvents);
var
  i: integer;
  vMarker: TTMSFNCGoogleMapsMarker;
begin
  aMap.BeginUpdate;
    for i := 0 to aEvents.Count - 1 do begin
      aMap.Markers.BeginUpdate;
        vMarker := aMap.Markers.Add;
        vMarker.Latitude := aEvents[i].Latitude;
        vMarker.Longitude := aEvents[i].Longitude;
        vMarker.IconURL := gEventIconURL;
        vMarker.Title := aEvents[i].Title;
      aMap.Markers.EndUpdate;
      end;
  aMap.EndUpdate;
end;

Any help or advice would be appreciated.

Hi,

No, with only 10 markers, it should be lightning fast. Can you send us a reproducible sample?
We have tried here with the sample code but cannot reproduce this here. We have even tested with 100 markers, clearing and adding new ones and it all happens in an instant.

I should have mentioned that I'm using Delphi 10.4 and it's an Android app. I shall endeavor to put together an example. It may be the way I'm using the component.

In my app I have a number of screens that show a map. The main form has an instance of TTMSFNCGoogleMaps in it. All the other forms use this instance of the Map as follows;

procedure TfmSelectRoute.FormShow(Sender: TObject);
begin
  // change map parent to this form
  loMap.BeginUpdate;   // loMap is a TLayout
    Map.BeginUpdate;
      Map.Parent := loMap;
      Map.Align := TAlignLayout.Client;
      Map.Visible := true;
    Map.EndUpdate;
  loMap.EndUpdate;

  DisplayRoute;
end;

This seems to work BUT it is extremely slow to update the map; especially when plotting polylines.
If I change the design to have a map component for each form, then updating the map works a fast as expected.
So what is the recommended design practice for maps on multiple forms in an app? A single map component seems desirable for efficiency but in practice it is very slow for some reason. Should I just put a map component on each form?

Hi,

It's unclear exactly what is going on and what is causing the slowness. If you could send us a sample that would be great. Other than that, the map itself is using a native underlying webbrowser component that is hooked to the main form. So it's always better to keep an instance per form to avoid issues. It shouldn't affect performance, but it was never the intention to support multiple forms/frames etc... . Perhaps you could programmatically create the map and use this function inside the multiple forms?

Map test.zip (26.3 KB)
Here's a very small Google Maps app that simply adds and plots a new polyline segment each half second. On my desktop PC it manages a few hundred segments before starting to lag behind in the plotting of the new segments. It takes about 30% CPU (at that stage) which seems quite high.
On my 32bit Samsung tablet it only has to do about 50 segments before it really starts lagging behind.
In the commercial app that I'm writing, I want to be able to have many segments of different colors in a similar way so this test app really shows up the issue I'm currently experiencing in my Android app.
You will need to add in your own Google Maps API Key via the Object Inspector for it to work.

Hi,

Thank you for your sample.
I'm able to reproduce this here and have applied a fix for this issue. The next version (v1.1.0.1) (currently uploading) will be available shortly with this fix included.

Awesome! After 1000 polylines there is now no noticeable delay plotting polylines or markers in Windows or on Android. CPU has gone down from 30% to next to nothing. Thankyou!

Hi,

Thank you for notifying this issue is fixed!

No problem. I’m just glad you fixed it!!!

image001.png