azure-maps-control 2.2.6 → 2.3.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.
@@ -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.6";
268
+ var version = "2.3.0";
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) {
@@ -10283,19 +10312,24 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10283
10312
  * Get reference to Mapbox Map
10284
10313
  * @internal
10285
10314
  */
10286
- Source.prototype._setMap = function (map) {
10315
+ Source.prototype._setMap = function (map, shouldInvokeEvent) {
10316
+ if (shouldInvokeEvent === void 0) { shouldInvokeEvent = true; }
10287
10317
  if (map == null || map === undefined) {
10288
10318
  var temp = this.map;
10289
10319
  delete this.map;
10290
- this._invokeEvent("sourceremoved", this);
10291
- if (temp) {
10292
- temp.events.invoke("sourceremoved", this);
10320
+ if (shouldInvokeEvent) {
10321
+ this._invokeEvent("sourceremoved", this);
10322
+ if (temp) {
10323
+ temp.events.invoke("sourceremoved", this);
10324
+ }
10293
10325
  }
10294
10326
  }
10295
10327
  else {
10296
10328
  this.map = map;
10297
- this._invokeEvent("sourceadded", this);
10298
- this.map.events.invoke("sourceadded", this);
10329
+ if (shouldInvokeEvent) {
10330
+ this._invokeEvent("sourceadded", this);
10331
+ this.map.events.invoke("sourceadded", this);
10332
+ }
10299
10333
  }
10300
10334
  };
10301
10335
  return Source;
@@ -10616,6 +10650,27 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10616
10650
  }
10617
10651
  return geoJsonSource;
10618
10652
  };
10653
+ DataSource.prototype._isDeepEqual = function (other) {
10654
+ if (this.constructor !== other.constructor) {
10655
+ return false;
10656
+ }
10657
+ var source = this._buildSource();
10658
+ var otherSource = other._buildSource();
10659
+ return source.type === otherSource.type &&
10660
+ // no data comparison since it is costly and not needed. If geojson data is different, but other source properties are same, we treat it as an update.
10661
+ //source.data === otherSource.data &&
10662
+ source.maxzoom === otherSource.maxzoom &&
10663
+ source.cluster === otherSource.cluster &&
10664
+ source.clusterRadius === otherSource.clusterRadius &&
10665
+ source.tolerance === otherSource.tolerance &&
10666
+ source.lineMetrics === otherSource.lineMetrics &&
10667
+ JSON.stringify(source.clusterProperties) === JSON.stringify(otherSource.clusterProperties) &&
10668
+ source.buffer === otherSource.buffer &&
10669
+ source.clusterMinPoints === otherSource.clusterMinPoints &&
10670
+ source.generateId === otherSource.generateId &&
10671
+ source.promoteId === otherSource.promoteId &&
10672
+ source.filter === otherSource.filter;
10673
+ };
10619
10674
  /**
10620
10675
  * @internal
10621
10676
  */
@@ -10897,6 +10952,26 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10897
10952
  }
10898
10953
  return vectorSource;
10899
10954
  };
10955
+ /**
10956
+ * @internal
10957
+ */
10958
+ VectorTileSource.prototype._isDeepEqual = function (other) {
10959
+ if (this.constructor !== other.constructor) {
10960
+ return false;
10961
+ }
10962
+ var source = this._buildSource();
10963
+ var otherSource = other._buildSource();
10964
+ return source.type === otherSource.type &&
10965
+ source.url === otherSource.url &&
10966
+ ((source.tiles === undefined && otherSource.tiles === undefined) ||
10967
+ (source.tiles && otherSource.tiles && source.tiles.length === otherSource.tiles.length && source.tiles.every(function (value, idx) { return value === otherSource.tiles[idx]; }))) &&
10968
+ source.minzoom === otherSource.minzoom &&
10969
+ source.maxzoom === otherSource.maxzoom &&
10970
+ source.bounds === otherSource.bounds &&
10971
+ source.attribution === otherSource.attribution &&
10972
+ source.promoteId === otherSource.promoteId &&
10973
+ source.scheme === otherSource.scheme;
10974
+ };
10900
10975
  return VectorTileSource;
10901
10976
  }(Source));
10902
10977
 
@@ -11188,11 +11263,41 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11188
11263
  /**
11189
11264
  * @internal
11190
11265
  * Specifies whether to create focusable indicators for the bubbles.
11266
+ * The default highlighting style is provided if the source is DataSource with Shape:
11267
+ * ```ts
11268
+ * const datasource = new DataSource('bubble-source');
11269
+ * datasource.setShapes([new Shape(new Point([-122.335, 47.62]))]);
11270
+ * this.map.sources.add(datasource);
11271
+ * const layer = new BubbleLayer(datasource, 'bubble', {
11272
+ * radius: 10,
11273
+ * color: 'cyan',
11274
+ * createIndicators: true,
11275
+ * });
11276
+ * ```
11277
+ *
11278
+ * For other sources, you can provide the accessibilityIdKey option to specify the property name of the feature to use as the accessibility id.
11279
+ * ```ts
11280
+ * const vtSource = new VectorTileSource("indoorTiles", { tiles, // provide your tile urls });
11281
+ * this.map.sources.add(vtSource);
11282
+ * const layer = new BubbleLayer(vtSource, 'bubble', {
11283
+ * createIndicators: true,
11284
+ * accessibilityIdKey: '{add your ID here}'
11285
+ * });
11286
+ * ```
11287
+ *
11288
+ * If you want to customize the highlighting style, you can use the focusin/focusout events to change the style of the bubble.
11289
+ * ```ts
11290
+ * this.map.events.add('focusin', 'bubble', (e) => { handle the style highlight });
11291
+ * ```
11191
11292
  *
11192
11293
  * Note: We treat this as an internal option for now because we hadn't fully decided the default styling for the indicators.
11193
11294
  * Once we decide, we will make this a public option or remove it.
11194
11295
  */
11195
11296
  _this.createIndicators = false;
11297
+ /**
11298
+ * @internal
11299
+ */
11300
+ _this.accessibilityIdKey = undefined;
11196
11301
  return _this;
11197
11302
  }
11198
11303
  return BubbleLayerOptions;
@@ -11265,6 +11370,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11265
11370
  }
11266
11371
  return ar;
11267
11372
  };
11373
+ var __spreadArray = (window && window.__spreadArray) || function (to, from) {
11374
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
11375
+ to[j] = from[i];
11376
+ return to;
11377
+ };
11268
11378
  /**
11269
11379
  * Renders Point objects as scalable circles (bubbles).
11270
11380
  */
@@ -11279,45 +11389,60 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11279
11389
  function BubbleLayer(source, id, options) {
11280
11390
  var _this = _super.call(this, id) || this;
11281
11391
  _this.accessibleIndicator = [];
11282
- _this.setAccessibleIndicator = function () { return __awaiter$1(_this, void 0, void 0, function () {
11283
- var features, createIndicator, insertHiddenBefore, attach;
11392
+ /** @internal */
11393
+ _this._setAccessibleIndicator = function () { return __awaiter$1(_this, void 0, void 0, function () {
11394
+ var renderedShapes, accessibilityIdKey, createIndicator, insertHiddenBefore, insertHiddenInFront, attach;
11284
11395
  var _this = this;
11285
11396
  return __generator$1(this, function (_a) {
11286
11397
  this.accessibleIndicator.forEach(function (indicator) { return indicator.remove(); });
11287
11398
  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 });
11399
+ renderedShapes = this.map.layers.getRenderedShapes(this.map.getCamera().bounds, this);
11400
+ accessibilityIdKey = this.options.accessibilityIdKey || (this._getDataSource() ? Shape._shapeIdPropName : undefined);
11401
+ createIndicator = function (renderedShapes, idx) {
11402
+ var curRenderedShape = renderedShapes[idx];
11403
+ var bubbleFeature = curRenderedShape instanceof Shape ? curRenderedShape.toJson() : curRenderedShape;
11404
+ var indicator = new AccessibleIndicator({ positionInSet: idx + 1, setSize: renderedShapes.length });
11292
11405
  var element = indicator.getElement();
11293
- var _a = __read$3(_this.map.positionsToPixels([bubbleFeature.data.geometry.coordinates]), 1), pixel = _a[0];
11406
+ var _a = __read$3(_this.map.positionsToPixels([_this.getFirstCoordinate(bubbleFeature.geometry.coordinates)]), 1), pixel = _a[0];
11294
11407
  element.addEventListener('focusin', function (event) {
11295
- _this.accessibleIndicator.filter(function (p) { return p !== indicator; }).forEach(function (popup) { return popup.remove(); });
11408
+ _this.accessibleIndicator.filter(function (i) { return i !== indicator; }).forEach(function (indicator) { return indicator.remove(); });
11296
11409
  // insert previous and next popups
11297
11410
  if (idx - 1 >= 0) {
11298
- insertHiddenBefore(indicator, createIndicator(features, idx - 1));
11411
+ insertHiddenBefore(indicator, createIndicator(renderedShapes, idx - 1));
11299
11412
  }
11300
- if (idx + 1 < features.length) {
11301
- attach(createIndicator(features, idx + 1));
11413
+ if (idx + 1 < renderedShapes.length) {
11414
+ attach(createIndicator(renderedShapes, idx + 1));
11415
+ }
11416
+ // if we are on boundaries: add the first / last indicator
11417
+ // to maintain indicators on full page navigation cycle
11418
+ if (idx >= 2 && idx == renderedShapes.length - 1) {
11419
+ insertHiddenInFront(createIndicator(renderedShapes, 0));
11420
+ }
11421
+ if (idx == 0 && renderedShapes.length >= 2) {
11422
+ attach(createIndicator(renderedShapes, renderedShapes.length - 1));
11423
+ }
11424
+ if (accessibilityIdKey !== undefined) {
11425
+ _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', accessibilityIdKey], bubbleFeature.properties[accessibilityIdKey]], '#000000', _this.options.strokeColor]);
11302
11426
  }
11303
- _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', '_azureMapsShapeId'], bubbleFeature.data.id], '#000000', _this.options.strokeColor]);
11304
11427
  var focusEvent = {
11305
11428
  target: element,
11306
11429
  type: 'focusin',
11307
11430
  map: _this.map,
11308
- shape: bubbleFeature,
11431
+ shape: curRenderedShape,
11309
11432
  originalEvent: event,
11310
11433
  pixel: pixel
11311
11434
  };
11312
11435
  _this._invokeEvent('focusin', focusEvent);
11313
11436
  });
11314
11437
  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]);
11438
+ if (accessibilityIdKey !== undefined) {
11439
+ _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', accessibilityIdKey], bubbleFeature.properties[accessibilityIdKey]], _this.options.strokeColor, _this.options.strokeColor]);
11440
+ }
11316
11441
  var focusEvent = {
11317
11442
  target: element,
11318
11443
  type: 'focusout',
11319
11444
  map: _this.map,
11320
- shape: bubbleFeature,
11445
+ shape: curRenderedShape,
11321
11446
  originalEvent: event,
11322
11447
  pixel: pixel
11323
11448
  };
@@ -11332,14 +11457,20 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11332
11457
  var baseElement = base.getElement();
11333
11458
  baseElement.parentElement.insertBefore(elementToSwapIn, baseElement);
11334
11459
  };
11460
+ insertHiddenInFront = function (toInsert) {
11461
+ toInsert.attach(_this.map);
11462
+ var elementToSwapIn = toInsert.getElement();
11463
+ var parent = elementToSwapIn.parentElement;
11464
+ parent.insertBefore(elementToSwapIn, parent.firstElementChild);
11465
+ };
11335
11466
  attach = function (popup) {
11336
11467
  popup.attach(_this.map);
11337
11468
  };
11338
- if (features.length > 0) {
11339
- attach(createIndicator(features, 0));
11469
+ if (renderedShapes.length > 0) {
11470
+ attach(createIndicator(renderedShapes, 0));
11340
11471
  }
11341
- if (features.length > 1) {
11342
- attach(createIndicator(features, features.length - 1));
11472
+ if (renderedShapes.length > 1) {
11473
+ attach(createIndicator(renderedShapes, renderedShapes.length - 1));
11343
11474
  }
11344
11475
  return [2 /*return*/];
11345
11476
  });
@@ -11392,18 +11523,71 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11392
11523
  this.options = newOptions;
11393
11524
  };
11394
11525
  BubbleLayer.prototype.onAdd = function (map) {
11526
+ var _this = this;
11395
11527
  _super.prototype.onAdd.call(this, map);
11396
11528
  if (this.options.createIndicators) {
11397
- map.events.addOnce('idle', this.setAccessibleIndicator);
11398
- map.events.add('moveend', this.setAccessibleIndicator);
11529
+ // Wait for map idle for the first time to ensure `layer.getRenderedShapes` return correct shapes.
11530
+ map.events.addOnce('idle', this._setAccessibleIndicator);
11531
+ // The rendered shapes may be changed when map is moved. Update the indicators when map is moved.
11532
+ map.events.add('moveend', this._setAccessibleIndicator);
11533
+ var dataSource = this._getDataSource();
11534
+ if (dataSource) {
11535
+ // The rendered shapes may be changed when data is added. Update the indicators when data is added.
11536
+ map.events.add('dataadded', dataSource, function () {
11537
+ // Wait for map idle to ensure `layer.getRenderedShapes` return correct shapes.
11538
+ map.events.addOnce('idle', _this._setAccessibleIndicator);
11539
+ });
11540
+ }
11541
+ else {
11542
+ var sourceId_1 = typeof this.options.source === 'string' ? this.options.source : this.options.source.getId();
11543
+ map.events.add('sourcedata', function (mapDataEvent) {
11544
+ var _a;
11545
+ // There's chances that mapDataEvent.isSourceLoaded doesn't update correctly when using flyTo, thus we check by using map.isSourceLoaded.
11546
+ if (((_a = mapDataEvent.source) === null || _a === void 0 ? void 0 : _a.getId()) === sourceId_1 && map._getMap().isSourceLoaded(sourceId_1)) {
11547
+ // Source event will be fired multiple times, and we are only interested when the source is loaded.
11548
+ // Thus design a cache key that only changed when camera & style properties are changed.
11549
+ var curCacheKey = _this._getSourceDataEventCacheKey();
11550
+ if (curCacheKey !== _this.sourceDataEventCacheKey) {
11551
+ _this._setAccessibleIndicator();
11552
+ _this.sourceDataEventCacheKey = curCacheKey;
11553
+ }
11554
+ }
11555
+ });
11556
+ }
11399
11557
  }
11400
11558
  };
11401
11559
  BubbleLayer.prototype.onRemove = function () {
11402
- _super.prototype.onRemove.call(this);
11403
11560
  if (this.options.createIndicators) {
11404
- this.map.events.remove('idle', this.setAccessibleIndicator);
11405
- this.map.events.remove('moveend', this.setAccessibleIndicator);
11561
+ this.map.events.remove('idle', this._setAccessibleIndicator);
11562
+ this.map.events.remove('moveend', this._setAccessibleIndicator);
11563
+ var dataSource = this._getDataSource();
11564
+ if (dataSource) {
11565
+ this.map.events.remove('dataadded', dataSource, this._setAccessibleIndicator);
11566
+ }
11567
+ else {
11568
+ this.map.events.remove('sourcedata', this._setAccessibleIndicator);
11569
+ }
11406
11570
  }
11571
+ _super.prototype.onRemove.call(this);
11572
+ };
11573
+ BubbleLayer.prototype._getSourceDataEventCacheKey = function () {
11574
+ if (!this.map) {
11575
+ return undefined;
11576
+ }
11577
+ var mapConfiguration = this.map.getServiceOptions().mapConfiguration;
11578
+ return __spreadArray(__spreadArray([], __read$3(this.map.getCamera().bounds)), [
11579
+ this.map.getCamera().zoom,
11580
+ this.map.getCamera().pitch,
11581
+ this.map.getStyle().style,
11582
+ mapConfiguration instanceof Object ? mapConfiguration.id : mapConfiguration
11583
+ ]).join(',');
11584
+ };
11585
+ BubbleLayer.prototype._getDataSource = function () {
11586
+ var source = typeof this.options.source === 'string' ? this.map.sources.getById(this.options.source) : this.options.source;
11587
+ if (source instanceof DataSource) {
11588
+ return source;
11589
+ }
11590
+ return undefined;
11407
11591
  };
11408
11592
  /**
11409
11593
  * @internal
@@ -11456,6 +11640,17 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11456
11640
  ids.add(this.options.source);
11457
11641
  return ids;
11458
11642
  };
11643
+ /**
11644
+ * The coordinates can be nested, so we need to get the first coordinate.
11645
+ * @param coordinates The property from the Geometry. Can be Position, Position[], Position[][], etc.
11646
+ * @returns
11647
+ */
11648
+ BubbleLayer.prototype.getFirstCoordinate = function (coordinates) {
11649
+ if (!Array.isArray(coordinates[0])) {
11650
+ return coordinates;
11651
+ }
11652
+ return this.getFirstCoordinate(coordinates[0]);
11653
+ };
11459
11654
  return BubbleLayer;
11460
11655
  }(Layer));
11461
11656
 
@@ -12539,7 +12734,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
12539
12734
  }
12540
12735
  return ar;
12541
12736
  };
12542
- var __spreadArray = (window && window.__spreadArray) || function (to, from) {
12737
+ var __spreadArray$1 = (window && window.__spreadArray) || function (to, from) {
12543
12738
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
12544
12739
  to[j] = from[i];
12545
12740
  return to;
@@ -12614,7 +12809,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
12614
12809
  finally { if (e_1) throw e_1.error; }
12615
12810
  }
12616
12811
  // Then execute the standard merge behavior.
12617
- var merged = _super.prototype.merge.apply(this, __spreadArray([], __read$4(valueList)));
12812
+ var merged = _super.prototype.merge.apply(this, __spreadArray$1([], __read$4(valueList)));
12618
12813
  if (isNewColorSet) {
12619
12814
  merged.fillPattern = undefined;
12620
12815
  }
@@ -15308,7 +15503,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
15308
15503
  }
15309
15504
  return ar;
15310
15505
  };
15311
- var __spreadArray$1 = (window && window.__spreadArray) || function (to, from) {
15506
+ var __spreadArray$2 = (window && window.__spreadArray) || function (to, from) {
15312
15507
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
15313
15508
  to[j] = from[i];
15314
15509
  return to;
@@ -15445,7 +15640,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
15445
15640
  for (var _i = 0; _i < arguments.length; _i++) {
15446
15641
  valueList[_i] = arguments[_i];
15447
15642
  }
15448
- var merged = _super.prototype.merge.apply(this, __spreadArray$1([], __read$6(valueList)));
15643
+ var merged = _super.prototype.merge.apply(this, __spreadArray$2([], __read$6(valueList)));
15449
15644
  if (merged.authType === exports.AuthenticationType.subscriptionKey) {
15450
15645
  merged.authContext = merged.aadAppId = merged.getToken = undefined;
15451
15646
  }
@@ -16116,10 +16311,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16116
16311
  if (add) {
16117
16312
  this.logoAnchor = document.createElement("a");
16118
16313
  this.logoAnchor.className = "azure-map-logo";
16119
- this.logoAnchor.href = "https://microsoft.com";
16314
+ this.logoAnchor.href = "https://aka.ms/azuremaps";
16120
16315
  this.logoAnchor.setAttribute("aria-label", "Microsoft");
16316
+ this.logoAnchor.setAttribute("target", "_blank");
16121
16317
  this.container.appendChild(this.logoAnchor);
16122
- this.logoTooltip = buildAccessibleTooltip("Visit microsoft.com");
16318
+ this.logoTooltip = buildAccessibleTooltip("Visit azure.microsoft.com");
16123
16319
  this.container.appendChild(this.logoTooltip);
16124
16320
  positionTooltip(this.logoTooltip, this.logoAnchor);
16125
16321
  }
@@ -16401,7 +16597,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16401
16597
  }
16402
16598
  return ar;
16403
16599
  };
16404
- var __spreadArray$2 = (window && window.__spreadArray) || function (to, from) {
16600
+ var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
16405
16601
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
16406
16602
  to[j] = from[i];
16407
16603
  return to;
@@ -16869,7 +17065,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16869
17065
  // Derive polygon layers from the label config.
16870
17066
  _this._polygonStyleLayer = _this._labelConfig.reduce(function (acc, cur) {
16871
17067
  if (cur.polygonSources) {
16872
- acc.push.apply(acc, __spreadArray$2([], __read$7(cur.polygonSources)));
17068
+ acc.push.apply(acc, __spreadArray$3([], __read$7(cur.polygonSources)));
16873
17069
  }
16874
17070
  return acc;
16875
17071
  }, []);
@@ -21354,7 +21550,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21354
21550
  }
21355
21551
  return ar;
21356
21552
  };
21357
- var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
21553
+ var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
21358
21554
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
21359
21555
  to[j] = from[i];
21360
21556
  return to;
@@ -21372,7 +21568,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21372
21568
  'data-azure-maps-attribution-order',
21373
21569
  'data-azure-maps-attribution-dynamic'
21374
21570
  ];
21375
- var allowedAttributionAttributes = __spreadArray$3([
21571
+ var allowedAttributionAttributes = __spreadArray$4([
21376
21572
  'href'
21377
21573
  ], __read$8(attributionRuleAttributes));
21378
21574
  var AttributionRuleProxy = /** @class */ (function () {
@@ -21597,7 +21793,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21597
21793
  };
21598
21794
  AttributionRuleProxy.prototype.applyAttributionResponse = function (attributions) {
21599
21795
  var _this = this;
21600
- var copyrights = attributions.map(function (resp) { return resp.copyrights || []; }).reduce(function (flat, copyrights) { return __spreadArray$3(__spreadArray$3([], __read$8(flat)), __read$8(copyrights)); }, []);
21796
+ var copyrights = attributions.map(function (resp) { return resp.copyrights || []; }).reduce(function (flat, copyrights) { return __spreadArray$4(__spreadArray$4([], __read$8(flat)), __read$8(copyrights)); }, []);
21601
21797
  if (copyrights.length == 0) {
21602
21798
  // no attribution for a provided tileset/bbox/z
21603
21799
  return;
@@ -21662,7 +21858,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21662
21858
  }
21663
21859
  return ar;
21664
21860
  };
21665
- var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
21861
+ var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
21666
21862
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
21667
21863
  to[j] = from[i];
21668
21864
  return to;
@@ -21781,10 +21977,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21781
21977
  }, function () { return document.createElement('span'); });
21782
21978
  });
21783
21979
  var registeredRuleSet = new Set(Object.values(registeredRules));
21784
- var redundantRules = new Set(__spreadArray$4([], __read$9(allRules)).filter(function (rule) { return !registeredRuleSet.has(rule); }));
21785
- var redundantElements = new Set(__spreadArray$4([], __read$9(redundantRules)).map(function (rule) { return rule.getElement(); }));
21980
+ var redundantRules = new Set(__spreadArray$5([], __read$9(allRules)).filter(function (rule) { return !registeredRuleSet.has(rule); }));
21981
+ var redundantElements = new Set(__spreadArray$5([], __read$9(redundantRules)).map(function (rule) { return rule.getElement(); }));
21786
21982
  // eject redundant rules associated elements altogether
21787
- __spreadArray$4([], __read$9(redundantElements)).filter(function (elem) { return elem.parentElement !== null; })
21983
+ __spreadArray$5([], __read$9(redundantElements)).filter(function (elem) { return elem.parentElement !== null; })
21788
21984
  .forEach(function (elem) { return elem.parentElement.removeChild(elem); });
21789
21985
  _this.rules = Object.values(registeredRules);
21790
21986
  var attributionsToApply = attributions
@@ -21820,7 +22016,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21820
22016
  var visibleTextNodes = function (elem) {
21821
22017
  return Array.from(elem.style.display != 'none' ? elem.children : [])
21822
22018
  .map(function (elem) { return visibleTextNodes(elem); })
21823
- .reduce(function (flattened, nodes) { return __spreadArray$4(__spreadArray$4([], __read$9(flattened)), __read$9(nodes)); }, Array.from(elem.style.display != 'none' ? elem.childNodes : []).filter(function (node) { return node.nodeType == node.TEXT_NODE; }));
22019
+ .reduce(function (flattened, nodes) { return __spreadArray$5(__spreadArray$5([], __read$9(flattened)), __read$9(nodes)); }, Array.from(elem.style.display != 'none' ? elem.childNodes : []).filter(function (node) { return node.nodeType == node.TEXT_NODE; }));
21824
22020
  };
21825
22021
  var newRenderContext = _this.virtualContext.cloneNode(true);
21826
22022
  var visibleNodes = visibleTextNodes(newRenderContext);
@@ -21835,7 +22031,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21835
22031
  // }
21836
22032
  // });
21837
22033
  // strip all predefined keywords
21838
- visibleNodes.forEach(function (node) { return node.textContent = __spreadArray$4([], __read$9(attributionFilters)).reduce(function (target, filter) { return target.replace(filter, '').trim(); }, node.textContent); });
22034
+ visibleNodes.forEach(function (node) { return node.textContent = __spreadArray$5([], __read$9(attributionFilters)).reduce(function (target, filter) { return target.replace(filter, '').trim(); }, node.textContent); });
21839
22035
  // strip year from each node
21840
22036
  // visibleNodes.forEach(node => node.textContent = node.textContent.replace(copyrightYearPattern, '').trim());
21841
22037
  // deduplicate attribution text
@@ -25027,7 +25223,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25027
25223
  this._removeListener(eventType, target, callback);
25028
25224
  }
25029
25225
  else {
25030
- target._removeEventListener(eventType, callback);
25226
+ target === null || target === void 0 ? void 0 : target._removeEventListener(eventType, callback);
25031
25227
  }
25032
25228
  }
25033
25229
  }
@@ -25517,10 +25713,15 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25517
25713
  return ids;
25518
25714
  };
25519
25715
  FundamentalMapLayer.prototype._updateLayoutProperty = function (name, newValue, oldValue, subValue) {
25520
- var _this = this;
25716
+ if (isEqual_1(newValue, oldValue))
25717
+ return;
25718
+ var map = this.map._getMap();
25521
25719
  this.layers.forEach(function (layer) {
25522
- if (!(isEqual_1(newValue, oldValue))) {
25523
- _this.map._getMap().setLayoutProperty(layer.id, name, subValue || newValue);
25720
+ if (map.getLayer(layer.id)) {
25721
+ map.setLayoutProperty(layer.id, name, subValue || newValue);
25722
+ }
25723
+ else {
25724
+ console.warn("Could not update layout property " + name + " for layer " + layer.id + " to " + (subValue || newValue));
25524
25725
  }
25525
25726
  });
25526
25727
  };
@@ -25554,7 +25755,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25554
25755
  }
25555
25756
  return ar;
25556
25757
  };
25557
- var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
25758
+ var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
25558
25759
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
25559
25760
  to[j] = from[i];
25560
25761
  return to;
@@ -25615,10 +25816,12 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25615
25816
  // Place the new layer behind the specified before layer.
25616
25817
  var layerIndex = this.layerIndex.findIndex(function (l) { return l.getId() === layer.getId(); });
25617
25818
  var userLayerIndex = this.userLayers.findIndex(function (ul) { return ul.layer.getId() === layer.getId(); });
25618
- var tempLayer = this.layerIndex[layerIndex];
25619
25819
  this._removeMapboxLayers(layer);
25620
25820
  this._addMapboxLayers(layer, before);
25621
- this.map.events._disableLayerEvents(tempLayer);
25821
+ var tempLayer = this.layerIndex[layerIndex];
25822
+ if (tempLayer) {
25823
+ this.map.events._disableLayerEvents(tempLayer);
25824
+ }
25622
25825
  this.map.events._enableLayerEvents(layer);
25623
25826
  this.layerIndex.splice(layerIndex, 1);
25624
25827
  var beforeIndex = this.layerIndex.findIndex(function (l) { return l.getId() === before; });
@@ -25626,7 +25829,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25626
25829
  if (!(layer instanceof FundamentalMapLayer)) {
25627
25830
  this.userLayers[userLayerIndex] = { layer: layer, before: before };
25628
25831
  }
25629
- tempLayer.onRemove();
25832
+ if (tempLayer) {
25833
+ tempLayer.onRemove();
25834
+ }
25630
25835
  layer.onAdd(this.map);
25631
25836
  }
25632
25837
  else {
@@ -25837,9 +26042,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25837
26042
  LayerManager.prototype.clear = function () {
25838
26043
  for (var layerIndexIndex = this.layerIndex.length - 1; layerIndexIndex >= 0; layerIndexIndex--) {
25839
26044
  var tempLayer = this.layerIndex[layerIndexIndex];
25840
- this._removeMapboxLayers(tempLayer, true);
25841
- this.layerIndex.splice(layerIndexIndex, 1);
25842
- tempLayer.onRemove();
26045
+ if (tempLayer) {
26046
+ this._removeMapboxLayers(tempLayer, true);
26047
+ this.layerIndex.splice(layerIndexIndex, 1);
26048
+ tempLayer.onRemove();
26049
+ }
25843
26050
  }
25844
26051
  this.userLayers = [];
25845
26052
  };
@@ -25990,7 +26197,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25990
26197
  // If a specified layer hasn't been added to the map throw an error.
25991
26198
  var index = this_1.layerIndex.findIndex(function (l) { return l.getId() === layerId; });
25992
26199
  if (index > -1) {
25993
- layerIds.push.apply(layerIds, __spreadArray$5([], __read$b(this_1.layerIndex[index]._getLayerIds()
26200
+ layerIds.push.apply(layerIds, __spreadArray$6([], __read$b(this_1.layerIndex[index]._getLayerIds()
25994
26201
  .filter(function (id) { return !!_this.map._getMap().getLayer(id); }))));
25995
26202
  }
25996
26203
  else {
@@ -26279,6 +26486,37 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26279
26486
  FundamentalMapSource.prototype._buildSource = function () {
26280
26487
  return this.source;
26281
26488
  };
26489
+ /**
26490
+ * @internal
26491
+ */
26492
+ FundamentalMapSource.prototype._isDeepEqual = function (other) {
26493
+ if (this.constructor !== other.constructor) {
26494
+ return false;
26495
+ }
26496
+ var source = this.source;
26497
+ var otherSource = other.source;
26498
+ var baseEqual = source.type === otherSource.type &&
26499
+ source.url === otherSource.url
26500
+ && ((source.tiles === undefined && otherSource.tiles === undefined) ||
26501
+ (source.tiles && otherSource.tiles && source.tiles.length === otherSource.tiles.length && source.tiles.every(function (value, idx) { return value === otherSource.tiles[idx]; })))
26502
+ && source.minzoom === otherSource.minzoom
26503
+ && source.maxzoom === otherSource.maxzoom
26504
+ && source.bounds === otherSource.bounds
26505
+ && source.attribution === otherSource.attribution;
26506
+ var rasterEqual = source.type !== "raster" || (source.type === "raster"
26507
+ && source.type === otherSource.type
26508
+ && source.tileSize === otherSource.tileSize
26509
+ && source.scheme === otherSource.scheme);
26510
+ var rasterDemEqual = source.type !== "raster-dem" || (source.type === "raster-dem"
26511
+ && source.type === otherSource.type
26512
+ && source.tileSize === otherSource.tileSize
26513
+ && source.encoding === otherSource.encoding);
26514
+ var vectorEqual = source.type !== "vector" || (source.type === "vector"
26515
+ && source.type === otherSource.type
26516
+ && source.promoteId === otherSource.promoteId
26517
+ && source.scheme === otherSource.scheme);
26518
+ return baseEqual && rasterEqual && rasterDemEqual && vectorEqual;
26519
+ };
26282
26520
  /**
26283
26521
  * Updates the source info to convert the tiles to url strings.
26284
26522
  * @param sourceDef The original source info.
@@ -26575,39 +26813,52 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26575
26813
  var _this = this;
26576
26814
  if (sources) {
26577
26815
  Object.keys(sources).forEach(function (sourceId) {
26816
+ var sourceToAdd = sources[sourceId];
26817
+ var newSource;
26818
+ if (sourceToAdd.type === "vector") {
26819
+ newSource = new FundamentalMapSource(sourceId, {
26820
+ name: sourceId,
26821
+ tiles: sourceToAdd.tiles,
26822
+ type: "vector",
26823
+ url: sourceToAdd.url
26824
+ });
26825
+ }
26826
+ else if (sourceToAdd.type === "raster") {
26827
+ newSource = new FundamentalMapSource(sourceId, {
26828
+ name: sourceId,
26829
+ tiles: sourceToAdd.tiles,
26830
+ type: "raster",
26831
+ url: sourceToAdd.url
26832
+ });
26833
+ }
26834
+ else {
26835
+ // Do not throw for the source of unknown type.
26836
+ // throw new Error(`Unable to construct source with ID ${sourceId}.`);
26837
+ // no other handling for the source we don't sync into the state here
26838
+ return;
26839
+ }
26578
26840
  if (!_this.sources.has(sourceId)) {
26579
- var sourceToAdd = sources[sourceId];
26580
- if (sourceToAdd.type === "vector") {
26581
- var newSource = new FundamentalMapSource(sourceId, {
26582
- name: sourceId,
26583
- tiles: sourceToAdd.tiles,
26584
- type: "vector",
26585
- url: sourceToAdd.url
26586
- });
26587
- _this.sources.set(sourceId, newSource);
26588
- newSource._setMap(_this.map);
26589
- }
26590
- else if (sourceToAdd.type === "raster") {
26591
- var newSource = new FundamentalMapSource(sourceId, {
26592
- name: sourceId,
26593
- tiles: sourceToAdd.tiles,
26594
- type: "raster",
26595
- url: sourceToAdd.url
26596
- });
26597
- _this.sources.set(sourceId, newSource);
26598
- newSource._setMap(_this.map);
26599
- }
26600
- else {
26601
- throw new Error("Unable to construct source with ID " + sourceId + ".");
26602
- }
26841
+ _this.sources.set(sourceId, newSource);
26842
+ newSource._setMap(_this.map);
26603
26843
  }
26604
- });
26605
- Object.keys(this.sources).forEach(function (sourceId) {
26606
- if (!sources.hasOwnProperty(sourceId)) {
26607
- _this.sources.get(sourceId)._setMap(null);
26608
- _this.sources.delete(sourceId);
26844
+ else if (_this.sources.has(sourceId) && !_this.sources.get(sourceId)._isDeepEqual(newSource)) {
26845
+ // source with same id but different properties: update
26846
+ _this.sources.set(sourceId, newSource);
26847
+ newSource._setMap(_this.map, false);
26609
26848
  }
26610
26849
  });
26850
+ // counter-intuitive: below is a bug and will do nothing since Object.keys(this.sources) will always return [], it should rather be:
26851
+ // Array.from(this.sources.keys()).forEach(sourceId => {
26852
+ // however, we have seen the first party users are compensating for this with their code containing explicit azm.sources.remove but not containing the check for existing
26853
+ // such removal will cause the exception, since the source would already be removed
26854
+ //
26855
+ // given this bug was here historically, we keep the removal unfixed here (already fixed in v3) to make sure we don't cause any unintented side effects for existing users
26856
+ // Object.keys(this.sources).forEach(sourceId => {
26857
+ // if (!sources.hasOwnProperty(sourceId)) {
26858
+ // this.sources.get(sourceId)._setMap(null);
26859
+ // this.sources.delete(sourceId);
26860
+ // }
26861
+ // });
26611
26862
  }
26612
26863
  };
26613
26864
  return SourceManager;
@@ -26749,7 +27000,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26749
27000
  }
26750
27001
  return ar;
26751
27002
  };
26752
- var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
27003
+ var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
26753
27004
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
26754
27005
  to[j] = from[i];
26755
27006
  return to;
@@ -26824,7 +27075,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26824
27075
  }
26825
27076
  finally { if (e_1) throw e_1.error; }
26826
27077
  }
26827
- return _super.prototype.merge.apply(this, __spreadArray$6([], __read$c(valuesList)));
27078
+ return _super.prototype.merge.apply(this, __spreadArray$7([], __read$c(valuesList)));
26828
27079
  };
26829
27080
  return CameraBoundsOptions;
26830
27081
  }(Options));
@@ -27313,7 +27564,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27313
27564
  }
27314
27565
  return ar;
27315
27566
  };
27316
- var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
27567
+ var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
27317
27568
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
27318
27569
  to[j] = from[i];
27319
27570
  return to;
@@ -27433,6 +27684,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27433
27684
  * @deprecated use `view` instead.
27434
27685
  */
27435
27686
  _this.userRegion = _this.view;
27687
+ /**
27688
+ * allows substituting a default MapControl's style transformer with custom one
27689
+ * Default style transformer is meant to update the incoming fetched style to desired state, as well as to synchronize the SDK state with style state
27690
+ * and move additional layers over
27691
+ * @internal
27692
+ */
27693
+ _this.customStyleTransform = undefined;
27436
27694
  return _this;
27437
27695
  }
27438
27696
  /**
@@ -27472,7 +27730,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27472
27730
  finally { if (e_1) throw e_1.error; }
27473
27731
  }
27474
27732
  // Then execute the standard merge behavior.
27475
- return _super.prototype.merge.apply(this, __spreadArray$7([], __read$d(valueList)));
27733
+ return _super.prototype.merge.apply(this, __spreadArray$8([], __read$d(valueList)));
27476
27734
  };
27477
27735
  return StyleOptions;
27478
27736
  }(Options));
@@ -27530,7 +27788,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27530
27788
  }
27531
27789
  return ar;
27532
27790
  };
27533
- var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
27791
+ var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
27534
27792
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
27535
27793
  to[j] = from[i];
27536
27794
  return to;
@@ -27765,10 +28023,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27765
28023
  // won't change default behavior in Options as usually that's what desired
27766
28024
  // instead capture it here and reassign.
27767
28025
  var currentTransforms = this._transformers;
27768
- var transformersToMerge = valueList ? valueList.filter(function (value) { return value !== undefined; }).reduce(function (flattened, value) { return __spreadArray$8(__spreadArray$8([], __read$e(flattened)), __read$e(value._transformers || [])); }, []) : [];
28026
+ var transformersToMerge = valueList ? valueList.filter(function (value) { return value !== undefined; }).reduce(function (flattened, value) { return __spreadArray$9(__spreadArray$9([], __read$e(flattened)), __read$e(value._transformers || [])); }, []) : [];
27769
28027
  // Then execute the standard merge behavior.
27770
28028
  // If subscription key auth method isn't being used then the subscription key property should be undefined.
27771
- var merged = _super.prototype.merge.apply(this, __spreadArray$8([], __read$e(valueList)));
28029
+ var merged = _super.prototype.merge.apply(this, __spreadArray$9([], __read$e(valueList)));
27772
28030
  if (merged.authOptions.authType !== exports.AuthenticationType.subscriptionKey) {
27773
28031
  merged["subscription-key"] = merged.subscriptionKey = undefined;
27774
28032
  }
@@ -27780,7 +28038,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27780
28038
  if (merged.mapConfiguration && typeof merged.mapConfiguration !== 'string') {
27781
28039
  merged.mapConfiguration = __assign$7(__assign$7({}, merged.mapConfiguration), { defaultConfiguration: merged.mapConfiguration.defaultConfiguration || merged.mapConfiguration['defaultStyle'], configurations: merged.mapConfiguration.configurations || merged.mapConfiguration['styles'] });
27782
28040
  }
27783
- this._transformers = __spreadArray$8(__spreadArray$8([], __read$e(currentTransforms || [])), __read$e(transformersToMerge.filter(function (toMerge) { return !currentTransforms.includes(toMerge); })));
28041
+ this._transformers = __spreadArray$9(__spreadArray$9([], __read$e(currentTransforms || [])), __read$e(transformersToMerge.filter(function (toMerge) { return !currentTransforms.includes(toMerge); })));
27784
28042
  if (this.transformRequest && !this._transformers.includes(this.transformRequest)) {
27785
28043
  this._transformers.push(this.transformRequest);
27786
28044
  }
@@ -28028,7 +28286,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28028
28286
  }
28029
28287
  return ar;
28030
28288
  };
28031
- var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
28289
+ var __spreadArray$a = (window && window.__spreadArray) || function (to, from) {
28032
28290
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
28033
28291
  to[j] = from[i];
28034
28292
  return to;
@@ -28081,7 +28339,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28081
28339
  var deferredLayers = Object.entries(layerGroupLayers).reduce(function (deferred, _a) {
28082
28340
  var _b = __read$f(_a, 2), groupName = _b[0], layers = _b[1];
28083
28341
  var isInInitialLayerGroup = validInitLayerGroups.includes(groupName);
28084
- return __spreadArray$9(__spreadArray$9([], __read$f(deferred)), __read$f(layers.filter(function (layer) {
28342
+ return __spreadArray$a(__spreadArray$a([], __read$f(deferred)), __read$f(layers.filter(function (layer) {
28085
28343
  var _a;
28086
28344
  // Exclude custom layers
28087
28345
  if (layer.type === 'custom')
@@ -28133,13 +28391,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28133
28391
  };
28134
28392
  _this.map.events.addOnce('load', _this._progressiveLoadingState.pendingVisibilityChange);
28135
28393
  };
28136
- this._onStyleData = function () {
28137
- _this._lookUpAsync(_this.map.getStyle()).then(function (style) {
28138
- _this.map.events.invoke("stylechanged", {
28139
- style: style.name,
28140
- map: _this.map,
28141
- type: "stylechanged"
28142
- });
28394
+ this._onStyleData = function (definition) {
28395
+ _this.map.events.invoke("stylechanged", {
28396
+ style: definition.name,
28397
+ map: _this.map,
28398
+ type: "stylechanged"
28143
28399
  });
28144
28400
  };
28145
28401
  /**
@@ -28246,7 +28502,8 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28246
28502
  return baseName in styleNamesMap ? styleNamesMap[baseName] : baseName;
28247
28503
  };
28248
28504
  if (!this.serviceOptions.mapConfiguration) {
28249
- newPromise = new HijackablePromise(this._request(this.serviceOptions.staticAssetsDomain, constants.stylePath + "/" + constants.styleResourcePath, "StyleDefinitions", { version: this.serviceOptions.styleDefinitionsVersion }).then(function (definitions) { return ({
28505
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
28506
+ 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 ({
28250
28507
  version: isNaN(definitions.version) ? 0 : parseFloat(definitions.version),
28251
28508
  defaultConfiguration: definitions.defaultStyle,
28252
28509
  configurations: definitions.styles
@@ -28285,12 +28542,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28285
28542
  protocol: "https"
28286
28543
  }).toString(),
28287
28544
  }); })
28288
- }); }));
28545
+ }); }); }));
28289
28546
  }
28290
28547
  else if (typeof this.serviceOptions.mapConfiguration === 'string') {
28291
- newPromise = new HijackablePromise(this._request(this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + this.serviceOptions.mapConfiguration, "StyleDefinitions"
28548
+ var ensureAuthentication = this.map.authentication ? this.map.authentication.initialize() : Promise.resolve();
28549
+ newPromise = new HijackablePromise(ensureAuthentication.then(function () { return _this._request(_this.serviceOptions.domain, constants.styleResourcePath + "/mapconfigurations/metadata/" + _this.serviceOptions.mapConfiguration, "StyleDefinitions"
28292
28550
  // reassign properties from legacy mapConfiguration to new structure if needed
28293
- ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }));
28551
+ ).then(function (definitions) { return (__assign$8(__assign$8({}, definitions), { defaultConfiguration: definitions.defaultConfiguration || definitions['defaultStyle'], configurations: definitions.configurations || definitions['styles'] })); }); }));
28294
28552
  }
28295
28553
  else {
28296
28554
  newPromise = HijackablePromise.resolve(this.serviceOptions.mapConfiguration);
@@ -28321,23 +28579,183 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28321
28579
  if (styleDefinition.style) {
28322
28580
  return styleDefinition.style;
28323
28581
  }
28324
- throw Error("Style definition does not contain neither URL nor style object.");
28582
+ throw Error("Style definition neither contains URL nor style object.");
28583
+ };
28584
+ StyleManager.prototype.deriveNewStyleAndLayerGroups = function (previousStyle, nextStyle) {
28585
+ var _a, _b, _c, _d, _e, _f;
28586
+ // Layers in the next style with default properties that do not align with current StyleOptions
28587
+ // should be modified before they are applied to the map.
28588
+ var styleOptions = this.map.getStyle();
28589
+ var trafficOptions = this.map.getTraffic();
28590
+ var layersGroups = {};
28591
+ for (var i = 0; i < nextStyle.layers.length; i++) {
28592
+ var nextLayer = nextStyle.layers[i];
28593
+ var layerGroup = LayerGroupComparator.getLayerGroup(nextLayer);
28594
+ if (!layerGroup) {
28595
+ layersGroups[nextLayer.id] = [nextLayer];
28596
+ continue;
28597
+ }
28598
+ if (!layersGroups[layerGroup]) {
28599
+ layersGroups[layerGroup] = [];
28600
+ }
28601
+ var layerGroupLayers = layersGroups[layerGroup];
28602
+ layerGroupLayers.push(nextLayer);
28603
+ // 1. Set visiblity of fill-extrusion layers according to StyleOptions.showBuildingModels
28604
+ if (!styleOptions.showBuildingModels && nextLayer.type === "fill-extrusion") {
28605
+ nextLayer.layout = (_a = nextLayer.layout) !== null && _a !== void 0 ? _a : {};
28606
+ nextLayer.layout.visibility = "none";
28607
+ }
28608
+ else if (nextLayer.type === "fill-extrusion") {
28609
+ nextLayer.layout = (_b = nextLayer.layout) !== null && _b !== void 0 ? _b : {};
28610
+ nextLayer.layout.visibility = "visible";
28611
+ }
28612
+ // 2. Set visibility of traffic layers depending on traffic settings.
28613
+ if (trafficOptions.flow !== "none" && layerGroup) {
28614
+ if (layerGroup === "traffic_" + trafficOptions.flow && nextLayer.type == "line") {
28615
+ nextLayer.layout = (_c = nextLayer.layout) !== null && _c !== void 0 ? _c : {};
28616
+ nextLayer.layout.visibility = "visible";
28617
+ }
28618
+ }
28619
+ // 3. Set visibility of labels
28620
+ var isLabelLayerGroup = layerGroup === 'labels' || layerGroup === 'labels_places' || layerGroup === 'labels_indoor';
28621
+ if (isLabelLayerGroup && nextLayer.type === 'symbol') {
28622
+ if (styleOptions.showLabels && ((_d = nextLayer.layout) === null || _d === void 0 ? void 0 : _d.visibility) !== "none") {
28623
+ nextLayer.layout = (_e = nextLayer.layout) !== null && _e !== void 0 ? _e : {};
28624
+ nextLayer.layout.visibility = "visible";
28625
+ }
28626
+ else {
28627
+ nextLayer.layout = (_f = nextLayer.layout) !== null && _f !== void 0 ? _f : {};
28628
+ nextLayer.layout.visibility = "none";
28629
+ }
28630
+ }
28631
+ }
28632
+ return [nextStyle, layersGroups];
28633
+ };
28634
+ StyleManager.prototype.injectUserLayersIntoStyle = function (previousStyle, nextStyle, layerGroupLayers) {
28635
+ // Custom layers added to mapbox through this SDK should be carried over to the next style.
28636
+ return !previousStyle
28637
+ ? nextStyle
28638
+ : this.map.layers._getUserLayers().reduce(function (style, userLayer) {
28639
+ if (userLayer.layer instanceof WebGLLayer) {
28640
+ // mapbox custom layers cannot be serialized and preserved,
28641
+ // return to continue to the next user layer.
28642
+ return style;
28643
+ }
28644
+ var before = layerGroupLayers[userLayer.before] && layerGroupLayers[userLayer.before].length > 0
28645
+ ? layerGroupLayers[userLayer.before][0]
28646
+ : undefined;
28647
+ var layer = previousStyle.layers.find(function (layer) { return layer.id === userLayer.layer.getId(); });
28648
+ // when setStyle diff attempt is unsuccesful, _load will be called on the style that may have already injected user layers -> clean it up
28649
+ var existingLayerIdx = nextStyle.layers.findIndex(function (layer) { return layer.id === userLayer.layer.getId(); });
28650
+ if (existingLayerIdx > -1) {
28651
+ nextStyle.layers.splice(existingLayerIdx, 1);
28652
+ }
28653
+ if (layer) {
28654
+ var sourcesToCopy = new Set(Array.from(userLayer.layer._getSourceIds())
28655
+ .map(function (sourceId) { return previousStyle.sources[sourceId] ? { source: previousStyle.sources[sourceId], id: sourceId } : undefined; })
28656
+ .filter(function (source) { return source !== undefined; }));
28657
+ var insertIdx = before ? style.layers.findIndex(function (layer) { return layer.id === before.id; }) : -1;
28658
+ if (insertIdx > -1) {
28659
+ style.layers.splice(insertIdx, 0, layer);
28660
+ }
28661
+ else {
28662
+ style.layers.push(layer);
28663
+ }
28664
+ sourcesToCopy.forEach(function (_a) {
28665
+ var source = _a.source, id = _a.id;
28666
+ style.sources[id] = source;
28667
+ });
28668
+ }
28669
+ return style;
28670
+ }, __assign$8({}, nextStyle));
28325
28671
  };
28326
28672
  /**
28327
28673
  * @internal
28328
28674
  */
28329
28675
  StyleManager.prototype.setStyle = function (styleOptions, diff) {
28676
+ var _this = this;
28330
28677
  if (diff === void 0) { diff = true; }
28331
- try {
28332
- this.map._getMap().setStyle(this.getStyle(styleOptions), {
28333
- diff: diff,
28334
- stylePatch: this._stylePatch.bind(this),
28335
- validate: this.serviceOptions.validateStyle
28336
- });
28678
+ var transformStyleFunc;
28679
+ var targetDefinition = this._lookUp(styleOptions);
28680
+ if (!targetDefinition) {
28681
+ throw Error("Style definition " + styleOptions.style + " is not available.");
28682
+ }
28683
+ if (!targetDefinition.url && !targetDefinition.style) {
28684
+ throw Error("Style definition neither contains URL nor style object.");
28685
+ }
28686
+ var styleDataCallback = function () { return _this._onStyleData(targetDefinition); };
28687
+ var patchStyleEvent = function () {
28688
+ // FIXME: below diffing will be soon fixed on the maplibre side
28689
+ // If there was a previous styledata change event attached, remove it.
28690
+ // When the sprite url changes between style changes then maplibre can't perform the diff
28691
+ // In such cases it recalculate the style again. Removing previous attached
28692
+ // event listener makes sure that style changed event is not fired twice in these cases.
28693
+ _this.map.events.remove("styledata", styleDataCallback);
28694
+ _this.map.events.addOnce("styledata", styleDataCallback);
28695
+ };
28696
+ if (styleOptions && styleOptions.customStyleTransform) {
28697
+ transformStyleFunc = function (prev, next) {
28698
+ var target = styleOptions.customStyleTransform(prev, next);
28699
+ patchStyleEvent();
28700
+ return target;
28701
+ };
28337
28702
  }
28338
- catch (e) {
28339
- throw e;
28703
+ else {
28704
+ transformStyleFunc = function (previousStyle, style) {
28705
+ // make sure we always have a shallow clone to prevent mutating explicit json(rather then url) styles being set
28706
+ var nextStyle = __assign$8(__assign$8({}, style), { layers: __spreadArray$a([], __read$f(style.layers)), sources: __assign$8({}, style.sources) });
28707
+ var shouldProgressiveLoading = (styleOptions.progressiveLoading &&
28708
+ // The feature only effective at the initial load.
28709
+ !_this.map._isLoaded());
28710
+ // Shallow-clone the style object and duplicate layer.layout properties to avoid side-effects.
28711
+ if (shouldProgressiveLoading && Array.isArray(style === null || style === void 0 ? void 0 : style.layers)) {
28712
+ nextStyle = __assign$8({}, style);
28713
+ nextStyle.layers = nextStyle.layers.map(function (layer) {
28714
+ var nextLayer = __assign$8({}, layer);
28715
+ if (layer.layout) {
28716
+ nextLayer.layout = __assign$8({}, layer.layout);
28717
+ }
28718
+ return nextLayer;
28719
+ });
28720
+ }
28721
+ // 1. derive the base new style (without user layers) and layer groups
28722
+ var _a = __read$f(_this.deriveNewStyleAndLayerGroups(previousStyle, nextStyle), 2), targetStyle = _a[0], layerGroupLayers = _a[1];
28723
+ // 2. side effect: progressively render map layers to the canvas to shorten the time to the first meaningful render.
28724
+ if (shouldProgressiveLoading) {
28725
+ var initLayerGroups = styleOptions.progressiveLoadingInitialLayerGroups;
28726
+ if (Array.isArray(initLayerGroups) && initLayerGroups.length > 0) {
28727
+ _this._deferLayerGroupVisibilities(layerGroupLayers, initLayerGroups);
28728
+ }
28729
+ }
28730
+ // 3. copy user layers and sources from previous style into new one
28731
+ var targetStyleWithUserLayers = _this.injectUserLayersIntoStyle(previousStyle, targetStyle, layerGroupLayers);
28732
+ // 4. side effects: sync our control's LayerManager and SourceManager
28733
+ var nextFundamentalLayers = Object.entries(layerGroupLayers).map(function (_a) {
28734
+ var _b = __read$f(_a, 2), layerGroupId = _b[0], layers = _b[1];
28735
+ return _this._buildFundamentalLayerFrom(layers, layerGroupId);
28736
+ });
28737
+ var layerIndex = _this.map.layers._getUserLayers().reduce(function (layerIndex, userLayer) {
28738
+ var layerInsertIndex = userLayer.before ? layerIndex.findIndex(function (layer) { return layer.getId() === userLayer.before; }) : -1;
28739
+ if (layerInsertIndex > -1) {
28740
+ layerIndex.splice(layerInsertIndex, 0, userLayer.layer);
28741
+ }
28742
+ else {
28743
+ layerIndex.push(userLayer.layer);
28744
+ }
28745
+ return layerIndex;
28746
+ }, nextFundamentalLayers);
28747
+ _this.map.layers['layerIndex'] = layerIndex;
28748
+ _this.map.sources._syncSources(targetStyleWithUserLayers.sources);
28749
+ // 5. temporarily patch style data event
28750
+ patchStyleEvent();
28751
+ return targetStyleWithUserLayers;
28752
+ };
28340
28753
  }
28754
+ this.map._getMap().setStyle(targetDefinition.url || targetDefinition.style, {
28755
+ diff: diff,
28756
+ validate: this.serviceOptions.validateStyle,
28757
+ transformStyle: transformStyleFunc
28758
+ });
28341
28759
  };
28342
28760
  /**
28343
28761
  * Gets the color theme (light/dark) for the style type specified by the style options.
@@ -28402,135 +28820,6 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28402
28820
  StyleManager.prototype.clearStyleSet = function () {
28403
28821
  this.unsetIndoorState();
28404
28822
  };
28405
- /**
28406
- * Function invoked by mapbox after a style is fetched but before it is committed to the map state.
28407
- *
28408
- * @param previousStyle The current style.
28409
- * @param nextStyle The next style which is to be applied.
28410
- * @param preserveLayer Preserve a layer from the previous style in the next style.
28411
- * @param updatePaintProperty Modify paint properties of a layer in the next style before the style is applied.
28412
- * @param updateLayoutProperty Modify layout properties of a layer in the next style before the style is applied.
28413
- * @param updateFilter Modify filter property of a layer in the next style before the style is applied.
28414
- */
28415
- StyleManager.prototype._stylePatch = function (previousStyle, nextStyle, preserveLayer, updatePaintProperty, updateLayoutProperty, updateFilter) {
28416
- var _this = this;
28417
- // Layers in the next style with default properties that do not align with current StyleOptions
28418
- // should be modified before they are applied to the map.
28419
- var styleOptions = this.map.getStyle();
28420
- var trafficOptions = this.map.getTraffic();
28421
- var shouldProgressiveLoading = (styleOptions.progressiveLoading &&
28422
- // The feature only effective at the initial load.
28423
- !this.map._isLoaded());
28424
- var setLayerVisibility = function (layer, visibility) {
28425
- var _a;
28426
- if (!shouldProgressiveLoading) {
28427
- // No need to apply the visibility change to maplibre while progressive loading is enabled.
28428
- // This can save a lot of CPU time.
28429
- updateLayoutProperty(layer.id, 'visibility', visibility);
28430
- }
28431
- layer.layout = (_a = layer.layout) !== null && _a !== void 0 ? _a : {};
28432
- layer.layout.visibility = visibility;
28433
- };
28434
- var layerGroupLayers = {};
28435
- nextStyle.layers.forEach(function (nextLayer) {
28436
- var _a;
28437
- var layerGroup = LayerGroupComparator.getLayerGroup(nextLayer);
28438
- if (layerGroup) {
28439
- // Set visibility of fill-extrusion layers according to StyleOptions.showBuildingModels
28440
- if (nextLayer.type === 'fill-extrusion') {
28441
- setLayerVisibility(nextLayer, styleOptions.showBuildingModels ? 'visible' : 'none');
28442
- }
28443
- // Set visibility of traffic layers depending on traffic settings.
28444
- if (trafficOptions.flow !== 'none' && nextLayer.type == 'line' &&
28445
- (layerGroup === "traffic_" + trafficOptions.flow ||
28446
- // Check if deprecated flow types are used and the layer is a bing-traffic layer.
28447
- // Needed for backwards compatibility in Bing styles to support deprecated flow types.
28448
- (['absolute', 'relative-delay'].includes(trafficOptions.flow) && nextLayer['source'] === "bing-traffic"))) {
28449
- setLayerVisibility(nextLayer, 'visible');
28450
- }
28451
- // Set visibility of labels
28452
- var isLabelLayerGroup = layerGroup === 'labels' || layerGroup === 'labels_places' || layerGroup === 'labels_indoor';
28453
- if (isLabelLayerGroup && nextLayer.type === 'symbol') {
28454
- var isLayerVisible = ((_a = nextLayer.layout) === null || _a === void 0 ? void 0 : _a.visibility) !== 'none';
28455
- setLayerVisibility(nextLayer, isLayerVisible && styleOptions.showLabels ? 'visible' : 'none');
28456
- }
28457
- // Once this _stylePatch returns control to maplibre the next style will be applied immediately in the same context.
28458
- // To avoid potential data races update LayerManager with new a new set of FundamentalMapLayers from here instead of
28459
- // waiting for a styledata.load event to trigger a sync in a different context.
28460
- if (layerGroupLayers[layerGroup]) {
28461
- layerGroupLayers[layerGroup].push(nextLayer);
28462
- }
28463
- else {
28464
- layerGroupLayers[layerGroup] = [nextLayer];
28465
- }
28466
- }
28467
- });
28468
- if (shouldProgressiveLoading) {
28469
- var initLayerGroups = styleOptions.progressiveLoadingInitialLayerGroups;
28470
- if (Array.isArray(initLayerGroups) && initLayerGroups.length > 0) {
28471
- this._deferLayerGroupVisibilities(layerGroupLayers, initLayerGroups);
28472
- }
28473
- }
28474
- // A FundamentalMapLayer (grouped layer) representation of the next style must be built.
28475
- var previousLayers = this.map.layers.getLayers();
28476
- var nextLayers = Object.entries(layerGroupLayers).map(function (_a) {
28477
- var _b = __read$f(_a, 2), layerGroupName = _b[0], layerGroupMapboxLayers = _b[1];
28478
- return _this._buildFundamentalLayerFrom(layerGroupMapboxLayers, layerGroupName);
28479
- });
28480
- // Update FundamentalMapLayers in LayerManager
28481
- var userLayers = this.map.layers._getUserLayers();
28482
- var layersToRemove = previousLayers.filter(function (c) {
28483
- return (nextLayers.findIndex(function (n) { return c.getId() === n.getId(); }) < 0 &&
28484
- userLayers.findIndex(function (n) { return c.getId() === n.layer.getId(); }) < 0);
28485
- });
28486
- var prevNextIntersection = nextLayers.filter(function (n) { return previousLayers.find(function (c) { return c.getId() === n.getId(); }); });
28487
- var ePrevNextIntersection = prevNextIntersection.entries();
28488
- var replace = ePrevNextIntersection.next();
28489
- nextLayers.forEach(function (newFundamentalLayer) {
28490
- if (replace.value && replace.value[1].getId() === newFundamentalLayer.getId()) {
28491
- // Replace the existing layer with this ID with the new one.
28492
- var insertBefore = previousLayers.findIndex(function (l) { return l.getId() === newFundamentalLayer.getId(); });
28493
- _this.map.layers.remove(newFundamentalLayer.getId());
28494
- _this.map.layers.add(newFundamentalLayer, previousLayers[insertBefore].getId());
28495
- replace = ePrevNextIntersection.next();
28496
- }
28497
- else {
28498
- if (replace.value) {
28499
- // Insert new layer before the next common layer.
28500
- _this.map.layers.add(newFundamentalLayer, replace.value[1]);
28501
- }
28502
- else {
28503
- _this.map.layers.add(newFundamentalLayer);
28504
- }
28505
- }
28506
- });
28507
- layersToRemove.forEach(function (layer) {
28508
- _this.map.layers.remove(layer);
28509
- });
28510
- // Layers added to mapbox through this SDK since loading the last style should be
28511
- // carried over to the next style.
28512
- userLayers.forEach(function (userLayer) {
28513
- if (userLayer.layer instanceof WebGLLayer) {
28514
- // mapbox custom layers cannot be serialized and preserved,
28515
- // return to continue to the next user layer.
28516
- return;
28517
- }
28518
- var before = undefined;
28519
- if (_this.map.layers.getLayerById(userLayer.before)) {
28520
- var beforeCandidates = _this.map.layers.getLayerById(userLayer.before)._buildLayers();
28521
- before = (beforeCandidates.length > 0) ? beforeCandidates[0] : undefined;
28522
- }
28523
- preserveLayer(userLayer.layer.getId(), before === null || before === void 0 ? void 0 : before.id);
28524
- _this.map.layers.move(userLayer.layer, userLayer.before);
28525
- });
28526
- this.map.sources._syncSources(nextStyle.sources);
28527
- // If there was a previous styledata change event attached, remove it.
28528
- // When the sprite url changes between style changes then mapbox can't perform the diff
28529
- // In such cases it recalculate the style again. Removing previous attached
28530
- // event listener makes sure that style changed event is not fired twice in these cases.
28531
- this.map.events.remove("styledata", this._onStyleData);
28532
- this.map.events.addOnce("styledata", this._onStyleData);
28533
- };
28534
28823
  StyleManager.prototype._buildFundamentalLayerFrom = function (layers, id) {
28535
28824
  if (layers && layers.length > 0) {
28536
28825
  var newLayer = new FundamentalMapLayer(layers, id);
@@ -28834,7 +29123,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28834
29123
  }
28835
29124
  return ar;
28836
29125
  };
28837
- var __spreadArray$a = (window && window.__spreadArray) || function (to, from) {
29126
+ var __spreadArray$b = (window && window.__spreadArray) || function (to, from) {
28838
29127
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
28839
29128
  to[j] = from[i];
28840
29129
  return to;
@@ -28961,6 +29250,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28961
29250
  showLogo: _this.styleOptions.showLogo,
28962
29251
  customAttribution: _this.styleOptions.customAttribution
28963
29252
  });
29253
+ _this.controls.add(_this.copyrightControl, {
29254
+ position: exports.ControlPosition.NonFixed
29255
+ });
28964
29256
  // Initialize state of map
28965
29257
  // --> Initialize the authentication manager
28966
29258
  var authManInit = _this.authentication ?
@@ -28988,17 +29280,14 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28988
29280
  _this.map.showTileBoundaries = _this.styleOptions.showTileBoundaries;
28989
29281
  _this.localizedStringsPromise = Localizer.getStrings(_this.styleOptions.language);
28990
29282
  authManInit
28991
- .then(function () { return _this.styles.initStyleset(); })
29283
+ // reuses this.styles.initPromise if initStyleset is already called
29284
+ .then(function () { return _this.styles.definitions(); })
28992
29285
  .then(function (definitions) {
28993
29286
  // Check that the map hasn't been removed for any reason.
28994
29287
  // If so no need to finish styling the map.
28995
29288
  if (_this.removed) {
28996
29289
  return;
28997
29290
  }
28998
- // Add controls after initStyleset to prevent redundant initStyleset calls
28999
- _this.controls.add(_this.copyrightControl, {
29000
- position: exports.ControlPosition.NonFixed
29001
- });
29002
29291
  if (_this.authentication && !_this.authentication.getToken()) {
29003
29292
  throw new Error("AuthenticationManager finished initializing, but no token is available");
29004
29293
  }
@@ -29058,6 +29347,16 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29058
29347
  }
29059
29348
  return _this;
29060
29349
  }
29350
+ Object.defineProperty(Map.prototype, "isDisposed", {
29351
+ /**
29352
+ * Returns true if the map has been disposed.
29353
+ */
29354
+ get: function () {
29355
+ return this.removed;
29356
+ },
29357
+ enumerable: false,
29358
+ configurable: true
29359
+ });
29061
29360
  /**
29062
29361
  * Returns the HTMLCanvasElement that the map is drawn to.
29063
29362
  */
@@ -29094,9 +29393,17 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29094
29393
  else {
29095
29394
  this.accessibleMapDelegate.removeFromMap();
29096
29395
  }
29097
- if (this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration) {
29396
+ var shouldReloadStyle = this.styles.serviceOptions.mapConfiguration !== this.serviceOptions.mapConfiguration
29397
+ || this.styles.serviceOptions.staticAssetsDomain !== this.serviceOptions.staticAssetsDomain
29398
+ || this.styles.serviceOptions.styleDefinitionsVersion !== this.serviceOptions.styleDefinitionsVersion
29399
+ || this.styles.serviceOptions.domain !== this.serviceOptions.domain
29400
+ || this.styles.serviceOptions.styleAPIVersion !== this.serviceOptions.styleAPIVersion;
29401
+ // NOTE: only perform a reload when the style dependent properties are changed
29402
+ //|| this.styles.serviceOptions.validateStyle !== this.serviceOptions.validateStyle
29403
+ //|| this.styles.serviceOptions.transformRequest !== this.serviceOptions.transformRequest
29404
+ this.styles.serviceOptions = this.serviceOptions;
29405
+ if (shouldReloadStyle) {
29098
29406
  this.styles.initPromise = null;
29099
- this.styles.serviceOptions.mapConfiguration = this.serviceOptions.mapConfiguration;
29100
29407
  this.setStyle({});
29101
29408
  }
29102
29409
  };
@@ -29648,7 +29955,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29648
29955
  urls = layer.getOptions().subdomains || [];
29649
29956
  }
29650
29957
  // Add the tile urls to the layer, but don't update the map yet.
29651
- urls.push.apply(urls, __spreadArray$a([], __read$g(tileSources)));
29958
+ urls.push.apply(urls, __spreadArray$b([], __read$g(tileSources)));
29652
29959
  layer._setOptionsNoUpdate({
29653
29960
  subdomains: urls
29654
29961
  });
@@ -30169,7 +30476,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
30169
30476
  }
30170
30477
  return ar;
30171
30478
  };
30172
- var __spreadArray$b = (window && window.__spreadArray) || function (to, from) {
30479
+ var __spreadArray$c = (window && window.__spreadArray) || function (to, from) {
30173
30480
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
30174
30481
  to[j] = from[i];
30175
30482
  return to;
@@ -30315,7 +30622,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
30315
30622
  lineLength = 50;
30316
30623
  }
30317
30624
  var lines = c.split(/<(tr|div|br|li|h[0-9]|p>)/);
30318
- longestStringLength = Math.max.apply(Math, __spreadArray$b([], __read$h((lines.map(function (el) { return el.replace(/<[a-zA-Z0-9\s=\/]+>/g, "").length; }))))) - 1;
30625
+ longestStringLength = Math.max.apply(Math, __spreadArray$c([], __read$h((lines.map(function (el) { return el.replace(/<[a-zA-Z0-9\s=\/]+>/g, "").length; }))))) - 1;
30319
30626
  var w = Math.ceil(longestStringLength * 3.5);
30320
30627
  if (w < width) {
30321
30628
  width = w;