@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
30 lines (29 loc) • 1.03 kB
JavaScript
import { isStreetViewProvider, isStreetViewView } from '../../state/streetview.js';
/**
* Shares the footage displayed by each StreetView Component,
* so that the Components display it again when the shared state is restored.
*/
export default class StreetViewSerializer {
context;
constructor(context) {
this.context = context;
}
get streetview() {
return this.context.stateManager.state.streetview;
}
brainSerialize(streetview) {
return JSON.stringify(streetview.views);
}
/**
* Applies the shared views, ignoring the providers and the views that are not valid:
* a shared state can have been created by another version of the application.
*/
brainDeserialize(str) {
const parsedViews = JSON.parse(str);
for (const [provider, view] of Object.entries(parsedViews ?? {})) {
if (isStreetViewProvider(provider) && isStreetViewView(view)) {
this.streetview.views[provider] = view;
}
}
}
}