azure-maps-control 2.2.5 → 2.2.7

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.
@@ -265,7 +265,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
265
265
  return Url;
266
266
  }());
267
267
 
268
- var version = "2.2.5";
268
+ var version = "2.2.7";
269
269
 
270
270
  /**
271
271
  * A helper class that provides methods for getting various forms of the map controls current version.
@@ -645,7 +645,6 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
645
645
  * Build the outermost container for the control, applies styling including any listeners for auto styling.
646
646
  */
647
647
  ControlBase.prototype.buildContainer = function (map, style, ariaLabel, tagName) {
648
- var _this = this;
649
648
  this._map = map;
650
649
  this._container = document.createElement(tagName || "div");
651
650
  this._container.classList.add("azure-maps-control-container");
@@ -654,11 +653,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
654
653
  }
655
654
  // Set the style or add the auto listener.
656
655
  if (style.toLowerCase() === exports.ControlStyle.auto) {
657
- this._map.styles.definitions().then(function (definitions) {
658
- if (_this._map) {
659
- _this._map.events.add("stylechanged", _this._onStyleChange);
660
- }
661
- });
656
+ if (this._map) {
657
+ this._map.events.add("stylechanged", this._onStyleChange);
658
+ }
662
659
  }
663
660
  else {
664
661
  this._container.classList.add(style);
@@ -4436,6 +4433,12 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
4436
4433
  _this.hasFocus = false;
4437
4434
  _this.styleButtons = new Dictionary();
4438
4435
  _this.styleIcons = new Dictionary();
4436
+ // we need to rely on this to avoid potentially redundant thumbnail requests and .blob calls
4437
+ _this.thumbnailCache = {
4438
+ assumedConfiguration: undefined,
4439
+ response: new Dictionary(),
4440
+ blob: new Dictionary()
4441
+ };
4439
4442
  /**
4440
4443
  * Callback handler for the style changing.
4441
4444
  */
@@ -4449,6 +4452,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
4449
4452
  if (!_this.styleOpsGrid) {
4450
4453
  return;
4451
4454
  }
4455
+ // do not recreate the styleOpsGrid if it is initialized and configuration object reference has not changed
4456
+ if (_this.styleOpsGrid.children.length > 0 && _this.thumbnailCache.assumedConfiguration === definitions) {
4457
+ return;
4458
+ }
4459
+ _this.thumbnailCache.assumedConfiguration = definitions;
4452
4460
  Array.from(_this.styleOpsGrid.children).forEach(function (element) { return element.remove(); });
4453
4461
  _this.styleButtons.clear();
4454
4462
  _this.populateOpsGridFromDefinitions(definitions);
@@ -4554,6 +4562,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
4554
4562
  _super.prototype.onRemove.call(this);
4555
4563
  this.styleOpsGrid = null;
4556
4564
  this.styleButtons.clear();
4565
+ this.thumbnailCache.response.clear();
4566
+ this.thumbnailCache.blob.clear();
4567
+ this.thumbnailCache.assumedConfiguration = undefined;
4557
4568
  this.map.events.remove("stylechanged", this.onStyleChange);
4558
4569
  this.map.events.remove("mapconfigurationchanged", this.onMapConfigurationChange);
4559
4570
  };
@@ -4613,7 +4624,18 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
4613
4624
  styleOptionButton.setAttribute("type", "button");
4614
4625
  var styleIconImage = new Image();
4615
4626
  fetchIconPromise
4616
- .then(function (response) { return response.blob(); })
4627
+ .then(function (response) {
4628
+ if (_this.thumbnailCache.blob.has(response.url)) {
4629
+ return _this.thumbnailCache.blob.get(response.url);
4630
+ }
4631
+ else {
4632
+ // we need the response.clone() to allow reading over body multiple times since response objects are cached
4633
+ // and can be reused across multiple invocations
4634
+ var blobPromise = response.clone().blob();
4635
+ _this.thumbnailCache.blob.set(response.url, blobPromise);
4636
+ return blobPromise;
4637
+ }
4638
+ })
4617
4639
  .then(function (blob) {
4618
4640
  var iconUrl = URL.createObjectURL(blob);
4619
4641
  styleIconImage.src = iconUrl;
@@ -4721,7 +4743,14 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
4721
4743
  if (mapServiceOptions.transformRequest) {
4722
4744
  merge_1(requestParams, mapServiceOptions.transformRequest(requestParams.url, "Thumbnail"));
4723
4745
  }
4724
- var fetchThumbnailPromise = fetch(requestParams.url, { headers: requestParams.headers });
4746
+ var fetchThumbnailPromise;
4747
+ if (_this.thumbnailCache.response.has(requestParams.url)) {
4748
+ fetchThumbnailPromise = Promise.resolve(_this.thumbnailCache.response.get(requestParams.url));
4749
+ }
4750
+ else {
4751
+ fetchThumbnailPromise = fetch(requestParams.url, { headers: requestParams.headers });
4752
+ _this.thumbnailCache.response.set(requestParams.url, fetchThumbnailPromise);
4753
+ }
4725
4754
  // Add button for each style
4726
4755
  var styleOptionButton = _this.buildSelectStyleBtn(style.name, definitions, fetchThumbnailPromise);
4727
4756
  _this.styleOpsGrid.appendChild(styleOptionButton);
@@ -9999,7 +10028,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
9999
10028
  };
10000
10029
  ZoomControl.prototype.updateZoomButtonsState = function () {
10001
10030
  var zoomInDisabled = this.map.getCamera().zoom >= this.map._getMap().getMaxZoom();
10002
- // small values need special handling, since depending on the height of the map view
10031
+ // small values need special handling, since depending on the height of the map view
10003
10032
  // the actual zoom we can zoom out to can be above or below 0 when the entire map fits the height into the view
10004
10033
  // use web mercator bounds to check if entire latitude range is visible
10005
10034
  var reachedLatitudeBoundaries = BoundingBox.getSouth(this.map.getCamera().bounds) <= -WEBMERCATOR_MAXLAT
@@ -10011,7 +10040,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10011
10040
  }
10012
10041
  if (this.zoomOutButton && this.zoomOutButton.disabled != zoomOutDisabled) {
10013
10042
  this.zoomOutButton.disabled = zoomOutDisabled;
10014
- this.zoomInButton.setAttribute("aria-label", zoomInDisabled ? "Zoom Out disabled" : "Zoom Out");
10043
+ this.zoomOutButton.setAttribute("aria-label", zoomInDisabled ? "Zoom Out disabled" : "Zoom Out");
10015
10044
  }
10016
10045
  };
10017
10046
  ZoomControl.prototype.constructZoomInButton = function (map) {
@@ -11280,44 +11309,58 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11280
11309
  var _this = _super.call(this, id) || this;
11281
11310
  _this.accessibleIndicator = [];
11282
11311
  _this.setAccessibleIndicator = function () { return __awaiter$1(_this, void 0, void 0, function () {
11283
- var features, createIndicator, insertHiddenBefore, attach;
11312
+ var renderedShapes, createIndicator, insertHiddenBefore, insertHiddenInFront, attach;
11284
11313
  var _this = this;
11285
11314
  return __generator$1(this, function (_a) {
11286
11315
  this.accessibleIndicator.forEach(function (indicator) { return indicator.remove(); });
11287
11316
  this.accessibleIndicator = [];
11288
- features = this.map.layers.getRenderedShapes(this.map.getCamera().bounds, this);
11289
- createIndicator = function (features, idx) {
11290
- var bubbleFeature = features[idx];
11291
- var indicator = new AccessibleIndicator({ positionInSet: idx + 1, setSize: features.length });
11317
+ renderedShapes = this.map.layers.getRenderedShapes(this.map.getCamera().bounds, this);
11318
+ createIndicator = function (renderedShapes, idx) {
11319
+ var curRenderedShape = renderedShapes[idx];
11320
+ var bubbleFeature = curRenderedShape instanceof Shape ? curRenderedShape.toJson() : curRenderedShape;
11321
+ var indicator = new AccessibleIndicator({ positionInSet: idx + 1, setSize: renderedShapes.length });
11292
11322
  var element = indicator.getElement();
11293
- var _a = __read$3(_this.map.positionsToPixels([bubbleFeature.data.geometry.coordinates]), 1), pixel = _a[0];
11323
+ var _a = __read$3(_this.map.positionsToPixels([_this.getFirstCoordinate(bubbleFeature.geometry.coordinates)]), 1), pixel = _a[0];
11294
11324
  element.addEventListener('focusin', function (event) {
11295
- _this.accessibleIndicator.filter(function (p) { return p !== indicator; }).forEach(function (popup) { return popup.remove(); });
11325
+ _this.accessibleIndicator.filter(function (i) { return i !== indicator; }).forEach(function (indicator) { return indicator.remove(); });
11296
11326
  // insert previous and next popups
11297
11327
  if (idx - 1 >= 0) {
11298
- insertHiddenBefore(indicator, createIndicator(features, idx - 1));
11328
+ insertHiddenBefore(indicator, createIndicator(renderedShapes, idx - 1));
11329
+ }
11330
+ if (idx + 1 < renderedShapes.length) {
11331
+ attach(createIndicator(renderedShapes, idx + 1));
11299
11332
  }
11300
- if (idx + 1 < features.length) {
11301
- attach(createIndicator(features, idx + 1));
11333
+ // if we are on boundaries: add the first / last indicator
11334
+ // to maintain indicators on full page navigation cycle
11335
+ if (idx >= 2 && idx == renderedShapes.length - 1) {
11336
+ insertHiddenInFront(createIndicator(renderedShapes, 0));
11337
+ }
11338
+ if (idx == 0 && renderedShapes.length >= 2) {
11339
+ attach(createIndicator(renderedShapes, renderedShapes.length - 1));
11340
+ }
11341
+ // NOTE: a11y only works for AZM shapes for now. (.id and _azureMapsShapeId required)
11342
+ if (bubbleFeature.id !== undefined) {
11343
+ _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', '_azureMapsShapeId'], bubbleFeature.id], '#000000', _this.options.strokeColor]);
11302
11344
  }
11303
- _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', '_azureMapsShapeId'], bubbleFeature.data.id], '#000000', _this.options.strokeColor]);
11304
11345
  var focusEvent = {
11305
11346
  target: element,
11306
11347
  type: 'focusin',
11307
11348
  map: _this.map,
11308
- shape: bubbleFeature,
11349
+ shape: curRenderedShape,
11309
11350
  originalEvent: event,
11310
11351
  pixel: pixel
11311
11352
  };
11312
11353
  _this._invokeEvent('focusin', focusEvent);
11313
11354
  });
11314
11355
  element.addEventListener('focusout', function (event) {
11315
- _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', '_azureMapsShapeId'], bubbleFeature.data.id], _this.options.strokeColor, _this.options.strokeColor]);
11356
+ if (bubbleFeature.id !== undefined) {
11357
+ _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', '_azureMapsShapeId'], bubbleFeature.id], _this.options.strokeColor, _this.options.strokeColor]);
11358
+ }
11316
11359
  var focusEvent = {
11317
11360
  target: element,
11318
11361
  type: 'focusout',
11319
11362
  map: _this.map,
11320
- shape: bubbleFeature,
11363
+ shape: curRenderedShape,
11321
11364
  originalEvent: event,
11322
11365
  pixel: pixel
11323
11366
  };
@@ -11332,14 +11375,20 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11332
11375
  var baseElement = base.getElement();
11333
11376
  baseElement.parentElement.insertBefore(elementToSwapIn, baseElement);
11334
11377
  };
11378
+ insertHiddenInFront = function (toInsert) {
11379
+ toInsert.attach(_this.map);
11380
+ var elementToSwapIn = toInsert.getElement();
11381
+ var parent = elementToSwapIn.parentElement;
11382
+ parent.insertBefore(elementToSwapIn, parent.firstElementChild);
11383
+ };
11335
11384
  attach = function (popup) {
11336
11385
  popup.attach(_this.map);
11337
11386
  };
11338
- if (features.length > 0) {
11339
- attach(createIndicator(features, 0));
11387
+ if (renderedShapes.length > 0) {
11388
+ attach(createIndicator(renderedShapes, 0));
11340
11389
  }
11341
- if (features.length > 1) {
11342
- attach(createIndicator(features, features.length - 1));
11390
+ if (renderedShapes.length > 1) {
11391
+ attach(createIndicator(renderedShapes, renderedShapes.length - 1));
11343
11392
  }
11344
11393
  return [2 /*return*/];
11345
11394
  });
@@ -11399,11 +11448,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11399
11448
  }
11400
11449
  };
11401
11450
  BubbleLayer.prototype.onRemove = function () {
11402
- _super.prototype.onRemove.call(this);
11403
11451
  if (this.options.createIndicators) {
11404
11452
  this.map.events.remove('idle', this.setAccessibleIndicator);
11405
11453
  this.map.events.remove('moveend', this.setAccessibleIndicator);
11406
11454
  }
11455
+ _super.prototype.onRemove.call(this);
11407
11456
  };
11408
11457
  /**
11409
11458
  * @internal
@@ -11456,6 +11505,17 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11456
11505
  ids.add(this.options.source);
11457
11506
  return ids;
11458
11507
  };
11508
+ /**
11509
+ * The coordinates can be nested, so we need to get the first coordinate.
11510
+ * @param coordinates The property from the Geometry. Can be Position, Position[], Position[][], etc.
11511
+ * @returns
11512
+ */
11513
+ BubbleLayer.prototype.getFirstCoordinate = function (coordinates) {
11514
+ if (!Array.isArray(coordinates[0])) {
11515
+ return coordinates;
11516
+ }
11517
+ return this.getFirstCoordinate(coordinates[0]);
11518
+ };
11459
11519
  return BubbleLayer;
11460
11520
  }(Layer));
11461
11521
 
@@ -17308,7 +17368,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
17308
17368
  this._removeListener(eventType, target, callback);
17309
17369
  }
17310
17370
  else {
17311
- target._removeEventListener(eventType, callback);
17371
+ target === null || target === void 0 ? void 0 : target._removeEventListener(eventType, callback);
17312
17372
  }
17313
17373
  }
17314
17374
  }
@@ -18118,9 +18178,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
18118
18178
  LayerManager.prototype.clear = function () {
18119
18179
  for (var layerIndexIndex = this.layerIndex.length - 1; layerIndexIndex >= 0; layerIndexIndex--) {
18120
18180
  var tempLayer = this.layerIndex[layerIndexIndex];
18121
- this._removeMapboxLayers(tempLayer, true);
18122
- this.layerIndex.splice(layerIndexIndex, 1);
18123
- tempLayer.onRemove();
18181
+ if (tempLayer) {
18182
+ this._removeMapboxLayers(tempLayer, true);
18183
+ this.layerIndex.splice(layerIndexIndex, 1);
18184
+ tempLayer.onRemove();
18185
+ }
18124
18186
  }
18125
18187
  this.userLayers = [];
18126
18188
  };
@@ -20527,7 +20589,8 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20527
20589
  return baseName in styleNamesMap ? styleNamesMap[baseName] : baseName;
20528
20590
  };
20529
20591
  if (!this.serviceOptions.mapConfiguration) {
20530
- newPromise = new HijackablePromise(this._request(this.serviceOptions.staticAssetsDomain, constants.stylePath + "/" + constants.styleResourcePath, "StyleDefinitions", { version: this.serviceOptions.styleDefinitionsVersion }).then(function (definitions) { return ({
20592
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
20593
+ newPromise = new HijackablePromise(ensureAuthentication.then(function () { return _this._request(_this.serviceOptions.staticAssetsDomain, constants.stylePath + "/" + constants.styleResourcePath, "StyleDefinitions", { version: _this.serviceOptions.styleDefinitionsVersion }).then(function (definitions) { return ({
20531
20594
  version: isNaN(definitions.version) ? 0 : parseFloat(definitions.version),
20532
20595
  defaultConfiguration: definitions.defaultStyle,
20533
20596
  configurations: definitions.styles
@@ -20566,12 +20629,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20566
20629
  protocol: "https"
20567
20630
  }).toString(),
20568
20631
  }); })
20569
- }); }));
20632
+ }); }); }));
20570
20633
  }
20571
20634
  else if (typeof this.serviceOptions.mapConfiguration === 'string') {
20572
- newPromise = new HijackablePromise(this._request(this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + this.serviceOptions.mapConfiguration, "StyleDefinitions"
20635
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
20636
+ newPromise = new HijackablePromise(ensureAuthentication.then(function () { return _this._request(_this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + _this.serviceOptions.mapConfiguration, "StyleDefinitions"
20573
20637
  // reassign properties from legacy mapConfiguration to new structure if needed
20574
- ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }));
20638
+ ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }); }));
20575
20639
  }
20576
20640
  else {
20577
20641
  newPromise = HijackablePromise.resolve(this.serviceOptions.mapConfiguration);
@@ -20695,6 +20759,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20695
20759
  */
20696
20760
  StyleManager.prototype._stylePatch = function (previousStyle, nextStyle, preserveLayer, updatePaintProperty, updateLayoutProperty, updateFilter) {
20697
20761
  var _this = this;
20762
+ // Skip the style patch if the map has been disposed.
20763
+ if (this.map.isDisposed)
20764
+ return;
20698
20765
  // Layers in the next style with default properties that do not align with current StyleOptions
20699
20766
  // should be modified before they are applied to the map.
20700
20767
  var styleOptions = this.map.getStyle();
@@ -20802,7 +20869,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20802
20869
  before = (beforeCandidates.length > 0) ? beforeCandidates[0] : undefined;
20803
20870
  }
20804
20871
  preserveLayer(userLayer.layer.getId(), before === null || before === void 0 ? void 0 : before.id);
20805
- _this.map.layers.move(userLayer.layer, userLayer.before);
20872
+ _this.map.layers.move(userLayer.layer.getId(), userLayer.before);
20806
20873
  });
20807
20874
  this.map.sources._syncSources(nextStyle.sources);
20808
20875
  // If there was a previous styledata change event attached, remove it.
@@ -21267,9 +21334,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21267
21334
  _this._setAutoResize(_this.styleOptions.autoResize);
21268
21335
  _this.map.showTileBoundaries = _this.styleOptions.showTileBoundaries;
21269
21336
  _this.localizedStringsPromise = Localizer.getStrings(_this.styleOptions.language);
21270
- var stylesInit = _this.styles.initStyleset();
21271
- Promise.all([authManInit, stylesInit]).then(function (_a) {
21272
- var _b = __read$e(_a, 2), _ = _b[0], definitions = _b[1];
21337
+ authManInit
21338
+ // reuses this.styles.initPromise if initStyleset is already called
21339
+ .then(function () { return _this.styles.definitions(); })
21340
+ .then(function (definitions) {
21273
21341
  // Check that the map hasn't been removed for any reason.
21274
21342
  // If so no need to finish styling the map.
21275
21343
  if (_this.removed) {
@@ -21332,6 +21400,16 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21332
21400
  }
21333
21401
  return _this;
21334
21402
  }
21403
+ Object.defineProperty(Map.prototype, "isDisposed", {
21404
+ /**
21405
+ * Returns true if the map has been disposed.
21406
+ */
21407
+ get: function () {
21408
+ return this.removed;
21409
+ },
21410
+ enumerable: false,
21411
+ configurable: true
21412
+ });
21335
21413
  /**
21336
21414
  * Returns the HTMLCanvasElement that the map is drawn to.
21337
21415
  */
@@ -21368,9 +21446,17 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21368
21446
  else {
21369
21447
  this.accessibleMapDelegate.removeFromMap();
21370
21448
  }
21371
- if (this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration) {
21449
+ var shouldReloadStyle = this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration
21450
+ || this.styles.serviceOptions.staticAssetsDomain !== this.serviceOptions.staticAssetsDomain
21451
+ || this.styles.serviceOptions.styleDefinitionsVersion !== this.serviceOptions.styleDefinitionsVersion
21452
+ || this.styles.serviceOptions.domain !== this.serviceOptions.domain
21453
+ || this.styles.serviceOptions.styleAPIVersion !== this.serviceOptions.styleAPIVersion;
21454
+ // NOTE: only perform a reload when the style dependent properties are changed
21455
+ //|| this.styles.serviceOptions.validateStyle !== this.serviceOptions.validateStyle
21456
+ //|| this.styles.serviceOptions.transformRequest !== this.serviceOptions.transformRequest
21457
+ this.styles.serviceOptions = this.serviceOptions;
21458
+ if (shouldReloadStyle) {
21372
21459
  this.styles.initPromise = null;
21373
- this.styles.serviceOptions.mapConfiguration = this.serviceOptions.mapConfiguration;
21374
21460
  this.setStyle({});
21375
21461
  }
21376
21462
  };