ThinkGeo.com    |     Documentation    |     Premium Support

How to remove the image Layer?

when I input a lon/lat and show tha Map in the second time the imgLayer will show twice. (I just show one image in the map)

How to remove the image Layer?


        Dim imgLayer As New InMemoryFeatureLayer()

        imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap

        imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = New GeoImage("D:\GIS\D1.gif")

        imgLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        imgLayer.InternalFeatures.Add("Car", New Feature(New PointShape(longitude, latitude)))


        Dim carOverlay As New LayerOverlay()


        If Not carOverlay.Layers.Contains("imgLayer") Then

            carOverlay.Layers.Add("imgLayer", imgLayer)

        Else

            carOverlay.Layers.Remove("imgLayer")

            carOverlay.Layers.Add("imgLayer", imgLayer)

        End If


        WinformsMap1.Overlays.Add(carOverlay)


        Dim rectangle = New RectangleShape(longitude - 0.01, latitude + 0.001, longitude + 0.01, latitude - 0.001)

        WinformsMap1.CurrentExtent = rectangle


        WinformsMap1.Refresh()




Carol,


Two things probabally you need to pay some attention to:
1)      Make sure the imageLayer only contains one feature every time. 
I am not sure the code you pasted above is the code excuted in the Form_loaded event of your application or some event, while I just want to let you know make sure every time you clear the internal features first if not.
 
2)      Please call the Refresh(carOverlay) instead of Refresh after you changed anything in the carOverlay.
 
Because I cannot see all your codes excuting sequence, so the obove 2 suggesutions just a reminder to you.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale