From b013692527c4ea07546655053ac4165a32407a95 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 8 Aug 2023 08:20:34 +0200 Subject: [PATCH] Make sure filters are called before actually displaying a feature on the map fix #1005 --- umap/static/umap/js/umap.layer.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 06035165..590d69d3 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -312,13 +312,7 @@ L.U.DataLayer = L.Evented.extend({ if (visible) this.map.removeLayer(this.layer) const Class = L.U.Layer[this.options.type] || L.U.Layer.Default this.layer = new Class(this) - const filterKeys = this.map.getFilterKeys(), - filter = this.map.options.filter - this.eachLayer(function (layer) { - if (filter && !layer.matchFilter(filter, filterKeys)) return - if (!layer.matchFacets()) return - this.layer.addLayer(layer) - }) + this.eachLayer((feature) => this.showFeature(feature)) if (visible) this.map.addLayer(this.layer) this.propagateRemote() }, @@ -498,15 +492,23 @@ L.U.DataLayer = L.Evented.extend({ return this.options.type === 'Cluster' }, + showFeature: function (feature) { + const filterKeys = this.map.getFilterKeys(), + filter = this.map.options.filter + if (filter && !feature.matchFilter(filter, filterKeys)) return + if (!feature.matchFacets()) return + this.layer.addLayer(feature) + }, + addLayer: function (feature) { const id = L.stamp(feature) feature.connectToDataLayer(this) this._index.push(id) this._layers[id] = feature - this.layer.addLayer(feature) this.indexProperties(feature) - if (this.hasDataLoaded()) this.fire('datachanged') this.map.features_index[feature.getSlug()] = feature + this.showFeature(feature) + if (this.hasDataLoaded()) this.fire('datachanged') }, removeLayer: function (feature) {