nakarte

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

commit 794f50b2ae1ff5a97e734fc76c111b53995e6d4a
parent 8ca0142eca500248c882c4ec4d260efd5723c619
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Wed, 12 Jul 2017 12:17:32 +0300

[panoramas] upgrade old hashState

Diffstat:
Msrc/App.js | 4+++-
Msrc/lib/leaflet.control.panoramas/index.js | 35+++++++++++++++++++++++++++++++----
Msrc/lib/leaflet.hashState/leaflet.hashState.js | 10++++++----
3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/src/App.js b/src/App.js @@ -57,9 +57,11 @@ function setUp() { new L.Control.TrackList.Ruler(tracklist).addTo(map); - new L.Control.Panoramas(document.getElementById('street-view')) + const panoramas = new L.Control.Panoramas(document.getElementById('street-view')) .addTo(map) .enableHashState('n2'); + L.Control.Panoramas.hashStateUpgrader(panoramas).enableHashState('n'); + new L.Control.Coordinates({position: 'topleft'}).addTo(map); diff --git a/src/lib/leaflet.control.panoramas/index.js b/src/lib/leaflet.control.panoramas/index.js @@ -5,7 +5,6 @@ import ko from 'vendored/knockout'; import googleProvider from './lib/google'; import mapillaryProvider from './lib/mapillary'; - function fireRefreshEventOnWindow() { const evt = document.createEvent("HTMLEvents"); evt.initEvent('resize', true, false); @@ -308,8 +307,12 @@ L.Control.Panoramas.include({ this.disableControl(); return true; } - this.enableControl(); + const coverageCode = state[0]; + if (!coverageCode || coverageCode[0] !== '_') { + return false; + } + this.enableControl(); this.googleCoverageSelected(coverageCode.includes('g')); this.mapillaryCoverageSelected(coverageCode.includes('m')); if (state.length > 2) { @@ -324,4 +327,28 @@ L.Control.Panoramas.include({ return true; } } -); -\ No newline at end of file +); + + +L.Control.Panoramas.hashStateUpgrader = function(panoramasControl) { + return L.Util.extend({}, L.Mixin.HashState, { + unserializeState: function(oldState) { + if (oldState) { + console.log('Upgrading'); + const upgradedState = ['_g']; + if (oldState.length) { + upgradedState.push('g', ...oldState); + } + setTimeout(()=> panoramasControl.unserializeState(upgradedState), 0); + } + return false; + }, + + serializeState: function() { + return null; + }, + }); + + + +}; +\ No newline at end of file diff --git a/src/lib/leaflet.hashState/leaflet.hashState.js b/src/lib/leaflet.hashState/leaflet.hashState.js @@ -8,10 +8,12 @@ L.Mixin.HashState = { const eventSource = this.stateChangeEventsSource ? this[this.stateChangeEventsSource] : this; // setup event listeners - this.stateChangeEvents.forEach((event) => { - eventSource.on(event, this._onControlStateChanged, this); - } - ); + if (this.stateChangeEvents) { + this.stateChangeEvents.forEach((event) => { + eventSource.on(event, this._onControlStateChanged, this); + } + ); + } hashState.addEventListener(key, (state) => this._onExternalStateChanged(state));