compassinformatics / cpsi-mapview

GNU General Public License v3.0
6 stars 14 forks source link

Vector Layer Labels MenuItem #144

Closed geographika closed 4 years ago

geographika commented 4 years ago

Currently CpsiMapview.view.menuitem.LayerLabels only supports WMS layers. The same class would ideally also work for vector based layers.

image

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; }

jansule commented 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:

  1. Apply labeling on feature level (as the style function returns a style object for every feature)
  2. Apply additional SLDs that integrate labeling and can be parsed as a whole

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

chrismayer commented 4 years ago

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.

geographika commented 4 years ago

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.

chrismayer commented 4 years ago

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.

jansule commented 4 years ago

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:

jansule commented 4 years ago

Yes the SLD option sounds good.

Thanks for the feedback. I will then start to implement it that way.