Do not let advancedFilters control add/remove features from map
This should be done by the datalayer itself, which is now the case.
This commit is contained in:
parent
5058e27496
commit
ac30e71e74
4 changed files with 20 additions and 31 deletions
|
@ -885,38 +885,12 @@ L.U.Map.include({
|
|||
}
|
||||
|
||||
const filterFeatures = function () {
|
||||
let noResults = true
|
||||
let found = false
|
||||
this.eachBrowsableDataLayer((datalayer) => {
|
||||
datalayer.eachFeature(function (feature) {
|
||||
feature.properties.isVisible = true
|
||||
for (const [property, values] of Object.entries(
|
||||
this.map.options.advancedFilters
|
||||
)) {
|
||||
if (values.length > 0) {
|
||||
if (
|
||||
!feature.properties[property] ||
|
||||
!values.includes(feature.properties[property])
|
||||
) {
|
||||
feature.properties.isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if (feature.properties.isVisible) {
|
||||
noResults = false
|
||||
if (!this.isLoaded()) this.fetchData()
|
||||
this.map.addLayer(feature)
|
||||
this.fire('show')
|
||||
} else {
|
||||
this.map.removeLayer(feature)
|
||||
this.fire('hide')
|
||||
}
|
||||
})
|
||||
datalayer.resetLayer(true)
|
||||
if (datalayer.hasDataVisible()) found = true
|
||||
})
|
||||
if (noResults) {
|
||||
this.help.show('advancedFiltersNoResults')
|
||||
} else {
|
||||
this.help.hide()
|
||||
}
|
||||
if (!found) this.ui.alert({content: L._('No results for these filters'), level: 'info'})
|
||||
}
|
||||
|
||||
propertiesContainer.innerHTML = ''
|
||||
|
|
|
@ -571,7 +571,6 @@ L.U.Help = L.Class.extend({
|
|||
advancedFilterKey: L._(
|
||||
'Comma separated list of properties to use for checkbox filtering'
|
||||
),
|
||||
advancedFiltersNoResults: L._('No results for these filters'),
|
||||
interactive: L._('If false, the polygon will act as a part of the underlying map.'),
|
||||
outlink: L._('Define link to open in a new window on polygon click.'),
|
||||
dynamicRemoteData: L._('Fetch data each time map view changes.'),
|
||||
|
|
|
@ -469,6 +469,17 @@ L.U.FeatureMixin = {
|
|||
return false
|
||||
},
|
||||
|
||||
matchAdvancedFilters: function () {
|
||||
const filters = this.map.options.advancedFilters
|
||||
for (const [property, expected] of Object.entries(filters)) {
|
||||
if (expected.length) {
|
||||
let value = this.properties[property]
|
||||
if (!value || !expected.includes(value)) return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
onVertexRawClick: function (e) {
|
||||
new L.Toolbar.Popup(e.latlng, {
|
||||
className: 'leaflet-inplace-toolbar',
|
||||
|
|
|
@ -285,6 +285,10 @@ L.U.DataLayer = L.Evented.extend({
|
|||
this.parentPane.appendChild(this.pane)
|
||||
},
|
||||
|
||||
hasDataVisible: function () {
|
||||
return !!Object.keys(this.layer._layers).length
|
||||
},
|
||||
|
||||
resetLayer: function (force) {
|
||||
if (this.layer && this.options.type === this.layer._type && !force) return
|
||||
const visible = this.isVisible()
|
||||
|
@ -297,6 +301,7 @@ L.U.DataLayer = L.Evented.extend({
|
|||
filter = this.map.options.filter
|
||||
this.eachLayer(function (layer) {
|
||||
if (filter && !layer.matchFilter(filter, filterKeys)) return
|
||||
if (!layer.matchAdvancedFilters()) return
|
||||
this.layer.addLayer(layer)
|
||||
})
|
||||
if (visible) this.map.addLayer(this.layer)
|
||||
|
|
Loading…
Reference in a new issue