ThinkGeo.com    |     Documentation    |     Premium Support

Overlays not found

Hi everyone!


I've added an InMemoryFeatureLayer with one feature with no problems. But, once I try to add another feature looking for the layer it shows a KeyNotFoundException from the overlays collection of the map, and when I ask how many overlays does the map has it says no one even when I've added 3 diferent overlays with GdiPlusRasterLayers.


I let you my code, maybe I forget something, with the line wich launch the exception on a yellow background


Thank you,


Astartea


 



  Private Sub frmMap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            mapa.MapUnit = GeographyUnit.DecimalDegree
            mapa.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.FromArgb(255, 241, 237, 181))
            Dim rectangulo As RectangleShape
            rectangulo = New RectangleShape(-3.15388811037155, 43.4446654862572, -2.8764833252153, 43.2311187333275)
            Dim capaPuntos As New InMemoryFeatureLayer()
            capaPuntos.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap
            If IO.File.Exists(Application.StartupPath & "\Images\torre50px.png") Then
                capaPuntos.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = New GeoImage(Application.StartupPath & "\Images\torre50px.png")
                capaPuntos.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
                Dim lat As Double = 43.3598647660424
                Dim lon As Double = -3.01456344530197
                Dim nombre As String = "Estacion 1"
                capaPuntos.InternalFeatures.Add(New Feature(lon, lat, nombre, New String() {"ID:" + nombre}))
                Dim overlayPuntos As New LayerOverlay()
                overlayPuntos.Layers.Add("PuntosLayer", capaPuntos)
                mapa.Overlays.Add("puntos", overlayPuntos)
            End If
            mapa.CurrentExtent = rectangulo
            mapa.Refresh()
        End Sub

        Private Sub method()
            Dim lat2 As Double = 43.3552513665367
            Dim lon2 As Double = -3.00265443727585
            Dim nombre2 As String = "Estacion 2"
            Dim feature As New Feature(lon2, lat2, nombre2, New String() {"ID:" + nombre2})
            mapa.Overlays("puntos").Lock.EnterWriteLock()
            Try
                Dim laCapa As InMemoryFeatureLayer = mapa.FindFeatureLayer("PuntosLayer")
                If Not laCapa.InternalFeatures.Contains(nombre2) Then
                    laCapa.InternalFeatures.Add(nombre2, feature)
                End If
            Catch ex As Exception
                MsgBox("Falla al aNadir puntos en la capa de memoria")
            Finally
                mapa.Overlays("puntos").Lock.ExitWriteLock()
            End Try
            mapa.Refresh()
        End Sub

PD: I've found it is not necessary execute the EnterWriteLock() but, what is that for? ensure not current use of the layer? I'm very interested on it.


 



Miren,


I couldn't recreate this problem. Are you using the latest public release 3.0.362? Could you please try the attached sample to see if that works fine on your machine?


By the way, I changed your code a bit to make it well arranged :)


Thanks,


Ben



1171-TestForMiren6256.zip (13.8 KB)

Ben, 
  
 I’ve run the test and it works fine. after that I’ve tried again with my own and now it works. I’m not very sure but, I think there were no diferences. 
 I don’t know I’ve made so much changes trying to make it work that probably I changed something without notice. 
 Anyway, you’ve been very kind Ben so thank you very much, and if I have this problem again I’ll try not changing anything untill I had an answer. :) 
  
 Thanks, 
 Miren 


Miren, 
  
   Glad to see it worked for you.  I am closing this one for Ben.  Let us know if you run into anything else. 
  
 David