nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit fedc929a1f08649304535a01f52c21bfe8f2e02a
parent cdf076e3ef95c16fad4d9364bd9a4d5b625e9d89
Author: Sergey Orlov <wladimirych@gmail.com>
Date:   Wed, 17 Feb 2021 22:16:48 +0100

location: move forced and default location logic to caller

Fixes #663

Diffstat:
Msrc/App.js | 15+++++++++------
Msrc/lib/leaflet.control.locate/index.js | 20++++++--------------
2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -105,11 +105,8 @@ function setUp() { notify(customMessage); } }).addTo(map); - - let {lat, lng, zoom, valid: validPositionInHash} = map.validateState(hashState.getState('m')); - locateControl.moveMapToCurrentLocation(config.defaultZoom, L.latLng(config.defaultLocation), - validPositionInHash ? L.latLng(lat, lng) : null, validPositionInHash ? zoom : null); - map.enableHashState('m'); + let {valid: validPositionInHash} = map.validateState(hashState.getState('m')); + map.enableHashState('m', [config.defaultZoom, ...config.defaultLocation]); /* controls top-right corner */ @@ -178,8 +175,14 @@ function setUp() { } startInfo.tracksAfterLoadFromHash = trackNames(); + /* set map position */ + if (!validPositionInHash) { - tracklist.whenLoadDone(() => tracklist.setViewToAllTracks(true)); + if (hasTrackParamsInHash) { + tracklist.whenLoadDone(() => tracklist.setViewToAllTracks(true)); + } else { + locateControl.moveMapToCurrentLocation(config.defaultZoom); + } } /* adaptive layout */ diff --git a/src/lib/leaflet.control.locate/index.js b/src/lib/leaflet.control.locate/index.js @@ -128,8 +128,8 @@ const LocateControl = L.Control.extend({ return container; }, - moveMapToCurrentLocation: function(zoom, fallbackLatLng, forceLatLng, forceZoom) { - let storedPosition; + moveMapToCurrentLocation: function(zoom) { + let storedPosition = null; try { storedPosition = JSON.parse(localStorage.getItem(LOCALSTORAGE_POSITION)); let {lat, lon} = storedPosition; @@ -143,21 +143,16 @@ const LocateControl = L.Control.extend({ } if (storedPosition) { - this._map.setView(forceLatLng ? forceLatLng : storedPosition, forceZoom ? forceZoom : zoom, { - animate: false, - }); + this._map.setView(storedPosition, zoom, {animate: false}); if (!('geolocation' in navigator)) { return; } navigator.geolocation.getCurrentPosition( (pos) => { this._storePositionToLocalStorage(pos); - if (!forceLatLng) { - // TODO: check if map has not moved - this._map.setView(L.latLng(pos.coords.latitude, pos.coords.longitude), zoom, { - animate: false, - }); - } + this._map.setView(L.latLng(pos.coords.latitude, pos.coords.longitude), zoom, { + animate: false, + }); }, (e) => { if (e.code === 1) { @@ -168,9 +163,6 @@ const LocateControl = L.Control.extend({ timeout: 500, maximumAge: 0 }); - } else { - this._map.setView(forceLatLng ? forceLatLng : fallbackLatLng, forceZoom ? forceZoom : zoom, - {animate: false}); } },