@opengeoweb/webmap 4.10.0 → 4.12.0

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/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('throttle-debounce'), require('moment'), require('proj4')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'throttle-debounce', 'moment', 'proj4'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Webmap = {}, global.throttleDebounce, global.moment, global.proj4));
5
- })(this, (function (exports, throttleDebounce, moment, proj4) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('throttle-debounce'), require('lodash'), require('moment'), require('proj4')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'throttle-debounce', 'lodash', 'moment', 'proj4'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Webmap = {}, global.throttleDebounce, global.lodash, global.moment, global.proj4));
5
+ })(this, (function (exports, throttleDebounce, lodash, moment, proj4) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -82,6 +82,18 @@
82
82
  return __assign.apply(this, arguments);
83
83
  };
84
84
 
85
+ function __rest(s, e) {
86
+ var t = {};
87
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
88
+ t[p] = s[p];
89
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
90
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
91
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
92
+ t[p[i]] = s[p[i]];
93
+ }
94
+ return t;
95
+ }
96
+
85
97
  function __values(o) {
86
98
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
87
99
  if (m) return m.call(o);
@@ -121,22 +133,6 @@
121
133
  return to.concat(ar || Array.prototype.slice.call(from));
122
134
  }
123
135
 
124
- /* *
125
- * Licensed under the Apache License, Version 2.0 (the "License");
126
- * you may not use this file except in compliance with the License.
127
- * You may obtain a copy of the License at
128
- *
129
- * http://www.apache.org/licenses/LICENSE-2.0
130
- *
131
- * Unless required by applicable law or agreed to in writing, software
132
- * distributed under the License is distributed on an "AS IS" BASIS,
133
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134
- * See the License for the specific language governing permissions and
135
- * limitations under the License.
136
- *
137
- * Copyright 2020 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
138
- * Copyright 2020 - Finnish Meteorological Institute (FMI)
139
- * */
140
136
  /* debug helper */
141
137
 
142
138
  var enableConsoleDebugging = false;
@@ -170,20 +166,6 @@
170
166
 
171
167
  return true;
172
168
  };
173
- /**
174
- * Checks if a variable is null or not
175
- * @param variable The variable to check
176
- * @returns true if variable is indeed null, otherwise false.
177
- */
178
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
179
-
180
- var isNull = function isNull(variable) {
181
- if (variable === null) {
182
- return true;
183
- }
184
-
185
- return false;
186
- };
187
169
  /**
188
170
  * Converts a variable to an array. If the variable is not an array it will be pushed as the first entry in a new array. If the variable is already an array, nothing will be done.
189
171
  * @param array The variable to convert
@@ -440,14 +422,27 @@
440
422
  var addDimensionsForLayer = function addDimensionsForLayer(layerObjectFromWMS) {
441
423
  if (!layerObjectFromWMS.Dimension) return [];
442
424
  var layerDimensions = toArray(layerObjectFromWMS.Dimension);
443
- var list = layerDimensions.map(function (layerDimension) {
425
+ var layerDimensionsExtents = toArray(layerObjectFromWMS.Extent);
426
+ var dimensionList = layerDimensions.map(function (layerDimension) {
427
+ var dimensionName = layerDimension.attr && layerDimension.attr.name.toLowerCase();
428
+ /* Find corresponding Dimension Extent if given */
429
+
430
+ var dimExtentIndex = layerDimensionsExtents.findIndex(function (layerDimensionsExtent) {
431
+ var extentName = layerDimensionsExtent.attr && layerDimensionsExtent.attr.name && layerDimensionsExtent.attr.name.toLowerCase();
432
+ return dimensionName === extentName;
433
+ });
434
+ var dimExtent = dimExtentIndex !== -1 ? layerDimensionsExtents[dimExtentIndex] : null;
435
+ var dimensionValues = dimExtent && dimExtent.value || layerDimension.value || '';
436
+ var dimensionCurrentValue = dimExtent && dimExtent.attr && dimExtent.attr["default"] || layerDimension.attr["default"] || '';
444
437
  return {
445
- name: layerDimension.attr.name,
438
+ name: dimensionName,
446
439
  units: layerDimension.attr.units,
447
- currentValue: layerDimension.value
440
+ currentValue: dimensionCurrentValue.trim(),
441
+ unitSymbol: layerDimension.attr.unitSymbol,
442
+ values: dimensionValues.trim()
448
443
  };
449
444
  });
450
- return list;
445
+ return dimensionList;
451
446
  };
452
447
  var addBoundingBoxForLayer = function addBoundingBoxForLayer(layerObjectFromWMS) {
453
448
  var _a, _b, _c, _d;
@@ -455,10 +450,10 @@
455
450
  if (layerObjectFromWMS.EX_GeographicBoundingBox) {
456
451
  var layerBbox = layerObjectFromWMS.EX_GeographicBoundingBox;
457
452
  return {
458
- east: ((_a = layerBbox.eastBoundLongitude) === null || _a === void 0 ? void 0 : _a.value) || null,
459
- west: ((_b = layerBbox.westBoundLongitude) === null || _b === void 0 ? void 0 : _b.value) || null,
460
- north: ((_c = layerBbox.northBoundLatitude) === null || _c === void 0 ? void 0 : _c.value) || null,
461
- south: ((_d = layerBbox.southBoundLatitude) === null || _d === void 0 ? void 0 : _d.value) || null
453
+ east: (_a = layerBbox.eastBoundLongitude) === null || _a === void 0 ? void 0 : _a.value,
454
+ west: (_b = layerBbox.westBoundLongitude) === null || _b === void 0 ? void 0 : _b.value,
455
+ north: (_c = layerBbox.northBoundLatitude) === null || _c === void 0 ? void 0 : _c.value,
456
+ south: (_d = layerBbox.southBoundLatitude) === null || _d === void 0 ? void 0 : _d.value
462
457
  };
463
458
  }
464
459
 
@@ -474,6 +469,157 @@
474
469
 
475
470
  return undefined;
476
471
  };
472
+ /**
473
+ * Sorts an array with objects by object key.
474
+ *
475
+ * @param array Array of objects
476
+ * @param key The key of the object to use for sorting
477
+ * @returns Sorted array.
478
+ */
479
+
480
+ function sortArrayOfObjectsByKey(array, key) {
481
+ var spreadArray = __spreadArray([], __read(array));
482
+
483
+ return spreadArray.sort(function (a, b) {
484
+ var x = a[key];
485
+ var y = b[key];
486
+ if (x < y) return -1;
487
+ if (x > y) return 1;
488
+ return 0;
489
+ });
490
+ }
491
+ /**
492
+ * A LayerTree with deeply nested children will be flattened into a 1D array. Children properties are removed and result is sorted alphabetically by the layers title.
493
+ * @param layerTree a WMS LayerTree
494
+ * @returns Flat array of layers as LayerProps[]
495
+ */
496
+
497
+ var flattenLayerTree = function flattenLayerTree(layerTree) {
498
+ var omit = function omit(prop, _a) {
499
+ var _b = prop;
500
+ _a[_b];
501
+ var rest = __rest(_a, [_typeof(_b) === "symbol" ? _b : _b + ""]);
502
+
503
+ return rest;
504
+ };
505
+
506
+ var recurseLayerTree = function recurseLayerTree(data) {
507
+ return data && Array.isArray(data) ? data.reduce(function (acc, item) {
508
+ item.name && acc.push(omit('children', item));
509
+ item.children && acc.push.apply(acc, __spreadArray([], __read(recurseLayerTree(item.children))));
510
+ return acc;
511
+ }, []) : [];
512
+ };
513
+
514
+ var flatLayerObject = recurseLayerTree(layerTree.children);
515
+ return sortArrayOfObjectsByKey(flatLayerObject, 'title');
516
+ };
517
+ /**
518
+ * Makes a LayerProps object from the WMSLayerFromGetCapabilities and nestedLayerPath
519
+ * @param layer WMSLayerFromGetCapabilities
520
+ * @param path The path of the layer in the WMS GetCapabilities tree (Array of strings)
521
+ * @param isleaf Is this a group layer or an actual layer
522
+ * @param nestedLayerPath The path of the layer in the WMS GetCapabilities, in this case array of LayerProps
523
+ * @returns
524
+ */
525
+
526
+ var makeNodeLayerFromWMSGetCapabilityLayer = function makeNodeLayerFromWMSGetCapabilityLayer(layer, path, isleaf, nestedLayerPath) {
527
+ if (path === void 0) {
528
+ path = [];
529
+ }
530
+
531
+ if (isleaf === void 0) {
532
+ isleaf = false;
533
+ }
534
+
535
+ if (nestedLayerPath === void 0) {
536
+ nestedLayerPath = [];
537
+ }
538
+
539
+ var geographicBoundingBox = nestedLayerPath.reverse().reduce(function (p, c) {
540
+ return p || c.geographicBoundingBox;
541
+ }, addBoundingBoxForLayer(layer));
542
+ var dimensions = nestedLayerPath.reverse().reduce(function (p, c) {
543
+ if (p && Array.isArray(p) && p.length > 0) {
544
+ return p;
545
+ }
546
+
547
+ return c.dimensions || [];
548
+ }, addDimensionsForLayer(layer));
549
+ var styles = nestedLayerPath.reverse().reduce(function (p, c) {
550
+ if (c.styles && Array.isArray(c.styles) && c.styles.length) {
551
+ return c.styles.concat(p);
552
+ }
553
+
554
+ return p;
555
+ }, addStylesForLayer(layer));
556
+ var queryable = layer.attr ? parseInt(layer.attr.queryable, 10) === 1 : false;
557
+ var crs = layer.BoundingBox && Array.isArray(layer.BoundingBox) && layer.BoundingBox.length ? lodash.compact(layer.BoundingBox.map(function (wmsBBOX) {
558
+ if (wmsBBOX.attr) {
559
+ var crsName = wmsBBOX.attr.CRS || wmsBBOX.attr.SRS;
560
+ return {
561
+ name: crsName,
562
+ bbox: {
563
+ left: parseFloat(wmsBBOX.attr.minx),
564
+ right: parseFloat(wmsBBOX.attr.maxx),
565
+ bottom: parseFloat(wmsBBOX.attr.miny),
566
+ top: parseFloat(wmsBBOX.attr.maxy)
567
+ }
568
+ };
569
+ }
570
+
571
+ return undefined;
572
+ })) : [];
573
+ return {
574
+ name: layer.Name ? layer.Name.value : null,
575
+ title: layer.Title ? layer.Title.value : 'Layer',
576
+ leaf: isleaf,
577
+ path: path,
578
+ keywords: toArray(layer.KeywordList && layer.KeywordList.Keyword).map(function (keywords) {
579
+ return keywords.value;
580
+ }),
581
+ "abstract": layer.Abstract ? layer.Abstract.value : undefined,
582
+ styles: styles,
583
+ dimensions: dimensions,
584
+ geographicBoundingBox: geographicBoundingBox,
585
+ queryable: queryable,
586
+ crs: crs
587
+ };
588
+ };
589
+ /**
590
+ * Builds a standardized LayerTree object based on WMSLayerFromGetCapabilities object.
591
+ * @param wmsLayer The WMSLayerFromGetCapabilities object
592
+ * @param nestedPath - Optional, only to be used by buildLayerTreeFromNestedWMSLayer
593
+ * @param nestedLayerPath - Optional, only to be used by buildLayerTreeFromNestedWMSLayer
594
+ * @returns A LayerTree object.
595
+ */
596
+
597
+ var buildLayerTreeFromNestedWMSLayer = function buildLayerTreeFromNestedWMSLayer(wmsLayer, nestedPath, nestedLayerPath) {
598
+ if (nestedPath === void 0) {
599
+ nestedPath = [];
600
+ }
601
+
602
+ if (nestedLayerPath === void 0) {
603
+ nestedLayerPath = [];
604
+ }
605
+
606
+ var isleaf = wmsLayer.Name && !wmsLayer.Layer;
607
+ var layerProps = makeNodeLayerFromWMSGetCapabilityLayer(wmsLayer, nestedPath, isleaf, nestedLayerPath);
608
+ var pathName = wmsLayer.Title && wmsLayer.Title.value || '';
609
+
610
+ var layerTree = __assign(__assign({}, layerProps), {
611
+ children: []
612
+ });
613
+
614
+ if (wmsLayer.Layer) {
615
+ var childLayers = wmsLayer.Layer['length'] ? wmsLayer.Layer : [wmsLayer.Layer];
616
+ layerTree.children = sortArrayOfObjectsByKey(childLayers.map(function (layerChild) {
617
+ return buildLayerTreeFromNestedWMSLayer(layerChild, __spreadArray(__spreadArray([], __read(nestedPath)), [pathName]), __spreadArray(__spreadArray([], __read(nestedLayerPath)), [layerProps]));
618
+ }), 'title');
619
+ }
620
+
621
+ return layerTree;
622
+ };
477
623
 
478
624
  /* *
479
625
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -1070,7 +1216,7 @@
1070
1216
 
1071
1217
  WMBBOX.prototype.setBBOX = function (left, bottom, right, top) {
1072
1218
  /* Check if we recieve more than one parameter by checking the second bottom parameter. */
1073
- if (bottom) {
1219
+ if (bottom !== undefined) {
1074
1220
  this.left = left; // -180; // 0
1075
1221
 
1076
1222
  this.bottom = bottom; // -90; // 1`
@@ -1082,7 +1228,7 @@
1082
1228
  /* Check if we recieve more than one parameter by checking the second bottom parameter. */
1083
1229
 
1084
1230
 
1085
- if (!bottom) {
1231
+ if (bottom === undefined) {
1086
1232
  /* Otherwise it can be a bbox object or a string in the form "left,bottom,right,top" */
1087
1233
  if (_typeof(left) === 'object') {
1088
1234
  /* A bbox object is given, so it is not a string */
@@ -7638,63 +7784,6 @@
7638
7784
  }, WMServiceStoreXML2JSONRequest.proxy);
7639
7785
  });
7640
7786
  };
7641
- var sortByKey = function sortByKey(array, key) {
7642
- return array.sort(function (a, b) {
7643
- var x = a[key];
7644
- var y = b[key];
7645
- if (x < y) return -1;
7646
- if (x > y) return 1;
7647
- return 0;
7648
- });
7649
- };
7650
- var recursivelyFindLayer = function recursivelyFindLayer( // eslint-disable-next-line @typescript-eslint/no-explicit-any
7651
- layers, // eslint-disable-next-line @typescript-eslint/no-explicit-any
7652
- rootNode, path) {
7653
- for (var j = 0; j < layers.length; j += 1) {
7654
- var isleaf = false;
7655
- if (layers[j].Name) isleaf = true;
7656
-
7657
- try {
7658
- if (layers[j].Layer) isleaf = false;
7659
- } catch (e) {// do nothing
7660
- }
7661
-
7662
- var nodeObject = void 0;
7663
-
7664
- if (layers[j].Name) {
7665
- nodeObject = {
7666
- name: layers[j].Name.value,
7667
- title: layers[j].Title.value,
7668
- leaf: isleaf,
7669
- path: path,
7670
- keywords: toArray(layers[j].KeywordList && layers[j].KeywordList.Keyword).map(function (keywords) {
7671
- return keywords.value;
7672
- }),
7673
- "abstract": layers[j].Abstract && layers[j].Abstract.value,
7674
- styles: addStylesForLayer(layers[j]),
7675
- dimensions: addDimensionsForLayer(layers[j]),
7676
- geographicBoundingBox: addBoundingBoxForLayer(layers[j])
7677
- };
7678
- } else {
7679
- var nodeText = isNull(layers[j].Title) ? 'Layer' : layers[j].Title.value;
7680
- nodeObject = {
7681
- title: nodeText,
7682
- leaf: isleaf,
7683
- styles: []
7684
- };
7685
- }
7686
-
7687
- rootNode.push(nodeObject);
7688
-
7689
- if (layers[j].Layer) {
7690
- nodeObject.children = [];
7691
- recursivelyFindLayer(toArray(layers[j].Layer), nodeObject.children, __spreadArray(__spreadArray([], __read(path)), [layers[j].Title.value]));
7692
- }
7693
- } // Sort nodes alphabetically.
7694
-
7695
-
7696
- sortByKey(rootNode, 'title');
7697
- };
7698
7787
  var generatedServiceIds = 0;
7699
7788
 
7700
7789
  var generateWMJSServiceId = function generateWMJSServiceId() {
@@ -7845,7 +7934,8 @@
7845
7934
  */
7846
7935
 
7847
7936
 
7848
- WMJSService.prototype.getCapabilities = function (succescallback, failcallback, forceReload, options) {
7937
+ WMJSService.prototype.getCapabilities = function (succescallback, failcallback, forceReload, // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
7938
+ options) {
7849
7939
  var _this = this;
7850
7940
 
7851
7941
  if (options) {
@@ -7991,15 +8081,6 @@
7991
8081
  }
7992
8082
 
7993
8083
  var parse = function parse(jsonData) {
7994
- var nodeStructure = {
7995
- leaf: false,
7996
- expanded: true,
7997
- children: [],
7998
- title: '',
7999
- keywords: [],
8000
- "abstract": ''
8001
- };
8002
-
8003
8084
  var rootLayer = _this.getCapabilityElement(jsonData).Layer;
8004
8085
 
8005
8086
  try {
@@ -8009,16 +8090,8 @@
8009
8090
  return;
8010
8091
  }
8011
8092
 
8012
- var WMSLayers = toArray(rootLayer.Layer);
8013
-
8014
- try {
8015
- nodeStructure.title = rootLayer.Title.value;
8016
- } catch (e) {
8017
- nodeStructure.title = I18n.unnamed_service.text;
8018
- }
8019
-
8020
- recursivelyFindLayer(WMSLayers, nodeStructure.children, []);
8021
- succes(nodeStructure);
8093
+ var layerTreeStructure = buildLayerTreeFromNestedWMSLayer(rootLayer);
8094
+ succes(layerTreeStructure);
8022
8095
  };
8023
8096
 
8024
8097
  var callback = function callback(jsonData) {
@@ -8048,22 +8121,8 @@
8048
8121
  return;
8049
8122
  }
8050
8123
 
8051
- var callback = function callback(data) {
8052
- _this._flatLayerObject = [];
8053
-
8054
- var getNames = function getNames(layers) {
8055
- for (var j = 0; j < layers.length; j += 1) {
8056
- if (layers[j].name) {
8057
- _this._flatLayerObject.push(layers[j]);
8058
- }
8059
-
8060
- if (layers[j].children) {
8061
- getNames(layers[j].children);
8062
- }
8063
- }
8064
- };
8065
-
8066
- getNames(data.children);
8124
+ var callback = function callback(layerTree) {
8125
+ _this._flatLayerObject = flattenLayerTree(layerTree);
8067
8126
  succes(_this._flatLayerObject);
8068
8127
  };
8069
8128
 
@@ -8135,57 +8194,23 @@
8135
8194
  */
8136
8195
 
8137
8196
 
8138
- var addDimsForLayer = function addDimsForLayer(layerObjectFromWMS, layer, layerDimNamesToRemove) {
8197
+ var addDimsForLayer = function addDimsForLayer(layerProps, layer, layerDimNamesToRemove) {
8139
8198
  /* Information from the WMS GetCapabilities document */
8140
- var layerDims = toArray(layerObjectFromWMS.Dimension);
8141
- var layerDimExtents = toArray(layerObjectFromWMS.Extent);
8199
+ var layerDims = layerProps.dimensions || [];
8142
8200
 
8143
8201
  var _loop_1 = function _loop_1(d) {
8144
8202
  /* Obtain layerDim info from the GetCapabilities document and put into a WMSLayerDimInfo object */
8145
- var dimAttributes = layerDims[d].attr;
8203
+ var dimName = (layerDims[d].name || '').toLowerCase();
8146
8204
  var layerDim = {
8147
- name: dimAttributes.name.toLowerCase(),
8148
- units: dimAttributes.units,
8149
- unitSymbol: dimAttributes.unitSymbol,
8150
- value: layerDims[d].value,
8151
- "default": dimAttributes["default"],
8152
- isRefTimeDimension: dimAttributes.name.toLowerCase() === 'reference_time'
8205
+ name: dimName,
8206
+ units: layerDims[d].units || '',
8207
+ unitSymbol: layerDims[d].unitSymbol || '',
8208
+ value: layerDims[d].values || '',
8209
+ "default": layerDims[d].currentValue,
8210
+ isRefTimeDimension: dimName === 'reference_time'
8153
8211
  };
8154
- /* Add information to WMSLayerDimInfo from Extent elements: WMS 1.1.1 */
8155
-
8156
- for (var i = 0; i < layerDimExtents.length; i += 1) {
8157
- if (layerDimExtents[i].attr.name.toLowerCase() === layerDim.name) {
8158
- /* Check if a value in the WMS Extent is given: */
8159
- if (layerDimExtents[i].value) {
8160
- layerDim.value = layerDimExtents[i].value.trim();
8161
- }
8162
- /* Check for default in the WMS Extent */
8163
-
8164
-
8165
- if (layerDimExtents[i].attr["default"]) {
8166
- layerDim["default"] = layerDimExtents[i].attr["default"].trim();
8167
- }
8168
- }
8169
- }
8170
- /* Graceful WMS check: Check if value is set, if not base it on the default */
8171
-
8172
-
8173
- if (!layerDim.value && layerDim["default"]) {
8174
- layerDim.value = layerDim["default"];
8175
- }
8176
- /* Graceful WMS check: Check if default is set, if not base it on the value */
8177
-
8178
-
8179
- if (!layerDim["default"] && layerDim.value) {
8180
- /* If it is not set, take either the last value in case start/stop/res is defined, otherwise the first */
8181
- var s = layerDim.value.split('/');
8182
- var defaultIndex = 0;
8183
- if (s.length > 1) defaultIndex = 1;else if (s.length > 0) defaultIndex = 0;
8184
- layerDim["default"] = s[defaultIndex];
8185
- }
8186
8212
  /* Flag that this dim should not be removed from the layer */
8187
8213
 
8188
-
8189
8214
  layerDimNamesToRemove["delete"](layerDim.name);
8190
8215
  /* Now configure the dimensions in the Layer based on the obtained info */
8191
8216
 
@@ -8242,21 +8267,11 @@
8242
8267
  * @param wmLayer The WMLayer object to configure
8243
8268
  */
8244
8269
 
8245
- var configureStyles = function configureStyles(nestedLayerPath, wmLayer) {
8246
- var _a;
8247
- /* Now add the previous parent layer objects style info (inherit) and end with the Style info from this layer */
8248
-
8249
-
8250
- try {
8251
- for (var o = 0; o < nestedLayerPath.length; o += 1) {
8252
- // eslint-disable-next-line no-param-reassign
8253
- (_a = wmLayer.styles).push.apply(_a, __spreadArray([], __read(addStylesForLayer(nestedLayerPath[o]))));
8254
- } // eslint-disable-next-line no-empty
8255
-
8256
- } catch (_b) {}
8270
+ var configureStyles = function configureStyles(layerProps, wmLayer) {
8271
+ // eslint-disable-next-line no-param-reassign
8272
+ wmLayer.styles = layerProps.styles || [];
8257
8273
  /* Set the default style */
8258
8274
 
8259
-
8260
8275
  if (wmLayer.styles.length > 0) {
8261
8276
  /* Check if the current style is in the list */
8262
8277
  var styleIndex = wmLayer.styles.findIndex(function (style) {
@@ -8278,7 +8293,7 @@
8278
8293
  * @param wmLayer The WMLayer object to configure
8279
8294
  */
8280
8295
 
8281
- var configureDimensions = function configureDimensions(nestedLayerPath, wmLayer) {
8296
+ var configureDimensions = function configureDimensions(layerProps, wmLayer) {
8282
8297
  /*
8283
8298
  WMS 1.1.1:
8284
8299
  <Dimension name="time" units="ISO8601"/>
@@ -8296,12 +8311,9 @@
8296
8311
  /* Now start adding all dimensions starting with the parent layer. Layers more deeply nested will inherit Dimension info */
8297
8312
 
8298
8313
 
8299
- for (var o = 0; o < nestedLayerPath.length; o += 1) {
8300
- addDimsForLayer(nestedLayerPath[o], wmLayer, layerDimNamesToRemove);
8301
- }
8314
+ addDimsForLayer(layerProps, wmLayer, layerDimNamesToRemove);
8302
8315
  /* The list with dimensions to remove is now complete, remove the unneeded dimensions from the layer */
8303
8316
 
8304
-
8305
8317
  layerDimNamesToRemove.forEach(function (dimName) {
8306
8318
  var dimIndex = wmLayer.dimensions.findIndex(function (dim) {
8307
8319
  return dim.name === dimName;
@@ -8323,6 +8335,14 @@
8323
8335
  wmLayer.parentMap.configureMapDimensions(wmLayer);
8324
8336
  }
8325
8337
  };
8338
+ var configureGeographicBoundingBox = function configureGeographicBoundingBox(layerProps, wmLayer) {
8339
+ var bbox = layerProps.geographicBoundingBox;
8340
+
8341
+ if (bbox) {
8342
+ // eslint-disable-next-line no-param-reassign
8343
+ wmLayer.geographicBoundingBox = bbox;
8344
+ }
8345
+ };
8326
8346
 
8327
8347
  var WMLayer =
8328
8348
  /** @class */
@@ -8346,10 +8366,6 @@
8346
8366
  this.parseLayerPromise = this.parseLayerPromise.bind(this);
8347
8367
  this.cloneLayer = this.cloneLayer.bind(this);
8348
8368
  this.setName = this.setName.bind(this);
8349
- this.getLayerRelative = this.getLayerRelative.bind(this);
8350
- this.autoSelectLayer = this.autoSelectLayer.bind(this);
8351
- this.getNextLayer = this.getNextLayer.bind(this);
8352
- this.getPreviousLayer = this.getPreviousLayer.bind(this);
8353
8369
  this.setStyle = this.setStyle.bind(this);
8354
8370
  this.getStyles = this.getStyles.bind(this);
8355
8371
  this.getStyleObject = this.getStyleObject.bind(this);
@@ -8704,162 +8720,67 @@
8704
8720
 
8705
8721
  this.title = this.name;
8706
8722
  this["abstract"] = '';
8707
- this.path = '';
8708
- var foundLayer = 0; // Function will be called when the layer with the right name is found in the getcap doc
8709
-
8710
- var foundLayerFunction = function foundLayerFunction(jsonlayer, path, nestedLayerPath) {
8711
- _this.title = jsonlayer.Title.value;
8723
+ this.path = ''; // Function will be called when the layer with the right name is found in the getcap doc
8712
8724
 
8713
- try {
8714
- _this["abstract"] = jsonlayer.Abstract.value;
8715
- } catch (e) {
8716
- _this["abstract"] = I18n.not_available_message.text;
8717
- }
8718
-
8719
- _this.path = path;
8725
+ var populateLayerFromTreeElement = function populateLayerFromTreeElement(jsonlayer) {
8726
+ _this.title = jsonlayer.title || jsonlayer.name || '';
8727
+ _this["abstract"] = jsonlayer["abstract"] || I18n.not_available_message.text;
8728
+ _this.path = jsonlayer.path.join('/');
8720
8729
  /** ***************** Go through styles **************** */
8721
8730
 
8722
- configureStyles(nestedLayerPath, _this);
8731
+ configureStyles(jsonlayer, _this);
8723
8732
  /** ***************** Go through Dimensions **************** */
8724
8733
 
8725
- configureDimensions(nestedLayerPath, _this);
8726
- var gp = toArray(jsonlayer.SRS);
8727
-
8728
- if (isDefined(jsonlayer.CRS)) {
8729
- gp = toArray(jsonlayer.CRS);
8730
- }
8734
+ configureDimensions(jsonlayer, _this);
8735
+ /** ***************** Go through geographicBoundingBox **************** */
8731
8736
 
8732
- var tempSRS = [];
8737
+ configureGeographicBoundingBox(jsonlayer, _this);
8738
+ _this.queryable = jsonlayer.queryable || false;
8733
8739
 
8734
- var getgpbbox = function getgpbbox(data) {
8735
- if (isDefined(data.BoundingBox)) {
8736
- // Fill in SRS and BBOX on basis of BoundingBox attribute
8737
- var gpbbox = toArray(data.BoundingBox);
8738
-
8739
- for (var j = 0; j < gpbbox.length; j += 1) {
8740
- var srs = void 0;
8741
- srs = gpbbox[j].attr.SRS;
8742
-
8743
- if (isDefined(gpbbox[j].attr.CRS)) {
8744
- srs = gpbbox[j].attr.CRS;
8745
- }
8746
-
8747
- if (srs) {
8748
- if (srs.length > 0) {
8749
- srs = decodeURIComponent(srs);
8750
- }
8751
- }
8752
-
8753
- var alreadyAdded = false;
8754
-
8755
- for (var i = 0; i < _this.projectionProperties.length; i += 1) {
8756
- if (srs === _this.projectionProperties[i].srs) {
8757
- alreadyAdded = true;
8758
- break;
8759
- }
8760
- }
8761
-
8762
- if (alreadyAdded === false) {
8763
- var geoProperty = new WMProjection();
8764
- geoProperty.srs = srs;
8765
- var swapBBOX = false;
8766
-
8767
- if (_this.version === WMSVersion.version130) {
8768
- if (geoProperty.srs === 'EPSG:4326' && _this.wms130bboxcompatibilitymode === false) {
8769
- swapBBOX = true;
8770
- }
8771
- }
8772
-
8773
- if (swapBBOX === false) {
8774
- geoProperty.bbox.left = parseFloat(gpbbox[j].attr.minx);
8775
- geoProperty.bbox.bottom = parseFloat(gpbbox[j].attr.miny);
8776
- geoProperty.bbox.right = parseFloat(gpbbox[j].attr.maxx);
8777
- geoProperty.bbox.top = parseFloat(gpbbox[j].attr.maxy);
8778
- } else {
8779
- geoProperty.bbox.left = parseFloat(gpbbox[j].attr.miny);
8780
- geoProperty.bbox.bottom = parseFloat(gpbbox[j].attr.minx);
8781
- geoProperty.bbox.right = parseFloat(gpbbox[j].attr.maxy);
8782
- geoProperty.bbox.top = parseFloat(gpbbox[j].attr.maxx);
8783
- }
8740
+ if (jsonlayer.crs) {
8741
+ jsonlayer.crs.forEach(function (p) {
8742
+ var wmProjection = new WMProjection();
8743
+ wmProjection.srs = p.name || '';
8784
8744
 
8785
- _this.projectionProperties.push(geoProperty);
8745
+ if (p.bbox) {
8746
+ var swapBBOX = _this.version === WMSVersion.version130 && wmProjection.srs === 'EPSG:4326' && _this.wms130bboxcompatibilitymode === false;
8786
8747
 
8787
- tempSRS.push(geoProperty.srs);
8748
+ if (swapBBOX) {
8749
+ wmProjection.bbox.setBBOX(p.bbox.bottom, p.bbox.left, p.bbox.top, p.bbox.right);
8750
+ } else {
8751
+ wmProjection.bbox.setBBOX(p.bbox.left, p.bbox.bottom, p.bbox.right, p.bbox.top);
8788
8752
  }
8789
8753
  }
8790
- }
8791
- };
8792
-
8793
- getgpbbox(jsonlayer);
8794
- getgpbbox(rootLayer); // Fill in SRS on basis of SRS attribute
8795
-
8796
- for (var j = 0; j < gp.length; j += 1) {
8797
- if (tempSRS.indexOf(gp[j].value) === -1) {
8798
- var geoProperty = new WMProjection();
8799
- debug(exports.DebugType.Error, "Warning: BoundingBOX missing for SRS " + gp[j].value);
8800
- geoProperty.bbox.left = -180;
8801
- geoProperty.bbox.bottom = -90;
8802
- geoProperty.bbox.right = 180;
8803
- geoProperty.bbox.top = 90;
8804
- geoProperty.srs = gp[j].value;
8805
-
8806
- _this.projectionProperties.push(geoProperty);
8807
- }
8808
- }
8809
-
8810
- tempSRS = [];
8811
- /* Check if layer is queryable */
8812
8754
 
8813
- _this.queryable = false;
8814
-
8815
- try {
8816
- if (parseInt(jsonlayer.attr.queryable, 10) === 1) _this.queryable = true;else _this.queryable = false;
8817
- } catch (e) {
8818
- debug(exports.DebugType.Error, "Unable to detect whether this layer is queryable (for layer " + _this.title + ")");
8755
+ _this.projectionProperties.push(wmProjection);
8756
+ });
8819
8757
  }
8820
-
8821
- foundLayer = 1;
8822
8758
  };
8823
8759
 
8824
- function recursivelyFindLayer(thisLayer, JSONLayers, path, _prevNestedLayerPath) {
8825
- for (var k = 0; k < JSONLayers.length; k += 1) {
8826
- var nestedLayerPath_1 = [];
8827
-
8828
- for (var i = 0; i < _prevNestedLayerPath.length; i += 1) {
8829
- nestedLayerPath_1.push(_prevNestedLayerPath[i]);
8830
- }
8760
+ var layerTreeStructure = buildLayerTreeFromNestedWMSLayer(rootLayer);
8761
+ /* Recursively walk the layertree until a child is found with the corresponding name */
8831
8762
 
8832
- nestedLayerPath_1.push(JSONLayers[k]);
8833
-
8834
- if (JSONLayers[k].Layer) {
8835
- var pathnew = path;
8836
-
8837
- try {
8838
- pathnew += JSONLayers[k].Title.value + "/";
8839
- } catch (e) {
8840
- /* Do nothing */
8841
- }
8763
+ var findTreeNode = function findTreeNode(tree) {
8764
+ if (tree.name === _this.name) {
8765
+ return tree;
8766
+ }
8842
8767
 
8843
- recursivelyFindLayer(thisLayer, toArray(JSONLayers[k].Layer), pathnew, nestedLayerPath_1);
8844
- } else if (JSONLayers[k].Name) {
8845
- if (JSONLayers[k].Name.value === thisLayer.name) {
8846
- foundLayerFunction(JSONLayers[k], path, nestedLayerPath_1);
8847
- return undefined;
8848
- }
8849
- }
8768
+ if (tree.children) {
8769
+ var foundChild_1;
8770
+ tree.children.find(function (node) {
8771
+ foundChild_1 = findTreeNode(node);
8772
+ return foundChild_1;
8773
+ });
8774
+ return foundChild_1;
8850
8775
  }
8851
8776
 
8852
8777
  return undefined;
8853
- } // Try to recursively find the name in the getcap doc
8854
-
8778
+ };
8855
8779
 
8856
- var JSONLayers = toArray(rootLayer.Layer);
8857
- var path = '';
8858
- var nestedLayerPath = [rootLayer];
8859
- recursivelyFindLayer(this, JSONLayers, path, nestedLayerPath);
8780
+ var foundLayer = findTreeNode(layerTreeStructure);
8860
8781
 
8861
- if (foundLayer === 0) {
8862
- // Layer was not found...
8782
+ if (!foundLayer) {
8783
+ /* Layer was not found... */
8863
8784
  var message = '';
8864
8785
 
8865
8786
  if (this.name) {
@@ -8876,6 +8797,8 @@
8876
8797
  /* Layer was found */
8877
8798
 
8878
8799
 
8800
+ populateLayerFromTreeElement(foundLayer);
8801
+
8879
8802
  if (this.onReady) {
8880
8803
  this.onReady(this);
8881
8804
  }
@@ -8984,67 +8907,6 @@
8984
8907
  this.name = name;
8985
8908
  return this.parseLayerPromise(false);
8986
8909
  };
8987
-
8988
- WMLayer.prototype.getLayerRelative = function (success, failure, prevNext) {
8989
- var _this = this;
8990
-
8991
- var localPrevNext = prevNext;
8992
-
8993
- if (!isDefined(prevNext)) {
8994
- localPrevNext = 0;
8995
- }
8996
-
8997
- var getLayerObjectsFinished = function getLayerObjectsFinished(layerObjects) {
8998
- var currentLayerIndex = -1;
8999
-
9000
- for (var j = 0; j < layerObjects.length; j += 1) {
9001
- if (layerObjects[j].name === _this.name) {
9002
- currentLayerIndex = j;
9003
- break;
9004
- }
9005
- }
9006
-
9007
- if (currentLayerIndex === -1) {
9008
- failure("Current layer [" + _this.name + "] not in this service");
9009
- return;
9010
- }
9011
-
9012
- if (localPrevNext === -1) currentLayerIndex -= 1;
9013
- if (localPrevNext === 1) currentLayerIndex += 1;
9014
- if (currentLayerIndex > layerObjects.length - 1) currentLayerIndex = 0;
9015
- if (currentLayerIndex < 0) currentLayerIndex = layerObjects.length - 1;
9016
- success(layerObjects[currentLayerIndex], currentLayerIndex, layerObjects.length);
9017
- };
9018
-
9019
- var wmjsService = WMGetServiceFromStore(this.service);
9020
- wmjsService.getLayerObjectsFlat(getLayerObjectsFinished, failure, undefined);
9021
- };
9022
-
9023
- WMLayer.prototype.autoSelectLayer = function (success, failure) {
9024
- var getLayerObjectsFinished = function getLayerObjectsFinished(layerObjects) {
9025
- for (var j = 0; j < layerObjects.length; j += 1) {
9026
- if (isDefined(layerObjects[j].name)) {
9027
- if (layerObjects[j].name.indexOf('baselayer') === -1) {
9028
- if (layerObjects[j].path.indexOf('baselayer') === -1) {
9029
- success(layerObjects[j]);
9030
- return;
9031
- }
9032
- }
9033
- }
9034
- }
9035
- };
9036
-
9037
- var wmjsService = WMGetServiceFromStore(this.service);
9038
- wmjsService.getLayerObjectsFlat(getLayerObjectsFinished, failure, undefined);
9039
- };
9040
-
9041
- WMLayer.prototype.getNextLayer = function (success, failure) {
9042
- this.getLayerRelative(success, failure, 1);
9043
- };
9044
-
9045
- WMLayer.prototype.getPreviousLayer = function (success, failure) {
9046
- this.getLayerRelative(success, failure, -1);
9047
- };
9048
8910
  /**
9049
8911
  * Sets the style by its name
9050
8912
  * @param style: The name of the style (not the object)