Custom Theme on several layers

Sep 25, 2011 at 5:23 PM

Hello ,

I want to use  customs themes on sevral layers.

When I work on on layer it's feel good.

I use a classic code like:

  Dim myTheme As SharpMap.Rendering.Thematics.CustomTheme = New SharpMap.Rendering.Thematics.CustomTheme(AddressOf MyStyle)

     Private Shared Function myStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle

        Dim style As New SharpMap.Styles.VectorStyle()
        If CInt(row("Popsdc")) > 2000000 Then
            style.Fill = Brushes.Yellow
        Else
            style.Fill = Brushes.Red
        End If
        Return style
    End Function

And I get a map with two colors (red and yellow).

Now I want to apply   different themes on several layer s(using only one delegate method), thing like that

Private Shared Function myStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle

        Dim style As New SharpMap.Styles.VectorStyle()

if  I am layer A (<- of course this line isn't vb code)
        If CInt(row("Popsdc")) > 2000000 Then
            style.Fill = Brushes.Yellow
        Else
            style.Fill = Brushes.Red
        End If

If for render layer B

        If CInt(row("Pop")) > 500 Then
            style.Fill = Brushes.Blue

        Else
            style.Fill = Brushes.Green

        End If
        Return style
    End Function

I've tried to retreive the layer name from the row with row.table.tablename, but this proprerty returns always the string 'table'

Is there a solution to retreive the layer name in the delegate method ?

Can anyone help

Thanks in advance.

Eric

 

Developer
Sep 26, 2011 at 4:18 AM
Edited Sep 26, 2011 at 4:20 AM

For each layer you use a function for your style:

layerA.Theme=myStyleA ( function A)

layerB.Theme=myStyleB (function B)

Regards,

TrieuVy

Coordinator
Sep 26, 2011 at 7:44 AM

Hello Eric,

If you would really want to do that, you need to modify the [Vector|Label]Layer.RenderInternal(Graphics g, Map map, BoundingBox envelope, ITheme theme) a bit.

At the beginning of the foreach loop over the tables in the dataset, you need to add

features.TableName = LayerName;

I don't understand why you would want to do that, since as the complexity of your GetStyle method increases, the more will the rendering performance decrease.

As TreuVy suggests just pass the appropriate GetStyle method to the constructor of CustomTheme:

layerA.Theme = new CustomTheme( GetStylePopsdc );
layerA.Theme = new CustomTheme( GetStylePop );

Hth FObermaier

Sep 26, 2011 at 2:50 PM

Thank you for yours answers.

I want to do that because I leave  the user to load how many layers he wants and perform how many thematics he wants also. So it's not possible in this case do define a specific method for each layer as I don't know how many layers are loaded and which structure they have.

I need to calculate de CustomTheme on the fly, by retreiving the structure of the datatable link with the layer.

I understand that the rendering performance decrease, but with not too big layers (less than 500 features) it's still prety good.

I will have a look in the layerRenderInternal.

Eric

Oct 9, 2011 at 12:47 AM

Hello

I modified VectorLayer.RenderInternal and add

features.TableName = LayerName;
That works well, I'm able to retrieve the layer name in the GotStyle.
To speed up the rendering, I calculate the thematic color before for each layer.
A thing like that:

Private Shared Function myStyle(ByVal row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle

Dim style As New SharpMap.Styles.VectorStyle()

 

if  row.TableTablename=_layerName(0) then        style.fill=_colorOfGeomA(row("ID"))

 

if  row.TableTablename=_layerName(1) then        style.fill=_colorOfGeomB(row("ID")) 

 

if  row.TableTablename=_layerName(2) then        style.fill=_colorOfGeomC(row("ID"))

 

Eric