UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

117 lines (116 loc) 4.37 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import ConfigManager from '../../tools/configuration/configmanager'; import { BrainIgnoreClone } from '../../tools/state/brain/decorators'; 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; } } __decorate([ BrainIgnoreClone ], BaseLayer.prototype, "parent", void 0); export default BaseLayer;