3

i'm using Gmap.NET with C# WPF, and i'd like to add a large amount of markers (~6k) on the map. But i still can't make add them asynchronously, Map is always freezing and not responding at all, until all markers will not be added... Here is my code sample:

private void MainMap_Loaded(object sender, RoutedEventArgs e)
{
    MainMap.Zoom = 12;

    LoadMarkers();
}

private async void LoadMarkers()
{
    await Task.Run(new Action(() =>
    {
            for (int i = 0; i <= 6000; i++)
            {
                Dispatcher.InvokeAsync(
                    new Action(
                        delegate()
                        {
                            PointLatLng point = new PointLatLng(GetRandomNumber(55.0000, 55.7510),
                                GetRandomNumber(36.0000, 38.9999));

                            var currentMarker = new GMap.NET.WindowsPresentation.GMapMarker(point);
                            {
                                currentMarker.Shape = new MarkerTemplate(this, currentMarker,
                                    string.Empty);
                                currentMarker.Offset = new Point(-16, -32);
                                currentMarker.ZIndex = int.MaxValue;

                            MainMap.Markers.Add(currentMarker);
                            }
                        }
                        ));
            }
        }));
}
daniele3004
  • 13,072
  • 12
  • 67
  • 75
Jesse
  • 79
  • 1
  • 8

1 Answers1

3

You probably need to design a cluster marker solution for GMap. Use the Map_OnMapZoomChanged event to hide/show markers accordingly.

With a bit of a work, you might be able to achieve a cluster like the Google Maps one:

GMap Marker Cluster

Good luck! Don't forget to open-source it when you're done :)

Ali Ashraf
  • 759
  • 1
  • 8
  • 17