UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

215 lines (214 loc) 9.26 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 LayerTimeFormatter from '../../tools/time/layertimeformatter.js'; import Layer from './layer.js'; import { BrainIgnore } from '../../tools/state/brain/decorators.js'; /* * This class is 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 listened to. * 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 must be known from the proxy */ class LayerWms extends Layer { // Base WMS attributes ogcServer; minResolution; maxResolution; layers; style; // Legend attributes legend; iconUrl; legendRule; legendImage; wasLegendExpanded; hiDPILegendImages; printNativeAngle; // TODO BGE Is it correct to have it at this level (should be for groups) ? // If the layer is queryable queryable = false; queryLayers; queryLayersRanges; wmsInfoFormat; filter; timeOptions; snapOptions; snapActive; timeRestriction; timeAttribute; enumeratedAttributes; editable; constructor(id, name, order, ogcServer, options) { let opts = options ?? {}; opts = LayerWms.isGMFTreeItem(opts) ? LayerWms.getOptionsFromGMFTreeItem(opts) : opts; super(id, name, order, opts); this.ogcServer = ogcServer; this.minResolution = opts?.minResolution; this.maxResolution = opts?.maxResolution; this.layers = opts?.layers; this.style = opts?.style; this.legend = opts?.legend ?? false; this.iconUrl = opts?.iconUrl; this.legendRule = opts?.legendRule; this.legendImage = opts?.legendImage; this.isLegendExpanded = opts?.isLegendExpanded ?? false; this.wasLegendExpanded = opts?.wasLegendExpanded ?? this.isLegendExpanded; this.hiDPILegendImages = opts?.hiDPILegendImages; this.printNativeAngle = opts?.printNativeAngle; this.queryable = opts?.queryable ?? false; this.wmsInfoFormat = opts?.wmsInfoFormat ?? LayerWms.getDefaultWmsInfoFormat(this.ogcServer); this.queryLayers = opts?.queryLayers; this.queryLayersRanges = opts?.queryLayersRanges || {}; this.timeOptions = opts?.time; this.timeAttribute = opts?.timeAttribute; this.editable = opts?.editable; this.snapOptions = opts?.snappingConfig; this.snapActive = this.snapOptions !== undefined; this.enumeratedAttributes = opts?.enumeratedAttributes; if (this.editable && (!this.ogcServer.oapifSupport || this.ogcServer.urlOapif?.length === 0)) { this.hasError = true; this.errorMessage = 'This layer is defined as editable but no Url for OgcApiFeatures service has been defined.'; this.editable = undefined; } this.setDefaultTimeRestriction(); } clone() { const options = { isDefaultChecked: this.isDefaultChecked, metadataUrl: this.metadataUrl, disclaimer: this.disclaimer, opacity: this.opacity, restricted: this.restricted, minResolution: this.minResolution, maxResolution: this.maxResolution, layers: this.layers, style: this.style, legend: this.legend, iconUrl: this.iconUrl, legendRule: this.legendRule, legendImage: this.legendImage, isLegendExpanded: this.isLegendExpanded, wasLegendExpanded: this.wasLegendExpanded, hiDPILegendImages: this.hiDPILegendImages, printNativeAngle: this.printNativeAngle, queryable: this.queryable, queryLayers: this.queryLayers, queryLayersRanges: this.queryLayersRanges, wmsInfoFormat: this.wmsInfoFormat, time: this.timeOptions, snappingConfig: this.snapOptions, timeAttribute: this.timeAttribute, editable: this.editable, enumeratedAttributes: this.enumeratedAttributes }; const clonedObject = new LayerWms(this.id, this.name, this.order, this.ogcServer, options); clonedObject.filter = this.filter; clonedObject.activeState = this.activeState; clonedObject.timeRestriction = this.timeRestriction; return clonedObject; } static isResolutionRangeRestricted(minResolution, maxResolution) { return (minResolution && minResolution !== 0) || (maxResolution && maxResolution !== 999999999); } hasRestrictedResolution() { return LayerWms.isResolutionRangeRestricted(this.minResolution, this.maxResolution); } static isInVisibleRange(resolution, minResolution, maxResolution) { if (resolution === undefined || resolution === null || !LayerWms.isResolutionRangeRestricted(minResolution, maxResolution)) { return true; } return resolution >= (minResolution ?? -1) && resolution <= (maxResolution ?? Infinity); } isVisibleAtResolution(resolution) { return LayerWms.isInVisibleRange(resolution, this.minResolution, this.maxResolution); } get hasFilter() { return this.filter !== null && this.filter !== undefined; } get hasTimeRestriction() { return !!this.timeRestriction; } setDefaultTimeRestriction() { if (this.timeOptions) { const timeFormatter = new LayerTimeFormatter(this.timeOptions); this.timeRestriction = timeFormatter.getFormattedDefault(); } } get serverUniqueQueryId() { return this.ogcServer.uniqueWmsQueryId; } get wfsQueryable() { return (this.queryable && this.ogcServer.wfsSupport && this.ogcServer.urlWfs !== undefined && this.queryLayers !== undefined); } get wmsQueryableOnly() { return this.queryable && !this.ogcServer.wfsSupport; } static isGMFTreeItem(options) { return 'id' in options; } static getOptionsFromGMFTreeItem(options) { const opts = { 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, minResolution: options.minResolutionHint, maxResolution: options.maxResolutionHint, layers: options.layers, style: options.style, legend: options.metadata?.legend, iconUrl: options.metadata?.iconUrl, legendRule: options.metadata?.legendRule, legendImage: options.metadata?.legendImage, isLegendExpanded: options.metadata?.isLegendExpanded, wasLegendExpanded: options.metadata?.wasLegendExpanded, printNativeAngle: options.metadata?.printNativeAngle, hiDPILegendImages: options.metadata?.hiDPILegendImages, time: options.time, snappingConfig: options.metadata?.snappingConfig, timeAttribute: options.metadata?.timeAttribute, enumeratedAttributes: options.metadata?.enumeratedAttributes }; if (options.childLayers) { opts.queryLayers = options.childLayers .filter((l) => l.queryable) .map((l) => l.name) .join(','); opts.queryLayersRanges = {}; options.childLayers.forEach((l) => { if (!l.queryable) { return; } if ((l.minResolutionHint && l.minResolutionHint !== 0) || (l.maxResolutionHint && l.maxResolutionHint !== 999999999)) { opts.queryLayersRanges[l.name] = { minResolution: l.minResolutionHint, maxResolution: l.maxResolutionHint }; } }); opts.queryable = opts.queryLayers.length > 0; } return opts; } static getDefaultWmsInfoFormat(serverOgc) { if (serverOgc.type === 'arcgis') { return 'application/geo+json'; } return 'application/vnd.ogc.gml'; } } __decorate([ BrainIgnore ], LayerWms.prototype, "ogcServer", void 0); export default LayerWms;