This project has moved and is read-only. For the latest updates, please go here.

How to differentiate layer color?

Mar 26, 2008 at 5:30 AM
I want to know how to differentiate a layer by it attributes field..i try using the custom theme but unfortunely it is not working.Please help..
Mar 26, 2008 at 8:06 AM
custom theme should work. What is the problem?
Mar 27, 2008 at 2:34 AM
Here is my code : -

Private Function GetColorStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle
Dim style As New SharpMap.Styles.VectorStyle()
Select Case row("NAME").ToString().ToLower()
Case "kota kangsar"
'If country name is kota kangsar, fill it with green
style.Fill = Brushes.Gold
Return style
Case "pulau mutiara"
'If country name is pulau mutiara fill it with Blue and add a red outline
style.Fill = Brushes.Blue
style.Outline = Pens.Red
Return style
Case "pulau hijau"
'If country name is pulau hijau, fill it with red
style.Fill = Brushes.Red
Return style
Case Else
Exit Select
End Select
'If country name starts with S make it yellow
If row("NAME").ToString().StartsWith("S") Then
style.Fill = Brushes.Yellow
Return style
' If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
ElseIf TypeOf row.Geometry Is SharpMap.Geometries.MultiPolygon AndAlso TryCast(row.Geometry, SharpMap.Geometries.MultiPolygon).Area < 30 OrElse TypeOf row.Geometry Is SharpMap.Geometries.Polygon AndAlso TryCast(row.Geometry, SharpMap.Geometries.Polygon).Area < 30 Then
style.Fill = Brushes.Cyan
Return style
Return Nothing
End If
End Function

'Set the color for each country layer
Dim iColor As New SharpMap.Rendering.Thematics.CustomTheme(GetColorStyle)
Dim ColorStyle As New SharpMap.Styles.VectorStyle()
ColorStyle.Fill = Brushes.Gray
iColor.DefaultStyle = defaultstyle
TryCast(myMap.Layers(0), SharpMap.Layers.VectorLayer).Theme = iColor

But then when i try to write code ' Dim iColor As New SharpMap.Rendering.Thematics.CustomTheme(GetColorStyle)',
there will be a blue trigger line under the '(GetColorStyle)' tells that the argument not specified for parameter 'row' of
'Private Function GetColorStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle'.

What should i do? really need help.
Mar 27, 2008 at 9:00 AM
Hi Viva, it's been a long while since I did any VB but I suspect you need the AddressOf Operator e.g.
Dim iColor As New SharpMap.Rendering.Thematics.CustomTheme(AddressOf GetColorStyle) HTH jd
Mar 27, 2008 at 9:06 AM
Hi john,

I've try to write this code but then it still give the same result.
Mar 27, 2008 at 9:18 AM
Edited Mar 27, 2008 at 9:32 AM
Hi again Viva, perhaps your delegate function should accept the FeatureDataRow ByRef eg
Private Function GetColorStyle(ByRef row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle.
Mar 29, 2008 at 8:55 AM act differently compared to C#, so u must use
Private Function GetColorStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.IStyle
instead of
"Private Function GetColorStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle "
for delegating

Orang indonesia bukan ?