UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

107 lines (106 loc) 3.65 kB
import ConfigManager from '../../tools/configuration/configmanager'; import { v4 as uuidv4 } from 'uuid'; class BaseLayer { get hasMetadata() { return this.metadataUrl !== undefined; } constructor(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, "id", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "treeItemId", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "order", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isDefaultChecked", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "disclaimer", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "metadataUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isVisible", { enumerable: true, configurable: true, writable: true, value: true }); Object.defineProperty(this, "hasError", { enumerable: true, configurable: true, writable: true, value: false }); Object.defineProperty(this, "errorMessage", { enumerable: true, configurable: true, writable: true, value: null }); Object.defineProperty(this, "parent", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.id = id; this.treeItemId = uuidv4(); this.name = name; this.order = order; this.isDefaultChecked = options?.isDefaultChecked || false; this.disclaimer = options?.disclaimer; this.metadataUrl = this.calculateMetadataUrl(options?.metadataUrl); } calculateMetadataUrl(metadataUrl) { if (!metadataUrl) { return undefined; } if (!metadataUrl.startsWith('http') && ConfigManager.getInstance().Config.metadata.metadataUrlPrefix) { return ConfigManager.getInstance().Config.metadata.metadataUrlPrefix + metadataUrl; } return metadataUrl; } /** * @returns the name of the class to facilitate the identification * of subclasses, even in Proxy objects. */ get className() { return this.constructor.name; } } export default BaseLayer;