UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

55 lines (54 loc) 1.95 kB
// SPDX-License-Identifier: Apache-2.0 import BaseLayer from './baselayer.js'; /* * This class is a used in the state of the application, which will be accessed behind a javascript proxy. * This means that each modification made to its properties must come from outside, * because they have to be made through the proxy, so that the modification can be listen. * Therefore, this class must not contain any method which is updating a value directly * For example, any method doing <this.xxx = value> is forbidden here, because the modification be known from the proxy */ class ThemeLayer extends BaseLayer { isExclusiveTheme; isExpanded; activeState = 'off'; icon; location; zoom; children = []; constructor(id, name, order, icon, options) { super(id, name, order, options); this.isExpanded = options?.isDefaultExpanded || true; this.isExclusiveTheme = options?.isExclusiveTheme ?? false; this.icon = icon; } clone() { const options = { disclaimer: this.disclaimer, isDefaultExpanded: this.isExpanded }; const clonedObject = new ThemeLayer(this.id, this.name, this.order, this.icon, options); clonedObject.activeState = this.activeState; // Clone children for (const child of this.children) { try { const clonedChild = child.clone(); clonedChild.parent = clonedObject; clonedObject.children.push(clonedChild); } catch { console.warn(`Cloning child ${child.name} of theme ${this.name} ins't supported`); } } return clonedObject; } get active() { return this.activeState === 'on'; } get inactive() { return this.activeState === 'off'; } get semiActive() { return this.activeState === 'semi'; } } export default ThemeLayer;