From 4347d40e6457c41f0bb3875c63bc499622985a78 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 26 Nov 2023 11:13:56 +0100 Subject: [PATCH] Set map default center even if waiting for user location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is an edge case when using "locate" a default view AND activating easing for transitions: in this case, Leaflet.locate needs a "starting view" to compute the easing to the new position (the user location). I could have only set the default_view when easing is on, but I thought it was simpler to just set it anyway… --- umap/static/umap/js/umap.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index ed54f43b..c65effef 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -688,7 +688,11 @@ L.U.Map.include({ // FIXME An invalid hash will cause the load to fail this._hash.update() } else if (this.options.defaultView === 'locate' && !this.options.noControl) { - this.once('locationerror', this._setDefaultCenter) + // When using locate as default map view AND activating easing + // Leaflet.locate will ask the map view to compute transition to user + // position, so in this case we do need a default center, so let's + // set it anyway + this._setDefaultCenter() this._controls.locate.start() } else if (this.options.defaultView === 'data') { this.onceDataLoaded(() => {