I have a function called AddPoint that adds a symbol to an InMemoryFeatureLayer on the map. I need to be able to label the symbol. I can get the symbol to display, but not the label.
I'm using Visual Studio 2010, vb.net. Here's the code. It is a simplified piece of a much larger application.
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.DesktopEdition
Imports System.Collections.ObjectModel
Public Class MapLabels
Public workLayers As New LayerOverlay
Public workSLayer As New InMemoryFeatureLayer() 'standard work layer
Public Sub AddPoint(ByVal Longitude As Double, ByVal Latitude As Double, ByVal PointName As String, _
ByVal SymbolSize As Single, ByVal SymbolColor As GeoColor, ByVal SymbolChar As PointSymbolType)
Dim f As Feature
Dim pt As PointShape
On Error GoTo AddPoint_ErrorHandler
'set the style for the work layer
workSLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("pt_name", "Arial", 10, DrawingFontStyles.Regular, GeoColor.StandardColors.Black, 0, -12)
workSLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(SymbolChar, SymbolColor, SymbolSize)
workSLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
pt = New PointShape
pt.Y = Latitude
pt.X = Longitude
f = pt.GetFeature
f.ColumnValues.Add("pt_name", PointName)
'add the feature to the work layer
workSLayer.InternalFeatures.Add(f)
'zoom to the feature
AtisMap.CurrentExtent = New RectangleShape(Longitude - 0.004, Latitude + 0.004, Longitude + 0.004, Latitude - 0.004)
AtisMap.Refresh()
Exit Sub
AddPoint_ErrorHandler:
MsgBox("Error:" & Err.Number & " " & Err.Description)
Resume
End Sub
Public Function CreateWorkLayer() As Boolean
On Error GoTo CreateWorkLayers_errorhandler
workLayers.Layers.Add("WorkS", workSLayer)
AtisMap.Overlays.Add("workLayer", workLayers)
CreateWorkLayer = True
Exit Function
CreateWorkLayers_errorhandler:
MsgBox("ERROR: " & Err.Number & " " & Err.Description)
End Function
Private Sub showShape()
Dim worldMapKitDesktopOverlay As WorldMapKitWmsDesktopOverlay = New WorldMapKitWmsDesktopOverlay()
Dim staticOverlay As New LayerOverlay()
AtisMap.MapUnit = GeographyUnit.DecimalDegree
AtisMap.ThreadingMode = MapThreadingMode.SingleThreaded
AtisMap.Overlays.Add(worldMapKitDesktopOverlay)
AtisMap.CurrentExtent = New RectangleShape(-74.011701, 40.712748, -74.009, 40.71)
AtisMap.BackColor = Color.GhostWhite
AtisMap.Refresh()
CreateWorkLayer()
End Sub
Private Sub btnAddPoint_Click(sender As System.Object, e As System.EventArgs) Handles btnAddPoint.Click
On Error GoTo data_err
Dim s As New PointSymbolType
Dim c As New GeoColor
Select Case cmbSymbol.Text
Case "Star"
s = PointSymbolType.Star
Case "Square"
s = PointSymbolType.Square
Case "Circle"
s = PointSymbolType.Circle
Case Else
s = PointSymbolType.Diamond
End Select
Select Case cmbColor.Text
Case "Red"
c = GeoColor.StandardColors.Red
Case "Blue"
c = GeoColor.StandardColors.Blue
Case "Green"
c = GeoColor.StandardColors.Green
Case Else
c = GeoColor.StandardColors.Purple
End Select
AddPoint(txtLong.Text, txtLat.Text, txtDesc.Text, 36, c, s)
Exit Sub
data_err:
MsgBox("Error in data entered")
End Sub
Private Sub MapLabels_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
showShape()
Me.Cursor = Cursors.Default
Application.DoEvents()
End Sub
End Class