azure-maps-control 2.2.7 → 2.3.1

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.7";
268
+ var version = "2.3.1";
269
269
 
270
270
  /**
271
271
  * A helper class that provides methods for getting various forms of the map controls current version.
@@ -10312,19 +10312,24 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10312
10312
  * Get reference to Mapbox Map
10313
10313
  * @internal
10314
10314
  */
10315
- Source.prototype._setMap = function (map) {
10315
+ Source.prototype._setMap = function (map, shouldInvokeEvent) {
10316
+ if (shouldInvokeEvent === void 0) { shouldInvokeEvent = true; }
10316
10317
  if (map == null || map === undefined) {
10317
10318
  var temp = this.map;
10318
10319
  delete this.map;
10319
- this._invokeEvent("sourceremoved", this);
10320
- if (temp) {
10321
- temp.events.invoke("sourceremoved", this);
10320
+ if (shouldInvokeEvent) {
10321
+ this._invokeEvent("sourceremoved", this);
10322
+ if (temp) {
10323
+ temp.events.invoke("sourceremoved", this);
10324
+ }
10322
10325
  }
10323
10326
  }
10324
10327
  else {
10325
10328
  this.map = map;
10326
- this._invokeEvent("sourceadded", this);
10327
- this.map.events.invoke("sourceadded", this);
10329
+ if (shouldInvokeEvent) {
10330
+ this._invokeEvent("sourceadded", this);
10331
+ this.map.events.invoke("sourceadded", this);
10332
+ }
10328
10333
  }
10329
10334
  };
10330
10335
  return Source;
@@ -10645,6 +10650,27 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10645
10650
  }
10646
10651
  return geoJsonSource;
10647
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
+ };
10648
10674
  /**
10649
10675
  * @internal
10650
10676
  */
@@ -10926,6 +10952,26 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
10926
10952
  }
10927
10953
  return vectorSource;
10928
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
+ };
10929
10975
  return VectorTileSource;
10930
10976
  }(Source));
10931
10977
 
@@ -11217,11 +11263,41 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11217
11263
  /**
11218
11264
  * @internal
11219
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
+ * ```
11220
11292
  *
11221
11293
  * Note: We treat this as an internal option for now because we hadn't fully decided the default styling for the indicators.
11222
11294
  * Once we decide, we will make this a public option or remove it.
11223
11295
  */
11224
11296
  _this.createIndicators = false;
11297
+ /**
11298
+ * @internal
11299
+ */
11300
+ _this.accessibilityIdKey = undefined;
11225
11301
  return _this;
11226
11302
  }
11227
11303
  return BubbleLayerOptions;
@@ -11294,6 +11370,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11294
11370
  }
11295
11371
  return ar;
11296
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
+ };
11297
11378
  /**
11298
11379
  * Renders Point objects as scalable circles (bubbles).
11299
11380
  */
@@ -11308,13 +11389,15 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11308
11389
  function BubbleLayer(source, id, options) {
11309
11390
  var _this = _super.call(this, id) || this;
11310
11391
  _this.accessibleIndicator = [];
11311
- _this.setAccessibleIndicator = function () { return __awaiter$1(_this, void 0, void 0, function () {
11312
- var renderedShapes, createIndicator, insertHiddenBefore, insertHiddenInFront, attach;
11392
+ /** @internal */
11393
+ _this._setAccessibleIndicator = function () { return __awaiter$1(_this, void 0, void 0, function () {
11394
+ var renderedShapes, accessibilityIdKey, createIndicator, insertHiddenBefore, insertHiddenInFront, attach;
11313
11395
  var _this = this;
11314
11396
  return __generator$1(this, function (_a) {
11315
11397
  this.accessibleIndicator.forEach(function (indicator) { return indicator.remove(); });
11316
11398
  this.accessibleIndicator = [];
11317
11399
  renderedShapes = this.map.layers.getRenderedShapes(this.map.getCamera().bounds, this);
11400
+ accessibilityIdKey = this.options.accessibilityIdKey || (this._getDataSource() ? Shape._shapeIdPropName : undefined);
11318
11401
  createIndicator = function (renderedShapes, idx) {
11319
11402
  var curRenderedShape = renderedShapes[idx];
11320
11403
  var bubbleFeature = curRenderedShape instanceof Shape ? curRenderedShape.toJson() : curRenderedShape;
@@ -11338,9 +11421,8 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11338
11421
  if (idx == 0 && renderedShapes.length >= 2) {
11339
11422
  attach(createIndicator(renderedShapes, renderedShapes.length - 1));
11340
11423
  }
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]);
11424
+ if (accessibilityIdKey !== undefined) {
11425
+ _this.map._getMap().setPaintProperty(_this.id, 'circle-stroke-color', ['case', ['==', ['get', accessibilityIdKey], bubbleFeature.properties[accessibilityIdKey]], '#000000', _this.options.strokeColor]);
11344
11426
  }
11345
11427
  var focusEvent = {
11346
11428
  target: element,
@@ -11353,8 +11435,8 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11353
11435
  _this._invokeEvent('focusin', focusEvent);
11354
11436
  });
11355
11437
  element.addEventListener('focusout', function (event) {
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]);
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]);
11358
11440
  }
11359
11441
  var focusEvent = {
11360
11442
  target: element,
@@ -11441,19 +11523,72 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
11441
11523
  this.options = newOptions;
11442
11524
  };
11443
11525
  BubbleLayer.prototype.onAdd = function (map) {
11526
+ var _this = this;
11444
11527
  _super.prototype.onAdd.call(this, map);
11445
11528
  if (this.options.createIndicators) {
11446
- map.events.addOnce('idle', this.setAccessibleIndicator);
11447
- 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
+ }
11448
11557
  }
11449
11558
  };
11450
11559
  BubbleLayer.prototype.onRemove = function () {
11451
11560
  if (this.options.createIndicators) {
11452
- this.map.events.remove('idle', this.setAccessibleIndicator);
11453
- 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
+ }
11454
11570
  }
11455
11571
  _super.prototype.onRemove.call(this);
11456
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;
11591
+ };
11457
11592
  /**
11458
11593
  * @internal
11459
11594
  */
@@ -12599,7 +12734,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
12599
12734
  }
12600
12735
  return ar;
12601
12736
  };
12602
- var __spreadArray = (window && window.__spreadArray) || function (to, from) {
12737
+ var __spreadArray$1 = (window && window.__spreadArray) || function (to, from) {
12603
12738
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
12604
12739
  to[j] = from[i];
12605
12740
  return to;
@@ -12674,7 +12809,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
12674
12809
  finally { if (e_1) throw e_1.error; }
12675
12810
  }
12676
12811
  // Then execute the standard merge behavior.
12677
- var merged = _super.prototype.merge.apply(this, __spreadArray([], __read$4(valueList)));
12812
+ var merged = _super.prototype.merge.apply(this, __spreadArray$1([], __read$4(valueList)));
12678
12813
  if (isNewColorSet) {
12679
12814
  merged.fillPattern = undefined;
12680
12815
  }
@@ -15368,7 +15503,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
15368
15503
  }
15369
15504
  return ar;
15370
15505
  };
15371
- var __spreadArray$1 = (window && window.__spreadArray) || function (to, from) {
15506
+ var __spreadArray$2 = (window && window.__spreadArray) || function (to, from) {
15372
15507
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
15373
15508
  to[j] = from[i];
15374
15509
  return to;
@@ -15505,7 +15640,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
15505
15640
  for (var _i = 0; _i < arguments.length; _i++) {
15506
15641
  valueList[_i] = arguments[_i];
15507
15642
  }
15508
- 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)));
15509
15644
  if (merged.authType === exports.AuthenticationType.subscriptionKey) {
15510
15645
  merged.authContext = merged.aadAppId = merged.getToken = undefined;
15511
15646
  }
@@ -16176,10 +16311,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16176
16311
  if (add) {
16177
16312
  this.logoAnchor = document.createElement("a");
16178
16313
  this.logoAnchor.className = "azure-map-logo";
16179
- this.logoAnchor.href = "https://microsoft.com";
16314
+ this.logoAnchor.href = "https://aka.ms/azuremaps";
16180
16315
  this.logoAnchor.setAttribute("aria-label", "Microsoft");
16316
+ this.logoAnchor.setAttribute("target", "_blank");
16181
16317
  this.container.appendChild(this.logoAnchor);
16182
- this.logoTooltip = buildAccessibleTooltip("Visit microsoft.com");
16318
+ this.logoTooltip = buildAccessibleTooltip("Visit azure.microsoft.com");
16183
16319
  this.container.appendChild(this.logoTooltip);
16184
16320
  positionTooltip(this.logoTooltip, this.logoAnchor);
16185
16321
  }
@@ -16256,7 +16392,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16256
16392
  }
16257
16393
  return ar;
16258
16394
  };
16259
- var __spreadArray$2 = (window && window.__spreadArray) || function (to, from) {
16395
+ var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
16260
16396
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
16261
16397
  to[j] = from[i];
16262
16398
  return to;
@@ -17858,10 +17994,15 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
17858
17994
  return ids;
17859
17995
  };
17860
17996
  FundamentalMapLayer.prototype._updateLayoutProperty = function (name, newValue, oldValue, subValue) {
17861
- var _this = this;
17997
+ if (isEqual_1(newValue, oldValue))
17998
+ return;
17999
+ var map = this.map._getMap();
17862
18000
  this.layers.forEach(function (layer) {
17863
- if (!(isEqual_1(newValue, oldValue))) {
17864
- _this.map._getMap().setLayoutProperty(layer.id, name, subValue || newValue);
18001
+ if (map.getLayer(layer.id)) {
18002
+ map.setLayoutProperty(layer.id, name, subValue || newValue);
18003
+ }
18004
+ else {
18005
+ console.warn("Could not update layout property " + name + " for layer " + layer.id + " to " + (subValue || newValue));
17865
18006
  }
17866
18007
  });
17867
18008
  };
@@ -17895,7 +18036,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
17895
18036
  }
17896
18037
  return ar;
17897
18038
  };
17898
- var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
18039
+ var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
17899
18040
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
17900
18041
  to[j] = from[i];
17901
18042
  return to;
@@ -17956,10 +18097,12 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
17956
18097
  // Place the new layer behind the specified before layer.
17957
18098
  var layerIndex = this.layerIndex.findIndex(function (l) { return l.getId() === layer.getId(); });
17958
18099
  var userLayerIndex = this.userLayers.findIndex(function (ul) { return ul.layer.getId() === layer.getId(); });
17959
- var tempLayer = this.layerIndex[layerIndex];
17960
18100
  this._removeMapboxLayers(layer);
17961
18101
  this._addMapboxLayers(layer, before);
17962
- this.map.events._disableLayerEvents(tempLayer);
18102
+ var tempLayer = this.layerIndex[layerIndex];
18103
+ if (tempLayer) {
18104
+ this.map.events._disableLayerEvents(tempLayer);
18105
+ }
17963
18106
  this.map.events._enableLayerEvents(layer);
17964
18107
  this.layerIndex.splice(layerIndex, 1);
17965
18108
  var beforeIndex = this.layerIndex.findIndex(function (l) { return l.getId() === before; });
@@ -17967,7 +18110,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
17967
18110
  if (!(layer instanceof FundamentalMapLayer)) {
17968
18111
  this.userLayers[userLayerIndex] = { layer: layer, before: before };
17969
18112
  }
17970
- tempLayer.onRemove();
18113
+ if (tempLayer) {
18114
+ tempLayer.onRemove();
18115
+ }
17971
18116
  layer.onAdd(this.map);
17972
18117
  }
17973
18118
  else {
@@ -18333,7 +18478,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
18333
18478
  // If a specified layer hasn't been added to the map throw an error.
18334
18479
  var index = this_1.layerIndex.findIndex(function (l) { return l.getId() === layerId; });
18335
18480
  if (index > -1) {
18336
- layerIds.push.apply(layerIds, __spreadArray$3([], __read$9(this_1.layerIndex[index]._getLayerIds()
18481
+ layerIds.push.apply(layerIds, __spreadArray$4([], __read$9(this_1.layerIndex[index]._getLayerIds()
18337
18482
  .filter(function (id) { return !!_this.map._getMap().getLayer(id); }))));
18338
18483
  }
18339
18484
  else {
@@ -18622,6 +18767,37 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
18622
18767
  FundamentalMapSource.prototype._buildSource = function () {
18623
18768
  return this.source;
18624
18769
  };
18770
+ /**
18771
+ * @internal
18772
+ */
18773
+ FundamentalMapSource.prototype._isDeepEqual = function (other) {
18774
+ if (this.constructor !== other.constructor) {
18775
+ return false;
18776
+ }
18777
+ var source = this.source;
18778
+ var otherSource = other.source;
18779
+ var baseEqual = source.type === otherSource.type &&
18780
+ source.url === otherSource.url
18781
+ && ((source.tiles === undefined && otherSource.tiles === undefined) ||
18782
+ (source.tiles && otherSource.tiles && source.tiles.length === otherSource.tiles.length && source.tiles.every(function (value, idx) { return value === otherSource.tiles[idx]; })))
18783
+ && source.minzoom === otherSource.minzoom
18784
+ && source.maxzoom === otherSource.maxzoom
18785
+ && source.bounds === otherSource.bounds
18786
+ && source.attribution === otherSource.attribution;
18787
+ var rasterEqual = source.type !== "raster" || (source.type === "raster"
18788
+ && source.type === otherSource.type
18789
+ && source.tileSize === otherSource.tileSize
18790
+ && source.scheme === otherSource.scheme);
18791
+ var rasterDemEqual = source.type !== "raster-dem" || (source.type === "raster-dem"
18792
+ && source.type === otherSource.type
18793
+ && source.tileSize === otherSource.tileSize
18794
+ && source.encoding === otherSource.encoding);
18795
+ var vectorEqual = source.type !== "vector" || (source.type === "vector"
18796
+ && source.type === otherSource.type
18797
+ && source.promoteId === otherSource.promoteId
18798
+ && source.scheme === otherSource.scheme);
18799
+ return baseEqual && rasterEqual && rasterDemEqual && vectorEqual;
18800
+ };
18625
18801
  /**
18626
18802
  * Updates the source info to convert the tiles to url strings.
18627
18803
  * @param sourceDef The original source info.
@@ -18918,39 +19094,52 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
18918
19094
  var _this = this;
18919
19095
  if (sources) {
18920
19096
  Object.keys(sources).forEach(function (sourceId) {
19097
+ var sourceToAdd = sources[sourceId];
19098
+ var newSource;
19099
+ if (sourceToAdd.type === "vector") {
19100
+ newSource = new FundamentalMapSource(sourceId, {
19101
+ name: sourceId,
19102
+ tiles: sourceToAdd.tiles,
19103
+ type: "vector",
19104
+ url: sourceToAdd.url
19105
+ });
19106
+ }
19107
+ else if (sourceToAdd.type === "raster") {
19108
+ newSource = new FundamentalMapSource(sourceId, {
19109
+ name: sourceId,
19110
+ tiles: sourceToAdd.tiles,
19111
+ type: "raster",
19112
+ url: sourceToAdd.url
19113
+ });
19114
+ }
19115
+ else {
19116
+ // Do not throw for the source of unknown type.
19117
+ // throw new Error(`Unable to construct source with ID ${sourceId}.`);
19118
+ // no other handling for the source we don't sync into the state here
19119
+ return;
19120
+ }
18921
19121
  if (!_this.sources.has(sourceId)) {
18922
- var sourceToAdd = sources[sourceId];
18923
- if (sourceToAdd.type === "vector") {
18924
- var newSource = new FundamentalMapSource(sourceId, {
18925
- name: sourceId,
18926
- tiles: sourceToAdd.tiles,
18927
- type: "vector",
18928
- url: sourceToAdd.url
18929
- });
18930
- _this.sources.set(sourceId, newSource);
18931
- newSource._setMap(_this.map);
18932
- }
18933
- else if (sourceToAdd.type === "raster") {
18934
- var newSource = new FundamentalMapSource(sourceId, {
18935
- name: sourceId,
18936
- tiles: sourceToAdd.tiles,
18937
- type: "raster",
18938
- url: sourceToAdd.url
18939
- });
18940
- _this.sources.set(sourceId, newSource);
18941
- newSource._setMap(_this.map);
18942
- }
18943
- else {
18944
- throw new Error("Unable to construct source with ID " + sourceId + ".");
18945
- }
19122
+ _this.sources.set(sourceId, newSource);
19123
+ newSource._setMap(_this.map);
18946
19124
  }
18947
- });
18948
- Object.keys(this.sources).forEach(function (sourceId) {
18949
- if (!sources.hasOwnProperty(sourceId)) {
18950
- _this.sources.get(sourceId)._setMap(null);
18951
- _this.sources.delete(sourceId);
19125
+ else if (_this.sources.has(sourceId) && !_this.sources.get(sourceId)._isDeepEqual(newSource)) {
19126
+ // source with same id but different properties: update
19127
+ _this.sources.set(sourceId, newSource);
19128
+ newSource._setMap(_this.map, false);
18952
19129
  }
18953
19130
  });
19131
+ // counter-intuitive: below is a bug and will do nothing since Object.keys(this.sources) will always return [], it should rather be:
19132
+ // Array.from(this.sources.keys()).forEach(sourceId => {
19133
+ // 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
19134
+ // such removal will cause the exception, since the source would already be removed
19135
+ //
19136
+ // 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
19137
+ // Object.keys(this.sources).forEach(sourceId => {
19138
+ // if (!sources.hasOwnProperty(sourceId)) {
19139
+ // this.sources.get(sourceId)._setMap(null);
19140
+ // this.sources.delete(sourceId);
19141
+ // }
19142
+ // });
18954
19143
  }
18955
19144
  };
18956
19145
  return SourceManager;
@@ -19092,7 +19281,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19092
19281
  }
19093
19282
  return ar;
19094
19283
  };
19095
- var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
19284
+ var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
19096
19285
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
19097
19286
  to[j] = from[i];
19098
19287
  return to;
@@ -19167,7 +19356,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19167
19356
  }
19168
19357
  finally { if (e_1) throw e_1.error; }
19169
19358
  }
19170
- return _super.prototype.merge.apply(this, __spreadArray$4([], __read$a(valuesList)));
19359
+ return _super.prototype.merge.apply(this, __spreadArray$5([], __read$a(valuesList)));
19171
19360
  };
19172
19361
  return CameraBoundsOptions;
19173
19362
  }(Options));
@@ -19656,7 +19845,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19656
19845
  }
19657
19846
  return ar;
19658
19847
  };
19659
- var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
19848
+ var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
19660
19849
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
19661
19850
  to[j] = from[i];
19662
19851
  return to;
@@ -19776,6 +19965,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19776
19965
  * @deprecated use `view` instead.
19777
19966
  */
19778
19967
  _this.userRegion = _this.view;
19968
+ /**
19969
+ * allows substituting a default MapControl's style transformer with custom one
19970
+ * 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
19971
+ * and move additional layers over
19972
+ * @internal
19973
+ */
19974
+ _this.customStyleTransform = undefined;
19779
19975
  return _this;
19780
19976
  }
19781
19977
  /**
@@ -19815,7 +20011,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19815
20011
  finally { if (e_1) throw e_1.error; }
19816
20012
  }
19817
20013
  // Then execute the standard merge behavior.
19818
- return _super.prototype.merge.apply(this, __spreadArray$5([], __read$b(valueList)));
20014
+ return _super.prototype.merge.apply(this, __spreadArray$6([], __read$b(valueList)));
19819
20015
  };
19820
20016
  return StyleOptions;
19821
20017
  }(Options));
@@ -19873,7 +20069,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
19873
20069
  }
19874
20070
  return ar;
19875
20071
  };
19876
- var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
20072
+ var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
19877
20073
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
19878
20074
  to[j] = from[i];
19879
20075
  return to;
@@ -20108,10 +20304,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20108
20304
  // won't change default behavior in Options as usually that's what desired
20109
20305
  // instead capture it here and reassign.
20110
20306
  var currentTransforms = this._transformers;
20111
- var transformersToMerge = valueList ? valueList.filter(function (value) { return value !== undefined; }).reduce(function (flattened, value) { return __spreadArray$6(__spreadArray$6([], __read$c(flattened)), __read$c(value._transformers || [])); }, []) : [];
20307
+ var transformersToMerge = valueList ? valueList.filter(function (value) { return value !== undefined; }).reduce(function (flattened, value) { return __spreadArray$7(__spreadArray$7([], __read$c(flattened)), __read$c(value._transformers || [])); }, []) : [];
20112
20308
  // Then execute the standard merge behavior.
20113
20309
  // If subscription key auth method isn't being used then the subscription key property should be undefined.
20114
- var merged = _super.prototype.merge.apply(this, __spreadArray$6([], __read$c(valueList)));
20310
+ var merged = _super.prototype.merge.apply(this, __spreadArray$7([], __read$c(valueList)));
20115
20311
  if (merged.authOptions.authType !== exports.AuthenticationType.subscriptionKey) {
20116
20312
  merged["subscription-key"] = merged.subscriptionKey = undefined;
20117
20313
  }
@@ -20123,7 +20319,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20123
20319
  if (merged.mapConfiguration && typeof merged.mapConfiguration !== 'string') {
20124
20320
  merged.mapConfiguration = __assign$7(__assign$7({}, merged.mapConfiguration), { defaultConfiguration: merged.mapConfiguration.defaultConfiguration || merged.mapConfiguration['defaultStyle'], configurations: merged.mapConfiguration.configurations || merged.mapConfiguration['styles'] });
20125
20321
  }
20126
- this._transformers = __spreadArray$6(__spreadArray$6([], __read$c(currentTransforms || [])), __read$c(transformersToMerge.filter(function (toMerge) { return !currentTransforms.includes(toMerge); })));
20322
+ this._transformers = __spreadArray$7(__spreadArray$7([], __read$c(currentTransforms || [])), __read$c(transformersToMerge.filter(function (toMerge) { return !currentTransforms.includes(toMerge); })));
20127
20323
  if (this.transformRequest && !this._transformers.includes(this.transformRequest)) {
20128
20324
  this._transformers.push(this.transformRequest);
20129
20325
  }
@@ -20371,7 +20567,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20371
20567
  }
20372
20568
  return ar;
20373
20569
  };
20374
- var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
20570
+ var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
20375
20571
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20376
20572
  to[j] = from[i];
20377
20573
  return to;
@@ -20424,7 +20620,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20424
20620
  var deferredLayers = Object.entries(layerGroupLayers).reduce(function (deferred, _a) {
20425
20621
  var _b = __read$d(_a, 2), groupName = _b[0], layers = _b[1];
20426
20622
  var isInInitialLayerGroup = validInitLayerGroups.includes(groupName);
20427
- return __spreadArray$7(__spreadArray$7([], __read$d(deferred)), __read$d(layers.filter(function (layer) {
20623
+ return __spreadArray$8(__spreadArray$8([], __read$d(deferred)), __read$d(layers.filter(function (layer) {
20428
20624
  var _a;
20429
20625
  // Exclude custom layers
20430
20626
  if (layer.type === 'custom')
@@ -20476,13 +20672,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20476
20672
  };
20477
20673
  _this.map.events.addOnce('load', _this._progressiveLoadingState.pendingVisibilityChange);
20478
20674
  };
20479
- this._onStyleData = function () {
20480
- _this._lookUpAsync(_this.map.getStyle()).then(function (style) {
20481
- _this.map.events.invoke("stylechanged", {
20482
- style: style.name,
20483
- map: _this.map,
20484
- type: "stylechanged"
20485
- });
20675
+ this._onStyleData = function (definition) {
20676
+ _this.map.events.invoke("stylechanged", {
20677
+ style: definition.name,
20678
+ map: _this.map,
20679
+ type: "stylechanged"
20486
20680
  });
20487
20681
  };
20488
20682
  /**
@@ -20666,23 +20860,183 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20666
20860
  if (styleDefinition.style) {
20667
20861
  return styleDefinition.style;
20668
20862
  }
20669
- throw Error("Style definition does not contain neither URL nor style object.");
20863
+ throw Error("Style definition neither contains URL nor style object.");
20864
+ };
20865
+ StyleManager.prototype.deriveNewStyleAndLayerGroups = function (previousStyle, nextStyle) {
20866
+ var _a, _b, _c, _d, _e, _f;
20867
+ // Layers in the next style with default properties that do not align with current StyleOptions
20868
+ // should be modified before they are applied to the map.
20869
+ var styleOptions = this.map.getStyle();
20870
+ var trafficOptions = this.map.getTraffic();
20871
+ var layersGroups = {};
20872
+ for (var i = 0; i < nextStyle.layers.length; i++) {
20873
+ var nextLayer = nextStyle.layers[i];
20874
+ var layerGroup = LayerGroupComparator.getLayerGroup(nextLayer);
20875
+ if (!layerGroup) {
20876
+ layersGroups[nextLayer.id] = [nextLayer];
20877
+ continue;
20878
+ }
20879
+ if (!layersGroups[layerGroup]) {
20880
+ layersGroups[layerGroup] = [];
20881
+ }
20882
+ var layerGroupLayers = layersGroups[layerGroup];
20883
+ layerGroupLayers.push(nextLayer);
20884
+ // 1. Set visiblity of fill-extrusion layers according to StyleOptions.showBuildingModels
20885
+ if (!styleOptions.showBuildingModels && nextLayer.type === "fill-extrusion") {
20886
+ nextLayer.layout = (_a = nextLayer.layout) !== null && _a !== void 0 ? _a : {};
20887
+ nextLayer.layout.visibility = "none";
20888
+ }
20889
+ else if (nextLayer.type === "fill-extrusion") {
20890
+ nextLayer.layout = (_b = nextLayer.layout) !== null && _b !== void 0 ? _b : {};
20891
+ nextLayer.layout.visibility = "visible";
20892
+ }
20893
+ // 2. Set visibility of traffic layers depending on traffic settings.
20894
+ if (trafficOptions.flow !== "none" && layerGroup) {
20895
+ if (layerGroup === "traffic_" + trafficOptions.flow && nextLayer.type == "line") {
20896
+ nextLayer.layout = (_c = nextLayer.layout) !== null && _c !== void 0 ? _c : {};
20897
+ nextLayer.layout.visibility = "visible";
20898
+ }
20899
+ }
20900
+ // 3. Set visibility of labels
20901
+ var isLabelLayerGroup = layerGroup === 'labels' || layerGroup === 'labels_places' || layerGroup === 'labels_indoor';
20902
+ if (isLabelLayerGroup && nextLayer.type === 'symbol') {
20903
+ if (styleOptions.showLabels && ((_d = nextLayer.layout) === null || _d === void 0 ? void 0 : _d.visibility) !== "none") {
20904
+ nextLayer.layout = (_e = nextLayer.layout) !== null && _e !== void 0 ? _e : {};
20905
+ nextLayer.layout.visibility = "visible";
20906
+ }
20907
+ else {
20908
+ nextLayer.layout = (_f = nextLayer.layout) !== null && _f !== void 0 ? _f : {};
20909
+ nextLayer.layout.visibility = "none";
20910
+ }
20911
+ }
20912
+ }
20913
+ return [nextStyle, layersGroups];
20914
+ };
20915
+ StyleManager.prototype.injectUserLayersIntoStyle = function (previousStyle, nextStyle, layerGroupLayers) {
20916
+ // Custom layers added to mapbox through this SDK should be carried over to the next style.
20917
+ return !previousStyle
20918
+ ? nextStyle
20919
+ : this.map.layers._getUserLayers().reduce(function (style, userLayer) {
20920
+ if (userLayer.layer instanceof WebGLLayer) {
20921
+ // mapbox custom layers cannot be serialized and preserved,
20922
+ // return to continue to the next user layer.
20923
+ return style;
20924
+ }
20925
+ var before = layerGroupLayers[userLayer.before] && layerGroupLayers[userLayer.before].length > 0
20926
+ ? layerGroupLayers[userLayer.before][0]
20927
+ : undefined;
20928
+ var layer = previousStyle.layers.find(function (layer) { return layer.id === userLayer.layer.getId(); });
20929
+ // when setStyle diff attempt is unsuccesful, _load will be called on the style that may have already injected user layers -> clean it up
20930
+ var existingLayerIdx = nextStyle.layers.findIndex(function (layer) { return layer.id === userLayer.layer.getId(); });
20931
+ if (existingLayerIdx > -1) {
20932
+ nextStyle.layers.splice(existingLayerIdx, 1);
20933
+ }
20934
+ if (layer) {
20935
+ var sourcesToCopy = new Set(Array.from(userLayer.layer._getSourceIds())
20936
+ .map(function (sourceId) { return previousStyle.sources[sourceId] ? { source: previousStyle.sources[sourceId], id: sourceId } : undefined; })
20937
+ .filter(function (source) { return source !== undefined; }));
20938
+ var insertIdx = before ? style.layers.findIndex(function (layer) { return layer.id === before.id; }) : -1;
20939
+ if (insertIdx > -1) {
20940
+ style.layers.splice(insertIdx, 0, layer);
20941
+ }
20942
+ else {
20943
+ style.layers.push(layer);
20944
+ }
20945
+ sourcesToCopy.forEach(function (_a) {
20946
+ var source = _a.source, id = _a.id;
20947
+ style.sources[id] = source;
20948
+ });
20949
+ }
20950
+ return style;
20951
+ }, __assign$8({}, nextStyle));
20670
20952
  };
20671
20953
  /**
20672
20954
  * @internal
20673
20955
  */
20674
20956
  StyleManager.prototype.setStyle = function (styleOptions, diff) {
20957
+ var _this = this;
20675
20958
  if (diff === void 0) { diff = true; }
20676
- try {
20677
- this.map._getMap().setStyle(this.getStyle(styleOptions), {
20678
- diff: diff,
20679
- stylePatch: this._stylePatch.bind(this),
20680
- validate: this.serviceOptions.validateStyle
20681
- });
20959
+ var transformStyleFunc;
20960
+ var targetDefinition = this._lookUp(styleOptions);
20961
+ if (!targetDefinition) {
20962
+ throw Error("Style definition " + styleOptions.style + " is not available.");
20963
+ }
20964
+ if (!targetDefinition.url && !targetDefinition.style) {
20965
+ throw Error("Style definition neither contains URL nor style object.");
20966
+ }
20967
+ var styleDataCallback = function () { return _this._onStyleData(targetDefinition); };
20968
+ var patchStyleEvent = function () {
20969
+ // FIXME: below diffing will be soon fixed on the maplibre side
20970
+ // If there was a previous styledata change event attached, remove it.
20971
+ // When the sprite url changes between style changes then maplibre can't perform the diff
20972
+ // In such cases it recalculate the style again. Removing previous attached
20973
+ // event listener makes sure that style changed event is not fired twice in these cases.
20974
+ _this.map.events.remove("styledata", styleDataCallback);
20975
+ _this.map.events.addOnce("styledata", styleDataCallback);
20976
+ };
20977
+ if (styleOptions && styleOptions.customStyleTransform) {
20978
+ transformStyleFunc = function (prev, next) {
20979
+ var target = styleOptions.customStyleTransform(prev, next);
20980
+ patchStyleEvent();
20981
+ return target;
20982
+ };
20682
20983
  }
20683
- catch (e) {
20684
- throw e;
20984
+ else {
20985
+ transformStyleFunc = function (previousStyle, style) {
20986
+ // make sure we always have a shallow clone to prevent mutating explicit json(rather then url) styles being set
20987
+ var nextStyle = __assign$8(__assign$8({}, style), { layers: __spreadArray$8([], __read$d(style.layers)), sources: __assign$8({}, style.sources) });
20988
+ var shouldProgressiveLoading = (styleOptions.progressiveLoading &&
20989
+ // The feature only effective at the initial load.
20990
+ !_this.map._isLoaded());
20991
+ // Shallow-clone the style object and duplicate layer.layout properties to avoid side-effects.
20992
+ if (shouldProgressiveLoading && Array.isArray(style === null || style === void 0 ? void 0 : style.layers)) {
20993
+ nextStyle = __assign$8({}, style);
20994
+ nextStyle.layers = nextStyle.layers.map(function (layer) {
20995
+ var nextLayer = __assign$8({}, layer);
20996
+ if (layer.layout) {
20997
+ nextLayer.layout = __assign$8({}, layer.layout);
20998
+ }
20999
+ return nextLayer;
21000
+ });
21001
+ }
21002
+ // 1. derive the base new style (without user layers) and layer groups
21003
+ var _a = __read$d(_this.deriveNewStyleAndLayerGroups(previousStyle, nextStyle), 2), targetStyle = _a[0], layerGroupLayers = _a[1];
21004
+ // 2. side effect: progressively render map layers to the canvas to shorten the time to the first meaningful render.
21005
+ if (shouldProgressiveLoading) {
21006
+ var initLayerGroups = styleOptions.progressiveLoadingInitialLayerGroups;
21007
+ if (Array.isArray(initLayerGroups) && initLayerGroups.length > 0) {
21008
+ _this._deferLayerGroupVisibilities(layerGroupLayers, initLayerGroups);
21009
+ }
21010
+ }
21011
+ // 3. copy user layers and sources from previous style into new one
21012
+ var targetStyleWithUserLayers = _this.injectUserLayersIntoStyle(previousStyle, targetStyle, layerGroupLayers);
21013
+ // 4. side effects: sync our control's LayerManager and SourceManager
21014
+ var nextFundamentalLayers = Object.entries(layerGroupLayers).map(function (_a) {
21015
+ var _b = __read$d(_a, 2), layerGroupId = _b[0], layers = _b[1];
21016
+ return _this._buildFundamentalLayerFrom(layers, layerGroupId);
21017
+ });
21018
+ var layerIndex = _this.map.layers._getUserLayers().reduce(function (layerIndex, userLayer) {
21019
+ var layerInsertIndex = userLayer.before ? layerIndex.findIndex(function (layer) { return layer.getId() === userLayer.before; }) : -1;
21020
+ if (layerInsertIndex > -1) {
21021
+ layerIndex.splice(layerInsertIndex, 0, userLayer.layer);
21022
+ }
21023
+ else {
21024
+ layerIndex.push(userLayer.layer);
21025
+ }
21026
+ return layerIndex;
21027
+ }, nextFundamentalLayers);
21028
+ _this.map.layers['layerIndex'] = layerIndex;
21029
+ _this.map.sources._syncSources(targetStyleWithUserLayers.sources);
21030
+ // 5. temporarily patch style data event
21031
+ patchStyleEvent();
21032
+ return targetStyleWithUserLayers;
21033
+ };
20685
21034
  }
21035
+ this.map._getMap().setStyle(targetDefinition.url || targetDefinition.style, {
21036
+ diff: diff,
21037
+ validate: this.serviceOptions.validateStyle,
21038
+ transformStyle: transformStyleFunc
21039
+ });
20686
21040
  };
20687
21041
  /**
20688
21042
  * Gets the color theme (light/dark) for the style type specified by the style options.
@@ -20747,138 +21101,6 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
20747
21101
  StyleManager.prototype.clearStyleSet = function () {
20748
21102
  this.unsetIndoorState();
20749
21103
  };
20750
- /**
20751
- * Function invoked by mapbox after a style is fetched but before it is committed to the map state.
20752
- *
20753
- * @param previousStyle The current style.
20754
- * @param nextStyle The next style which is to be applied.
20755
- * @param preserveLayer Preserve a layer from the previous style in the next style.
20756
- * @param updatePaintProperty Modify paint properties of a layer in the next style before the style is applied.
20757
- * @param updateLayoutProperty Modify layout properties of a layer in the next style before the style is applied.
20758
- * @param updateFilter Modify filter property of a layer in the next style before the style is applied.
20759
- */
20760
- StyleManager.prototype._stylePatch = function (previousStyle, nextStyle, preserveLayer, updatePaintProperty, updateLayoutProperty, updateFilter) {
20761
- var _this = this;
20762
- // Skip the style patch if the map has been disposed.
20763
- if (this.map.isDisposed)
20764
- return;
20765
- // Layers in the next style with default properties that do not align with current StyleOptions
20766
- // should be modified before they are applied to the map.
20767
- var styleOptions = this.map.getStyle();
20768
- var trafficOptions = this.map.getTraffic();
20769
- var shouldProgressiveLoading = (styleOptions.progressiveLoading &&
20770
- // The feature only effective at the initial load.
20771
- !this.map._isLoaded());
20772
- var setLayerVisibility = function (layer, visibility) {
20773
- var _a;
20774
- if (!shouldProgressiveLoading) {
20775
- // No need to apply the visibility change to maplibre while progressive loading is enabled.
20776
- // This can save a lot of CPU time.
20777
- updateLayoutProperty(layer.id, 'visibility', visibility);
20778
- }
20779
- layer.layout = (_a = layer.layout) !== null && _a !== void 0 ? _a : {};
20780
- layer.layout.visibility = visibility;
20781
- };
20782
- var layerGroupLayers = {};
20783
- nextStyle.layers.forEach(function (nextLayer) {
20784
- var _a;
20785
- var layerGroup = LayerGroupComparator.getLayerGroup(nextLayer);
20786
- if (layerGroup) {
20787
- // Set visibility of fill-extrusion layers according to StyleOptions.showBuildingModels
20788
- if (nextLayer.type === 'fill-extrusion') {
20789
- setLayerVisibility(nextLayer, styleOptions.showBuildingModels ? 'visible' : 'none');
20790
- }
20791
- // Set visibility of traffic layers depending on traffic settings.
20792
- if (trafficOptions.flow !== 'none' && nextLayer.type == 'line' &&
20793
- (layerGroup === "traffic_" + trafficOptions.flow ||
20794
- // Check if deprecated flow types are used and the layer is a bing-traffic layer.
20795
- // Needed for backwards compatibility in Bing styles to support deprecated flow types.
20796
- (['absolute', 'relative-delay'].includes(trafficOptions.flow) && nextLayer['source'] === "bing-traffic"))) {
20797
- setLayerVisibility(nextLayer, 'visible');
20798
- }
20799
- // Set visibility of labels
20800
- var isLabelLayerGroup = layerGroup === 'labels' || layerGroup === 'labels_places' || layerGroup === 'labels_indoor';
20801
- if (isLabelLayerGroup && nextLayer.type === 'symbol') {
20802
- var isLayerVisible = ((_a = nextLayer.layout) === null || _a === void 0 ? void 0 : _a.visibility) !== 'none';
20803
- setLayerVisibility(nextLayer, isLayerVisible && styleOptions.showLabels ? 'visible' : 'none');
20804
- }
20805
- // Once this _stylePatch returns control to maplibre the next style will be applied immediately in the same context.
20806
- // To avoid potential data races update LayerManager with new a new set of FundamentalMapLayers from here instead of
20807
- // waiting for a styledata.load event to trigger a sync in a different context.
20808
- if (layerGroupLayers[layerGroup]) {
20809
- layerGroupLayers[layerGroup].push(nextLayer);
20810
- }
20811
- else {
20812
- layerGroupLayers[layerGroup] = [nextLayer];
20813
- }
20814
- }
20815
- });
20816
- if (shouldProgressiveLoading) {
20817
- var initLayerGroups = styleOptions.progressiveLoadingInitialLayerGroups;
20818
- if (Array.isArray(initLayerGroups) && initLayerGroups.length > 0) {
20819
- this._deferLayerGroupVisibilities(layerGroupLayers, initLayerGroups);
20820
- }
20821
- }
20822
- // A FundamentalMapLayer (grouped layer) representation of the next style must be built.
20823
- var previousLayers = this.map.layers.getLayers();
20824
- var nextLayers = Object.entries(layerGroupLayers).map(function (_a) {
20825
- var _b = __read$d(_a, 2), layerGroupName = _b[0], layerGroupMapboxLayers = _b[1];
20826
- return _this._buildFundamentalLayerFrom(layerGroupMapboxLayers, layerGroupName);
20827
- });
20828
- // Update FundamentalMapLayers in LayerManager
20829
- var userLayers = this.map.layers._getUserLayers();
20830
- var layersToRemove = previousLayers.filter(function (c) {
20831
- return (nextLayers.findIndex(function (n) { return c.getId() === n.getId(); }) < 0 &&
20832
- userLayers.findIndex(function (n) { return c.getId() === n.layer.getId(); }) < 0);
20833
- });
20834
- var prevNextIntersection = nextLayers.filter(function (n) { return previousLayers.find(function (c) { return c.getId() === n.getId(); }); });
20835
- var ePrevNextIntersection = prevNextIntersection.entries();
20836
- var replace = ePrevNextIntersection.next();
20837
- nextLayers.forEach(function (newFundamentalLayer) {
20838
- if (replace.value && replace.value[1].getId() === newFundamentalLayer.getId()) {
20839
- // Replace the existing layer with this ID with the new one.
20840
- var insertBefore = previousLayers.findIndex(function (l) { return l.getId() === newFundamentalLayer.getId(); });
20841
- _this.map.layers.remove(newFundamentalLayer.getId());
20842
- _this.map.layers.add(newFundamentalLayer, previousLayers[insertBefore].getId());
20843
- replace = ePrevNextIntersection.next();
20844
- }
20845
- else {
20846
- if (replace.value) {
20847
- // Insert new layer before the next common layer.
20848
- _this.map.layers.add(newFundamentalLayer, replace.value[1]);
20849
- }
20850
- else {
20851
- _this.map.layers.add(newFundamentalLayer);
20852
- }
20853
- }
20854
- });
20855
- layersToRemove.forEach(function (layer) {
20856
- _this.map.layers.remove(layer);
20857
- });
20858
- // Layers added to mapbox through this SDK since loading the last style should be
20859
- // carried over to the next style.
20860
- userLayers.forEach(function (userLayer) {
20861
- if (userLayer.layer instanceof WebGLLayer) {
20862
- // mapbox custom layers cannot be serialized and preserved,
20863
- // return to continue to the next user layer.
20864
- return;
20865
- }
20866
- var before = undefined;
20867
- if (_this.map.layers.getLayerById(userLayer.before)) {
20868
- var beforeCandidates = _this.map.layers.getLayerById(userLayer.before)._buildLayers();
20869
- before = (beforeCandidates.length > 0) ? beforeCandidates[0] : undefined;
20870
- }
20871
- preserveLayer(userLayer.layer.getId(), before === null || before === void 0 ? void 0 : before.id);
20872
- _this.map.layers.move(userLayer.layer.getId(), userLayer.before);
20873
- });
20874
- this.map.sources._syncSources(nextStyle.sources);
20875
- // If there was a previous styledata change event attached, remove it.
20876
- // When the sprite url changes between style changes then mapbox can't perform the diff
20877
- // In such cases it recalculate the style again. Removing previous attached
20878
- // event listener makes sure that style changed event is not fired twice in these cases.
20879
- this.map.events.remove("styledata", this._onStyleData);
20880
- this.map.events.addOnce("styledata", this._onStyleData);
20881
- };
20882
21104
  StyleManager.prototype._buildFundamentalLayerFrom = function (layers, id) {
20883
21105
  if (layers && layers.length > 0) {
20884
21106
  var newLayer = new FundamentalMapLayer(layers, id);
@@ -21182,7 +21404,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21182
21404
  }
21183
21405
  return ar;
21184
21406
  };
21185
- var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
21407
+ var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
21186
21408
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
21187
21409
  to[j] = from[i];
21188
21410
  return to;
@@ -22008,7 +22230,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
22008
22230
  urls = layer.getOptions().subdomains || [];
22009
22231
  }
22010
22232
  // Add the tile urls to the layer, but don't update the map yet.
22011
- urls.push.apply(urls, __spreadArray$8([], __read$e(tileSources)));
22233
+ urls.push.apply(urls, __spreadArray$9([], __read$e(tileSources)));
22012
22234
  layer._setOptionsNoUpdate({
22013
22235
  subdomains: urls
22014
22236
  });
@@ -22297,9 +22519,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
22297
22519
  Map.prototype._rebuildStyle = function (diff) {
22298
22520
  if (diff === void 0) { diff = true; }
22299
22521
  return __awaiter$4(this, void 0, void 0, function () {
22522
+ var _this = this;
22300
22523
  return __generator$4(this, function (_a) {
22301
22524
  this.styles.setStyle(this.styleOptions, diff);
22302
- this.imageSprite._restoreImages();
22525
+ this.events.addOnce("stylechanged", function () { return _this.imageSprite._restoreImages(); });
22303
22526
  return [2 /*return*/];
22304
22527
  });
22305
22528
  });
@@ -22529,7 +22752,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
22529
22752
  }
22530
22753
  return ar;
22531
22754
  };
22532
- var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
22755
+ var __spreadArray$a = (window && window.__spreadArray) || function (to, from) {
22533
22756
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
22534
22757
  to[j] = from[i];
22535
22758
  return to;
@@ -22675,7 +22898,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
22675
22898
  lineLength = 50;
22676
22899
  }
22677
22900
  var lines = c.split(/<(tr|div|br|li|h[0-9]|p>)/);
22678
- longestStringLength = Math.max.apply(Math, __spreadArray$9([], __read$f((lines.map(function (el) { return el.replace(/<[a-zA-Z0-9\s=\/]+>/g, "").length; }))))) - 1;
22901
+ longestStringLength = Math.max.apply(Math, __spreadArray$a([], __read$f((lines.map(function (el) { return el.replace(/<[a-zA-Z0-9\s=\/]+>/g, "").length; }))))) - 1;
22679
22902
  var w = Math.ceil(longestStringLength * 3.5);
22680
22903
  if (w < width) {
22681
22904
  width = w;