From 4b05a62b8b89f21f3610d0fa7841e4ac9e33c506 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 16 Apr 2024 14:52:52 +0200 Subject: [PATCH 1/2] feat: open popup when default view is set to latest fix #1726 --- umap/static/umap/js/umap.features.js | 2 +- umap/static/umap/js/umap.js | 14 ++++++-------- umap/tests/integration/test_map.py | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index e5c86887..9252334c 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -310,13 +310,13 @@ U.FeatureMixin = { zoomTo: function (e) { e = e || {} const easing = e.easing !== undefined ? e.easing : this.map.getOption('easing') + if (e.callback) this.map.once('moveend', e.callback.call(this)) if (easing) { this.map.flyTo(this.getCenter(), this.getBestZoom()) } else { const latlng = e.latlng || this.getCenter() this.map.setView(latlng, this.getBestZoom() || this.map.getZoom()) } - if (e.callback) e.callback.call(this) }, getBestZoom: function () { diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 332f8dab..93d6b294 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -82,7 +82,6 @@ U.Map = L.Map.extend({ .split(',') } - let editedFeature = null const self = this try { @@ -334,7 +333,6 @@ U.Map = L.Map.extend({ if (this.options.editMode === 'advanced') { new U.SettingsToolbar({ actions: editActions }).addTo(this) } - } this._controls.zoom = new L.Control.Zoom({ zoomInTitle: L._('Zoom in'), @@ -388,7 +386,7 @@ U.Map = L.Map.extend({ document.body, 'umap-caption-bar-enabled', this.options.captionBar || - (this.options.slideshow && this.options.slideshow.active) + (this.options.slideshow && this.options.slideshow.active) ) L.DomUtil.classIf( document.body, @@ -716,7 +714,7 @@ U.Map = L.Map.extend({ if (datalayer) { const feature = datalayer.getFeatureByIndex(-1) if (feature) { - feature.zoomTo() + feature.zoomTo({ callback: this.options.noControl ? null : feature.view }) return } } @@ -1582,10 +1580,10 @@ U.Map = L.Map.extend({ initCaptionBar: function () { const container = L.DomUtil.create( - 'div', - 'umap-caption-bar', - this._controlContainer - ), + 'div', + 'umap-caption-bar', + this._controlContainer + ), name = L.DomUtil.create('h3', '', container) L.DomEvent.disableClickPropagation(container) this.permissions.addOwnerLink('span', container) diff --git a/umap/tests/integration/test_map.py b/umap/tests/integration/test_map.py index 8ede6547..87c673eb 100644 --- a/umap/tests/integration/test_map.py +++ b/umap/tests/integration/test_map.py @@ -85,6 +85,7 @@ def test_default_view_latest_with_marker(map, live_server, datalayer, page): expect(page).to_have_url(re.compile(r".*#7/48\..+/14\..+")) layers = page.locator(".umap-browser .datalayer h5") expect(layers).to_have_count(1) + expect(page.locator(".leaflet-popup")).to_be_visible() def test_default_view_latest_with_line(map, live_server, page): From 0acf5f2f2f9de690e167a52eea23d9d4bc56d05c Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 17 Apr 2024 14:55:20 +0200 Subject: [PATCH 2/2] chore: change zoomTo signature to make it more explicit --- umap/static/umap/js/umap.features.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 9252334c..d7d9f4e9 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -307,14 +307,13 @@ U.FeatureMixin = { return value }, - zoomTo: function (e) { - e = e || {} - const easing = e.easing !== undefined ? e.easing : this.map.getOption('easing') - if (e.callback) this.map.once('moveend', e.callback.call(this)) + zoomTo: function ({ easing, latlng, callback } = {}) { + if (easing === undefined) easing = this.map.getOption('easing') + if (callback) this.map.once('moveend', callback.call(this)) if (easing) { this.map.flyTo(this.getCenter(), this.getBestZoom()) } else { - const latlng = e.latlng || this.getCenter() + latlng = latlng || this.getCenter() this.map.setView(latlng, this.getBestZoom() || this.map.getZoom()) } },