@opengeoweb/webmap 10.0.0 → 10.1.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.esm.js CHANGED
@@ -383,6 +383,41 @@ function _unsupportedIterableToArray(r, a) {
383
383
  }
384
384
  }
385
385
 
386
+ /* *
387
+ * Licensed under the Apache License, Version 2.0 (the "License");
388
+ * you may not use this file except in compliance with the License.
389
+ * You may obtain a copy of the License at
390
+ *
391
+ * http://www.apache.org/licenses/LICENSE-2.0
392
+ *
393
+ * Unless required by applicable law or agreed to in writing, software
394
+ * distributed under the License is distributed on an "AS IS" BASIS,
395
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
396
+ * See the License for the specific language governing permissions and
397
+ * limitations under the License.
398
+ *
399
+ * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
400
+ * Copyright 2024 - Finnish Meteorological Institute (FMI)
401
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
402
+ * */
403
+ /**
404
+ * Makes hashed georeferenced url without width, height and bbox
405
+ * @param url
406
+ * @returns
407
+ */
408
+ var makeHashUrlForGeoReferencedImage = function makeHashUrlForGeoReferencedImage(url) {
409
+ try {
410
+ var urlAsURL = new URL(url);
411
+ var urlParams = new URLSearchParams(urlAsURL.search);
412
+ urlParams["delete"]('BBOX');
413
+ urlParams["delete"]('WIDTH');
414
+ urlParams["delete"]('HEIGHT');
415
+ return "" + urlAsURL.origin + urlAsURL.pathname + "?" + urlParams.toString();
416
+ } catch (e) {
417
+ return undefined;
418
+ }
419
+ };
420
+
386
421
  /* *
387
422
  * Licensed under the Apache License, Version 2.0 (the "License");
388
423
  * you may not use this file except in compliance with the License.
@@ -435,6 +470,7 @@ var WMEmptyLayerTitle = 'empty layer';
435
470
  var WMDateOutSideRange = 'outside range';
436
471
  var WMDateTooEarlyString = 'date too early';
437
472
  var WMDateTooLateString = 'date too late';
473
+ var WMInvalidDateValues = new Set([WMDateOutSideRange, WMDateTooEarlyString, WMDateTooLateString]);
438
474
  var WMSJSMAP_MINIMUM_MAP_WIDTH = 4;
439
475
  var WMSJSMAP_MINIMUM_MAP_HEIGHT = 4;
440
476
  var WMSVersion = {
@@ -864,6 +900,8 @@ var WMImage = /*#__PURE__*/function () {
864
900
  */
865
901
  function WMImage(src, callback, options) {
866
902
  var _this = this;
903
+ this._resolveList = [];
904
+ this.geoReference = null;
867
905
  this._loadDuration = undefined;
868
906
  this._loadStartTime = 0;
869
907
  this.randomize = false;
@@ -916,6 +954,15 @@ var WMImage = /*#__PURE__*/function () {
916
954
  };
917
955
  }
918
956
  var _proto = WMImage.prototype;
957
+ _proto.setGeoReference = function setGeoReference(geoReference) {
958
+ if (this.geoReference) {
959
+ return;
960
+ }
961
+ this.geoReference = {
962
+ extent: [].concat(geoReference.extent),
963
+ resolution: geoReference.resolution
964
+ };
965
+ };
919
966
  _proto.init = function init() {
920
967
  this._srcLoaded = 'undefined image';
921
968
  this._isLoaded = false;
@@ -1019,10 +1066,39 @@ var WMImage = /*#__PURE__*/function () {
1019
1066
  */;
1020
1067
  _proto.hasError = function hasError() {
1021
1068
  return this._hasError;
1069
+ };
1070
+ _proto._resolveAll = function _resolveAll() {
1071
+ while (this._resolveList.length !== 0) {
1072
+ var resolve = this._resolveList.pop();
1073
+ resolve && resolve(this);
1074
+ }
1022
1075
  }
1023
1076
  /**
1024
1077
  * Start loading the image
1025
1078
  */;
1079
+ _proto.loadAwait =
1080
+ /*#__PURE__*/
1081
+ function () {
1082
+ var _loadAwait = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1083
+ var _this2 = this;
1084
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1085
+ while (1) switch (_context.prev = _context.next) {
1086
+ case 0:
1087
+ return _context.abrupt("return", new Promise(function (resolve) {
1088
+ _this2._resolveList.push(resolve);
1089
+ _this2.load();
1090
+ }));
1091
+ case 1:
1092
+ case "end":
1093
+ return _context.stop();
1094
+ }
1095
+ }, _callee);
1096
+ }));
1097
+ function loadAwait() {
1098
+ return _loadAwait.apply(this, arguments);
1099
+ }
1100
+ return loadAwait;
1101
+ }();
1026
1102
  _proto.load = function load() {
1027
1103
  if (!this._isLoading) {
1028
1104
  this._load();
@@ -1042,7 +1118,7 @@ var WMImage = /*#__PURE__*/function () {
1042
1118
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1043
1119
  ;
1044
1120
  _proto._getImageWithHeaders = function _getImageWithHeaders(url, headers) {
1045
- var _this2 = this;
1121
+ var _this3 = this;
1046
1122
  var fetchHeaders = new Headers();
1047
1123
  if (headers && headers.length > 0) {
1048
1124
  for (var _iterator = _createForOfIteratorHelperLoose(headers), _step; !(_step = _iterator()).done;) {
@@ -1069,7 +1145,7 @@ var WMImage = /*#__PURE__*/function () {
1069
1145
  response.arrayBuffer().then(function (buffer) {
1070
1146
  var base64Flag = 'data:image/png;base64,';
1071
1147
  var imageStr = arrayBufferToBase64(buffer);
1072
- _this2.getElement().src = base64Flag + imageStr;
1148
+ _this3.getElement().src = base64Flag + imageStr;
1073
1149
  })["catch"](function () {
1074
1150
  debugLogger(DebugType.Error);
1075
1151
  });
@@ -1078,7 +1154,7 @@ var WMImage = /*#__PURE__*/function () {
1078
1154
  if (url.startsWith('http://')) {
1079
1155
  debugLogger(DebugType.Error);
1080
1156
  }
1081
- _this2._loadEvent(true);
1157
+ _this3._loadEvent(true);
1082
1158
  });
1083
1159
  };
1084
1160
  _proto._load = function _load() {
@@ -1140,6 +1216,7 @@ var WMImage = /*#__PURE__*/function () {
1140
1216
  this._isLoading = false;
1141
1217
  this._isLoaded = true;
1142
1218
  this._srcLoaded = this.srcToLoad;
1219
+ this._resolveAll();
1143
1220
  (_this$loadEventCallba = this.loadEventCallback) == null || _this$loadEventCallba.call(this, this);
1144
1221
  };
1145
1222
  _proto.getLoadDuration = function getLoadDuration() {
@@ -1171,6 +1248,7 @@ var WMImageEventType;
1171
1248
  WMImageEventType[WMImageEventType["Loaded"] = 0] = "Loaded";
1172
1249
  WMImageEventType[WMImageEventType["Deleted"] = 1] = "Deleted";
1173
1250
  })(WMImageEventType || (WMImageEventType = {}));
1251
+ var WMIMAGESTORE_MAX_ALTIMAGES_TO_KEEP = 4;
1174
1252
  var WMImageStore = /*#__PURE__*/function () {
1175
1253
  /**
1176
1254
  * Constructs a new WMImageStore with given amount of image cache.
@@ -1179,12 +1257,13 @@ var WMImageStore = /*#__PURE__*/function () {
1179
1257
  */
1180
1258
  function WMImageStore(maxNumberOfImages, options) {
1181
1259
  this.imagesbysrc = new Map();
1260
+ this.imagesbyGeoRef = new Map();
1182
1261
  this.imageLife = 0;
1183
1262
  this._imageLifeCounter = 0;
1184
1263
  this._loadEventCallbackList = []; // Array of callbacks, as multiple instances can register listeners
1185
1264
  this._maxNumberOfImages = maxNumberOfImages;
1186
1265
  this._options = options;
1187
- this.emptyImage = new WMImage(null, null, null);
1266
+ this.emptyImage = new WMImage(null, null);
1188
1267
  this.imageLoadEventCallback = this.imageLoadEventCallback.bind(this);
1189
1268
  this.getImageForSrc = this.getImageForSrc.bind(this);
1190
1269
  this.clear = this.clear.bind(this);
@@ -1196,7 +1275,7 @@ var WMImageStore = /*#__PURE__*/function () {
1196
1275
  }
1197
1276
  var _proto = WMImageStore.prototype;
1198
1277
  _proto.load = function load(imageUrl) {
1199
- return this.getImage(imageUrl).load();
1278
+ return this.getImage(imageUrl).loadAwait();
1200
1279
  };
1201
1280
  _proto.imageLoadEventCallback = function imageLoadEventCallback(_img, imageEventType) {
1202
1281
  for (var _iterator = _createForOfIteratorHelperLoose(this._loadEventCallbackList), _step; !(_step = _iterator()).done;) {
@@ -1249,6 +1328,68 @@ var WMImageStore = /*#__PURE__*/function () {
1249
1328
  });
1250
1329
  return numLoading;
1251
1330
  }
1331
+ /**
1332
+ * getAltGeoReferencedImage will return an ready and loaded image for similar query parameters as requested.
1333
+ * This image can be used to display something during the period when the requested image one is still loading.
1334
+ * The alternative image will have the same query parameters but can have a different extent and resolution.
1335
+ * @param srcToLoad The url of the image for which we want to find an alternative
1336
+ * @param _extent Extent of the requested image
1337
+ * @param _resolution Resolution of the request image
1338
+ * @returns A WMImage which is ready to display. Can have a different extent and resolution then what was asked in srcToLoad
1339
+ */;
1340
+ _proto.getAltGeoReferencedImage = function getAltGeoReferencedImage(srcToLoad,
1341
+ // eslint-disable-next-line no-unused-vars
1342
+ _extent,
1343
+ // eslint-disable-next-line no-unused-vars
1344
+ _resolution) {
1345
+ var hashUrl = makeHashUrlForGeoReferencedImage(srcToLoad);
1346
+ if (!hashUrl) {
1347
+ return false;
1348
+ }
1349
+ // Sort the imagesbyGeoRef array
1350
+ var imagesbyGeoRefArray = this.imagesbyGeoRef.get(hashUrl);
1351
+ if (!imagesbyGeoRefArray || imagesbyGeoRefArray.length === 0) {
1352
+ return false;
1353
+ }
1354
+ // Clean the set, only keep the most recent images
1355
+ var imagesbyGeoRefArraySortByImageLife = imagesbyGeoRefArray.sort(function (a, b) {
1356
+ if (a.imageLife > b.imageLife) {
1357
+ return -1;
1358
+ }
1359
+ if (a.imageLife < b.imageLife) {
1360
+ return 1;
1361
+ }
1362
+ return 0;
1363
+ }).slice(0, WMIMAGESTORE_MAX_ALTIMAGES_TO_KEEP);
1364
+ // Set this array back in the array
1365
+ this.imagesbyGeoRef.set(hashUrl, imagesbyGeoRefArraySortByImageLife);
1366
+ // Now filter out the loaded images, which can be used as alternative
1367
+ var sortByImageLifeFilterdLoaded = imagesbyGeoRefArraySortByImageLife.filter(function (image) {
1368
+ return image.isLoadedWithoutErrors();
1369
+ });
1370
+ // Just return most recent available image: TODO: Possibly make use of extent and resolution to find a better one.
1371
+ return sortByImageLifeFilterdLoaded.length > 0 ? sortByImageLifeFilterdLoaded[0] : false;
1372
+ };
1373
+ _proto.getGeoReferencedImage = function getGeoReferencedImage(src, geoReference) {
1374
+ var image = this.getImage(src);
1375
+ if (image) {
1376
+ // Make a hashUrl without BBOX
1377
+ if (!image.hashUrl) {
1378
+ var _this$imagesbyGeoRef$;
1379
+ var hashUrl = makeHashUrlForGeoReferencedImage(image.srcToLoad);
1380
+ if (!hashUrl) {
1381
+ return null;
1382
+ }
1383
+ image.hashUrl = hashUrl;
1384
+ if (image.hashUrl && !this.imagesbyGeoRef.has(image.hashUrl)) {
1385
+ this.imagesbyGeoRef.set(image.hashUrl, []);
1386
+ }
1387
+ image.hashUrl && ((_this$imagesbyGeoRef$ = this.imagesbyGeoRef.get(image.hashUrl)) == null ? void 0 : _this$imagesbyGeoRef$.push(image));
1388
+ }
1389
+ image.setGeoReference(geoReference);
1390
+ }
1391
+ return image;
1392
+ }
1252
1393
  /**
1253
1394
  * Get an WMImage object for given URL
1254
1395
  * @param {*} src The url for the image
@@ -1259,8 +1400,8 @@ var WMImageStore = /*#__PURE__*/function () {
1259
1400
  if (!src) {
1260
1401
  return null;
1261
1402
  }
1262
- /** Check if we have an image in the pipeline * */
1263
- var image = this.getImageForSrc(src);
1403
+ // Check if we have an image in the pipeline
1404
+ var image = this.imagesbysrc.get(src);
1264
1405
  if (image !== undefined) {
1265
1406
  this._imageLifeCounter += 1;
1266
1407
  image.imageLife = this._imageLifeCounter;
@@ -1268,41 +1409,50 @@ var WMImageStore = /*#__PURE__*/function () {
1268
1409
  }
1269
1410
  // Create image
1270
1411
  if (this.imagesbysrc.size < this._maxNumberOfImages) {
1271
- image = new WMImage(src, function (img) {
1412
+ var _newImage = new WMImage(src, function (img) {
1272
1413
  _this.imageLoadEventCallback(img, WMImageEventType.Loaded);
1273
1414
  });
1274
- image.setSource(src, loadOptions);
1275
- this.imagesbysrc.set(src, image);
1415
+ _newImage.setSource(src, loadOptions);
1416
+ this.imagesbysrc.set(src, _newImage);
1276
1417
  this._imageLifeCounter += 1;
1277
- image.imageLife = this._imageLifeCounter;
1278
- return image;
1418
+ _newImage.imageLife = this._imageLifeCounter;
1419
+ return _newImage;
1279
1420
  }
1280
- /* We have to reuse an image */
1281
- var imageId = '';
1282
- var minImageLife = this._imageLifeCounter;
1283
- this.imagesbysrc.forEach(function (img, url) {
1284
- if (img && img.isLoading() === false || img && img.hasError() === true) {
1285
- if (minImageLife >= img.imageLife) {
1286
- minImageLife = img.imageLife;
1287
- imageId = url;
1288
- }
1421
+ // We have to reuse an image
1422
+ var imagesAsList = Array.from(this.imagesbysrc.values()).filter(function (imageBySrc) {
1423
+ return !imageBySrc || !imageBySrc.isLoading() || imageBySrc.hasError();
1424
+ });
1425
+ imagesAsList.sort(function (a, b) {
1426
+ if (a.imageLife < b.imageLife) {
1427
+ return -1;
1428
+ }
1429
+ if (a.imageLife > b.imageLife) {
1430
+ return 1;
1289
1431
  }
1432
+ return 0;
1290
1433
  });
1291
- if (imageId === '') {
1292
- return this.emptyImage;
1293
- }
1294
- image = this.imagesbysrc.get(imageId);
1295
- if (image) {
1296
- this.imagesbysrc["delete"](imageId);
1297
- this.imageLoadEventCallback(image, WMImageEventType.Deleted);
1298
- image.clear();
1299
- image.setSource(src, loadOptions);
1300
- this.imagesbysrc.set(src, image);
1301
- this._imageLifeCounter += 1;
1302
- image.imageLife = this._imageLifeCounter;
1303
- return image;
1304
- }
1305
- return null;
1434
+ var imageIdByUrl = (imagesAsList == null ? void 0 : imagesAsList.length) > 0 ? imagesAsList[0].srcToLoad : '';
1435
+ if (imageIdByUrl === '') {
1436
+ console.error('IMAGESTORE TO LARGE TO LOAD');
1437
+ } else {
1438
+ var hashUrl = makeHashUrlForGeoReferencedImage(imageIdByUrl);
1439
+ hashUrl && this.imagesbyGeoRef["delete"](hashUrl);
1440
+ var reuseImage = this.imagesbysrc.get(imageIdByUrl);
1441
+ if (reuseImage) {
1442
+ this.imagesbysrc["delete"](imageIdByUrl);
1443
+ this.imageLoadEventCallback(reuseImage, WMImageEventType.Deleted);
1444
+ reuseImage.clear();
1445
+ }
1446
+ }
1447
+ // Force return of new image
1448
+ var newImage = new WMImage(src, function (img) {
1449
+ _this.imageLoadEventCallback(img, WMImageEventType.Loaded);
1450
+ });
1451
+ newImage.setSource(src, loadOptions);
1452
+ this.imagesbysrc.set(src, newImage);
1453
+ this._imageLifeCounter += 1;
1454
+ newImage.imageLife = this._imageLifeCounter;
1455
+ return newImage;
1306
1456
  };
1307
1457
  return WMImageStore;
1308
1458
  }();
@@ -3981,9 +4131,9 @@ var WMJSDimension = /*#__PURE__*/function () {
3981
4131
  } else if (this._type === 'timevalues') {
3982
4132
  /* Filter all dates from the array which are lower than given start value */
3983
4133
  /* TODO: Maarten Plieger 2020-06-10: Make this also work for WMS times advertised as a comma separated list */
3984
- var _newValue2 = parseISO8601DateToDate(newStartValueTime.toISOString());
4134
+ var _newValue = parseISO8601DateToDate(newStartValueTime.toISOString());
3985
4135
  var newArray = this._allDates.filter(function (x) {
3986
- return x >= _newValue2;
4136
+ return x >= _newValue;
3987
4137
  });
3988
4138
  var newValues = '';
3989
4139
  for (var j = 0; j < newArray.length; j += 1) {
@@ -4263,36 +4413,37 @@ var WMJSDimension = /*#__PURE__*/function () {
4263
4413
  this.reInitializeValues(this.values);
4264
4414
  }
4265
4415
  };
4266
- _proto.getClosestValue = function getClosestValue(_newValue, evenWhenOutsideRange) {
4416
+ _proto.getClosestValueForTime = function getClosestValueForTime(timeStamp) {
4417
+ var timeToFind = new Date(timeStamp).toISOString().substring(0, 19) + "Z";
4418
+ return this.getClosestValue(timeToFind);
4419
+ };
4420
+ _proto.getClosestValue = function getClosestValue(inputValue, evenWhenOutsideRange) {
4267
4421
  if (evenWhenOutsideRange === void 0) {
4268
4422
  evenWhenOutsideRange = false;
4269
4423
  }
4270
4424
  this.initialize();
4271
4425
  if (!this._initialized) {
4272
- return _newValue;
4273
- }
4274
- var newValue = _newValue && _newValue.indexOf('/') !== -1 ? _newValue.split('/')[0] : _newValue;
4275
- if (newValue === 'current' || newValue === 'default' || newValue === '') {
4276
- return this.defaultValue;
4277
- }
4278
- if (newValue === 'middle') {
4279
- var middleIndex = Math.ceil(this.size() / 2) - 1;
4280
- if (middleIndex < 0) {
4281
- middleIndex = 0;
4282
- }
4283
- return this.getValueForIndex(middleIndex);
4284
- }
4285
- if (newValue === 'latest') {
4286
- return this.getLastValue();
4287
- }
4288
- if (newValue === 'earliest') {
4289
- return this.getFirstValue();
4426
+ return inputValue;
4427
+ }
4428
+ var newValue = (inputValue == null ? void 0 : inputValue.indexOf('/')) === -1 ? inputValue : inputValue.split('/')[0];
4429
+ switch (newValue) {
4430
+ case 'current':
4431
+ case 'default':
4432
+ case '':
4433
+ return this.defaultValue;
4434
+ case 'middle':
4435
+ {
4436
+ var middleIndex = Math.ceil(this.size() / 2) - 1;
4437
+ return this.getValueForIndex(middleIndex > 0 ? middleIndex : 0);
4438
+ }
4439
+ case 'earliest':
4440
+ return this.getFirstValue();
4441
+ case 'latest':
4442
+ return this.getLastValue();
4290
4443
  }
4291
- var index = -1;
4292
4444
  var value = WMDateOutSideRange;
4293
4445
  try {
4294
- index = this.getIndexForValue(newValue);
4295
- value = this.getValueForIndex(index);
4446
+ value = this.getValueForIndex(this.getIndexForValue(newValue) || -1);
4296
4447
  } catch (e) {
4297
4448
  if (typeof e.message === 'number') {
4298
4449
  if (e.message === '0') {
@@ -7321,15 +7472,18 @@ var privateWmsFlattenLayerTree = function privateWmsFlattenLayerTree(layerTree)
7321
7472
  var flatLayerObject = recurseLayerTree(layerTree.children);
7322
7473
  return sortArrayOfObjectsByKey(flatLayerObject, 'title');
7323
7474
  };
7324
- var privateGetWMSUrl = function privateGetWMSUrl(service, additionalParams) {
7475
+ var privateGetOGCCapabilitiesUrl = function privateGetOGCCapabilitiesUrl(url, service, additionalParams) {
7476
+ if (url === void 0) {
7477
+ url = '';
7478
+ }
7325
7479
  if (service === void 0) {
7326
- service = '';
7480
+ service = 'WMS';
7327
7481
  }
7328
7482
  if (additionalParams === void 0) {
7329
7483
  additionalParams = {};
7330
7484
  }
7331
- return getUriAddParam(service, Object.assign({
7332
- service: 'WMS',
7485
+ return getUriAddParam(url, Object.assign({
7486
+ service: service,
7333
7487
  request: 'GetCapabilities'
7334
7488
  }, additionalParams));
7335
7489
  };
@@ -7372,7 +7526,7 @@ var privateWmsGetCapabilities = /*#__PURE__*/function () {
7372
7526
  addParams = forceReload ? {
7373
7527
  random: Math.random()
7374
7528
  } : {};
7375
- url = privateGetWMSUrl(serviceUrl.indexOf('?') === -1 ? serviceUrl + "?" : serviceUrl, addParams);
7529
+ url = privateGetOGCCapabilitiesUrl(serviceUrl.indexOf('?') === -1 ? serviceUrl + "?" : serviceUrl, 'WMS', addParams);
7376
7530
  return _context.abrupt("return", WMXMLParser(url, headers));
7377
7531
  case 13:
7378
7532
  case "end":
@@ -7384,6 +7538,67 @@ var privateWmsGetCapabilities = /*#__PURE__*/function () {
7384
7538
  return _ref2.apply(this, arguments);
7385
7539
  };
7386
7540
  }();
7541
+ var privateWmtsGetCapabilities = /*#__PURE__*/function () {
7542
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(serviceUrl, headers, forceReload) {
7543
+ var addParams, url, fetchHeaders, _iterator, _step, header;
7544
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7545
+ while (1) switch (_context2.prev = _context2.next) {
7546
+ case 0:
7547
+ if (headers === void 0) {
7548
+ headers = [];
7549
+ }
7550
+ if (forceReload === void 0) {
7551
+ forceReload = false;
7552
+ }
7553
+ if (isDefined(serviceUrl)) {
7554
+ _context2.next = 4;
7555
+ break;
7556
+ }
7557
+ throw new Error(consoleErrorMessages.noServiceDefined);
7558
+ case 4:
7559
+ if (!(serviceUrl.length === 0)) {
7560
+ _context2.next = 6;
7561
+ break;
7562
+ }
7563
+ throw new Error(consoleErrorMessages.serviceUrlEmpty);
7564
+ case 6:
7565
+ if (!(!serviceUrl.startsWith('http://') && !serviceUrl.startsWith('https:') && !serviceUrl.startsWith('//'))) {
7566
+ _context2.next = 8;
7567
+ break;
7568
+ }
7569
+ throw new Error(consoleErrorMessages.serviceUrlEmpty);
7570
+ case 8:
7571
+ addParams = forceReload ? {
7572
+ random: Math.random()
7573
+ } : {};
7574
+ url = privateGetOGCCapabilitiesUrl(serviceUrl.indexOf('?') === -1 ? serviceUrl + "?" : serviceUrl, 'WMTS', addParams);
7575
+ fetchHeaders = new Headers();
7576
+ if (headers && headers.length > 0) {
7577
+ for (_iterator = _createForOfIteratorHelperLoose(headers); !(_step = _iterator()).done;) {
7578
+ header = _step.value;
7579
+ fetchHeaders.append(header.name, header.value);
7580
+ }
7581
+ }
7582
+ return _context2.abrupt("return", fetch(url, {
7583
+ headers: fetchHeaders
7584
+ }).then(function (response) {
7585
+ return response.text();
7586
+ }));
7587
+ case 13:
7588
+ case "end":
7589
+ return _context2.stop();
7590
+ }
7591
+ }, _callee2);
7592
+ }));
7593
+ return function privateWmtsGetCapabilities(_x4, _x5, _x6) {
7594
+ return _ref3.apply(this, arguments);
7595
+ };
7596
+ }();
7597
+ /**
7598
+ * privateWmsGetCapabilityElement
7599
+ * @param jsonData
7600
+ * @returns
7601
+ */
7387
7602
  var privateWmsGetCapabilityElement = function privateWmsGetCapabilityElement(jsonData) {
7388
7603
  var capabilityObject;
7389
7604
  try {
@@ -10947,7 +11162,8 @@ var privateWebMapUtils = {
10947
11162
  privateGetWMSServiceInfo: privateGetWMSServiceInfo,
10948
11163
  privateWmsGetLayerTree: privateWmsGetLayerTree,
10949
11164
  privateWmsFlattenLayerTree: privateWmsFlattenLayerTree,
11165
+ privateWmtsGetCapabilities: privateWmtsGetCapabilities,
10950
11166
  QUERYWMS_GETCAPABILITIES: QUERYWMS_GETCAPABILITIES
10951
11167
  };
10952
11168
 
10953
- export { DateInterval, DebugType, EVENT_GETCAPABILITIES_READY, EVENT_GETCAPABILITIES_START, LayerType, ParseISOTimeRangeDuration, URLDecode, URLEncode, WEBMAP_NAMESPACE, WMBBOX, WMDateOutSideRange, WMDateTooEarlyString, WMDateTooLateString, WMEmptyLayerName, WMEmptyLayerTitle, WMImage, WMImageEventType, WMImageStore, WMJSDimension, WMJSMAP_LONLAT_EPSGCODE, WMJSMap, WMJScheckURL, WMLayer, WMListener, WMProj4Defs, WMProjection, WMSJSMAP_MINIMUM_MAP_HEIGHT, WMSJSMAP_MINIMUM_MAP_WIDTH, WMSVersion, WMXMLStringToJson, bgImageStoreLength, buildMapLayerDims, buildWMSGetMapRequest, clearImageCacheForAllMaps, debugLogger, detectLeftButton, detectRightButton, drawScaleBar, drawTextBG, generateLayerId, generateMapId, generateTimesliderId, getBBOXandProjString, getErrorsToDisplay, getGeoCoordFromLatLong, getGeoCoordFromPixelCoord, getLatLongFromPixelCoord, getLayerIndex, getLegendGraphicURLForLayer, getPixelCoordFromGeoCoord, getPixelCoordFromLatLong, getScaleBarProperties, getUriWithParam, getWMJSDimensionForLayerAndDimension, getWMJSMapById, getWMJSMapIds, getWMJSTimeDimensionForLayerId, getWMLayerById, getWMSGetFeatureInfoRequestURL, getWMSRequests, getWMSServiceId, handleDateUtilsISOString, invalidateWMSGetCapabilities, isDefined, isProjectionSupported, legendImageStore, legendImageStoreLength, mapImageStoreLength, mockGetCapabilities, parseISO8601DateToDate, parseISO8601IntervalToDateInterval, privateWebMapUtils, queryWMSGetCapabilities, queryWMSLayer, queryWMSLayers, queryWMSLayersTree, queryWMSServiceInfo, registerWMJSMap, registerWMLayer, roundWithTimeStep, setWMSGetCapabilitiesFetcher, tilesettings, toArray, unRegisterAllWMJSLayersAndMaps, unRegisterWMJSLayer, unRegisterWMJSMap, index as webmapTestSettings, webmapTranslations, utils as webmapUtils, wmServiceListener, wmsQueryClient };
11169
+ export { DateInterval, DebugType, EVENT_GETCAPABILITIES_READY, EVENT_GETCAPABILITIES_START, LayerType, ParseISOTimeRangeDuration, URLDecode, URLEncode, WEBMAP_NAMESPACE, WMBBOX, WMDateOutSideRange, WMDateTooEarlyString, WMDateTooLateString, WMEmptyLayerName, WMEmptyLayerTitle, WMImage, WMImageEventType, WMImageStore, WMInvalidDateValues, WMJSDimension, WMJSMAP_LONLAT_EPSGCODE, WMJSMap, WMJScheckURL, WMLayer, WMListener, WMProj4Defs, WMProjection, WMSJSMAP_MINIMUM_MAP_HEIGHT, WMSJSMAP_MINIMUM_MAP_WIDTH, WMSVersion, WMXMLStringToJson, bgImageStoreLength, buildMapLayerDims, buildWMSGetMapRequest, clearImageCacheForAllMaps, debugLogger, detectLeftButton, detectRightButton, drawScaleBar, drawTextBG, generateLayerId, generateMapId, generateTimesliderId, getBBOXandProjString, getErrorsToDisplay, getGeoCoordFromLatLong, getGeoCoordFromPixelCoord, getLatLongFromPixelCoord, getLayerIndex, getLegendGraphicURLForLayer, getPixelCoordFromGeoCoord, getPixelCoordFromLatLong, getScaleBarProperties, getUriWithParam, getWMJSDimensionForLayerAndDimension, getWMJSMapById, getWMJSMapIds, getWMJSTimeDimensionForLayerId, getWMLayerById, getWMSGetFeatureInfoRequestURL, getWMSRequests, getWMSServiceId, handleDateUtilsISOString, invalidateWMSGetCapabilities, isDefined, isProjectionSupported, legendImageStore, legendImageStoreLength, mapImageStoreLength, mockGetCapabilities, parseISO8601DateToDate, parseISO8601IntervalToDateInterval, privateWebMapUtils, queryWMSGetCapabilities, queryWMSLayer, queryWMSLayers, queryWMSLayersTree, queryWMSServiceInfo, registerWMJSMap, registerWMLayer, roundWithTimeStep, setWMSGetCapabilitiesFetcher, tilesettings, toArray, unRegisterAllWMJSLayersAndMaps, unRegisterWMJSLayer, unRegisterWMJSMap, index as webmapTestSettings, webmapTranslations, utils as webmapUtils, wmServiceListener, wmsQueryClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/webmap",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "description": "GeoWeb webmap library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -9,6 +9,7 @@ declare const privateWebMapUtils: {
9
9
  privateGetWMSServiceInfo: (getCapabilitiesJson: import("./lib").GetCapabilitiesJson, serviceUrl: string) => import("./lib").WMSServiceInfo;
10
10
  privateWmsGetLayerTree: (jsonData: import("./lib").GetCapabilitiesJson) => import("./lib").LayerTree;
11
11
  privateWmsFlattenLayerTree: (layerTree: import("./lib").LayerTree) => import("./lib").LayerProps[];
12
+ privateWmtsGetCapabilities: (serviceUrl: string, headers?: import("./lib").Header[], forceReload?: boolean) => Promise<string>;
12
13
  QUERYWMS_GETCAPABILITIES: string;
13
14
  };
14
15
  export { privateWebMapUtils };
@@ -253,13 +253,13 @@ interface IWMJSMap {
253
253
  * @param f
254
254
  * @param keep
255
255
  */
256
- addListener(name: string, f: (param?: unknown) => void, keep?: boolean): boolean;
256
+ addListener<T>(name: string, f: (param: T) => void | boolean, keep?: boolean): boolean;
257
257
  /**
258
258
  * Remove something from the event listener
259
259
  * @param name
260
260
  * @param f
261
261
  */
262
- removeListener(name: string, f: (param?: unknown) => void): void;
262
+ removeListener<T>(name: string, f: (param: T) => void): void;
263
263
  /**
264
264
  * Get a direct handle to the event listener system
265
265
  */
@@ -3,6 +3,7 @@ export declare const WMEmptyLayerTitle = "empty layer";
3
3
  export declare const WMDateOutSideRange = "outside range";
4
4
  export declare const WMDateTooEarlyString = "date too early";
5
5
  export declare const WMDateTooLateString = "date too late";
6
+ export declare const WMInvalidDateValues: Set<string>;
6
7
  export declare const WMSJSMAP_MINIMUM_MAP_WIDTH = 4;
7
8
  export declare const WMSJSMAP_MINIMUM_MAP_HEIGHT = 4;
8
9
  export declare const WMSVersion: {
@@ -3,6 +3,10 @@ export interface WMImageOptions {
3
3
  headers: Headers[];
4
4
  fakeMaxAge?: number;
5
5
  }
6
+ export interface WMGeoReference {
7
+ extent: number[];
8
+ resolution: number;
9
+ }
6
10
  /**
7
11
  * Returns the current time in ms
8
12
  * @returns the current time in ms
@@ -27,6 +31,10 @@ export default class WMImage {
27
31
  _loadStartTime: number;
28
32
  _loadDuration?: number;
29
33
  _fakeMaxAge?: number | null;
34
+ _resolveList: ((i: WMImage) => void)[];
35
+ geoReference: WMGeoReference | null;
36
+ hashUrl: string | undefined;
37
+ setGeoReference(geoReference: WMGeoReference): void;
30
38
  /**
31
39
  *
32
40
  * @param src Optionally set the source URL to load
@@ -73,14 +81,16 @@ export default class WMImage {
73
81
  * Check if the image has an error
74
82
  */
75
83
  hasError(): boolean;
84
+ private _resolveAll;
76
85
  /**
77
86
  * Start loading the image
78
87
  */
88
+ loadAwait(): Promise<WMImage>;
79
89
  load(): void;
80
90
  forceReload(randomize?: boolean): void;
81
91
  private _getImageWithHeaders;
82
- private _load;
83
- private _loadEvent;
92
+ _load(): void;
93
+ _loadEvent(hasError: boolean): void;
84
94
  getLoadDuration(): number | undefined;
85
95
  /**
86
96
  * Get the width of the current image
@@ -1,4 +1,4 @@
1
- import WMImage, { WMImageOptions } from './WMImage';
1
+ import WMImage, { WMGeoReference, WMImageOptions } from './WMImage';
2
2
  export declare enum WMImageEventType {
3
3
  Loaded = 0,
4
4
  Deleted = 1
@@ -16,6 +16,7 @@ export default class WMImageStore {
16
16
  id: string;
17
17
  };
18
18
  emptyImage: WMImage;
19
+ imagesbyGeoRef: Map<string, WMImage[]>;
19
20
  /**
20
21
  * Constructs a new WMImageStore with given amount of image cache.
21
22
  * @param {*} maxNumberOfImages
@@ -24,7 +25,7 @@ export default class WMImageStore {
24
25
  constructor(maxNumberOfImages: number, options: {
25
26
  id: string;
26
27
  });
27
- load(imageUrl: string): void;
28
+ load(imageUrl: string): Promise<WMImage>;
28
29
  imageLoadEventCallback(_img: WMImage, imageEventType: WMImageEventType): void;
29
30
  /**
30
31
  * Check if we have similar images with the same source in the pipeline
@@ -35,6 +36,17 @@ export default class WMImageStore {
35
36
  removeAllEventCallbacks(): void;
36
37
  removeEventCallback(id: string): void;
37
38
  getNumImagesLoading(): number;
39
+ /**
40
+ * getAltGeoReferencedImage will return an ready and loaded image for similar query parameters as requested.
41
+ * This image can be used to display something during the period when the requested image one is still loading.
42
+ * The alternative image will have the same query parameters but can have a different extent and resolution.
43
+ * @param srcToLoad The url of the image for which we want to find an alternative
44
+ * @param _extent Extent of the requested image
45
+ * @param _resolution Resolution of the request image
46
+ * @returns A WMImage which is ready to display. Can have a different extent and resolution then what was asked in srcToLoad
47
+ */
48
+ getAltGeoReferencedImage(srcToLoad: string, _extent: number[], _resolution: number): WMImage | false;
49
+ getGeoReferencedImage(src: string, geoReference: WMGeoReference): WMImage;
38
50
  /**
39
51
  * Get an WMImage object for given URL
40
52
  * @param {*} src The url for the image
@@ -69,7 +69,8 @@ export default class WMJSDimension implements Dimension {
69
69
  setClosestValue(newValue?: string | null, evenWhenOutsideRange?: boolean): void;
70
70
  addTimeRangeDurationToValue(value: string): string;
71
71
  setTimeRangeDuration(duration: string): void;
72
- getClosestValue(_newValue: string, evenWhenOutsideRange?: boolean): string;
72
+ getClosestValueForTime(timeStamp: number): string;
73
+ getClosestValue(inputValue: string, evenWhenOutsideRange?: boolean): string;
73
74
  /**
74
75
  * Get dimension value for specified index
75
76
  */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Makes hashed georeferenced url without width, height and bbox
3
+ * @param url
4
+ * @returns
5
+ */
6
+ export declare const makeHashUrlForGeoReferencedImage: (url: string) => string | undefined;
@@ -6,8 +6,14 @@ import { Capability, GetCapabilitiesJson, Header, LayerProps, LayerTree, WMSLaye
6
6
  * @returns Flat array of layers as LayerProps[]
7
7
  */
8
8
  export declare const privateWmsFlattenLayerTree: (layerTree: LayerTree) => LayerProps[];
9
- export declare const privateGetWMSUrl: (service?: string, additionalParams?: {}) => string;
9
+ export declare const privateGetOGCCapabilitiesUrl: (url?: string, service?: string, additionalParams?: {}) => string;
10
10
  export declare const privateWmsGetCapabilities: (serviceUrl: string, headers?: Header[], forceReload?: boolean) => Promise<GetCapabilitiesJson>;
11
+ export declare const privateWmtsGetCapabilities: (serviceUrl: string, headers?: Header[], forceReload?: boolean) => Promise<string>;
12
+ /**
13
+ * privateWmsGetCapabilityElement
14
+ * @param jsonData
15
+ * @returns
16
+ */
11
17
  export declare const privateWmsGetCapabilityElement: (jsonData: GetCapabilitiesJson) => Capability;
12
18
  export declare const privateCheckException: (jsonData: GetCapabilitiesJson) => string | undefined;
13
19
  export declare const privateWmsGetRootLayerFromGetCapabilities: (jsonData: GetCapabilitiesJson) => WMSLayerFromGetCapabilities;