ThinkGeo.com    |     Documentation    |     Premium Support

CustomStyles adding ValueStyle Line first then TextStyle to same layer

Please see the following code. I would like to use ValueStyles for the line type and for the actual labels themselves simply use a text style. This will be used towards a 'Major Roads" layer and so will feature afterwards the symbols behind them after I get passed this part. With the following code, the label is rendered behind the value style. Why is that?


 


 


                            Case "Shapefile" 'Features from SHP
                                With layerToAdd.ZoomLevelSet.GetZoomLevels(layerZoomOn)
                                    layerValueStyle = CreateValueStylesFromLID(layerID, connStr)
                                    Dim textStyle As TextStyle = Nothing
                                    'Draw labels?
                                    If layerUseLabels = -1 Then
                                        Dim intFontStyle As Integer = 0
                                        'Trickiness for combo styles
                                        If layerFontBold <> 0 Then intFontStyle += 2
                                        If layerFontItalic <> 0 Then intFontStyle += 4
                                        If layerFontUnderline <> 0 Then intFontStyle += 8
                                        If layerFontStrikeout <> 0 Then intFontStyle += 16
                                        If intFontStyle = 0 Then intFontStyle = 1

                                        Dim textFont As New GeoFont(layerFontName, layerFontSize, intFontStyle)
                                        textStyle = New TextStyle(layerLabelField, textFont, New GeoSolidBrush(layerFontColor))

                                        textStyle.FittingPolygon = layerFittingPolygon
                                        textStyle.BestPlacement = layerBestPlacement
                                        textStyle.SuppressPartialLabels = layerSuppressPartials
                                        textStyle.ForceHorizontalLabelForLine = layerHorizontalLabels

                                    End If
                                    .CustomStyles.Add(layerValueStyle)

                                    If Not textStyle Is Nothing Then .CustomStyles.Add(textStyle)
                                    .ApplyUntilZoomLevel = layerZoomOff
                                End With


Nelson, 
  
 For your case, we recommend to create another layer just for labeling, add the ValueStyle to the original layer and add the labelStyle to your new layer. In that way, you can control the order of different styles easily, especially when you have multi layers to label. Please have a look at Samples->Labeling->LabelNiceLookingRoads for example. 
  
 Thanks, 
  
 Ben 


Multiple layers would be undesirable, as we are just looking to acheive a standard Highway/Major Roads look including different line colors dependant on the type of road and an approriate symbol as well. Is there no way to use a Value Style in one pass to do this? It seems odd that I would have the option to turn on and off my highway labels…

Nelson, 
  
 If you have both text style and value style on one layer, we will always render the line first and draw the text at last. That’s fine. But if you have multi layers, that way doesn’t work properly and we strongly recommend you to separate the text style to another layer as that is the easiest way to control label’s order. Also, for your case, we just initialize the layers at beginning and when users turn on / off the labels, we just set the IsVisible property for the label layers, that’s simple and codes is cleaner, isn’t it? 
  
 Maybe I overlooked something; let me know how you think about it. 
  
 Thanks, 
  
 Ben. 


I can see a request down the line from one of our clients specifically asking about requiring layers for other layers to be on and what not so at some point I will need to tackle this type of scenario, I suppose. 
  
 If I can add the text to the ValueStyle then I will just have to re-code to get this done; after all, this is probably the right aproach any ways. Hindisght is 20/20. Thanks again.

Nelson, 
  
 I think that’s the right way as now it might seem not that convenient but when you get to a large data, you will see how easy it is to extend the label layers clearly without any problem. That’s not too late anyway; we are always learning stuff from imperfect :) 
  
 Ben