Closed geographika closed 4 years ago
When styling vector based layers, we stumble upon the problem that the applied OpenLayers Style often is a style function rather than a style object. This happens when styles are based on feature properties. In contrast to style objects, OpenLayers only accepts a single style function. A given style function cannot be extended directly, so I see two possible solutions to handle labeling in our case:
The pro of point 2 is that the workflow would be quite similar to the one we use when styling WMS. But it would also mean that every style for vector based layers would have to be available in two versions (style without label, style with label).
The pro of point 1 is that we do not have to provide two versions of every style. But the handling for labeling VectorTiles would be more complex, as we can only access the features that are in the current extent.
Personally, I recommend following approach 2, as we leave the actual styling of the features to OpenLayers and can be sure that styling behaves similar to all other layers.
@geographika what approach would you rather have implemented?
@verendi @chrismayer
As already discussed internally with @jansule I also second approach 2. This also would keep all styles at one place (within their definition as SLD) which is another advantage.
Yes the SLD option sounds good. I'll have to get familiar with TextSymbolizers. Is it possible to load the SLD from either a .xml file on the server or via a remote URL? The backend MapServer we use should be able to generate SLD styles from the same layer used for the WMS with a GetStyle request.
I'll have to get familiar with TextSymbolizers.
Use the GeoStyler demo application in order to create TextSymbolizers with the GUI. It shows you the SLD syntax in a text editor: https://geostyler.github.io/geostyler-demo/
Is it possible to load the SLD from either a .xml file on the server or via a remote URL?
Not sure if I understood what the difference is but as long as the remote server supports CORS it should be doable.
Is it possible to load the SLD from either a .xml file on the server or via a remote URL?
At the end of the day, the mapserver also just returns a xml, so it should not matter from where we retrieve the SLD. But as @chrismayer said, we have to be able to actually retrieve it (i.e. CORS).
Use the GeoStyler demo application in order to create TextSymbolizers with the GUI. It shows you the SLD syntax in a text editor: https://geostyler.github.io/geostyler-demo/
Just some additional hints:
loadData
-> Wfs Data Parser
and keeping the defaults. {{
) in the TextSymbolizer Label field. (E.g. "Region {{GEN}}"
will be rendered to "Region Hamburg"
)Yes the SLD option sounds good.
Thanks for the feedback. I will then start to implement it that way.
Currently CpsiMapview.view.menuitem.LayerLabels only supports WMS layers. The same class would ideally also work for vector based layers.
Note any updates would also need to be taken into account the following in CpsiMapview.view.layer.StyleSwitcherRadioGroup
if (layer.get('labelsActive') === true) { newStyle += ',' + labelClassName; }