@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
262 lines (261 loc) • 10 kB
JavaScript
import LayerTimeFormatter from '../../tools/time/layertimeformatter';
import Layer from './layer';
class LayerWms extends Layer {
constructor(id, name, order, ogcServer, options) {
let opts = options ?? {};
opts = LayerWms.isGMFTreeItem(opts) ? LayerWms.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
*/
// Base WMS attributes
Object.defineProperty(this, "ogcServer", {
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, "layers", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "style", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
// Legend attributes
Object.defineProperty(this, "legend", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "iconUrl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "legendRule", {
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
});
Object.defineProperty(this, "hiDPILegendImages", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "printNativeAngle", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
}); // TODO BGE Is it correct to have it at this level (should be for groups) ?
// If the layer is queryable
Object.defineProperty(this, "queryable", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
Object.defineProperty(this, "queryLayers", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "filter", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "timeOptions", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "timeRestriction", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "timeAttribute", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "editable", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
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.queryLayers = opts?.queryLayers;
this.timeOptions = opts?.time;
this.timeAttribute = opts?.timeAttribute;
this.editable = opts?.editable;
if (this.queryable && (!this.ogcServer.wfsSupport || this.ogcServer.urlWfs?.length === 0)) {
this.hasError = true;
this.errorMessage = 'This layer is defined as queryable but no Url for Wfs has been defined.';
this.queryable = false;
}
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,
protected: this.protected,
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,
time: this.timeOptions,
timeAttribute: this.timeAttribute,
editable: this.editable
};
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;
}
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);
}
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 && Boolean(this.ogcServer?.urlWfs && this.queryLayers);
}
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: 1, // TODO REG : Set default opacity
protected: options.metadata?.protected,
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,
timeAttribute: options.metadata?.timeAttribute
};
if (options.childLayers) {
opts.queryLayers = options.childLayers
.filter((l) => l.queryable)
.map((l) => l.name)
.join(',');
opts.queryable = opts.queryLayers.length > 0;
}
return opts;
}
}
export default LayerWms;