azure-maps-control 2.2.7 → 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.7";
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.
@@ -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
  }
@@ -16461,7 +16597,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16461
16597
  }
16462
16598
  return ar;
16463
16599
  };
16464
- var __spreadArray$2 = (window && window.__spreadArray) || function (to, from) {
16600
+ var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
16465
16601
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
16466
16602
  to[j] = from[i];
16467
16603
  return to;
@@ -16929,7 +17065,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
16929
17065
  // Derive polygon layers from the label config.
16930
17066
  _this._polygonStyleLayer = _this._labelConfig.reduce(function (acc, cur) {
16931
17067
  if (cur.polygonSources) {
16932
- acc.push.apply(acc, __spreadArray$2([], __read$7(cur.polygonSources)));
17068
+ acc.push.apply(acc, __spreadArray$3([], __read$7(cur.polygonSources)));
16933
17069
  }
16934
17070
  return acc;
16935
17071
  }, []);
@@ -21414,7 +21550,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21414
21550
  }
21415
21551
  return ar;
21416
21552
  };
21417
- var __spreadArray$3 = (window && window.__spreadArray) || function (to, from) {
21553
+ var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
21418
21554
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
21419
21555
  to[j] = from[i];
21420
21556
  return to;
@@ -21432,7 +21568,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21432
21568
  'data-azure-maps-attribution-order',
21433
21569
  'data-azure-maps-attribution-dynamic'
21434
21570
  ];
21435
- var allowedAttributionAttributes = __spreadArray$3([
21571
+ var allowedAttributionAttributes = __spreadArray$4([
21436
21572
  'href'
21437
21573
  ], __read$8(attributionRuleAttributes));
21438
21574
  var AttributionRuleProxy = /** @class */ (function () {
@@ -21657,7 +21793,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21657
21793
  };
21658
21794
  AttributionRuleProxy.prototype.applyAttributionResponse = function (attributions) {
21659
21795
  var _this = this;
21660
- 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)); }, []);
21661
21797
  if (copyrights.length == 0) {
21662
21798
  // no attribution for a provided tileset/bbox/z
21663
21799
  return;
@@ -21722,7 +21858,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21722
21858
  }
21723
21859
  return ar;
21724
21860
  };
21725
- var __spreadArray$4 = (window && window.__spreadArray) || function (to, from) {
21861
+ var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
21726
21862
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
21727
21863
  to[j] = from[i];
21728
21864
  return to;
@@ -21841,10 +21977,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21841
21977
  }, function () { return document.createElement('span'); });
21842
21978
  });
21843
21979
  var registeredRuleSet = new Set(Object.values(registeredRules));
21844
- var redundantRules = new Set(__spreadArray$4([], __read$9(allRules)).filter(function (rule) { return !registeredRuleSet.has(rule); }));
21845
- 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(); }));
21846
21982
  // eject redundant rules associated elements altogether
21847
- __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; })
21848
21984
  .forEach(function (elem) { return elem.parentElement.removeChild(elem); });
21849
21985
  _this.rules = Object.values(registeredRules);
21850
21986
  var attributionsToApply = attributions
@@ -21880,7 +22016,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21880
22016
  var visibleTextNodes = function (elem) {
21881
22017
  return Array.from(elem.style.display != 'none' ? elem.children : [])
21882
22018
  .map(function (elem) { return visibleTextNodes(elem); })
21883
- .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; }));
21884
22020
  };
21885
22021
  var newRenderContext = _this.virtualContext.cloneNode(true);
21886
22022
  var visibleNodes = visibleTextNodes(newRenderContext);
@@ -21895,7 +22031,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
21895
22031
  // }
21896
22032
  // });
21897
22033
  // strip all predefined keywords
21898
- 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); });
21899
22035
  // strip year from each node
21900
22036
  // visibleNodes.forEach(node => node.textContent = node.textContent.replace(copyrightYearPattern, '').trim());
21901
22037
  // deduplicate attribution text
@@ -25577,10 +25713,15 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25577
25713
  return ids;
25578
25714
  };
25579
25715
  FundamentalMapLayer.prototype._updateLayoutProperty = function (name, newValue, oldValue, subValue) {
25580
- var _this = this;
25716
+ if (isEqual_1(newValue, oldValue))
25717
+ return;
25718
+ var map = this.map._getMap();
25581
25719
  this.layers.forEach(function (layer) {
25582
- if (!(isEqual_1(newValue, oldValue))) {
25583
- _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));
25584
25725
  }
25585
25726
  });
25586
25727
  };
@@ -25614,7 +25755,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25614
25755
  }
25615
25756
  return ar;
25616
25757
  };
25617
- var __spreadArray$5 = (window && window.__spreadArray) || function (to, from) {
25758
+ var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
25618
25759
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
25619
25760
  to[j] = from[i];
25620
25761
  return to;
@@ -25675,10 +25816,12 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25675
25816
  // Place the new layer behind the specified before layer.
25676
25817
  var layerIndex = this.layerIndex.findIndex(function (l) { return l.getId() === layer.getId(); });
25677
25818
  var userLayerIndex = this.userLayers.findIndex(function (ul) { return ul.layer.getId() === layer.getId(); });
25678
- var tempLayer = this.layerIndex[layerIndex];
25679
25819
  this._removeMapboxLayers(layer);
25680
25820
  this._addMapboxLayers(layer, before);
25681
- this.map.events._disableLayerEvents(tempLayer);
25821
+ var tempLayer = this.layerIndex[layerIndex];
25822
+ if (tempLayer) {
25823
+ this.map.events._disableLayerEvents(tempLayer);
25824
+ }
25682
25825
  this.map.events._enableLayerEvents(layer);
25683
25826
  this.layerIndex.splice(layerIndex, 1);
25684
25827
  var beforeIndex = this.layerIndex.findIndex(function (l) { return l.getId() === before; });
@@ -25686,7 +25829,9 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
25686
25829
  if (!(layer instanceof FundamentalMapLayer)) {
25687
25830
  this.userLayers[userLayerIndex] = { layer: layer, before: before };
25688
25831
  }
25689
- tempLayer.onRemove();
25832
+ if (tempLayer) {
25833
+ tempLayer.onRemove();
25834
+ }
25690
25835
  layer.onAdd(this.map);
25691
25836
  }
25692
25837
  else {
@@ -26052,7 +26197,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26052
26197
  // If a specified layer hasn't been added to the map throw an error.
26053
26198
  var index = this_1.layerIndex.findIndex(function (l) { return l.getId() === layerId; });
26054
26199
  if (index > -1) {
26055
- 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()
26056
26201
  .filter(function (id) { return !!_this.map._getMap().getLayer(id); }))));
26057
26202
  }
26058
26203
  else {
@@ -26341,6 +26486,37 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26341
26486
  FundamentalMapSource.prototype._buildSource = function () {
26342
26487
  return this.source;
26343
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
+ };
26344
26520
  /**
26345
26521
  * Updates the source info to convert the tiles to url strings.
26346
26522
  * @param sourceDef The original source info.
@@ -26637,39 +26813,52 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26637
26813
  var _this = this;
26638
26814
  if (sources) {
26639
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
+ }
26640
26840
  if (!_this.sources.has(sourceId)) {
26641
- var sourceToAdd = sources[sourceId];
26642
- if (sourceToAdd.type === "vector") {
26643
- var newSource = new FundamentalMapSource(sourceId, {
26644
- name: sourceId,
26645
- tiles: sourceToAdd.tiles,
26646
- type: "vector",
26647
- url: sourceToAdd.url
26648
- });
26649
- _this.sources.set(sourceId, newSource);
26650
- newSource._setMap(_this.map);
26651
- }
26652
- else if (sourceToAdd.type === "raster") {
26653
- var newSource = new FundamentalMapSource(sourceId, {
26654
- name: sourceId,
26655
- tiles: sourceToAdd.tiles,
26656
- type: "raster",
26657
- url: sourceToAdd.url
26658
- });
26659
- _this.sources.set(sourceId, newSource);
26660
- newSource._setMap(_this.map);
26661
- }
26662
- else {
26663
- throw new Error("Unable to construct source with ID " + sourceId + ".");
26664
- }
26841
+ _this.sources.set(sourceId, newSource);
26842
+ newSource._setMap(_this.map);
26665
26843
  }
26666
- });
26667
- Object.keys(this.sources).forEach(function (sourceId) {
26668
- if (!sources.hasOwnProperty(sourceId)) {
26669
- _this.sources.get(sourceId)._setMap(null);
26670
- _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);
26671
26848
  }
26672
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
+ // });
26673
26862
  }
26674
26863
  };
26675
26864
  return SourceManager;
@@ -26811,7 +27000,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26811
27000
  }
26812
27001
  return ar;
26813
27002
  };
26814
- var __spreadArray$6 = (window && window.__spreadArray) || function (to, from) {
27003
+ var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
26815
27004
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
26816
27005
  to[j] = from[i];
26817
27006
  return to;
@@ -26886,7 +27075,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
26886
27075
  }
26887
27076
  finally { if (e_1) throw e_1.error; }
26888
27077
  }
26889
- return _super.prototype.merge.apply(this, __spreadArray$6([], __read$c(valuesList)));
27078
+ return _super.prototype.merge.apply(this, __spreadArray$7([], __read$c(valuesList)));
26890
27079
  };
26891
27080
  return CameraBoundsOptions;
26892
27081
  }(Options));
@@ -27375,7 +27564,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27375
27564
  }
27376
27565
  return ar;
27377
27566
  };
27378
- var __spreadArray$7 = (window && window.__spreadArray) || function (to, from) {
27567
+ var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
27379
27568
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
27380
27569
  to[j] = from[i];
27381
27570
  return to;
@@ -27495,6 +27684,13 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27495
27684
  * @deprecated use `view` instead.
27496
27685
  */
27497
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;
27498
27694
  return _this;
27499
27695
  }
27500
27696
  /**
@@ -27534,7 +27730,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27534
27730
  finally { if (e_1) throw e_1.error; }
27535
27731
  }
27536
27732
  // Then execute the standard merge behavior.
27537
- return _super.prototype.merge.apply(this, __spreadArray$7([], __read$d(valueList)));
27733
+ return _super.prototype.merge.apply(this, __spreadArray$8([], __read$d(valueList)));
27538
27734
  };
27539
27735
  return StyleOptions;
27540
27736
  }(Options));
@@ -27592,7 +27788,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27592
27788
  }
27593
27789
  return ar;
27594
27790
  };
27595
- var __spreadArray$8 = (window && window.__spreadArray) || function (to, from) {
27791
+ var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
27596
27792
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
27597
27793
  to[j] = from[i];
27598
27794
  return to;
@@ -27827,10 +28023,10 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27827
28023
  // won't change default behavior in Options as usually that's what desired
27828
28024
  // instead capture it here and reassign.
27829
28025
  var currentTransforms = this._transformers;
27830
- 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 || [])); }, []) : [];
27831
28027
  // Then execute the standard merge behavior.
27832
28028
  // If subscription key auth method isn't being used then the subscription key property should be undefined.
27833
- 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)));
27834
28030
  if (merged.authOptions.authType !== exports.AuthenticationType.subscriptionKey) {
27835
28031
  merged["subscription-key"] = merged.subscriptionKey = undefined;
27836
28032
  }
@@ -27842,7 +28038,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
27842
28038
  if (merged.mapConfiguration && typeof merged.mapConfiguration !== 'string') {
27843
28039
  merged.mapConfiguration = __assign$7(__assign$7({}, merged.mapConfiguration), { defaultConfiguration: merged.mapConfiguration.defaultConfiguration || merged.mapConfiguration['defaultStyle'], configurations: merged.mapConfiguration.configurations || merged.mapConfiguration['styles'] });
27844
28040
  }
27845
- 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); })));
27846
28042
  if (this.transformRequest && !this._transformers.includes(this.transformRequest)) {
27847
28043
  this._transformers.push(this.transformRequest);
27848
28044
  }
@@ -28090,7 +28286,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28090
28286
  }
28091
28287
  return ar;
28092
28288
  };
28093
- var __spreadArray$9 = (window && window.__spreadArray) || function (to, from) {
28289
+ var __spreadArray$a = (window && window.__spreadArray) || function (to, from) {
28094
28290
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
28095
28291
  to[j] = from[i];
28096
28292
  return to;
@@ -28143,7 +28339,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28143
28339
  var deferredLayers = Object.entries(layerGroupLayers).reduce(function (deferred, _a) {
28144
28340
  var _b = __read$f(_a, 2), groupName = _b[0], layers = _b[1];
28145
28341
  var isInInitialLayerGroup = validInitLayerGroups.includes(groupName);
28146
- 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) {
28147
28343
  var _a;
28148
28344
  // Exclude custom layers
28149
28345
  if (layer.type === 'custom')
@@ -28195,13 +28391,11 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28195
28391
  };
28196
28392
  _this.map.events.addOnce('load', _this._progressiveLoadingState.pendingVisibilityChange);
28197
28393
  };
28198
- this._onStyleData = function () {
28199
- _this._lookUpAsync(_this.map.getStyle()).then(function (style) {
28200
- _this.map.events.invoke("stylechanged", {
28201
- style: style.name,
28202
- map: _this.map,
28203
- type: "stylechanged"
28204
- });
28394
+ this._onStyleData = function (definition) {
28395
+ _this.map.events.invoke("stylechanged", {
28396
+ style: definition.name,
28397
+ map: _this.map,
28398
+ type: "stylechanged"
28205
28399
  });
28206
28400
  };
28207
28401
  /**
@@ -28385,23 +28579,183 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28385
28579
  if (styleDefinition.style) {
28386
28580
  return styleDefinition.style;
28387
28581
  }
28388
- 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));
28389
28671
  };
28390
28672
  /**
28391
28673
  * @internal
28392
28674
  */
28393
28675
  StyleManager.prototype.setStyle = function (styleOptions, diff) {
28676
+ var _this = this;
28394
28677
  if (diff === void 0) { diff = true; }
28395
- try {
28396
- this.map._getMap().setStyle(this.getStyle(styleOptions), {
28397
- diff: diff,
28398
- stylePatch: this._stylePatch.bind(this),
28399
- validate: this.serviceOptions.validateStyle
28400
- });
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
+ };
28401
28702
  }
28402
- catch (e) {
28403
- 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
+ };
28404
28753
  }
28754
+ this.map._getMap().setStyle(targetDefinition.url || targetDefinition.style, {
28755
+ diff: diff,
28756
+ validate: this.serviceOptions.validateStyle,
28757
+ transformStyle: transformStyleFunc
28758
+ });
28405
28759
  };
28406
28760
  /**
28407
28761
  * Gets the color theme (light/dark) for the style type specified by the style options.
@@ -28466,138 +28820,6 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28466
28820
  StyleManager.prototype.clearStyleSet = function () {
28467
28821
  this.unsetIndoorState();
28468
28822
  };
28469
- /**
28470
- * Function invoked by mapbox after a style is fetched but before it is committed to the map state.
28471
- *
28472
- * @param previousStyle The current style.
28473
- * @param nextStyle The next style which is to be applied.
28474
- * @param preserveLayer Preserve a layer from the previous style in the next style.
28475
- * @param updatePaintProperty Modify paint properties of a layer in the next style before the style is applied.
28476
- * @param updateLayoutProperty Modify layout properties of a layer in the next style before the style is applied.
28477
- * @param updateFilter Modify filter property of a layer in the next style before the style is applied.
28478
- */
28479
- StyleManager.prototype._stylePatch = function (previousStyle, nextStyle, preserveLayer, updatePaintProperty, updateLayoutProperty, updateFilter) {
28480
- var _this = this;
28481
- // Skip the style patch if the map has been disposed.
28482
- if (this.map.isDisposed)
28483
- return;
28484
- // Layers in the next style with default properties that do not align with current StyleOptions
28485
- // should be modified before they are applied to the map.
28486
- var styleOptions = this.map.getStyle();
28487
- var trafficOptions = this.map.getTraffic();
28488
- var shouldProgressiveLoading = (styleOptions.progressiveLoading &&
28489
- // The feature only effective at the initial load.
28490
- !this.map._isLoaded());
28491
- var setLayerVisibility = function (layer, visibility) {
28492
- var _a;
28493
- if (!shouldProgressiveLoading) {
28494
- // No need to apply the visibility change to maplibre while progressive loading is enabled.
28495
- // This can save a lot of CPU time.
28496
- updateLayoutProperty(layer.id, 'visibility', visibility);
28497
- }
28498
- layer.layout = (_a = layer.layout) !== null && _a !== void 0 ? _a : {};
28499
- layer.layout.visibility = visibility;
28500
- };
28501
- var layerGroupLayers = {};
28502
- nextStyle.layers.forEach(function (nextLayer) {
28503
- var _a;
28504
- var layerGroup = LayerGroupComparator.getLayerGroup(nextLayer);
28505
- if (layerGroup) {
28506
- // Set visibility of fill-extrusion layers according to StyleOptions.showBuildingModels
28507
- if (nextLayer.type === 'fill-extrusion') {
28508
- setLayerVisibility(nextLayer, styleOptions.showBuildingModels ? 'visible' : 'none');
28509
- }
28510
- // Set visibility of traffic layers depending on traffic settings.
28511
- if (trafficOptions.flow !== 'none' && nextLayer.type == 'line' &&
28512
- (layerGroup === "traffic_" + trafficOptions.flow ||
28513
- // Check if deprecated flow types are used and the layer is a bing-traffic layer.
28514
- // Needed for backwards compatibility in Bing styles to support deprecated flow types.
28515
- (['absolute', 'relative-delay'].includes(trafficOptions.flow) && nextLayer['source'] === "bing-traffic"))) {
28516
- setLayerVisibility(nextLayer, 'visible');
28517
- }
28518
- // Set visibility of labels
28519
- var isLabelLayerGroup = layerGroup === 'labels' || layerGroup === 'labels_places' || layerGroup === 'labels_indoor';
28520
- if (isLabelLayerGroup && nextLayer.type === 'symbol') {
28521
- var isLayerVisible = ((_a = nextLayer.layout) === null || _a === void 0 ? void 0 : _a.visibility) !== 'none';
28522
- setLayerVisibility(nextLayer, isLayerVisible && styleOptions.showLabels ? 'visible' : 'none');
28523
- }
28524
- // Once this _stylePatch returns control to maplibre the next style will be applied immediately in the same context.
28525
- // To avoid potential data races update LayerManager with new a new set of FundamentalMapLayers from here instead of
28526
- // waiting for a styledata.load event to trigger a sync in a different context.
28527
- if (layerGroupLayers[layerGroup]) {
28528
- layerGroupLayers[layerGroup].push(nextLayer);
28529
- }
28530
- else {
28531
- layerGroupLayers[layerGroup] = [nextLayer];
28532
- }
28533
- }
28534
- });
28535
- if (shouldProgressiveLoading) {
28536
- var initLayerGroups = styleOptions.progressiveLoadingInitialLayerGroups;
28537
- if (Array.isArray(initLayerGroups) && initLayerGroups.length > 0) {
28538
- this._deferLayerGroupVisibilities(layerGroupLayers, initLayerGroups);
28539
- }
28540
- }
28541
- // A FundamentalMapLayer (grouped layer) representation of the next style must be built.
28542
- var previousLayers = this.map.layers.getLayers();
28543
- var nextLayers = Object.entries(layerGroupLayers).map(function (_a) {
28544
- var _b = __read$f(_a, 2), layerGroupName = _b[0], layerGroupMapboxLayers = _b[1];
28545
- return _this._buildFundamentalLayerFrom(layerGroupMapboxLayers, layerGroupName);
28546
- });
28547
- // Update FundamentalMapLayers in LayerManager
28548
- var userLayers = this.map.layers._getUserLayers();
28549
- var layersToRemove = previousLayers.filter(function (c) {
28550
- return (nextLayers.findIndex(function (n) { return c.getId() === n.getId(); }) < 0 &&
28551
- userLayers.findIndex(function (n) { return c.getId() === n.layer.getId(); }) < 0);
28552
- });
28553
- var prevNextIntersection = nextLayers.filter(function (n) { return previousLayers.find(function (c) { return c.getId() === n.getId(); }); });
28554
- var ePrevNextIntersection = prevNextIntersection.entries();
28555
- var replace = ePrevNextIntersection.next();
28556
- nextLayers.forEach(function (newFundamentalLayer) {
28557
- if (replace.value && replace.value[1].getId() === newFundamentalLayer.getId()) {
28558
- // Replace the existing layer with this ID with the new one.
28559
- var insertBefore = previousLayers.findIndex(function (l) { return l.getId() === newFundamentalLayer.getId(); });
28560
- _this.map.layers.remove(newFundamentalLayer.getId());
28561
- _this.map.layers.add(newFundamentalLayer, previousLayers[insertBefore].getId());
28562
- replace = ePrevNextIntersection.next();
28563
- }
28564
- else {
28565
- if (replace.value) {
28566
- // Insert new layer before the next common layer.
28567
- _this.map.layers.add(newFundamentalLayer, replace.value[1]);
28568
- }
28569
- else {
28570
- _this.map.layers.add(newFundamentalLayer);
28571
- }
28572
- }
28573
- });
28574
- layersToRemove.forEach(function (layer) {
28575
- _this.map.layers.remove(layer);
28576
- });
28577
- // Layers added to mapbox through this SDK since loading the last style should be
28578
- // carried over to the next style.
28579
- userLayers.forEach(function (userLayer) {
28580
- if (userLayer.layer instanceof WebGLLayer) {
28581
- // mapbox custom layers cannot be serialized and preserved,
28582
- // return to continue to the next user layer.
28583
- return;
28584
- }
28585
- var before = undefined;
28586
- if (_this.map.layers.getLayerById(userLayer.before)) {
28587
- var beforeCandidates = _this.map.layers.getLayerById(userLayer.before)._buildLayers();
28588
- before = (beforeCandidates.length > 0) ? beforeCandidates[0] : undefined;
28589
- }
28590
- preserveLayer(userLayer.layer.getId(), before === null || before === void 0 ? void 0 : before.id);
28591
- _this.map.layers.move(userLayer.layer.getId(), userLayer.before);
28592
- });
28593
- this.map.sources._syncSources(nextStyle.sources);
28594
- // If there was a previous styledata change event attached, remove it.
28595
- // When the sprite url changes between style changes then mapbox can't perform the diff
28596
- // In such cases it recalculate the style again. Removing previous attached
28597
- // event listener makes sure that style changed event is not fired twice in these cases.
28598
- this.map.events.remove("styledata", this._onStyleData);
28599
- this.map.events.addOnce("styledata", this._onStyleData);
28600
- };
28601
28823
  StyleManager.prototype._buildFundamentalLayerFrom = function (layers, id) {
28602
28824
  if (layers && layers.length > 0) {
28603
28825
  var newLayer = new FundamentalMapLayer(layers, id);
@@ -28901,7 +29123,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
28901
29123
  }
28902
29124
  return ar;
28903
29125
  };
28904
- var __spreadArray$a = (window && window.__spreadArray) || function (to, from) {
29126
+ var __spreadArray$b = (window && window.__spreadArray) || function (to, from) {
28905
29127
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
28906
29128
  to[j] = from[i];
28907
29129
  return to;
@@ -29733,7 +29955,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
29733
29955
  urls = layer.getOptions().subdomains || [];
29734
29956
  }
29735
29957
  // Add the tile urls to the layer, but don't update the map yet.
29736
- urls.push.apply(urls, __spreadArray$a([], __read$g(tileSources)));
29958
+ urls.push.apply(urls, __spreadArray$b([], __read$g(tileSources)));
29737
29959
  layer._setOptionsNoUpdate({
29738
29960
  subdomains: urls
29739
29961
  });
@@ -30254,7 +30476,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
30254
30476
  }
30255
30477
  return ar;
30256
30478
  };
30257
- var __spreadArray$b = (window && window.__spreadArray) || function (to, from) {
30479
+ var __spreadArray$c = (window && window.__spreadArray) || function (to, from) {
30258
30480
  for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
30259
30481
  to[j] = from[i];
30260
30482
  return to;
@@ -30400,7 +30622,7 @@ EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous po
30400
30622
  lineLength = 50;
30401
30623
  }
30402
30624
  var lines = c.split(/<(tr|div|br|li|h[0-9]|p>)/);
30403
- 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;
30404
30626
  var w = Math.ceil(longestStringLength * 3.5);
30405
30627
  if (w < width) {
30406
30628
  width = w;