diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 2c67911c..726b9591 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -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', () => { diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index c3f2e75c..7de50be8 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -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()) }, }