简体   繁体   中英

show 1 million locations with markers on a map based on OpenStreetMap from C# VS2013 WPF

I would like to show 1 million locations on a map based on OpenStreetMap.

I work on C# VS2013 and GMAP.NET WPF. But, when I added markers for each location, the map cannot be shown up because the marker is a bitmap image. And 1 million markers consume too much memory on my laptop (with 8 GB mem).

The code is:

   public void add_marker(List<Tuple<double, double>> latLongList, ref GMapControl myMap)
    {
            System.Windows.Media.Imaging.BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.UriSource = new Uri(@"C:\djx_2014_6_3\my_projects\test_gmap_dot_net\GMap_WPF\try1\try_gmap_wpf\try_gmap_wpf\images\map_marker.png", UriKind.Absolute);
            bitmapImage.DecodePixelHeight = 5;
            bitmapImage.DecodePixelWidth = 5;
            bitmapImage.EndInit();
            foreach(var v  in latLongList)
            {
                GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(v.Item1, v.Item2);
                GMapMarker marker = new GMapMarker(point);
                System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                image.Source = bitmapImage;
                marker.Shape = image;
                marker.ZIndex = 5;
                myMap.Markers.Add(marker);
            }
    }

I do not want to use the image as markers but I cannot find out how to use default marker in openStreetMap.

Any help would be appreciated.

WPF wasn't designed to be used for things like this. First of all you're creating a Bitmap for each tag, which is a user control and comes with some pretty heavy overhead for GUI hit-testing and binding etc. Secondly, WPF renders with DirectX, which means at some point all that data has to be set up with vertex buffers and uploaded into the graphics card. If you use data binding or try to create separate UI elements then this is going to take a lot of initial set-up time and memory, as you have already discovered. And if you try to draw them yourself (eg by creating your own user control and overriding OnRender) then it can be even worse, since all that work is now being done every frame (apart from buffered stuff which still incurs the initial setup anyway so you're back to square one).

If I had to do this myself I would start by organizing the data set with an appropriate 2D structure such as a kd tree, an R*-tree or even a basic quad-tree. This will allow you to quickly determine at any given moment which markers are in the view frustum.

Next, I would add the appropriate bindings to scrollbars etc so that I could monitor exactly where the current view frustum was, and then each frame I would update the list of visible tags based on that. So long as you don't have more than a few thousand objects comes into view at once you should be ok, otherwise you'll have to stagger the updates over multiple frames with a queue.

If that doesn't suit your needs then you really have only two options left: 1) generate the raw bitmap data yourself manually, or 2) use a more suitable technology.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM