UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

138 lines (137 loc) 6.16 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; }; // SPDX-License-Identifier: Apache-2.0 import { BrainIgnore } from '../../tools/state/brain/decorators.js'; import Layer from './layer.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 LayerWmts extends Layer { url; layer; dimensions; imageType; style; minResolution; maxResolution; legend; legendImage; isLegendExpanded; wasLegendExpanded; // 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 ? ogcServer; wmsLayers; queryLayers; maxQueryResolution; minQueryResolution; printLayers; hiDPILegendImages; /** Linked ol layer, starting with an underscore to not be part of the proxy. **/ _olayer; 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.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.maxQueryResolution = opts.maxQueryResolution; this.minQueryResolution = opts.minQueryResolution; 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, restricted: this.restricted, dimensions: this.dimensions, imageType: this.imageType, style: this.style, queryLayers: this.queryLayers, maxQueryResolution: this.maxQueryResolution, minQueryResolution: this.minQueryResolution, 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: options.metadata?.opacity, restricted: options.public === undefined ? (options.metadata?.protected ?? false) : !options.public, dimensions: options.dimensions, imageType: options.imageType, style: options.style, wmsLayers: options.metadata?.wmsLayers, ogcServer: options.metadata?.ogcServer, queryLayers: options.metadata?.queryLayers, maxQueryResolution: options.metadata?.maxQueryResolution, minQueryResolution: options.metadata?.minQueryResolution, 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 }; } } __decorate([ BrainIgnore ], LayerWmts.prototype, "ogcServer", void 0); export default LayerWmts;