Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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);
                             }
                         }
                         ));
             }
         }));
    }
Posted
Updated 30-Sep-19 13:17pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900