From d61feec2ba41feff9ba7db3ceee0e13521b6c7f5 Mon Sep 17 00:00:00 2001 From: Francesco Boccacci Date: Tue, 29 Aug 2023 09:13:22 +0200 Subject: [PATCH] Reproject query geometries when project layers have a different CRS (ref: `"querybbox"`, `"querybypolygon"` and `"querybydrawpolygon"` controls) (#478) * :bug: Add check source.external boolen value * explode conditionals * explicit `is_coors` variable * If visible is set to false due a CORS issue, no more control is set visible. Map canvas is dirty * Add also visibility property of a layer (ex. external wms) * extract function `isExternalImageLayer(layer)` * change comment * change comment * 3.8.8 * :bug: Fix issue results on query by bbox and query by polygon map control. Use original geometry if layer projection is the same of map projection. Otherwise, use a reprojected geometry without replace original one * Change boolean condition * Use same boolean condition * inline comment * comments --------- Co-authored-by: Raruto --- src/app/core/utils/geo.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/app/core/utils/geo.js b/src/app/core/utils/geo.js index 45015c809..ed37bd0f3 100644 --- a/src/app/core/utils/geo.js +++ b/src/app/core/utils/geo.js @@ -996,7 +996,7 @@ const geoutils = { feature_count, filterConfig, multilayers, - projection:mapProjection + projection: mapProjection }) } else { const d = $.Deferred(); @@ -1006,12 +1006,14 @@ const geoutils = { const queryErrors = []; let layersLenght = layers.length; layers.forEach(layer => { - const filter = new Filter(filterConfig); + const filter = new Filter(filterConfig); const layerCrs = layer.getProjection().getCode(); - /** - * convert - */ - filter.setGeometry((mapCrs !== layerCrs) ? geometry.clone().transform(mapCrs, layerCrs): geometry); + // Convert filter geometry from `mapCRS` to `layerCrs` + filter.setGeometry( + (mapCrs === layerCrs) + ? geometry + : geometry.clone().transform(mapCrs, layerCrs) + ); layer.query({ filter, feature_count @@ -1045,19 +1047,22 @@ const geoutils = { const mapCrs = projection.getCode(); const filter = new Filter(filterConfig); if (multilayers) { - let filterGeometry = geometry; if (!layers.length) d.resolve([]); const multiLayers = _.groupBy(layers, layer => `${layer.getMultiLayerId()}_${layer.getProjection().getCode()}`); const numberRequestd = Object.keys(multiLayers).length; let layersLength = numberRequestd; for (let key in multiLayers) { const _multilayer = multiLayers[key]; - const layers = _multilayer; - const multilayer = multiLayers[key][0]; - const provider = multilayer.getProvider('filter'); - const layerCrs = multilayer.getProjection().getCode(); - if (mapCrs !== layerCrs) filterGeometry = filterGeometry.clone().transform(mapCrs, layerCrs); - filter.setGeometry(filterGeometry); + const layers = _multilayer; + const multilayer = multiLayers[key][0]; + const provider = multilayer.getProvider('filter'); + const layerCrs = multilayer.getProjection().getCode(); + // Convert filter geometry from `mapCRS` to `layerCrs` + filter.setGeometry( + (mapCrs === layerCrs) + ? geometry + : geometry.clone().transform(mapCrs, layerCrs) + ); provider.query({ filter, layers, @@ -1076,7 +1081,12 @@ const geoutils = { let layersLenght = layers.length; layers.forEach(layer => { const layerCrs = layer.getProjection().getCode(); - filter.setGeometry((mapCrs !== layerCrs) ? geometry.clone().transform(mapCrs, layerCrs): geometry); + // Convert filter geometry from `mapCRS` to `layerCrs` + filter.setGeometry( + (mapCrs === layerCrs) + ? geometry + : geometry.clone().transform(mapCrs, layerCrs) + ); layer.query({ filter, filterConfig,