When I add many markers >250 from a SQL DB , the map becomes unresponsive. -Why ?

Topics: Windows Forms
Nov 29, 2012 at 12:29 PM
Edited Nov 29, 2012 at 12:30 PM

 

The map becomes very SLOW. What do I do different ? 

 

        Dim lat As String = Nothing
        Dim lng As String = Nothing
        Dim layer_name As String = Nothing
        Dim info_1 As String = Nothing
        Dim info_2 As String = Nothing
        Dim mimage As String = Nothing
     
        GMap1.HoldInvalidation = True

        Try
            OBJCONN.Close() : OBJCONN.Open()
            Dim Q As New SqlCommand("SELECT * FROM LAYERS WHERE LAYER_NAME='" & L & "'", OBJCONN)
           
            
            Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://expressen.se/img/MapIcons/Events/Natural disaster/flood.png")
            Dim response As System.Net.WebResponse = req.GetResponse()
            Dim stream As Stream = response.GetResponseStream()
            Dim imgX As System.Drawing.Image = System.Drawing.Image.FromStream(stream)
            stream.Close()

            Dim R As SqlDataReader = Q.ExecuteReader
            While R.Read
                lat = R("LATITUDE").ToString
                lng = R("LONGITUDE").ToString()
                layer_name = R("Layer_name").ToString()
                info_1 = R("info_1").ToString()
                info_2 = R("info_2").ToString()
                mimage = R("MAP_MARKER_IMAGE")
                Dim m = New GMapMarkerImage(New PointLatLng(lat, lng), New Bitmap(imgX))
                Layer_GPSmarker.Markers.Add(m)
                m.ToolTipMode = MarkerTooltipMode.OnMouseOver
                m.ToolTipText = layer_name & vbCrLf & info_1 & vbCrLf & info_2
                GMap1.Overlays.Add(Layer_GPSmarker)

            End While
            R.Close()
            OBJCONN.Close()
            GMap1.Refresh()

        Catch
            'Felhantering
        End Try
    End Sub
Nov 29, 2012 at 12:52 PM

for each marker you add the same layer: GMap1.Overlays.Add(Layer_GPSmarker)

you only need to do this once at the startup

Nov 29, 2012 at 1:28 PM

Thank you Mr. Radioman , that did the trick.. The mapcontrol is now smooth and 'fluid' again !!