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.