UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

102 lines (101 loc) 3.71 kB
import BaseLayer from './baselayer'; import LayerTimeFormatter from '../../tools/time/layertimeformatter'; class GroupLayer extends BaseLayer { constructor(id, name, order, options) { super(id, name, order, options); /** * 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 */ Object.defineProperty(this, "isExclusiveGroup", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isExpanded", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "activeState", { enumerable: true, configurable: true, writable: true, value: 'off' }); Object.defineProperty(this, "timeOptions", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "timeAttribute", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "timeRestriction", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "children", { enumerable: true, configurable: true, writable: true, value: [] }); this.isExpanded = options?.isDefaultExpanded || false; this.isExclusiveGroup = options?.isExclusiveGroup ?? false; this.timeOptions = options?.time; this.timeAttribute = options?.timeAttribute; this.setDefaultTimeRestriction(); } clone() { const options = { isDefaultChecked: this.isDefaultChecked, metadataUrl: this.metadataUrl, disclaimer: this.disclaimer, isDefaultExpanded: this.isExpanded, isExclusiveGroup: this.isExclusiveGroup, time: this.timeOptions, timeAttribute: this.timeAttribute }; const clonedObject = new GroupLayer(this.id, this.name, this.order, options); clonedObject.activeState = this.activeState; clonedObject.timeRestriction = this.timeRestriction; // Clone children for (const child of this.children) { const clonedChild = child.clone(); clonedChild.parent = clonedObject; clonedObject.children.push(clonedChild); } return clonedObject; } get active() { return this.activeState === 'on'; } get inactive() { return this.activeState === 'off'; } get semiActive() { return this.activeState === 'semi'; } get hasTimeRestriction() { return !!this.timeRestriction; } setDefaultTimeRestriction() { if (this.timeOptions) { const timeFormatter = new LayerTimeFormatter(this.timeOptions); this.timeRestriction = timeFormatter.getFormattedDefault(); } } } export default GroupLayer;