WPF Gmap.NET adds a lot of markers

I am using Gmap.NET with C # WPF and I would like to add a large number of markers (~ 6k) on the map. But I still can't add them asynchronously, Map always freezes and doesn't react at all until all markers are added ... Here is my example code:

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);
                            }
                        }
                        ));
            }
        }));
}

      

+3


source to share


1 answer


You probably need to develop a clustered marker solution for GMap. Use event Map_OnMapZoomChanged

to hide / show markers accordingly.

With a little work, you can create a cluster like Google Maps :



GMap Marker Cluster

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

+1


source







All Articles