UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

69 lines (68 loc) 2.38 kB
import GirafeSingleton from '../../base/GirafeSingleton'; import LayerManager from '../layers/layermanager'; import StateManager from '../state/statemanager'; import StateDeserializer from './statedeserializer'; import StateSerializer from './stateserializer'; class ShareManager extends GirafeSingleton { constructor(type) { super(type); Object.defineProperty(this, "stateManager", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "layerManager", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "serializer", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "deserializer", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.stateManager = StateManager.getInstance(); this.layerManager = LayerManager.getInstance(); this.serializer = new StateSerializer(); this.deserializer = new StateDeserializer(); } getStateToShare() { const encodedState = this.serializer.getSerializedState(this.stateManager.state); return encodedState; } hasSharedState() { const encodedState = this.getStateFromUrl(); return encodedState !== null; } getStateFromUrl() { let encodedState = window.location.hash; if (encodedState && encodedState.length > 0) { if (encodedState.startsWith('#')) { encodedState = encodedState.substring(1); } if (encodedState.length > 0) { return encodedState; } } return null; } setStateFromUrl() { // NOTE: This method should only be called when themes.json has been loaded // (i.e. from the ThemesManager), because it needs the themes. const encodedState = this.getStateFromUrl(); if (encodedState) { this.deserializer.deserializeAndSetState(encodedState); } this.stateManager.state.sharedStateIsLoaded = true; } } export default ShareManager;