Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter application requires grouped layers #396

Open
ddrinka opened this issue Mar 17, 2025 · 4 comments
Open

Filter application requires grouped layers #396

ddrinka opened this issue Mar 17, 2025 · 4 comments

Comments

@ddrinka
Copy link

ddrinka commented Mar 17, 2025

It seems like WMS filters can only apply to layers belonging to a group:

if (filter.filterParams) {

QGIS Server does not have that restriction. I'm able to apply a FILTER parameter to a request for a single layer.

@ddrinka ddrinka changed the title Filter application requires groups layers Filter application requires grouped layers Mar 17, 2025
@manisandro
Copy link
Member

The filter plugin will currently only apply to theme layers, and any theme WMS from QGIS will come with sublayers (the toplevel layer begin the project itself, and the sublayers mirroring the QGIS layertree). How did you hit this restriction?

@ddrinka
Copy link
Author

ddrinka commented Mar 18, 2025

I'm providing a WMS URL via a query parameter (l=wms:https://...#LayerName) that I want to filter using a custom filter, also via query parameters. I've tried grouping the layers and providing the group to the query, but then the filter isn't able to "see" the sublayers--I didn't quite manage to dig into what was actually happening there, but it didn't just work.

I'm absolutely open to understanding better ways to use the url-based layer functionality. I'm very much in trial-and-error mode. For instance, it looks like there might be a way to actually load a new theme configuration from a URL to a JSON file rather than a WMS layer directly? But I haven't figured that out yet, and can't find it in any documentation.

@manisandro
Copy link
Member

Maybe it actually works. Can you try with this change

diff --git a/utils/LayerUtils.js b/utils/LayerUtils.js
index 8572603d..ff65a8a6 100644
--- a/utils/LayerUtils.js
+++ b/utils/LayerUtils.js
@@ -198,17 +198,17 @@ const LayerUtils = {
                 STYLES: styles.join(","),
                 ...layer.dimensionValues
             };
-            if (filter.filterParams) {
-                newParams.FILTER = Object.entries(filter.filterParams).reduce((res, [layername, filters]) => {
-                    if (!layerNames.includes(layername)) {
-                        return res;
-                    }
-                    return [...res, layername + ":" + filters.map(expr => Array.isArray(expr) ? LayerUtils.formatFilterExpr(expr) : "AND").join(" ")];
-                }, []).join(";");
-            }
-            if (filter.filterGeom) {
-                newParams.FILTER_GEOM = VectorLayerUtils.geoJSONGeomToWkt(filter.filterGeom);
-            }
+        }
+        if (filter.filterParams) {
+            newParams.FILTER = Object.entries(filter.filterParams).reduce((res, [layername, filters]) => {
+                if (!newParams.LAYERS.split(",").includes(layername)) {
+                    return res;
+                }
+                return [...res, layername + ":" + filters.map(expr => Array.isArray(expr) ? LayerUtils.formatFilterExpr(expr) : "AND").join(" ")];
+            }, []).join(";");
+        }
+        if (filter.filterGeom) {
+            newParams.FILTER_GEOM = VectorLayerUtils.geoJSONGeomToWkt(filter.filterGeom);
         }
 
         return {

@ddrinka
Copy link
Author

ddrinka commented Mar 18, 2025

That's the change I had in mind. I'm targeting an existing install so I can't just patch that in, but I can try to set up a local copy to test with. It'll probably be a couple days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants