Allow to restrict browser items to current map view

This commit is contained in:
Yohan Boniface 2023-09-25 13:33:58 +02:00
parent 7ca4f0e11c
commit 9cf2bf1578
2 changed files with 15 additions and 4 deletions

View file

@ -692,6 +692,9 @@ L.U.Map.include({
const filter = L.DomUtil.create('input', '', browserContainer)
let filterValue = ''
const bboxLabel = L.DomUtil.add('label', '', browserContainer, L._('Current map view'))
inBbox = L.DomUtil.create('input', '', bboxLabel)
inBbox.type = 'checkbox'
const featuresContainer = L.DomUtil.create(
'div',
@ -760,15 +763,23 @@ L.U.Map.include({
const build = () => {
ul.innerHTML = ''
const bounds = this.getBounds()
datalayer.eachFeature((feature) => {
if (filterValue && !feature.matchFilter(filterValue, filterKeys)) return
if (inBbox.checked && !feature.isOnScreen(bounds)) return
ul.appendChild(addFeature(feature))
})
}
build()
L.DomEvent.on(inBbox, 'click', build)
L.DomEvent.on(inBbox, 'click', () => {
if (inBbox.checked) this.on('moveend', build)
else this.off('moveend', build)
})
datalayer.on('datachanged', build)
datalayer.map.ui.once('panel:closed', () => {
datalayer.off('datachanged', build)
this.off('moveend', build)
})
datalayer.map.ui.once('panel:ready', () => {
datalayer.map.ui.once('panel:ready', () => {

View file

@ -701,8 +701,8 @@ L.U.Marker = L.Marker.extend({
}
},
isOnScreen: function () {
const bounds = this.map.getBounds()
isOnScreen: function (bounds) {
bounds = bounds || this.map.getBounds()
return bounds.contains(this._latlng)
},
@ -935,8 +935,8 @@ L.U.PathMixin = {
return items
},
isOnScreen: function () {
const bounds = this.map.getBounds()
isOnScreen: function (bounds) {
bounds = bounds || this.map.getBounds()
return bounds.overlaps(this.getBounds())
},
}