ThinkGeo.com    |     Documentation    |     Premium Support

Custom Icons based on array values but need different icons

I may just be suffering from brain death, but I could use some help with an example that shows different images based on the values in an array.  I started with something below, but it just crashes (the map does not even show up)... it should give you an idea of what I am trying to do:


 



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WinformsMap1.MapUnit = GeographyUnit.DecimalDegree

        Dim LayerOverlay As LayerOverlay = New LayerOverlay()
        Dim worldLayer As ShapeFileFeatureLayer = New ShapeFileFeatureLayer("C:\Program Files (x86)\ThinkGeo\Map Suite Desktop Evaluation Edition 4.0\Samples\SampleData\Data\Countries02.shp")
        worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1
        worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
        LayerOverlay.Layers.Add("WorldLayer", worldLayer)
        WinformsMap1.Overlays.Add(LayerOverlay)

        'This is the point layer for all  points
        Dim pointLayer As New InMemoryFeatureLayer()
        pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        Dim dynamicOverlay As New LayerOverlay()
        dynamicOverlay.Layers.Add("PointLayer", pointLayer)
        WinformsMap1.Overlays.Add("PointOverlay", dynamicOverlay)

        WinformsMap1.CurrentExtent = New RectangleShape(0, 78, 30, 26)
        WinformsMap1.Refresh()

        AddData()
    End Sub

    Private Sub AddData()
        Dim data() As String = {"A", "B", "C"}
        Dim lat() As Double = {26.5, 27.5, 29}
        Dim lon() As Double = {-80.1, -82, -83}

        Dim pointLayer As InMemoryFeatureLayer = DirectCast(WinformsMap1.FindFeatureLayer("PointLayer"), InMemoryFeatureLayer)
        Dim textStyle As TextStyle = New TextStyle("NAME", New GeoFont(Me.Font.FontFamily.Name, 10), New GeoSolidBrush(GeoColor.StandardColors.Black))
        Dim iconValueStyle As IconValueStyle = New IconValueStyle()
        iconValueStyle.ColumnName = "TY"
        iconValueStyle.IconValueItems.Add(New IconValueItem("A", New GeoImage("./test.png"), textStyle))
        iconValueStyle.IconValueItems.Add(New IconValueItem("B", New GeoImage("./test1.png"), textStyle))
        iconValueStyle.IconValueItems.Add(New IconValueItem("C", New GeoImage("./test.png"), textStyle))
        pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(iconValueStyle)
        pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        For i As Integer = 0 To data.Count - 1
            Dim id As String = data(i)
            Dim feature1 As New Feature(lon(i), lat(i), id)
            If Not pointLayer.InternalFeatures.Contains(id) Then
                pointLayer.InternalFeatures.Add(data(i), feature1)
            End If
        Next
        WinformsMap1.Refresh(WinformsMap1.Overlays("PointOverlay"))
    End Sub



Michael,


I reviewed the code and found some minor problems, following is the updated version, hope it helps.

 

Private Sub DisplayMap_Load(ByVal sender As Object, ByVal e As EventArgs)
winformsMap1.MapUnit = GeographyUnit.DecimalDegree
 
Dim LayerOverlay As LayerOverlay = New LayerOverlay()
Dim worldLayer As ShapeFileFeatureLayer = New ShapeFileFeatureLayer("C:\Program Files (x86)\ThinkGeo\Map Suite Desktop Evaluation Edition 4.0\Samples\SampleData\Data\Countries02.shp")
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
LayerOverlay.Layers.Add("WorldLayer", worldLayer)
winformsMap1.Overlays.Add(LayerOverlay)
 
'This is the point layer for all points
Dim pointLayer As New InMemoryFeatureLayer()
pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
pointLayer.Open()
pointLayer.Columns.Add(New FeatureSourceColumn("Name", "string", 20))
pointLayer.Columns.Add(New FeatureSourceColumn("TY", "string", 20))
 
Dim dynamicOverlay As New LayerOverlay()
dynamicOverlay.Layers.Add("PointLayer", pointLayer)
winformsMap1.Overlays.Add("PointOverlay", dynamicOverlay)
 
winformsMap1.CurrentExtent = New RectangleShape(0, 78, 30, 26)
'winformsMap1.Refresh()
 
AddData()
End Sub
 
        Private Sub AddData()
            Dim data() As String = {"A", "B", "C"}
            Dim lat() As Double = {26.5, 27.5, 29}
            Dim lon() As Double = {-80.1, -82, -83}
 
            Dim pointLayer As InMemoryFeatureLayer = DirectCast(WinformsMap1.FindFeatureLayer("PointLayer"), InMemoryFeatureLayer)
            Dim textStyle As TextStyle = New TextStyle("NAME", New GeoFont(Me.Font.FontFamily.Name, 10), New GeoSolidBrush(GeoColor.StandardColors.Black))
            Dim iconValueStyle As IconValueStyle = New IconValueStyle()
            iconValueStyle.ColumnName = "TY"
            iconValueStyle.IconValueItems.Add(New IconValueItem("A", New GeoImage("./test.png"), textStyle))
            iconValueStyle.IconValueItems.Add(New IconValueItem("B", New GeoImage("./test1.png"), textStyle))
            iconValueStyle.IconValueItems.Add(New IconValueItem("C", New GeoImage("./test.png"), textStyle))
 
            pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(iconValueStyle)
            pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
 
            For i As Integer = 0 To data.Length - 1
                Dim id As String = data(i)
                Dim feature1 As New Feature(lon(i), lat(i), id)
                feature1.ColumnValues.Add("NAME", "NewYork")
                feature1.ColumnValues.Add("TY", data(i))
                If Not pointLayer.InternalFeatures.Contains(id) Then
                    pointLayer.InternalFeatures.Add(data(i), feature1)
                End If
            Next
            'WinformsMap1.Refresh(WinformsMap1.Overlays("PointOverlay"))
 
            pointLayer.Open()
            winformsMap1.CurrentExtent = pointLayer.GetBoundingBox()
 
            winformsMap1.Refresh()
        End Sub

Any more questions please feel free to let me know.
Thanks.
Yang

This works perfect… thanks!

Michael, 
  
 Thanks for letting us know the status. 
  
 Any more questions please feel free to ask. 
  
 Thanks. 
  
 Yale