I have many Questions to SharpMap view

Topics: Algorithms, SharpMap Project, SharpMap v0.9 / v1.x, WinForms Controls
Sep 14 at 8:29 PM
I have 4-5 Views in a Postgres Database with Polygon, Lines and Point Geometrys.

I generate dynamic Layer in a Loop. The first created Layer fired the Delegates for Layer.Theme, LabelLayer.Theme, LabelLayerPosition. The following layers fired the Delegates no more.
Public Class Test
  Private delObjektLabelBez As SharpMap.Layers.LabelLayer.GetLabelMethod
  Private delObjektLabelPos As SharpMap.Layers.LabelLayer.GetLocationMethod
  Private delObjektLabelStyle As SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod
  Private delObjektStyle As SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod
  '
  Public Sub CreateLayers(ByVal config as OtherClass)
     '
     delObjektLabelBez = New SharpMap.Layers.LabelLayer.GetLabelMethod(AddressOf LabelObjektBezeichnung)
     delObjektLabelPos = New SharpMap.Layers.LabelLayer.GetLocationMethod(AddressOf LabelBezeichnungPos)
     delObjektStyle = New SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod(AddressOf GetObjektStyle)
     delObjektLabelStyle = New SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod(AddressOf GetObjektLabelStyle)
     '
     For each itm as OtherClassItem in config
        Select Case itm.Name
           Case "Name1"
              Dim smp as New SharpMap.Data.Providers.PostGIS(itm.Datasource, itm.Table, itm.Field)
              Dim vLay as New SharpMap.Layers.VectorLayer(itm.Name, smp)
              Dim layTheme = New SharpMap.Rendering.Thematics.CustomTheme(delObjektStyle)
              vLay.Theme = layTheme
              '
              Dim labLay As New SharpMap.Layers.LabelLayer("Lable: " & itm.Name)
              Dim labTheme as New SharpMap.Rendering.Thematics.CustomTheme(delObjektLabelStyle)
              labLay.DataSource = vLay.DataSource
          labLay.Theme = labTheme
              labLay.LabelStringDelegate = delObjektLabelBez
          labLay.LabelPositionDelegate = delObjektLabelPos
              '
              Me.Mapbox.Map.Layers.Add(vLay)
              Me.Mapbox.Map.Layers.Add(labLay)
              '
           Case "Name2"
              '
              other code
              '
              Dim labLay As New SharpMap.Layers.LabelLayer("Lable: " & itm.Name)
              Dim labTheme as New SharpMap.Rendering.Thematics.CustomTheme(delObjektLabelStyle)
              labLay.DataSource = vLay.DataSource
          labLay.Theme = labTheme
              labLay.LabelStringDelegate = delObjektLabelBez
          labLay.LabelPositionDelegate = delObjektLabelPos
              '
              Me.Mapbox.Map.Layers.Add(vLay)
              Me.Mapbox.Map.Layers.Add(labLay)
              '
        End Select
        '
     Next
     '
     Other Code .....
     '
  End Sub
  '
  Private Function GetObjektStyle(ByVal fdr As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle
    '
    Dim style As New SharpMap.Styles.VectorStyle
    Dim c as Color
    Dim p as Pen
    Dim b as Brush
    '
    Select Case fdr.Table.TableName
       Case "Name1"  -- Polygon
          Select Case fdr("FilterColumn")
             Case 1
               c = Color.Green
               p = New Pen(Color.Black, 1)
           b = New SolidBrush(c)
             Case 2
               c = Color.Blue
               p = New Pen(Color.Black, 1)
           b = New SolidBrush(c)
             Case Else
               c = Color.Red
               p = New Pen(Color.Black, 1)
           b = New SolidBrush(c)
          End Select
          '
          style.Fill = b
      style.Outline = p
          '
       Case "Name2" -- Lines
         '
         this Code will not Run
         '
       Case Else
    End Select
    '
    Return style  
    '
  End Function
  '
End Class
I have already Testing with Delegates Funktion for every Layer alone, without success. What am I doing wrong?
Coordinator
Sep 15 at 7:04 AM
Edited Sep 15 at 8:48 AM
When you leave CreateLayers function, all layers have their correct themes applied?
When entering the GetObjektStyle method, fdr.Table.TableName is what you expect?

For performance reasons, you are probably better off using a UniqueValuesTheme. The styles you are returning are more or less static. You are not rendering some custom symbol or computing a line width based on information in the FeatureDataRow.
Sep 15 at 8:35 AM
I have a lot of testing, the layer distinguished by the geometries. previously I had for every layer a own method to gererate the style. mostly the lines layer not working. my thought was one method for all layerstyle, the difference for the style is tablename Table1 = polygon,Table2=lines, Table3= Points. it was just an approach I've tried.

I have the polygon layerstyle with "style.fill" for the area and "style.outline" for the outline, the area is colored the line (outline) is not visible.

I can be hard to explain it in english. I do not know where my thinking is correct

PS: I may also write in German?
Coordinator
Sep 15 at 9:29 AM
Edited Sep 15 at 9:31 AM
  • For polygon borders to be rendered you have to set VectorStyle.EnableOutline = True
  • For lines to be rendered you have to set the VectorStyle.Line property. You can force lines to be rendered twice by setting the VectorStyle.Outline property, too, and in addition set VectorStyle.EnableOutline = True
Again have a look at UniqueValuesTheme(Of T) as this will be faster and not be wasting system resources.
Sep 15 at 9:58 AM
Okay "VectorStyle.EnableOutline = True " I have not seen. I have now enabled successfull :-)

there is the possibility of simply one arrow on the middle of the line from first Point to the last Point of the line (as a kind of flow arrow)?
Sep 15 at 1:00 PM
I have now got it,
Public Class Test
  Private delObjektLabelBez As SharpMap.Layers.LabelLayer.GetLabelMethod
  Private delObjektLabelPos As SharpMap.Layers.LabelLayer.GetLocationMethod
  Private delObjektLabelStyle As SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod
  Private delObjektStyle As SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod
  '
  Public Sub CreateLayers(ByVal config as OtherClass)
     '
     delObjektLabelBez = New SharpMap.Layers.LabelLayer.GetLabelMethod(AddressOf LabelObjektBezeichnung)
     delObjektLabelPos = New SharpMap.Layers.LabelLayer.GetLocationMethod(AddressOf LabelBezeichnungPos)
     delObjektStyle = New SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod(AddressOf GetObjektStyle)
     delObjektLabelStyle = New SharpMap.Rendering.Thematics.CustomTheme.GetStyleMethod(AddressOf GetObjektLabelStyle)
     '
     Dim layTheme as New SharpMap.Rendering.Thematics.CustomTheme(delObjektStyle)
     Dim labTheme as New SharpMap.Rendering.Thematics.CustomTheme(delObjektLabelStyle)
     '
     For each itm as OtherClassItem in config
        Select Case itm.Name
           Case "Name1"
              Dim smp as New SharpMap.Data.Providers.PostGIS(itm.Datasource, itm.Table, itm.Field)
              Dim vLay as New SharpMap.Layers.VectorLayer(itm.Name, smp)
              vLay.Theme = layTheme
              '
              Dim labLay As New SharpMap.Layers.LabelLayer("Lable: " & itm.Name)
              labLay.DataSource = vLay.DataSource
              labLay.Theme = labTheme
              labLay.LabelStringDelegate = delObjektLabelBez
              labLay.LabelPositionDelegate = delObjektLabelPos
              '
              Me.Mapbox.Map.Layers.Add(vLay)
              Me.Mapbox.Map.Layers.Add(labLay)
              '
           Case "Name2"
              '
              Dim smp as New SharpMap.Data.Providers.PostGIS(itm.Datasource, itm.Table, itm.Field)
              Dim vLay as New SharpMap.Layers.VectorLayer(itm.Name, smp)
              vLay.Theme = layTheme
              '
              Dim labLay As New SharpMap.Layers.LabelLayer("Lable: " & itm.Name)
              labLay.DataSource = vLay.DataSource
              labLay.Theme = labTheme
              labLay.LabelStringDelegate = delObjektLabelBez
              labLay.LabelPositionDelegate = delObjektLabelPos
              '
              Me.Mapbox.Map.Layers.Add(vLay)
              Me.Mapbox.Map.Layers.Add(labLay)
              '
        End Select
        '
     Next
     '
     Other Code .....
     '
  End Sub
  '
  Private Function GetObjektStyle(ByVal fdr As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.VectorStyle
    '
    Dim style As New SharpMap.Styles.VectorStyle
    Dim c as Color
    Dim p as Pen
    Dim b as Brush
    '
    Select Case fdr.Table.TableName
       Case "Name1"  -- Polygon
          Select Case fdr("FilterColumn")
             Case 1
             ' Formating Style for Polygons
          End Select
          '
          style.EnableOutline = True
          style.Fill = b
          style.Outline = p
          '
       Case "Name2" -- Lines
          Select Case fdr("FilterColumn")
             Case 1
             ' Formating Style for Lines
          End Select
          '
          style.Line = p
          '
       Case Else
    End Select
    '
    Return style  
    '
  End Function
  '
End Class