ThinkGeo.com    |     Documentation    |     Premium Support

Value style with geoImage

I have the following code to show features with diferent images according with its ID value:


 


Dim


 


pointsLayer As New


InMemoryFeatureLayer

 


 


Dim style As New  ValueStyle

style .ColumnName =



 


 


For Each row In ds.Tables("IDS"

).Rows

 


 


Dim subStyle As New

PointStyle

subStyle .PointType = PointType.Bitmap


subStyle .Image = New GeoImage(Imagenes(row(0).ToString)) 'this function (images(string)) returns the path for the image(.bmp)

 


 


New

ValueItem(row(0).ToStrin, subStyle ))

 


 


Next


pointsLayer .ZoomLevelSet.ZoomLevel01.CustomStyles.Add(estilo)


pointsLayer .ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20


pointsLayer .IsVisible =


 


True

winformsMap1.StaticOverlay.Layers.Add(


 


"pointsLayer"

, pointsLayer )  I've test if the problem cames from the image but it works perfectly in other enviroment (a picturebox for example or in a simple style with image).

 


I f anybody knows how to make it works I'll be really t


 


 


 


 


 


 


 


 


 






style .ValueItems.Add(





"ID"




Tiffany,


I'm sorry, your code is not displayed properly and I couldn't make it right as seems some code is lost. Can you repost the code again and following the instruction here? As you can see, with a couple lines of script you can make the code really nice.


 
Ben

 



Sorry, I don’t know what happens, there are some problems when you copy text from the Visual Studio. 
 Here we go: 
  
  Dim pointsLayer As New InMemoryFeatureLayer 
  
         Dim style As New ValueStyle 
         style.ColumnName = “ID” 
         For Each row In ds.Tables(“Entity”).Rows 
             Dim myStyle As New PointStyle 
             myStyle.PointType = PointType.Bitmap 
             myStyle.Image = New GeoImage(Imagenes(row(0).ToString)) 
             style.ValueItems.Add(New ValueItem(row(0).ToString, myStyle)) 
         Next 
  
         pointsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(style) 
         pointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
         pointsLayer.IsVisible = True 
  
         winformsMap1.StaticOverlay.Layers.Add(“pointsLayer”, pointsLayer)

Tiffany,


 
Your code is correct. As you didn’t provide codes how you add the features maybe something is wrong there. Please have a look at the complete code and see what’s the difference with yours.
 
Code:


 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        WinformsMap1.MapUnit = GeographyUnit.DecimalDegree

        ' Add 2 Features to a Feature List
        Dim features As New List(Of Feature)
        ' The "ID" Column for these feature are "Truck1" and "Truck2"
        features.Add(New Feature(0, 0, "feature1", New String() {"ID:Truck1"}))
        features.Add(New Feature(30, 30, "feature2", New String() {"ID:Truck2"}))

        ' Create a new InMemoryFeatureLayer, the layer has one column "ID", got the 2 records we just created
        Dim column As New FeatureSourceColumn("ID")
        Dim pointsLayer As New InMemoryFeatureLayer(New FeatureSourceColumn() {column}, features)

        ' Create a dictionary For adding the ValueStyle later
        Dim dictionary As New Dictionary(Of String, String)()
        dictionary.Add("Truck1", "..\..\images\Truck1.png")
        dictionary.Add("Truck2", "..\..\images\Truck2.png")

        ' Create the valueStyle
        Dim style As New ValueStyle
        style.ColumnName = "ID"
        For Each item As KeyValuePair(Of String, String) In dictionary
            Dim myStyle As New PointStyle
            myStyle.PointType = PointType.Bitmap
            myStyle.Image = New GeoImage(item.Value)
            style.ValueItems.Add(New ValueItem(item.Key, myStyle))
        Next

        ' Apply the style to layer
        pointsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(style)
        pointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        ' Add the layer to map and draw
        WinformsMap1.StaticOverlay.Layers.Add("pointsLayer", pointsLayer)
        WinformsMap1.Refresh()
    End Sub


 

Result:



Ben



165-TestValueStylesFor4917.zip (16.4 KB)

Thank you ben! 
 This is what I was doing to add features: 
  
 Dim feature As New Feature(x, y, entity) 
 feature.ColumnValues.Add("ID", entity) 
  
 But it works with your way, thank you very much

Always my pleasure! 
  
 Ben