From 36903d0f993518d048dc162a1f25e7431f1a791e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bl=C3=A4sta?= Date: Tue, 28 Mar 2023 11:56:19 +0200 Subject: [PATCH] Added support for QGIS Server filter --- src/layer/wms.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/layer/wms.js b/src/layer/wms.js index ee67e4ea6..cb022d56b 100644 --- a/src/layer/wms.js +++ b/src/layer/wms.js @@ -5,7 +5,7 @@ import maputils from '../maputils'; import image from './image'; function createTileSource(options) { - return new TileWMSSource(({ + const sourceOptions = { attributions: options.attribution, url: options.url, gutter: options.gutter, @@ -17,14 +17,21 @@ function createTileSource(options) { TILED: true, VERSION: options.version, FORMAT: options.format, - STYLES: options.style, - CQL_FILTER: options.filter + STYLES: options.style } - })); + }; + if (options.filter) { + if (options.filterType === 'qgis') { + sourceOptions.params.EXP_FILTER = options.filter; + } else { + sourceOptions.params.CQL_FILTER = options.filter; + } + } + return new TileWMSSource((sourceOptions)); } function createImageSource(options) { - return new ImageWMSSource(({ + const sourceOptions = { attributions: options.attribution, url: options.url, crossOrigin: 'anonymous', @@ -33,10 +40,17 @@ function createImageSource(options) { LAYERS: options.id, VERSION: options.version, FORMAT: options.format, - STYLES: options.style, - CQL_FILTER: options.filter + STYLES: options.style } - })); + }; + if (options.filter) { + if (options.filterType === 'qgis') { + sourceOptions.params.EXP_FILTER = options.filter; + } else { + sourceOptions.params.CQL_FILTER = options.filter; + } + } + return new ImageWMSSource((sourceOptions)); } function createWmsStyle(wmsOptions, source, viewer, defaultStyle = true) { @@ -106,6 +120,7 @@ const wms = function wms(layerOptions, viewer) { sourceOptions.projection = viewer.getProjection(); sourceOptions.id = wmsOptions.id; sourceOptions.filter = wmsOptions.filter; + sourceOptions.filterType = wmsOptions.filterType; sourceOptions.format = wmsOptions.format ? wmsOptions.format : sourceOptions.format; const styleSettings = viewer.getStyle(wmsOptions.styleName); const wmsStyleObject = styleSettings ? styleSettings[0].find(s => s.wmsStyle) : undefined;