I am spinning my wheels trying to upgrade from V2 and looking for the best way to plot multiple icons (all with different images) and then to be able to move them around as the new positions come in.
Any help available out there please
I am spinning my wheels trying to upgrade from V2 and looking for the best way to plot multiple icons (all with different images) and then to be able to move them around as the new positions come in.
Any help available out there please
Ewan,
Thanks for your post and questions!
Hope following project can satisfy with your requirement:
code.thinkgeo.com/projects/show/mapshapes
Let me know if any more questions.
Thanks.
Yale
Is there supposed to be some sample code along with the article ??
OK I found the code - but does this work with Desktop ?? I cannot seem to find reference to MapShapeLayer or MapShape in the documentation for Desktop V3
OK I am making progress ( I hope) but am stuck but am getting a null exception thrown from my iconLayer in the New_Raster_Position method ??
I hope you can help
Ewan
Private Sub Load_Raster_Map()
gisMAP.AdornmentOverlay.ShowLogo = False
gisMAP.ZoomLevelSnapping = ZoomLevelSnappingMode.None
If Not My.Settings.lastMAPmap = Nothing Then
If System.IO.File.Exists(My.Settings.lastMAPmap) = True Then
gisMAP.Overlays.Clear()
gisMAP.MapUnit = GeographyUnit.DecimalDegree
Dim worldImageLayer As New GdiPlusRasterLayer(My.Settings.lastMAPmap)
worldImageLayer.UpperThreshold = Double.MaxValue
worldImageLayer.LowerThreshold = 0
Dim staticOverlay As New LayerOverlay()
staticOverlay.Layers.Add(“WorldImageLayer”, worldImageLayer)
gisMAP.Overlays.Add(staticOverlay)
worldImageLayer.Open()
gisMAP.CurrentExtent = GetFullExtent()
gisMAP.Refresh()
gMapLBL.Text = GetFileNameWithoutExtension(worldImageLayer.PathFilename)
’ Setup the mapshape layer.
Dim iconLayer As New MapShapeLayer
iconLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = ThinkGeo.MapSuite.Core.PointType.Bitmap
iconLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.ContestedBorder2
iconLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
Dim iconOverlay As New LayerOverlay()
iconOverlay.Layers.Add(“iconLayer”, iconLayer)
gisMAP.Overlays.Add(“iconOverlay”, iconOverlay)
End If
End If
Select Case My.Settings.mapBalloon
Case Is = True
ToolBarBalloon.ImageIndex = 22
Case Is = False
ToolBarBalloon.ImageIndex = 21
End Select
End Sub
Private Sub New_Raster_Position(ByVal Unit_Name As String, ByVal Unit_Operator As String, ByVal Lat As Double, ByVal Lon As Double, ByVal Speed As Double, ByVal Direction As Integer, ByVal Status As String)
Dim IconPath As String = Get_GIS_Icon(Unit_Name)
If System.IO.File.Exists(IconPath) = False Then
IconPath = AppPath & “\icons\gis\base.png”
End If
gisMAP.Overlays(“iconOverlay”).Lock.EnterWriteLock()
Try
Dim iconLayer As MapShapeLayer = DirectCast(gisMAP.FindFeatureLayer(“iconLayer”), MapShapeLayer)
Dim myMapShape As New MapShape(New Feature(Lon, Lat, Unit_Name))
myMapShape.ZoomLevels.ZoomLevel01.DefaultPointStyle = New PointStyle(New GeoImage(IconPath))
myMapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
If Not iconLayer.MapShapes.ContainsKey(Unit_Name) Then
iconLayer.MapShapes.Add(Unit_Name, myMapShape)
Else
iconLayer.Open()
iconLayer.EditTools.BeginTransaction()
iconLayer.EditTools.Delete(Unit_Name)
iconLayer.EditTools.CommitTransaction()
iconLayer.Close()
iconLayer.MapShapes.Add(Unit_Name, myMapShape)
End If
Finally
gisMAP.Overlays(“iconOverlay”).Lock.ExitWriteLock()
End Try
gisMAP.Refresh()
End Sub
Public Class MapShape
Private m_feature As Feature
Private zoomLevelSet As ZoomLevelSet
Public Sub New()
Me.New(New Feature())
End Sub
’ Let’s use this as a handy constructor if you already have
’ a feature or want to create one inline.
Public Sub New(ByVal feature As Feature)
Me.m_feature = feature
zoomLevelSet = New ZoomLevelSet()
End Sub
’ This is the feature property, pretty simple.
Public Property Feature() As Feature
Get
Return m_feature
End Get
Set(ByVal value As Feature)
m_feature = value
End Set
End Property
’ This is the Zoom Level Set. This high level object has all of
’ the logic in it for zoom levels, drawing and everything.
Public Property ZoomLevels() As ZoomLevelSet
Get
Return zoomLevelSet
End Get
Set(ByVal value As ZoomLevelSet)
zoomLevelSet = value
End Set
End Property
End Class
Class MapShapeLayer
Inherits FeatureLayer
Private m_mapShapes As Dictionary(Of String, MapShape)
Public Sub New()
m_mapShapes = New Dictionary(Of String, MapShape)()
End Sub
’ Here is where you place all of your map shapes.
Public ReadOnly Property MapShapes() As Dictionary(Of String, MapShape)
Get
Return m_mapShapes
End Get
End Property
’ This is a required overload of the Layer. As you can see we simply
’ loop through all of our map shapes and then choose the correct zoom level.
’ After that, the zoom level class takes care of the heavy lifiting. You
’ have to love how easy this framework is to re-use.
Protected Overloads Overrides Sub DrawCore(ByVal canvas As GeoCanvas, ByVal labelsInAllLayers As Collection(Of SimpleCandidate))
For Each mapShapeKey As String In m_mapShapes.Keys
Dim mapShape As MapShape = m_mapShapes(mapShapeKey)
Dim currentZoomLevel As ZoomLevel = mapShape.ZoomLevels.GetZoomLevelForDrawing(canvas.CurrentWorldExtent, canvas.Width, GeographyUnit.DecimalDegree)
If currentZoomLevel IsNot Nothing Then
If canvas.CurrentWorldExtent.Intersects(mapShape.Feature.GetBoundingBox()) Then
currentZoomLevel.Draw(canvas, New Feature() {mapShape.Feature}, New Collection(Of SimpleCandidate)(), labelsInAllLayers)
End If
End If
Next
End Sub
End Class
Ewan,
I am really willing to help you, but with your code, I am very confused what you are trying to do and it absolutely cannot be compiled because it lakes many methods.
I made a sample using MapShape from our code project, in this sample, you can add MapShape when you MapClick on the MapControl.
Can you upload your sample project and paste out the exception stack trace to show your problem?
Thanks.
Yale
1033-MapShapesDemo.zip (29.5 KB)