UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

204 lines (203 loc) 7.79 kB
import Layer from './layer'; class LayerWmts extends Layer { constructor(id, name, order, url, layer, options, ogcServer) { let opts = options ?? {}; opts = LayerWmts.isGMFTreeItem(opts) ? LayerWmts.getOptionsFromGMFTreeItem(opts) : opts; super(id, name, order, opts); /** * 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, "url", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "layer", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "dimensions", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "imageType", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "style", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "minResolution", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "maxResolution", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "legend", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "legendImage", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isLegendExpanded", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "wasLegendExpanded", { enumerable: true, configurable: true, writable: true, value: void 0 }); // A WMTS layer can have WMS informations to be able to query infos and print with a WMS layer. // TODO REG : Shouldn't we link here directly an object of type LayerWMS ? Object.defineProperty(this, "ogcServer", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "wmsLayers", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "queryLayers", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "printLayers", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "hiDPILegendImages", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** Linked ol layer, starting with an underscore to not be part of the proxy. **/ Object.defineProperty(this, "_olayer", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.url = url; this.layer = layer; this.ogcServer = ogcServer; this.dimensions = opts.dimensions; this.imageType = opts.imageType; this.style = opts.style; this.wmsLayers = opts.wmsLayers; this.queryLayers = opts.queryLayers; this.printLayers = opts.printLayers; this.minResolution = opts.minResolution; this.maxResolution = opts.maxResolution; this.legend = opts.legend ?? false; this.legendImage = opts.legendImage; this.isLegendExpanded = opts?.isLegendExpanded ?? false; this.wasLegendExpanded = opts?.wasLegendExpanded ?? !this.isLegendExpanded; this.hiDPILegendImages = opts.hiDPILegendImages; } clone() { const options = { isDefaultChecked: this.isDefaultChecked, metadataUrl: this.metadataUrl, disclaimer: this.disclaimer, opacity: this.opacity, protected: this.protected, dimensions: this.dimensions, imageType: this.imageType, style: this.style, queryLayers: this.queryLayers, wmsLayers: this.wmsLayers, printLayers: this.printLayers, minResolution: this.minResolution, maxResolution: this.maxResolution, legend: this.legend, legendImage: this.legendImage, isLegendExpanded: this.isLegendExpanded, wasLegendExpanded: this.wasLegendExpanded, hiDPILegendImages: this.hiDPILegendImages }; const clonedObject = new LayerWmts(this.id, this.name, this.order, this.url, this.layer, options, this.ogcServer); clonedObject.activeState = this.activeState; return clonedObject; } get layerUniqueId() { if (this.dimensions) { return this.layer + JSON.stringify(this.dimensions); } return this.name; } hasRestrictedResolution() { return (this.minResolution && this.minResolution !== 0) || (this.maxResolution && this.maxResolution !== 999999999); } isVisibleAtResolution(resolution) { if (resolution === undefined || resolution === null || !this.hasRestrictedResolution()) { return true; } return resolution >= (this.minResolution ?? -1) && resolution <= (this.maxResolution ?? Infinity); } static isGMFTreeItem(options) { return 'id' in options; } static getOptionsFromGMFTreeItem(options) { return { isDefaultChecked: options.metadata?.isChecked, metadataUrl: options.metadata?.metadataUrl, disclaimer: options.metadata?.disclaimer, opacity: 1, // TODO REG : Set default opacity protected: options.metadata?.protected, dimensions: options.dimensions, imageType: options.imageType, style: options.style, wmsLayers: options.metadata?.wmsLayers, ogcServer: options.metadata?.ogcServer, queryLayers: options.metadata?.queryLayers, printLayers: options.metadata?.printLayers, minResolution: options.minResolutionHint, maxResolution: options.maxResolutionHint, legend: options.metadata?.legend, legendImage: options.metadata?.legendImage, isLegendExpanded: options.metadata?.isLegendExpanded, wasLegendExpanded: options.metadata?.wasLegendExpanded, hiDPILegendImages: options.metadata?.hiDPILegendImages }; } } export default LayerWmts;