lizmap-web-client icon indicating copy to clipboard operation
lizmap-web-client copied to clipboard

[Bug]: filter tool - multiple filters for the same layer but not combine them

Open josemvm opened this issue 10 months ago • 5 comments

What is the bug? (in English)

it's possible to define multiple filters for the same layer but not combine them, like filter1 AND filter2:

Image

Steps to reproduce the issue

try to define multiple filters for the same layer and pick some options

Versions, safeguards, check summary etc

Versions :

  • Lizmap Web Client : 3.8.4 - commit be354fcbc https://github.com/3liz/lizmap-web-client/commit/be354fcbc
  • Lizmap plugin : 4.4.6
  • QGIS Desktop : 3.34.14
  • QGIS Server : 3.34.14
  • Py-QGIS-Server : not used
  • QGIS Server plugin atlasprint : 3.4.1
  • QGIS Server plugin lizmap_server : 2.12.0
  • QGIS Server plugin wfsOutputExtension : 1.8.2
List of Lizmap Web Client modules :
* multiauth : 1.2.2
List of safeguards :
* Mode : normal
* Allow parent folder : no
* Prevent other drive : no
* Prevent PG service : no
* Prevent PG Auth DB : no
* Force PG user&pass : no
* Prevent ECW : no

Check Lizmap plugin

  • [x] I have done the step just before in the Lizmap QGIS desktop plugin before opening this ticket. Otherwise, my ticket is not considered valid and might get closed.

Operating system

ubuntu 22

Browsers

Firefox

Browsers version

134.0.2

Relevant log output


josemvm avatar Feb 05 '25 21:02 josemvm

Hi, I'd like to work on this issue. I see that multiple filters for the same layer are not being combined correctly. Could you provide more details on the expected filtering behavior? Should the filters be combined using AND/OR logic, or is there another approach preferred? Also, any guidance on the relevant files or functions handling the filter logic would be appreciated. Thanks!

sudhanshu112233shukla avatar Feb 07 '25 16:02 sudhanshu112233shukla

Ensuring multiple filters for the same layer are combined properly using "AND" logic.

// Function to apply multiple filters and combine them properly function applyLayerFilters(layer, filters) { if (!layer || !filters || filters.length === 0) return;

// Combine filters using "AND"
let combinedFilter = filters.map(filter => `(${filter})`).join(" AND ");

// Apply the combined filter using LeafletJS filtering
let newFilter = new L.Filter.Comparison({
    operator: L.Filter.Comparison.EQ,  // Adjust as needed
    property: 'custom_filter',
    value: combinedFilter
});

layer.setFilter(newFilter);

}

// Function to get the selected layer and apply filters function applyFiltersToSelectedLayer() { let selectedLayer = map.getLayerById("myLayer"); // Replace with actual layer ID

if (!selectedLayer) {
    console.error("Layer not found.");
    return;
}

// Example: Define multiple filters
let filters = [
    "population > 10000",
    "area < 500"
];

// Apply the combined filter to the selected layer
applyLayerFilters(selectedLayer, filters);

}

// Run filter application when needed document.getElementById("applyFiltersBtn").addEventListener("click", applyFiltersToSelectedLayer);

sudhanshu112233shukla avatar Feb 11 '25 18:02 sudhanshu112233shukla

Hi @sudhanshu112233shukla,

Thanks for wanting to contribute, before we look into your recent comments, do not forget to use Markdown formatting, example with

```javascript
your JS code here
```

For instance with your snipped you copy/pasted before (change language accordingly) :

// Function to apply multiple filters and combine them properly
function applyLayerFilters(layer, filters) {
if (!layer || !filters || filters.length === 0) return;

// Combine filters using "AND"
let combinedFilter = filters.map(filter => `(${filter})`).join(" AND ");

// Apply the combined filter using LeafletJS filtering
let newFilter = new L.Filter.Comparison({
    operator: L.Filter.Comparison.EQ,  // Adjust as needed
    property: 'custom_filter',
    value: combinedFilter
});

layer.setFilter(newFilter);

}

// Function to get the selected layer and apply filters
function applyFiltersToSelectedLayer() {
let selectedLayer = map.getLayerById("myLayer"); // Replace with actual layer ID

if (!selectedLayer) {
    console.error("Layer not found.");
    return;
}

// Example: Define multiple filters
let filters = [
    "population > 10000",
    "area < 500"
];

// Apply the combined filter to the selected layer
applyLayerFilters(selectedLayer, filters);

}

// Run filter application when needed
document.getElementById("applyFiltersBtn").addEventListener("click", applyFiltersToSelectedLayer);

Gustry avatar Feb 12 '25 10:02 Gustry

Sure sir , I'll do it as you said

sudhanshu112233shukla avatar Feb 14 '25 11:02 sudhanshu112233shukla

@sudhanshu112233shukla can you make a PR? that would be great!

josemvm avatar Mar 18 '25 11:03 josemvm