gmap.net

Gmap performance with a lot of markers?


I am using the WinForm version of Gmap.NET. What I'm doing is creating 1 overlay per marker and then add that to my map control. This significantly reduces the lag in my program. The only problem now is, if I wanted to hide an overlay, I have multiple overlays and I have to use an index number to hide that 1 overlay.

This is what I am doing to add my markers to my map. I create 1 overlay per marker: (Pseudo Code)

For (int i = 0; i >= dataset.rows.count; i++)
{
for each row in dataset
create overlay("stores")
add overlay to map
create marker(GPS from dataset)
addMarkerToOverlay
}

Now if I want to hide certain stores, maybe from a different State, I would have to do MapControl.Overlays(index).IsVisible = False. This is a problem because I have 100+ overlays. If I create 1 single overlay and add all my markers to it, the WinForm pretty much freezes and lags so much that it cannot be used.

I was wondering if anyone else has worked with Gmaps.NET before or know of any way I can boost performance? It would be nice to have all the markers on 1 single overlay so I can hide 1 overlay which would hide all the markers.

Here's my real code :

Dim i As Integer = (DS.Tables(0).Rows.Count - 1)
        Do While (i >= 0)
            Dim lat As Double = DS.Tables(0).Rows(i)(1)
            Dim lng As Double = DS.Tables(0).Rows(i)(2)

            Dim StoreOverlay As GMapOverlay = New GMapOverlay("Stores")
            map.Overlays.Add(StoreOverlay)

            Dim marker As GMapPoint
            marker = New GMapPoint(New PointLatLng(lat, lng), 15)
            StoreOverlay.Markers.Add(marker)

            i = (i - 1)
        Loop

Solution

  • For anyone else who is a noob like me and is having the same problem, here is the solution...

    Make sure do you not have the code to add layers inside your loop statement. I was creating 300+ layers with 300+ markers assigned to each layer.

    If you only have 1 layer and then add hundreds of markers onto it, you should be fine as long as you're not looping the adding of the layers as well. Silly mistake !