origo-map / multiselect-plugin

Multiselect plugin for Origo
MIT License
2 stars 10 forks source link

Wms feature info #16

Closed steff-o closed 1 year ago

steff-o commented 2 years ago

Resolves #11 by implementing two different strategies depending on the situation. Both strategies are only fully supported on Geoserver and supports filters (_CQLFILTER) on the wms layer. Technically the same approach would be easy to implement for Qgis and most likely AGS as well. But as Origo currently lacks an api-function for determining the kind of server for a layer, I chose not to implement yet another variant of that.

1 By configuration Alternative layers can be configured for each layer by adding the property alternativeLayersto the MultiSelect configuration. Each layer can have many alternative layers to support composite WMS layers.

const alternativeLayers = [
            {
              name: 'kombolager',
              queryInfoLayers: ['punktlager', 'multipolygonlager'],
              disableFilterHandling: false
            }
        ];

name: is the name of the layer in origo configuration for which the configuration applies to. The layer could be any kind of layer, but the filter feature only works for Geoserver WMS.

queryInfoLayers: List with names of layers from which features will be selected instead of the original layer. Only layer types that are implemented in Origo.getFeature() (WFS and AGS feature) is possible to use, but the filter feature only works for Geoserver WFS. Due to a limitation in Origo.getFeature() only layers that have the same default (on server) coordinate system as the map works. Alternative layers must be configured in origo configurantion and should be hidden and not added to the legend and not used for anything else to make sense and not get messed up by the filter handling.

disableFilterHandling: If the configured layer is a WMS layer and has a _CQLFILTER property set the default behavior is to set that filter on the alternative layers as well, which only works when the origonal layer is a Geoserver WMS layer and the alternative layer is a Geoserver WFS layer. As the current implementation of WFS layers in origo does not really support changing the filter and if using a different server than Geoserver this flag can be set to true to avoid trouble if not using filters. Defaults to false.

2 By changing default WMS behavior By setting WMSHandling: { source: "WMS" } on the MultiSelect configuration the default behavior of WMS- layers is changed to get the selected features from the WMS server itself instead of trying to get them from an implicit WFS endpoint. The setting applies to all WMS layers in the map. If a layer has an alternativeLayers-configuration it takes precedence over the WMSHandling.

The implementation works by creating a fetureInfo-request to the WMS server. If the layer has a filter it will be honored, which works for both Geoserver and QGis and probably just about any server that supports filters, but as a Geoserver vendor specific parameter is used to create an extent instead of just a feataureinfo point, it only works for Geoserver.

steff-o commented 1 year ago

@asemoller Could you check if this breaks anything for you? Everything should be opt-in so you don't have to test if it actually works.

We would prefer to merge these changes instead of keeping it in our own fork but there seems to be lack of interest for this codebase from most other parties at the moment. I think that others will come along soon when they start to use origo more in internal applications and therefore it would be nice to keep a common codebase from the start.

asemoller commented 1 year ago

@steff-o I'll have a look!

We would prefer to merge these changes instead of keeping it in our own fork but there seems to be lack of interest for this codebase from most other parties at the moment. I think that others will come along soon when they start to use origo more in internal applications and therefore it would be nice to keep a common codebase from the start.

I totally agree.

asemoller commented 1 year ago

Nothing seemed to break when I tested.

asemoller commented 1 year ago

Maybe someone else should test the functionality regarding the settings. Most of the WMS's we have are external and this solution doesn't seem to solve that problem (unless it's from geoserver?).

steff-o commented 1 year ago

Yes, it only works for Geoserver, but as all new functionality is opt-in it should default to the old behavior, which didn't work for most public WMS:es either... The problem is that there is no way to write it to work with all server types as the functionality relies on vendor specific parameters. It would be possible to write for at least AGS and Qgis if featureInfo is not turned off, but that would require knowing the server type beforehand. Instead of doubling that functionality, I was hoping to get that as an API-function in Origo before jumping in to implement all different kinds of vendor specific stuff. And to be honest, at the moment we are only are interested in our own Geoserver and I prefer merging this quickly and take some bugfixes and finetuning later as we have more PR:s in the pipe and would like to avoid keeping our own fork and the merging problems that will arise.

@jokd Any thoughts on if we can merge it as is?