@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
82 lines (81 loc) • 3.19 kB
JavaScript
import SelectionParam from '../../../models/selectionparam.js';
import { WebMapServiceImageryProvider, ImageryLayer } from 'cesium';
export default class WmsManager3d {
context;
map3d;
baseLayers = [];
// Group maps from the same server into one ImageryLayer
layersRecord = {};
constructor(map3d, context) {
this.map3d = map3d;
this.context = context;
}
removeAllBasemapLayers() {
this.baseLayers.forEach((layer) => this.map3d.imageryLayers.remove(layer));
this.baseLayers = [];
}
addLayer(layerWms) {
if (!(layerWms.serverUniqueQueryId in this.layersRecord)) {
this.layersRecord[layerWms.serverUniqueQueryId] = [];
}
const newImagery = this.newImagery(layerWms.ogcServer.url, layerWms.layers);
this.layersRecord[layerWms.serverUniqueQueryId].push({
layers: layerWms,
imagery: newImagery
});
this.map3d.imageryLayers.add(newImagery);
}
addBasemapLayer(layerWms) {
this.baseLayers.push(this.newImagery(layerWms.ogcServer.url, layerWms.layers));
}
newImagery(url, layers, format = 'image/png') {
return new ImageryLayer(new WebMapServiceImageryProvider({
url: url,
layers: layers,
parameters: {
transparent: true,
format: format
},
tileWidth: 4096,
tileHeight: 4096
}));
}
removeLayer(layerWms) {
const layersEntry = this.layersRecord[layerWms.serverUniqueQueryId];
if (layersEntry != undefined) {
this.map3d.imageryLayers.remove(layersEntry.filter((l) => l.layers === layerWms)[0].imagery);
this.layersRecord[layerWms.serverUniqueQueryId] = layersEntry.filter((l) => l.layers !== layerWms);
}
}
layerExists(layerWms) {
if (layerWms.serverUniqueQueryId in this.layersRecord) {
const layerDef = this.layersRecord[layerWms.serverUniqueQueryId];
const layer = layerDef.find((l) => l.layers.treeItemId === layerWms.treeItemId);
return layer !== undefined;
}
return false;
}
changeOpacity(layerWms) {
this.#manageLayerOptions(layerWms);
}
changeFilter(layerWms) {
this.#manageLayerOptions(layerWms);
}
#manageLayerOptions(layerWms) {
if (!this.layerExists(layerWms)) {
throw new Error('Cannot change filter for this layer: it does not exist');
}
const layersEntry = this.layersRecord[layerWms.serverUniqueQueryId];
const imagery = layersEntry.filter((l) => l.layers === layerWms)[0].imagery;
imagery.alpha = layerWms.opacity;
}
selectFeatures(extent) {
const state = this.context.stateManager.state;
const selectionParams = [];
for (const key in this.layersRecord) {
const layerDef = this.layersRecord[key];
selectionParams.push(new SelectionParam(layerDef[0].layers.ogcServer, layerDef.map((l) => l.layers), state.projection, extent));
}
state.selection.selectionParameters.push(...selectionParams);
}
}