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
 
@@ -21719,8 +21779,6 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21719
21779
  resolve(source);
21720
21780
  }
21721
21781
  else {
21722
- // force source loading as same resolved source in different style will get cached and won't emit events
21723
- source.load();
21724
21782
  source.on('data', function sourceDataListener(event) {
21725
21783
  if (event.sourceDataType == 'metadata') {
21726
21784
  source.off('data', sourceDataListener);
@@ -25029,7 +25087,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25029
25087
  this._removeListener(eventType, target, callback);
25030
25088
  }
25031
25089
  else {
25032
- target._removeEventListener(eventType, callback);
25090
+ target === null || target === void 0 ? void 0 : target._removeEventListener(eventType, callback);
25033
25091
  }
25034
25092
  }
25035
25093
  }
@@ -25839,9 +25897,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25839
25897
  LayerManager.prototype.clear = function () {
25840
25898
  for (var layerIndexIndex = this.layerIndex.length - 1; layerIndexIndex >= 0; layerIndexIndex--) {
25841
25899
  var tempLayer = this.layerIndex[layerIndexIndex];
25842
- this._removeMapboxLayers(tempLayer, true);
25843
- this.layerIndex.splice(layerIndexIndex, 1);
25844
- tempLayer.onRemove();
25900
+ if (tempLayer) {
25901
+ this._removeMapboxLayers(tempLayer, true);
25902
+ this.layerIndex.splice(layerIndexIndex, 1);
25903
+ tempLayer.onRemove();
25904
+ }
25845
25905
  }
25846
25906
  this.userLayers = [];
25847
25907
  };
@@ -28248,7 +28308,8 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28248
28308
  return baseName in styleNamesMap ? styleNamesMap[baseName] : baseName;
28249
28309
  };
28250
28310
  if (!this.serviceOptions.mapConfiguration) {
28251
- newPromise = new HijackablePromise(this._request(this.serviceOptions.staticAssetsDomain, constants.stylePath + "/" + constants.styleResourcePath, "StyleDefinitions", { version: this.serviceOptions.styleDefinitionsVersion }).then(function (definitions) { return ({
28311
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
28312
+ 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 ({
28252
28313
  version: isNaN(definitions.version) ? 0 : parseFloat(definitions.version),
28253
28314
  defaultConfiguration: definitions.defaultStyle,
28254
28315
  configurations: definitions.styles
@@ -28287,12 +28348,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28287
28348
  protocol: "https"
28288
28349
  }).toString(),
28289
28350
  }); })
28290
- }); }));
28351
+ }); }); }));
28291
28352
  }
28292
28353
  else if (typeof this.serviceOptions.mapConfiguration === 'string') {
28293
- newPromise = new HijackablePromise(this._request(this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + this.serviceOptions.mapConfiguration, "StyleDefinitions"
28354
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
28355
+ newPromise = new HijackablePromise(ensureAuthentication.then(function () { return _this._request(_this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + _this.serviceOptions.mapConfiguration, "StyleDefinitions"
28294
28356
  // reassign properties from legacy mapConfiguration to new structure if needed
28295
- ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }));
28357
+ ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }); }));
28296
28358
  }
28297
28359
  else {
28298
28360
  newPromise = HijackablePromise.resolve(this.serviceOptions.mapConfiguration);
@@ -28416,6 +28478,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28416
28478
  */
28417
28479
  StyleManager.prototype._stylePatch = function (previousStyle, nextStyle, preserveLayer, updatePaintProperty, updateLayoutProperty, updateFilter) {
28418
28480
  var _this = this;
28481
+ // Skip the style patch if the map has been disposed.
28482
+ if (this.map.isDisposed)
28483
+ return;
28419
28484
  // Layers in the next style with default properties that do not align with current StyleOptions
28420
28485
  // should be modified before they are applied to the map.
28421
28486
  var styleOptions = this.map.getStyle();
@@ -28523,7 +28588,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28523
28588
  before = (beforeCandidates.length > 0) ? beforeCandidates[0] : undefined;
28524
28589
  }
28525
28590
  preserveLayer(userLayer.layer.getId(), before === null || before === void 0 ? void 0 : before.id);
28526
- _this.map.layers.move(userLayer.layer, userLayer.before);
28591
+ _this.map.layers.move(userLayer.layer.getId(), userLayer.before);
28527
28592
  });
28528
28593
  this.map.sources._syncSources(nextStyle.sources);
28529
28594
  // If there was a previous styledata change event attached, remove it.
@@ -28992,9 +29057,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28992
29057
  _this._setAutoResize(_this.styleOptions.autoResize);
28993
29058
  _this.map.showTileBoundaries = _this.styleOptions.showTileBoundaries;
28994
29059
  _this.localizedStringsPromise = Localizer.getStrings(_this.styleOptions.language);
28995
- var stylesInit = _this.styles.initStyleset();
28996
- Promise.all([authManInit, stylesInit]).then(function (_a) {
28997
- var _b = __read$g(_a, 2), _ = _b[0], definitions = _b[1];
29060
+ authManInit
29061
+ // reuses this.styles.initPromise if initStyleset is already called
29062
+ .then(function () { return _this.styles.definitions(); })
29063
+ .then(function (definitions) {
28998
29064
  // Check that the map hasn't been removed for any reason.
28999
29065
  // If so no need to finish styling the map.
29000
29066
  if (_this.removed) {
@@ -29059,6 +29125,16 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29059
29125
  }
29060
29126
  return _this;
29061
29127
  }
29128
+ Object.defineProperty(Map.prototype, "isDisposed", {
29129
+ /**
29130
+ * Returns true if the map has been disposed.
29131
+ */
29132
+ get: function () {
29133
+ return this.removed;
29134
+ },
29135
+ enumerable: false,
29136
+ configurable: true
29137
+ });
29062
29138
  /**
29063
29139
  * Returns the HTMLCanvasElement that the map is drawn to.
29064
29140
  */
@@ -29095,9 +29171,17 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29095
29171
  else {
29096
29172
  this.accessibleMapDelegate.removeFromMap();
29097
29173
  }
29098
- if (this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration) {
29174
+ var shouldReloadStyle = this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration
29175
+ || this.styles.serviceOptions.staticAssetsDomain !== this.serviceOptions.staticAssetsDomain
29176
+ || this.styles.serviceOptions.styleDefinitionsVersion !== this.serviceOptions.styleDefinitionsVersion
29177
+ || this.styles.serviceOptions.domain !== this.serviceOptions.domain
29178
+ || this.styles.serviceOptions.styleAPIVersion !== this.serviceOptions.styleAPIVersion;
29179
+ // NOTE: only perform a reload when the style dependent properties are changed
29180
+ //|| this.styles.serviceOptions.validateStyle !== this.serviceOptions.validateStyle
29181
+ //|| this.styles.serviceOptions.transformRequest !== this.serviceOptions.transformRequest
29182
+ this.styles.serviceOptions = this.serviceOptions;
29183
+ if (shouldReloadStyle) {
29099
29184
  this.styles.initPromise = null;
29100
- this.styles.serviceOptions.mapConfiguration = this.serviceOptions.mapConfiguration;
29101
29185
  this.setStyle({});
29102
29186
  }
29103
29187
  };