@geogirafe/lib-geoportal 1.3.0-dev.3018313151 → 1.3.0-dev.3053452205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/api/apigeogirafeapp.js +3 -1
- package/assets/i18n/de.json +1 -0
- package/assets/i18n/en.json +1 -0
- package/assets/i18n/fr.json +1 -0
- package/assets/i18n/it.json +1 -0
- package/assets/icons/streetview-marker-mapillary.svg +1 -0
- package/components/layout/component.d.ts +5 -0
- package/components/map-grid/component.d.ts +4 -0
- package/components/map-grid/component.js +6 -0
- package/components/print/tools/MFPEncoder.d.ts +22 -10
- package/components/print/tools/MFPEncoder.js +75 -43
- package/components/streetview/component.d.ts +9 -2
- package/components/streetview/component.js +20 -8
- package/components/streetview/google.js +1 -1
- package/components/streetview/mapillary.d.ts +8 -0
- package/components/streetview/mapillary.js +20 -0
- package/components/streetview/style.css +16 -0
- package/components/streetview/tools/googleprovider.js +9 -2
- package/components/streetview/tools/mapillaryprovider.d.ts +70 -0
- package/components/streetview/tools/mapillaryprovider.js +150 -0
- package/models/layers/grouplayer.d.ts +3 -3
- package/models/layers/grouplayer.js +5 -48
- package/package.json +1 -1
- package/templates/iframe.html +1 -0
- package/templates/index.html +1 -0
- package/templates/mobile.html +1 -0
- package/templates/public/about.json +1 -1
- package/tools/app/geogirafeapp-mobile.js +2 -0
- package/tools/app/geogirafeapp.js +2 -0
- package/tools/configuration/girafeconfig.js +1 -8
- package/tools/configuration/streetviewconfig.d.ts +12 -1
- package/tools/configuration/streetviewconfig.js +26 -4
- package/tools/main.d.ts +3 -2
- package/tools/main.js +1 -1
- package/tools/state/layout.d.ts +5 -0
- package/tools/state/layout.js +2 -1
- package/tools/state/streetview.d.ts +1 -1
- package/tools/state/streetview.js +1 -1
- package/tools/tests/wmswfsmanagermocking.d.ts +2 -2
- package/tools/tests/wmswfsmanagermocking.js +68 -61
- package/tools/wms/wmsclient.d.ts +164 -26
- package/tools/wms/wmsclient.js +415 -233
package/tools/wms/wmsclient.js
CHANGED
|
@@ -5,7 +5,12 @@ import WMSCapabilities from 'ol/format/WMSCapabilities.js';
|
|
|
5
5
|
import WMSGetFeatureInfo from 'ol/format/WMSGetFeatureInfo.js';
|
|
6
6
|
import GeoJSON from 'ol/format/GeoJSON.js';
|
|
7
7
|
import SelectionParam from '../../models/selectionparam.js';
|
|
8
|
-
import
|
|
8
|
+
import { debounce } from '../utils/debounce.js';
|
|
9
|
+
/**
|
|
10
|
+
* Abstract class for WMS client.
|
|
11
|
+
* This class is responsible for linking the WMS layers to OL layers on the map and
|
|
12
|
+
* more generally, to their linked OGC server.
|
|
13
|
+
*/
|
|
9
14
|
export default class WmsClient {
|
|
10
15
|
map;
|
|
11
16
|
ogcServer;
|
|
@@ -15,6 +20,15 @@ export default class WmsClient {
|
|
|
15
20
|
wmsGetFeatureInfo = new WMSGetFeatureInfo();
|
|
16
21
|
capabilityPromise = null;
|
|
17
22
|
capabilities = null;
|
|
23
|
+
basemapLayers = new Map();
|
|
24
|
+
groupedLayers = new Map();
|
|
25
|
+
debounceUpdateLayers = debounce(this.updateLayerDirect.bind(this), 20);
|
|
26
|
+
layersToUpdate = new Map();
|
|
27
|
+
constructor(ogcServer, map, context) {
|
|
28
|
+
this.ogcServer = ogcServer;
|
|
29
|
+
this.map = map;
|
|
30
|
+
this.context = context;
|
|
31
|
+
}
|
|
18
32
|
get state() {
|
|
19
33
|
return this.context.stateManager.state;
|
|
20
34
|
}
|
|
@@ -23,216 +37,372 @@ export default class WmsClient {
|
|
|
23
37
|
this.context.configManager.Config.gmfauth?.audienceExcludedPaths ??
|
|
24
38
|
[]);
|
|
25
39
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Add a new basemap layer to the map.
|
|
42
|
+
*/
|
|
43
|
+
addBasemapLayer(layerWms) {
|
|
44
|
+
const source = this.createImageWMSSource([layerWms]);
|
|
45
|
+
const oLayer = new ImageLayer({
|
|
46
|
+
source: source,
|
|
47
|
+
opacity: layerWms.opacity
|
|
48
|
+
});
|
|
49
|
+
// For basemap, set a minimal number (arbitrary defined to less than -5000)
|
|
50
|
+
oLayer.setZIndex(-5000 - layerWms.order);
|
|
51
|
+
this.basemapLayers.set(layerWms.treeItemId, {
|
|
52
|
+
layerWmsArray: [layerWms],
|
|
53
|
+
oLayer: oLayer
|
|
54
|
+
});
|
|
55
|
+
this.map.addLayer(oLayer);
|
|
40
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Remove every basemap layer from the map.
|
|
59
|
+
*/
|
|
41
60
|
removeAllBasemapLayers() {
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
const pairedLayers = Array.from(this.basemapLayers.values());
|
|
62
|
+
for (const { oLayer } of pairedLayers) {
|
|
63
|
+
this.map.removeLayer(oLayer);
|
|
44
64
|
}
|
|
45
|
-
this.basemapLayers
|
|
65
|
+
this.basemapLayers.clear();
|
|
46
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Add a new layer to the map.
|
|
69
|
+
* The expected "activeState" is already "on"!
|
|
70
|
+
* This is expected to be immediate.
|
|
71
|
+
*/
|
|
47
72
|
addLayer(layerWms) {
|
|
48
|
-
this.
|
|
49
|
-
this.manageLayerOptions(layerWms);
|
|
50
|
-
}
|
|
51
|
-
addLayerInternal(layerWms) {
|
|
52
|
-
this.layers.push(layerWms);
|
|
53
|
-
if (!this.olayer) {
|
|
54
|
-
// Create a new ol layer and add it to the right server
|
|
55
|
-
this.olayer = new ImageLayer();
|
|
56
|
-
// Set zindex for this new layer
|
|
57
|
-
// (The bigger the order is, the deeper in the map it should be displayed.)
|
|
58
|
-
// (order is the inverse of z-index)
|
|
59
|
-
this.olayer.setZIndex(-layerWms.order);
|
|
60
|
-
this.map.addLayer(this.olayer);
|
|
61
|
-
}
|
|
62
|
-
const source = this.createImageWMSSource();
|
|
63
|
-
this.olayer.setSource(source);
|
|
73
|
+
this.updateLayerDirect([layerWms]);
|
|
64
74
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Remove a layer from the map.
|
|
77
|
+
* The expected "activeState" is already "off"!
|
|
78
|
+
* This is expected to be immediate.
|
|
79
|
+
*/
|
|
80
|
+
removeLayer(layerWms) {
|
|
81
|
+
this.updateLayerDirect([layerWms]);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Change the opacity of layers on the map.
|
|
85
|
+
* This can come from a group of layers and will be delayed.
|
|
86
|
+
*/
|
|
87
|
+
changeOpacity(layerWms) {
|
|
88
|
+
this.updateLayerDebounced(layerWms);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Change the filter of a layer on the map.
|
|
92
|
+
*/
|
|
93
|
+
changeFilter(layerWms) {
|
|
94
|
+
this.updateLayerDirect([layerWms]);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Change the time restriction of layers on the map.
|
|
98
|
+
* This can come from a group of layers and will be delayed.
|
|
99
|
+
*/
|
|
100
|
+
changeTimeRestriction(layerWms) {
|
|
101
|
+
this.updateLayerDebounced(layerWms);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Change the Swiper of a layer on the map.
|
|
105
|
+
* This is expected to be immediate.
|
|
106
|
+
*/
|
|
107
|
+
prepareSwipe(layerWms) {
|
|
108
|
+
this.updateLayerDirect([layerWms]);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Refresh the Z-Index of every layer on the map.
|
|
112
|
+
*/
|
|
113
|
+
refreshZIndexes() {
|
|
114
|
+
// We don't have any information about what moved. Redo all groups.
|
|
115
|
+
const allWmsLayers = [];
|
|
116
|
+
Array.from(this.groupedLayers.keys()).forEach((groupKey) => {
|
|
117
|
+
const group = this.groupedLayers.get(groupKey);
|
|
118
|
+
allWmsLayers.push(...group.layerWmsArray);
|
|
119
|
+
this.removeGroupedLayers(groupKey);
|
|
89
120
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
121
|
+
this.updateLayerDirect(allWmsLayers);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @returns true if a matching (OL) layer exists on the map, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
layerExists(layerWms) {
|
|
127
|
+
const groupLayerInfo = this.findExistingGroupLayerInfo([layerWms]);
|
|
128
|
+
return !!(this.layerIsBasemapLayer(layerWms) || (groupLayerInfo && this.groupedLayers.get(groupLayerInfo)));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @returns the (OL) layer associated with the given layerWms if the layer exists on the map.
|
|
132
|
+
* The resulting layer MUST NOT be edited. Edit the model instead.
|
|
133
|
+
*/
|
|
134
|
+
getOLayer(layerWms) {
|
|
135
|
+
if (this.basemapLayers.has(layerWms.treeItemId)) {
|
|
136
|
+
return this.basemapLayers.get(layerWms.treeItemId)?.oLayer ?? null;
|
|
137
|
+
}
|
|
138
|
+
const groupLayerInfo = this.findExistingGroupLayerInfo([layerWms]);
|
|
139
|
+
if (groupLayerInfo) {
|
|
140
|
+
const pairedLayer = this.groupedLayers.get(groupLayerInfo);
|
|
141
|
+
if (pairedLayer) {
|
|
142
|
+
return pairedLayer.oLayer;
|
|
93
143
|
}
|
|
94
|
-
}
|
|
95
|
-
return
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
96
146
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
// For basemap, set a minimal number (arbitrary defined to less than -5000)
|
|
104
|
-
olayer.setZIndex(-5000 - layerWms.order);
|
|
105
|
-
this.basemapLayers[layerWms.treeItemId] = {
|
|
106
|
-
layerWms: layerWms,
|
|
107
|
-
olayer: olayer
|
|
108
|
-
};
|
|
109
|
-
this.map.addLayer(olayer);
|
|
147
|
+
/**
|
|
148
|
+
* @returns The array of LayerWms, indicating which layer are grouped together.
|
|
149
|
+
*/
|
|
150
|
+
getLayerWmsArrays() {
|
|
151
|
+
return Array.from(this.groupedLayers.values()).map((pairedLayer) => pairedLayer.layerWmsArray);
|
|
110
152
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Update layer but with a small debounce to wait on other layers with similar changes.
|
|
155
|
+
* Useful to update multiple layers at once and avoid multiple rendering
|
|
156
|
+
* of the (OL) layer (avoid a blinking effect).
|
|
157
|
+
* @param layerWms
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
updateLayerDebounced(layerWms) {
|
|
161
|
+
this.layersToUpdate.set(layerWms.treeItemId, layerWms);
|
|
162
|
+
this.debounceUpdateLayers(Array.from(this.layersToUpdate.values()));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Update layers directly, without debounce.
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
updateLayerDirect(layerWmsArray) {
|
|
169
|
+
this.layersToUpdate.clear();
|
|
170
|
+
// Sort the layer per order (z-index).
|
|
171
|
+
layerWmsArray.sort((lWms1, lWms2) => lWms1.order - lWms2.order);
|
|
172
|
+
// Make groups regarding the properties of the layers (opacity, filter, etc.).
|
|
173
|
+
// Follow the order to not group a layer to a group after another group with no similar properties (respect z-index)
|
|
174
|
+
let previousLayerInfo;
|
|
175
|
+
let groupedLayers = [];
|
|
176
|
+
const groupOfGroupedLayers = [];
|
|
177
|
+
layerWmsArray.forEach((lWms) => {
|
|
178
|
+
const layerInfo = this.getLayerWmsInfo(lWms);
|
|
179
|
+
if (previousLayerInfo && this.isLayerInfoIdentical(previousLayerInfo, layerInfo)) {
|
|
180
|
+
// Note BGE 29-10-2026: Ideally check also if the group is possible regarding the layers from another OGC server.
|
|
181
|
+
groupedLayers.push(lWms);
|
|
117
182
|
}
|
|
118
|
-
else
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
183
|
+
else {
|
|
184
|
+
previousLayerInfo = layerInfo;
|
|
185
|
+
groupedLayers = [lWms];
|
|
186
|
+
groupOfGroupedLayers.push(groupedLayers);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
// Update/create Ol layers for every group.
|
|
190
|
+
groupOfGroupedLayers.forEach((groupedLayersWms) => this.updateGroupedLayers(groupedLayersWms));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Update, change, or add new groups of layers (GroupLayerInfo => PairedLayers (OL and LayerWms)).
|
|
194
|
+
* @param layerWmsArray layerWms with the assumption that they can be grouped together.
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
updateGroupedLayers(layerWmsArray) {
|
|
198
|
+
const groupLayerInfo = this.findExistingGroupLayerInfo(layerWmsArray);
|
|
199
|
+
if (groupLayerInfo) {
|
|
200
|
+
// The layer already exists.
|
|
201
|
+
const pairedLayers = this.groupedLayers.get(groupLayerInfo);
|
|
202
|
+
const amountOfLayer = pairedLayers?.layerWmsArray.length ?? 0;
|
|
203
|
+
if (amountOfLayer === layerWmsArray.length) {
|
|
204
|
+
// The same number of layers is changed? Update the group.
|
|
205
|
+
this.updateLayerGroup(groupLayerInfo);
|
|
132
206
|
}
|
|
133
207
|
else {
|
|
134
|
-
|
|
208
|
+
// The number of layers is changed? Delete the group and add new layers.
|
|
209
|
+
this.deleteGroupsAndCallUpdateOnLayers(layerWmsArray);
|
|
135
210
|
}
|
|
136
211
|
}
|
|
137
212
|
else {
|
|
138
|
-
|
|
213
|
+
// The layer does not exist. Add new layers and regroup new groups.
|
|
214
|
+
this.addNewGroupedLayers(layerWmsArray);
|
|
215
|
+
this.regroupSameGroups();
|
|
139
216
|
}
|
|
140
217
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Find a GroupLayerInfo that matches at least one layer of the provided array.
|
|
220
|
+
* @returns The existing GroupLayerInfo (key of the list of existing layers) or undefined.
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
findExistingGroupLayerInfo(layerWmsArray) {
|
|
224
|
+
const layerWmsArrayTreeIds = new Set(layerWmsArray.map((layerWms) => layerWms.treeItemId));
|
|
225
|
+
const oLayers = Array.from(this.groupedLayers.keys());
|
|
226
|
+
return oLayers.find((oLayer) => this.groupedLayers.get(oLayer)?.layerWmsArray.some((lWms) => layerWmsArrayTreeIds.has(lWms.treeItemId)));
|
|
145
227
|
}
|
|
146
|
-
|
|
147
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Returns a LayerInfo (opacity, hasFilter, etc.) of a LayerWms.
|
|
230
|
+
* It's not possible to request multiple layer with a filter, therefore
|
|
231
|
+
* a unique string is passed as "hasFilter" info if the layer has an active
|
|
232
|
+
* filter on it.
|
|
233
|
+
* @returns the LayerInfo of a LayerWms.
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
getLayerWmsInfo(layerWms) {
|
|
237
|
+
return {
|
|
238
|
+
opacity: layerWms.opacity,
|
|
239
|
+
hasFilter: layerWms.hasFilter ? layerWms.treeItemId : undefined,
|
|
240
|
+
hasTimeRestriction: layerWms.timeRestriction,
|
|
241
|
+
swip: layerWms.swiped !== 'no'
|
|
242
|
+
};
|
|
148
243
|
}
|
|
149
|
-
|
|
150
|
-
|
|
244
|
+
/**
|
|
245
|
+
* @returns {boolean} Returns true if the two LayerInfo objects are identical; otherwise, false.
|
|
246
|
+
*/
|
|
247
|
+
isLayerInfoIdentical(layerInfo1, layerInfo2) {
|
|
248
|
+
return (layerInfo1.opacity === layerInfo2.opacity &&
|
|
249
|
+
layerInfo1.hasFilter === layerInfo2.hasFilter &&
|
|
250
|
+
layerInfo1.hasTimeRestriction === layerInfo2.hasTimeRestriction &&
|
|
251
|
+
layerInfo1.swip === layerInfo2.swip);
|
|
151
252
|
}
|
|
152
|
-
|
|
153
|
-
|
|
253
|
+
/**
|
|
254
|
+
* @returns {GroupLayerInfo} Returns a GroupLayerInfo object containing the LayerInfo and zIndexes.
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
257
|
+
getGroupedLayerInfo(layerWmsArray) {
|
|
258
|
+
layerWmsArray.sort((a, b) => a.order - b.order);
|
|
259
|
+
const layerInfo = this.getLayerWmsInfo(layerWmsArray[0]);
|
|
260
|
+
return {
|
|
261
|
+
...layerInfo,
|
|
262
|
+
zIndexes: layerWmsArray.map((layer) => layer.order),
|
|
263
|
+
names: layerWmsArray.map((layer) => layer.name)
|
|
264
|
+
};
|
|
154
265
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Deletes the group and remove the matching OL layer from the map.
|
|
268
|
+
* @private
|
|
269
|
+
*/
|
|
270
|
+
removeGroupedLayers(groupLayerInfo) {
|
|
271
|
+
const pairedLayers = this.groupedLayers.get(groupLayerInfo);
|
|
272
|
+
const oLayer = pairedLayers?.oLayer;
|
|
273
|
+
if (oLayer) {
|
|
274
|
+
this.map.removeLayer(oLayer);
|
|
164
275
|
}
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
changeOpacity(layerWms) {
|
|
168
|
-
this.manageLayerOptions(layerWms);
|
|
276
|
+
this.groupedLayers.delete(groupLayerInfo);
|
|
169
277
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Creates a new group, create and add an OL layer to the map.
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
addNewGroupedLayers(layerWmsArray) {
|
|
283
|
+
const newGroupedLayerInfo = this.getGroupedLayerInfo(layerWmsArray);
|
|
284
|
+
const activeLayers = layerWmsArray.filter((l) => l.active);
|
|
285
|
+
if (activeLayers.length === 0) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.groupedLayers.set(newGroupedLayerInfo, {
|
|
289
|
+
layerWmsArray: layerWmsArray,
|
|
290
|
+
oLayer: this.createOlLayer(activeLayers)
|
|
291
|
+
});
|
|
175
292
|
}
|
|
176
|
-
|
|
177
|
-
|
|
293
|
+
/**
|
|
294
|
+
* For all provided layers, delete the group and remove the matching OL layer from the map.
|
|
295
|
+
* Create then new groups (and new ol layers) with all layers in the impacted groups.
|
|
296
|
+
* @private
|
|
297
|
+
*/
|
|
298
|
+
deleteGroupsAndCallUpdateOnLayers(layerWmsArray) {
|
|
299
|
+
const allLayersToUpdate = new Map();
|
|
300
|
+
layerWmsArray.forEach((lWms) => {
|
|
301
|
+
allLayersToUpdate.set(lWms.treeItemId, lWms);
|
|
302
|
+
const groupLayerInfo = this.findExistingGroupLayerInfo([lWms]);
|
|
303
|
+
if (groupLayerInfo) {
|
|
304
|
+
const layersWmsFromGroup = this.groupedLayers.get(groupLayerInfo)?.layerWmsArray ?? [];
|
|
305
|
+
layersWmsFromGroup.forEach((lWmsFromGroup) => {
|
|
306
|
+
allLayersToUpdate.set(lWmsFromGroup.treeItemId, lWmsFromGroup);
|
|
307
|
+
});
|
|
308
|
+
this.removeGroupedLayers(groupLayerInfo);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
this.updateLayerDirect(Array.from(allLayersToUpdate.values()));
|
|
178
312
|
}
|
|
179
|
-
|
|
180
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Compare the LayerGroupInfo and the properties of the contained layer to update the OL layer.
|
|
315
|
+
* Then, update the LayerGroupInfo then to match again the state of the contained layers.
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
318
|
+
updateLayerGroup(groupLayerInfo) {
|
|
319
|
+
const pairedLayer = this.groupedLayers.get(groupLayerInfo);
|
|
320
|
+
const layerWms = pairedLayer?.layerWmsArray ?? [];
|
|
321
|
+
const firstLayerWms = layerWms[0];
|
|
322
|
+
if (!firstLayerWms || !pairedLayer) {
|
|
323
|
+
console.error('No layerWms found');
|
|
181
324
|
return;
|
|
182
325
|
}
|
|
183
|
-
|
|
184
|
-
|
|
326
|
+
const newGroupLayerInfo = this.getGroupedLayerInfo(layerWms);
|
|
327
|
+
if (groupLayerInfo.opacity !== newGroupLayerInfo.opacity) {
|
|
328
|
+
pairedLayer.oLayer.setOpacity(newGroupLayerInfo.opacity);
|
|
185
329
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// TODO SMS: if all layers share the same opacity, then mustBeIndependent can be false even if isTransparent is true.
|
|
189
|
-
// This will be changed in the future.
|
|
190
|
-
const mustBeIndependent = layerWms.hasFilter || layerWms.hasTimeRestriction || layerWms.isTransparent || layerWms.swiped !== 'no';
|
|
191
|
-
if (!isBasemapLayer) {
|
|
192
|
-
if (isLayerIndependent && !mustBeIndependent) {
|
|
193
|
-
const olayer = this.independentLayers[layerWms.treeItemId].olayer;
|
|
194
|
-
// We delete the layer from the transparent layers
|
|
195
|
-
delete this.independentLayers[layerWms.treeItemId];
|
|
196
|
-
this.map.removeLayer(olayer);
|
|
197
|
-
// And add it to the normal layer again
|
|
198
|
-
this.addLayerInternal(layerWms);
|
|
199
|
-
}
|
|
200
|
-
else if (!isLayerIndependent && mustBeIndependent) {
|
|
201
|
-
this.makeLayerIndependent(layerWms);
|
|
202
|
-
}
|
|
330
|
+
else if (groupLayerInfo.zIndexes[0] !== newGroupLayerInfo.zIndexes[0]) {
|
|
331
|
+
pairedLayer.oLayer.setZIndex(newGroupLayerInfo.zIndexes[0]);
|
|
203
332
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
333
|
+
else {
|
|
334
|
+
// Redo the group to be sure to handle the update.
|
|
335
|
+
this.removeGroupedLayers(groupLayerInfo);
|
|
336
|
+
this.addNewGroupedLayers(layerWms);
|
|
207
337
|
}
|
|
208
|
-
|
|
209
|
-
|
|
338
|
+
// Update the group key
|
|
339
|
+
if (this.groupedLayers.has(groupLayerInfo)) {
|
|
340
|
+
this.groupedLayers.delete(groupLayerInfo);
|
|
341
|
+
this.groupedLayers.set(newGroupLayerInfo, pairedLayer);
|
|
210
342
|
}
|
|
211
|
-
|
|
212
|
-
this.
|
|
343
|
+
// Regroup same groups if needed.
|
|
344
|
+
this.regroupSameGroups();
|
|
213
345
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Regroup same groups if needed.
|
|
348
|
+
* Iterate on every group in the order (z-index) and regroup consecutive groups sharing the same properties.
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
351
|
+
regroupSameGroups() {
|
|
352
|
+
const zIndexOrderedGroupLayers = Array.from(this.groupedLayers.keys()).sort((group1, group2) => group1.zIndexes[0] - group2.zIndexes[0]);
|
|
353
|
+
const layerWmsArrayToMerge = [];
|
|
354
|
+
const firstGroupLayerInfo = zIndexOrderedGroupLayers.shift();
|
|
355
|
+
if (!firstGroupLayerInfo) {
|
|
356
|
+
return;
|
|
217
357
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
358
|
+
const lastGroup = zIndexOrderedGroupLayers.reduce((previousGroupLayerInfo, groupLayerInfo) => {
|
|
359
|
+
const previousGroupWmsLayersArray = this.groupedLayers.get(previousGroupLayerInfo)?.layerWmsArray ?? [];
|
|
360
|
+
if (this.isLayerInfoIdentical(previousGroupLayerInfo, groupLayerInfo)) {
|
|
361
|
+
// Note BGE 29-10-2026: Ideally check also if the group is possible regarding the layers from another OGC server.
|
|
362
|
+
layerWmsArrayToMerge.push(...previousGroupWmsLayersArray);
|
|
363
|
+
this.removeGroupedLayers(previousGroupLayerInfo);
|
|
364
|
+
}
|
|
365
|
+
else if (layerWmsArrayToMerge.length) {
|
|
366
|
+
this.removeGroupedLayers(previousGroupLayerInfo);
|
|
367
|
+
this.addNewGroupedLayers([...layerWmsArrayToMerge, ...previousGroupWmsLayersArray]);
|
|
368
|
+
layerWmsArrayToMerge.length = 0;
|
|
369
|
+
}
|
|
370
|
+
return groupLayerInfo;
|
|
371
|
+
}, firstGroupLayerInfo);
|
|
372
|
+
if (layerWmsArrayToMerge.length && lastGroup) {
|
|
373
|
+
const lastGroupWmsLayersArray = this.groupedLayers.get(lastGroup)?.layerWmsArray ?? [];
|
|
374
|
+
this.removeGroupedLayers(lastGroup);
|
|
375
|
+
this.addNewGroupedLayers([...layerWmsArrayToMerge, ...lastGroupWmsLayersArray]);
|
|
229
376
|
}
|
|
230
|
-
|
|
231
|
-
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* @returns a newly created ol layer with the right properties and options.
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
createOlLayer(layerWms) {
|
|
383
|
+
const oLayer = new ImageLayer();
|
|
384
|
+
// Set zindex for this new layer
|
|
385
|
+
// (The bigger the order is, the deeper in the map it should be displayed.)
|
|
386
|
+
// (order is the inverse of z-index)
|
|
387
|
+
oLayer.setZIndex(-layerWms[0].order);
|
|
388
|
+
this.map.addLayer(oLayer);
|
|
389
|
+
const source = this.createImageWMSSource(layerWms);
|
|
390
|
+
oLayer.setSource(source);
|
|
391
|
+
this.manageLayerOptions(layerWms[0], oLayer);
|
|
392
|
+
return oLayer;
|
|
393
|
+
}
|
|
394
|
+
manageLayerOptions(layerWms, oLayer) {
|
|
395
|
+
if (layerWms.hasValidOpacity) {
|
|
396
|
+
oLayer.setOpacity(layerWms.opacity);
|
|
232
397
|
}
|
|
398
|
+
this.updateLayerFilter(layerWms, oLayer);
|
|
399
|
+
this.updateTimeRestriction(layerWms, oLayer);
|
|
400
|
+
}
|
|
401
|
+
layerIsBasemapLayer(layerWms) {
|
|
402
|
+
return this.basemapLayers.has(layerWms.treeItemId);
|
|
233
403
|
}
|
|
234
|
-
updateLayerFilter(layerWms,
|
|
235
|
-
const source =
|
|
404
|
+
updateLayerFilter(layerWms, oLayer) {
|
|
405
|
+
const source = oLayer.getSource();
|
|
236
406
|
if (layerWms.hasFilter) {
|
|
237
407
|
const filterStr = WmsClient.buildFilterQuery(layerWms);
|
|
238
408
|
source.updateParams({ FILTER: filterStr });
|
|
@@ -246,23 +416,10 @@ export default class WmsClient {
|
|
|
246
416
|
}
|
|
247
417
|
}
|
|
248
418
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
* QGIS-server wants 1 filter per underlying WFS queryLayer, each in its own in parentheses
|
|
252
|
-
*
|
|
253
|
-
* MapServer: (<filter>...</filter><filter>...</filter>)
|
|
254
|
-
* QGIS-server: (<filter>...</filter>)(<filter>...</filter>)
|
|
255
|
-
*/
|
|
256
|
-
static buildFilterQuery(layerWms) {
|
|
257
|
-
if (layerWms.ogcServer.type === 'qgisserver') {
|
|
258
|
-
return WmsClientQgis.buildFilterQuery(layerWms);
|
|
259
|
-
}
|
|
260
|
-
return WmsClientMapServer.buildFilterQuery(layerWms);
|
|
261
|
-
}
|
|
262
|
-
updateTimeRestriction(layerWms, olayer) {
|
|
263
|
-
const source = olayer.getSource();
|
|
419
|
+
updateTimeRestriction(layerWms, oLayer) {
|
|
420
|
+
const source = oLayer.getSource();
|
|
264
421
|
if (layerWms.hasTimeRestriction) {
|
|
265
|
-
|
|
422
|
+
oLayer.getSource().updateParams({ TIME: layerWms.timeRestriction });
|
|
266
423
|
}
|
|
267
424
|
else {
|
|
268
425
|
// If present, remove the time parameter
|
|
@@ -273,25 +430,56 @@ export default class WmsClient {
|
|
|
273
430
|
}
|
|
274
431
|
}
|
|
275
432
|
}
|
|
433
|
+
createImageWMSSource(layerList) {
|
|
434
|
+
const url = this.ogcServer.url;
|
|
435
|
+
const imageType = this.ogcServer.imageType;
|
|
436
|
+
const orderedLayers = layerList.slice().sort((l1, l2) => {
|
|
437
|
+
return l2.order - l1.order;
|
|
438
|
+
});
|
|
439
|
+
const orderedLayerNames = this.getOpenLayerLayerNames(orderedLayers);
|
|
440
|
+
const requestedUrl = new URL(url);
|
|
441
|
+
const shouldExclude = this.audienceExcludedPaths.some((pattern) => new RegExp(pattern).test(requestedUrl.pathname));
|
|
442
|
+
const crossOrigin = this.state.oauth.audience?.includes(requestedUrl.hostname) && !shouldExclude ? 'use-credentials' : 'anonymous';
|
|
443
|
+
const source = new ImageWMS({
|
|
444
|
+
url: url,
|
|
445
|
+
params: {
|
|
446
|
+
LAYERS: orderedLayerNames,
|
|
447
|
+
FORMAT: imageType
|
|
448
|
+
},
|
|
449
|
+
crossOrigin: crossOrigin
|
|
450
|
+
});
|
|
451
|
+
// We intercept the event to set an error icon if the WMS query has an error.
|
|
452
|
+
// Otherwise, we do not see anything on the client.
|
|
453
|
+
source.on('imageloaderror', () => {
|
|
454
|
+
for (const layerWms of layerList) {
|
|
455
|
+
this.context.layerManager.setError(layerWms, 'Image cannot be loaded from WMS Server');
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
source.on('imageloadend', () => {
|
|
459
|
+
for (const layerWms of layerList) {
|
|
460
|
+
this.context.layerManager.unsetError(layerWms);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
return source;
|
|
464
|
+
}
|
|
276
465
|
selectFeatures(extent) {
|
|
277
|
-
if (this.
|
|
466
|
+
if (this.groupedLayers.size === 0) {
|
|
278
467
|
return;
|
|
279
468
|
}
|
|
280
469
|
const selectionParams = [];
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
else {
|
|
285
|
-
// This will need a WMS GetFeatureInfo.
|
|
286
|
-
// In this case multiple layers are not allowed, and we have to create 1 selection param per layer
|
|
287
|
-
for (const layer of this.layers) {
|
|
288
|
-
selectionParams.push(new SelectionParam(this.ogcServer, [layer], this.state.projection, extent, this.olayer));
|
|
470
|
+
Array.from(this.groupedLayers.values()).forEach((pairedLayers) => {
|
|
471
|
+
if (this.ogcServer.wfsSupport) {
|
|
472
|
+
selectionParams.push(new SelectionParam(this.ogcServer, pairedLayers.layerWmsArray, this.state.projection, extent, pairedLayers.oLayer));
|
|
289
473
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
474
|
+
else {
|
|
475
|
+
// No WFS support.
|
|
476
|
+
// This will need a WMS GetFeatureInfo.
|
|
477
|
+
// In this case multiple layers are not allowed, and we have to create 1 selection param per layer
|
|
478
|
+
for (const layerWms of pairedLayers.layerWmsArray) {
|
|
479
|
+
selectionParams.push(new SelectionParam(this.ogcServer, [layerWms], this.state.projection, extent, pairedLayers.oLayer));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
295
483
|
this.state.selection.selectionParameters.push(...selectionParams);
|
|
296
484
|
}
|
|
297
485
|
/**
|
|
@@ -299,11 +487,9 @@ export default class WmsClient {
|
|
|
299
487
|
*/
|
|
300
488
|
selectFeaturesByQuery(query) {
|
|
301
489
|
const selectionParams = [];
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
selectionParams.push(new SelectionParam(this.ogcServer, [indepLayer.layerWms], this.state.projection, undefined, indepLayer.olayer, query));
|
|
306
|
-
}
|
|
490
|
+
Array.from(this.groupedLayers.values()).forEach((pairedLayers) => {
|
|
491
|
+
selectionParams.push(new SelectionParam(this.ogcServer, pairedLayers.layerWmsArray, this.state.projection, undefined, pairedLayers.oLayer, query));
|
|
492
|
+
});
|
|
307
493
|
this.state.selection.selectionParameters.push(...selectionParams);
|
|
308
494
|
}
|
|
309
495
|
async getFeatureInfo(selectionParam) {
|
|
@@ -367,23 +553,6 @@ export default class WmsClient {
|
|
|
367
553
|
});
|
|
368
554
|
return features;
|
|
369
555
|
}
|
|
370
|
-
refreshZIndexes() {
|
|
371
|
-
// Recalculate source for Layers
|
|
372
|
-
if (this.layers.length > 0) {
|
|
373
|
-
// TODO: openLayer zindex = -order of the last layer in this.layers? not consistent: to improve?
|
|
374
|
-
for (const layerWms of this.layers) {
|
|
375
|
-
const zindex = -layerWms.order;
|
|
376
|
-
this.olayer.setZIndex(zindex);
|
|
377
|
-
}
|
|
378
|
-
const source = this.createImageWMSSource(this.layers);
|
|
379
|
-
this.olayer.setSource(source);
|
|
380
|
-
}
|
|
381
|
-
// Manage independant layers
|
|
382
|
-
for (const obj of Object.values(this.independentLayers)) {
|
|
383
|
-
const zindex = -obj.layerWms.order;
|
|
384
|
-
obj.olayer.setZIndex(zindex);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
556
|
async getWmsCapabilities(params) {
|
|
388
557
|
if (this.capabilityPromise !== null) {
|
|
389
558
|
return this.capabilityPromise;
|
|
@@ -414,9 +583,23 @@ export default class WmsClient {
|
|
|
414
583
|
})();
|
|
415
584
|
return this.capabilityPromise;
|
|
416
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
* MapServer wants 1 filter per underlying WFS queryLayer, all included in parentheses
|
|
588
|
+
* QGIS server wants 1 filter per underlying WFS queryLayer, each in its own in parentheses
|
|
589
|
+
*
|
|
590
|
+
* MapServer: (<filter>...</filter><filter>...</filter>)
|
|
591
|
+
* QGIS-server: (<filter>...</filter>)(<filter>...</filter>)
|
|
592
|
+
*/
|
|
593
|
+
static buildFilterQuery(layerWms) {
|
|
594
|
+
if (layerWms.ogcServer.type === 'qgisserver') {
|
|
595
|
+
return WmsClientQgis.buildFilterQuery(layerWms);
|
|
596
|
+
}
|
|
597
|
+
return WmsClientMapServer.buildFilterQuery(layerWms);
|
|
598
|
+
}
|
|
417
599
|
}
|
|
418
600
|
export class WmsClientQgis extends WmsClient {
|
|
419
|
-
/**
|
|
601
|
+
/**
|
|
602
|
+
* QGIS server does not filter on a WMS layer made from multiple underlying WFS queryLayers
|
|
420
603
|
* Solution: directly query the queryLayers
|
|
421
604
|
*/
|
|
422
605
|
getOpenLayerLayerNames(layerList) {
|
|
@@ -426,8 +609,7 @@ export class WmsClientQgis extends WmsClient {
|
|
|
426
609
|
return layerNames;
|
|
427
610
|
}
|
|
428
611
|
else {
|
|
429
|
-
|
|
430
|
-
return layerNames;
|
|
612
|
+
return layerList.map((l) => l.layers ?? l.name);
|
|
431
613
|
}
|
|
432
614
|
}
|
|
433
615
|
static buildFilterQuery(layerWms) {
|
|
@@ -435,8 +617,8 @@ export class WmsClientQgis extends WmsClient {
|
|
|
435
617
|
return '';
|
|
436
618
|
}
|
|
437
619
|
const filter = layerWms.filter;
|
|
438
|
-
const
|
|
439
|
-
return ('(' + filter.toWmsGetMapFilter() + ')').repeat(
|
|
620
|
+
const nbQueryLayers = layerWms.queryLayers.split(',').length;
|
|
621
|
+
return ('(' + filter.toWmsGetMapFilter() + ')').repeat(nbQueryLayers);
|
|
440
622
|
}
|
|
441
623
|
}
|
|
442
624
|
export class WmsClientMapServer extends WmsClient {
|
|
@@ -448,8 +630,8 @@ export class WmsClientMapServer extends WmsClient {
|
|
|
448
630
|
return '';
|
|
449
631
|
}
|
|
450
632
|
const filter = layerWms.filter;
|
|
451
|
-
const
|
|
452
|
-
return '(' + filter.toWmsGetMapFilter().repeat(
|
|
633
|
+
const nbQueryLayers = layerWms.queryLayers.split(',').length;
|
|
634
|
+
return '(' + filter.toWmsGetMapFilter().repeat(nbQueryLayers) + ')';
|
|
453
635
|
}
|
|
454
636
|
}
|
|
455
637
|
export const WmsClientDefault = WmsClientQgis;
|