@deck.gl/mapbox 9.3.0-alpha.6 → 9.3.0-beta.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.
package/dist/index.cjs CHANGED
@@ -25,10 +25,95 @@ __export(dist_exports, {
25
25
  module.exports = __toCommonJS(dist_exports);
26
26
 
27
27
  // dist/mapbox-overlay.js
28
- var import_core5 = require("@deck.gl/core");
28
+ var import_core4 = require("@deck.gl/core");
29
29
 
30
30
  // dist/deck-utils.js
31
+ var import_core3 = require("@deck.gl/core");
32
+
33
+ // dist/resolve-layer-groups.js
34
+ var import_core2 = require("@deck.gl/core");
35
+
36
+ // dist/mapbox-layer-group.js
31
37
  var import_core = require("@deck.gl/core");
38
+ var MapboxLayerGroup = class {
39
+ /* eslint-disable no-this-before-super */
40
+ constructor(props) {
41
+ (0, import_core.assert)(props.id, "id is required");
42
+ this.id = props.id;
43
+ this.type = "custom";
44
+ this.renderingMode = props.renderingMode || "3d";
45
+ this.slot = props.slot;
46
+ this.beforeId = props.beforeId;
47
+ this.map = null;
48
+ }
49
+ /* Mapbox custom layer methods */
50
+ onAdd(map, gl) {
51
+ this.map = map;
52
+ }
53
+ render(gl, renderParameters) {
54
+ if (!this.map)
55
+ return;
56
+ drawLayerGroup(this.map.__deck, this.map, this, renderParameters);
57
+ }
58
+ };
59
+
60
+ // dist/resolve-layer-groups.js
61
+ var UNDEFINED_BEFORE_ID = "__UNDEFINED__";
62
+ function getLayerGroupId(layer) {
63
+ if (layer.props.beforeId) {
64
+ return `deck-layer-group-before:${layer.props.beforeId}`;
65
+ } else if (layer.props.slot) {
66
+ return `deck-layer-group-slot:${layer.props.slot}`;
67
+ }
68
+ return "deck-layer-group-last";
69
+ }
70
+ function resolveLayerGroups(map, oldLayers, newLayers) {
71
+ if (!map || !map.style || !map.style._loaded) {
72
+ return;
73
+ }
74
+ const layers = (0, import_core2._flatten)(newLayers, Boolean);
75
+ if (oldLayers !== newLayers) {
76
+ const prevLayers = (0, import_core2._flatten)(oldLayers, Boolean);
77
+ const prevLayerGroupIds = new Set(prevLayers.map((l) => getLayerGroupId(l)));
78
+ const newLayerGroupIds = new Set(layers.map((l) => getLayerGroupId(l)));
79
+ for (const groupId of prevLayerGroupIds) {
80
+ if (!newLayerGroupIds.has(groupId)) {
81
+ if (map.getLayer(groupId)) {
82
+ map.removeLayer(groupId);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ const layerGroups = {};
88
+ for (const layer of layers) {
89
+ const groupId = getLayerGroupId(layer);
90
+ const mapboxGroup = map.getLayer(groupId);
91
+ if (mapboxGroup) {
92
+ const groupInstance = mapboxGroup.implementation || mapboxGroup;
93
+ layerGroups[groupId] = groupInstance;
94
+ } else {
95
+ const newGroup = new MapboxLayerGroup({
96
+ id: groupId,
97
+ slot: layer.props.slot,
98
+ beforeId: layer.props.beforeId
99
+ });
100
+ layerGroups[groupId] = newGroup;
101
+ map.addLayer(newGroup, layer.props.beforeId);
102
+ }
103
+ }
104
+ const mapLayers = map.style._order;
105
+ for (const [groupId, group] of Object.entries(layerGroups)) {
106
+ const beforeId = group.beforeId || UNDEFINED_BEFORE_ID;
107
+ const expectedGroupIndex = beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
108
+ const currentGropupIndex = mapLayers.indexOf(groupId);
109
+ if (currentGropupIndex !== expectedGroupIndex - 1) {
110
+ const moveBeforeId = beforeId === UNDEFINED_BEFORE_ID ? void 0 : beforeId;
111
+ map.moveLayer(groupId, moveBeforeId);
112
+ }
113
+ }
114
+ }
115
+
116
+ // dist/deck-utils.js
32
117
  var import_web_mercator = require("@math.gl/web-mercator");
33
118
  var MAPBOX_VIEW_ID = "mapbox";
34
119
  var TILE_SIZE = 512;
@@ -102,27 +187,6 @@ function getDefaultParameters(map, interleaved) {
102
187
  }
103
188
  return result;
104
189
  }
105
- function drawLayer(deck, map, layer, renderParameters) {
106
- if (!deck.isInitialized) {
107
- return;
108
- }
109
- let { currentViewport } = deck.userData;
110
- let clearStack = false;
111
- if (!currentViewport) {
112
- currentViewport = getViewport(deck, map, renderParameters);
113
- deck.userData.currentViewport = currentViewport;
114
- clearStack = true;
115
- }
116
- if (!currentViewport) {
117
- return;
118
- }
119
- deck._drawLayers("mapbox-repaint", {
120
- viewports: [currentViewport],
121
- layerFilter: (params) => (!deck.props.layerFilter || deck.props.layerFilter(params)) && (layer.id === params.layer.id || params.layer.props.operation.includes("terrain")),
122
- clearStack,
123
- clearCanvas: false
124
- });
125
- }
126
190
  function drawLayerGroup(deck, map, group, renderParameters) {
127
191
  if (!deck.isInitialized) {
128
192
  return;
@@ -171,9 +235,9 @@ function getProjection(map) {
171
235
  }
172
236
  function getDefaultView(map) {
173
237
  if (getProjection(map) === "globe") {
174
- return new import_core._GlobeView({ id: MAPBOX_VIEW_ID });
238
+ return new import_core3._GlobeView({ id: MAPBOX_VIEW_ID });
175
239
  }
176
- return new import_core.MapView({ id: MAPBOX_VIEW_ID });
240
+ return new import_core3.MapView({ id: MAPBOX_VIEW_ID });
177
241
  }
178
242
  function getViewState(map) {
179
243
  var _a;
@@ -243,8 +307,8 @@ function getViewport(deck, map, renderParameters) {
243
307
  }
244
308
  function afterRender(deck, map) {
245
309
  var _a, _b, _c, _d;
246
- const deckLayers = (0, import_core._flatten)(deck.props.layers, Boolean);
247
- const hasNonMapboxLayers = deckLayers.some((layer) => layer && !map.getLayer(layer.id));
310
+ const deckLayers = (0, import_core3._flatten)(deck.props.layers, Boolean);
311
+ const hasNonMapboxLayers = deckLayers.some((layer) => layer && !map.getLayer(getLayerGroupId(layer)));
248
312
  let viewports = deck.getViewports();
249
313
  const mapboxViewportIdx = viewports.findIndex((vp) => vp.id === MAPBOX_VIEW_ID);
250
314
  const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
@@ -260,7 +324,7 @@ function afterRender(deck, map) {
260
324
  }
261
325
  deck._drawLayers("mapbox-repaint", {
262
326
  viewports,
263
- layerFilter: (params) => (!deck.props.layerFilter || deck.props.layerFilter(params)) && (params.viewport.id !== MAPBOX_VIEW_ID || !map.getLayer(params.layer.id)),
327
+ layerFilter: (params) => (!deck.props.layerFilter || deck.props.layerFilter(params)) && (params.viewport.id !== MAPBOX_VIEW_ID || !map.getLayer(getLayerGroupId(params.layer))),
264
328
  clearCanvas: false
265
329
  });
266
330
  } else {
@@ -278,188 +342,6 @@ function onMapMove(deck, map) {
278
342
  deck.needsRedraw({ clearRedrawFlags: true });
279
343
  }
280
344
 
281
- // dist/resolve-layers.js
282
- var import_core2 = require("@deck.gl/core");
283
-
284
- // dist/mapbox-layer.js
285
- var MapboxLayer = class {
286
- /* eslint-disable no-this-before-super */
287
- constructor(props) {
288
- if (!props.id) {
289
- throw new Error("Layer must have an unique id");
290
- }
291
- this.id = props.id;
292
- this.type = "custom";
293
- this.renderingMode = props.renderingMode || "3d";
294
- this.slot = props.slot;
295
- this.map = null;
296
- this.props = props;
297
- }
298
- /* Mapbox custom layer methods */
299
- onAdd(map, gl) {
300
- this.map = map;
301
- }
302
- onRemove() {
303
- this.map = null;
304
- }
305
- setProps(props) {
306
- Object.assign(this.props, props, { id: this.id });
307
- }
308
- render(gl, renderParameters) {
309
- if (!this.map)
310
- return;
311
- drawLayer(this.map.__deck, this.map, this, renderParameters);
312
- }
313
- };
314
-
315
- // dist/resolve-layers.js
316
- var UNDEFINED_BEFORE_ID = "__UNDEFINED__";
317
- function resolveLayers(map, deck, oldLayers, newLayers) {
318
- if (!map || !deck || !map.style || !map.style._loaded) {
319
- return;
320
- }
321
- const layers = (0, import_core2._flatten)(newLayers, Boolean);
322
- if (oldLayers !== newLayers) {
323
- const prevLayers = (0, import_core2._flatten)(oldLayers, Boolean);
324
- const prevLayerIds = new Set(prevLayers.map((l) => l.id));
325
- for (const layer of layers) {
326
- prevLayerIds.delete(layer.id);
327
- }
328
- for (const id of prevLayerIds) {
329
- if (map.getLayer(id)) {
330
- map.removeLayer(id);
331
- }
332
- }
333
- }
334
- for (const layer of layers) {
335
- const mapboxLayer = map.getLayer(layer.id);
336
- if (mapboxLayer) {
337
- const layerInstance = mapboxLayer.implementation || mapboxLayer;
338
- layerInstance.setProps(layer.props);
339
- } else {
340
- map.addLayer(
341
- new MapboxLayer({
342
- id: layer.id,
343
- // @ts-expect-error slot is not defined in LayerProps
344
- slot: layer.props.slot
345
- }),
346
- // @ts-expect-error beforeId is not defined in LayerProps
347
- layer.props.beforeId
348
- );
349
- }
350
- }
351
- const mapLayers = map.style._order;
352
- const layerGroups = {};
353
- for (const layer of layers) {
354
- let { beforeId } = layer.props;
355
- if (!beforeId || !mapLayers.includes(beforeId)) {
356
- beforeId = UNDEFINED_BEFORE_ID;
357
- }
358
- layerGroups[beforeId] = layerGroups[beforeId] || [];
359
- layerGroups[beforeId].push(layer.id);
360
- }
361
- for (const beforeId in layerGroups) {
362
- const layerGroup = layerGroups[beforeId];
363
- let lastLayerIndex = beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
364
- let lastLayerId = beforeId === UNDEFINED_BEFORE_ID ? void 0 : beforeId;
365
- for (let i = layerGroup.length - 1; i >= 0; i--) {
366
- const layerId = layerGroup[i];
367
- const layerIndex = mapLayers.indexOf(layerId);
368
- if (layerIndex !== lastLayerIndex - 1) {
369
- map.moveLayer(layerId, lastLayerId);
370
- if (layerIndex > lastLayerIndex) {
371
- lastLayerIndex++;
372
- }
373
- }
374
- lastLayerIndex--;
375
- lastLayerId = layerId;
376
- }
377
- }
378
- }
379
-
380
- // dist/resolve-layer-groups.js
381
- var import_core4 = require("@deck.gl/core");
382
-
383
- // dist/mapbox-layer-group.js
384
- var import_core3 = require("@deck.gl/core");
385
- var MapboxLayerGroup = class {
386
- /* eslint-disable no-this-before-super */
387
- constructor(props) {
388
- (0, import_core3.assert)(props.id, "id is required");
389
- this.id = props.id;
390
- this.type = "custom";
391
- this.renderingMode = props.renderingMode || "3d";
392
- this.slot = props.slot;
393
- this.beforeId = props.beforeId;
394
- this.map = null;
395
- }
396
- /* Mapbox custom layer methods */
397
- onAdd(map, gl) {
398
- this.map = map;
399
- }
400
- render(gl, renderParameters) {
401
- if (!this.map)
402
- return;
403
- drawLayerGroup(this.map.__deck, this.map, this, renderParameters);
404
- }
405
- };
406
-
407
- // dist/resolve-layer-groups.js
408
- var UNDEFINED_BEFORE_ID2 = "__UNDEFINED__";
409
- function getLayerGroupId(layer) {
410
- if (layer.props.beforeId) {
411
- return `deck-layer-group-before:${layer.props.beforeId}`;
412
- } else if (layer.props.slot) {
413
- return `deck-layer-group-slot:${layer.props.slot}`;
414
- }
415
- return "deck-layer-group-last";
416
- }
417
- function resolveLayerGroups(map, oldLayers, newLayers) {
418
- if (!map || !map.style || !map.style._loaded) {
419
- return;
420
- }
421
- const layers = (0, import_core4._flatten)(newLayers, Boolean);
422
- if (oldLayers !== newLayers) {
423
- const prevLayers = (0, import_core4._flatten)(oldLayers, Boolean);
424
- const prevLayerGroupIds = new Set(prevLayers.map((l) => getLayerGroupId(l)));
425
- const newLayerGroupIds = new Set(layers.map((l) => getLayerGroupId(l)));
426
- for (const groupId of prevLayerGroupIds) {
427
- if (!newLayerGroupIds.has(groupId)) {
428
- if (map.getLayer(groupId)) {
429
- map.removeLayer(groupId);
430
- }
431
- }
432
- }
433
- }
434
- const layerGroups = {};
435
- for (const layer of layers) {
436
- const groupId = getLayerGroupId(layer);
437
- const mapboxGroup = map.getLayer(groupId);
438
- if (mapboxGroup) {
439
- const groupInstance = mapboxGroup.implementation || mapboxGroup;
440
- layerGroups[groupId] = groupInstance;
441
- } else {
442
- const newGroup = new MapboxLayerGroup({
443
- id: groupId,
444
- slot: layer.props.slot,
445
- beforeId: layer.props.beforeId
446
- });
447
- layerGroups[groupId] = newGroup;
448
- map.addLayer(newGroup, layer.props.beforeId);
449
- }
450
- }
451
- const mapLayers = map.style._order;
452
- for (const [groupId, group] of Object.entries(layerGroups)) {
453
- const beforeId = group.beforeId || UNDEFINED_BEFORE_ID2;
454
- const expectedGroupIndex = beforeId === UNDEFINED_BEFORE_ID2 ? mapLayers.length : mapLayers.indexOf(beforeId);
455
- const currentGropupIndex = mapLayers.indexOf(groupId);
456
- if (currentGropupIndex !== expectedGroupIndex - 1) {
457
- const moveBeforeId = beforeId === UNDEFINED_BEFORE_ID2 ? void 0 : beforeId;
458
- map.moveLayer(groupId, moveBeforeId);
459
- }
460
- }
461
- }
462
-
463
345
  // dist/mapbox-overlay.js
464
346
  var MapboxOverlay = class {
465
347
  constructor(props) {
@@ -469,8 +351,8 @@ var MapboxOverlay = class {
469
351
  if (!this._map)
470
352
  return;
471
353
  const projection = getProjection(this._map);
472
- if (projection && !this._props.views) {
473
- (_a = this._deck) == null ? void 0 : _a.setProps({ views: getDefaultView(this._map) });
354
+ if (projection) {
355
+ (_a = this._deck) == null ? void 0 : _a.setProps({ views: this._getViews(this._map) });
474
356
  }
475
357
  };
476
358
  this._updateContainerSize = () => {
@@ -487,7 +369,7 @@ var MapboxOverlay = class {
487
369
  const map = this._map;
488
370
  if (deck && map) {
489
371
  deck.setProps({
490
- views: this._props.views || getDefaultView(map),
372
+ views: this._getViews(map),
491
373
  viewState: getViewState(map)
492
374
  });
493
375
  if (deck.isInitialized) {
@@ -558,7 +440,6 @@ var MapboxOverlay = class {
558
440
  };
559
441
  const { interleaved = false } = props;
560
442
  this._interleaved = interleaved;
561
- this._renderLayersInGroups = props._renderLayersInGroups || false;
562
443
  this._props = this.filterProps(props);
563
444
  }
564
445
  /** Filter out props to pass to Deck **/
@@ -578,6 +459,7 @@ var MapboxOverlay = class {
578
459
  if (this._deck && this._map) {
579
460
  this._deck.setProps({
580
461
  ...this._props,
462
+ views: this._getViews(this._map),
581
463
  parameters: {
582
464
  ...getDefaultParameters(this._map, this._interleaved),
583
465
  ...this._props.parameters
@@ -602,11 +484,11 @@ var MapboxOverlay = class {
602
484
  pointerEvents: "none"
603
485
  });
604
486
  this._container = container;
605
- this._deck = new import_core5.Deck({
487
+ this._deck = new import_core4.Deck({
606
488
  ...this._props,
607
489
  parent: container,
608
490
  parameters: { ...getDefaultParameters(map, false), ...this._props.parameters },
609
- views: this._props.views || getDefaultView(map),
491
+ views: this._getViews(map),
610
492
  viewState: getViewState(map)
611
493
  });
612
494
  map.on("resize", this._updateContainerSize);
@@ -625,12 +507,13 @@ var MapboxOverlay = class {
625
507
  _onAddInterleaved(map) {
626
508
  const gl = map.painter.context.gl;
627
509
  if (gl instanceof WebGLRenderingContext) {
628
- import_core5.log.warn("Incompatible basemap library. See: https://deck.gl/docs/api-reference/mapbox/overview#compatibility")();
510
+ import_core4.log.warn("Incompatible basemap library. See: https://deck.gl/docs/api-reference/mapbox/overview#compatibility")();
629
511
  }
630
512
  this._deck = getDeckInstance({
631
513
  map,
632
- deck: new import_core5.Deck({
514
+ deck: new import_core4.Deck({
633
515
  ...this._props,
516
+ views: this._getViews(map),
634
517
  gl,
635
518
  parameters: { ...getDefaultParameters(map, true), ...this._props.parameters }
636
519
  })
@@ -639,12 +522,8 @@ var MapboxOverlay = class {
639
522
  this._resolveLayers(map, this._deck, [], this._props.layers);
640
523
  return document.createElement("div");
641
524
  }
642
- _resolveLayers(map, deck, prevLayers, newLayers) {
643
- if (this._renderLayersInGroups) {
644
- resolveLayerGroups(map, prevLayers, newLayers);
645
- } else {
646
- resolveLayers(map, deck, prevLayers, newLayers);
647
- }
525
+ _resolveLayers(map, _deck, prevLayers, newLayers) {
526
+ resolveLayerGroups(map, prevLayers, newLayers);
648
527
  }
649
528
  /** Called when the control is removed from a map */
650
529
  onRemove() {
@@ -684,17 +563,17 @@ var MapboxOverlay = class {
684
563
  }
685
564
  /** Forwards the Deck.pickObject method */
686
565
  pickObject(params) {
687
- (0, import_core5.assert)(this._deck);
566
+ (0, import_core4.assert)(this._deck);
688
567
  return this._deck.pickObject(params);
689
568
  }
690
569
  /** Forwards the Deck.pickMultipleObjects method */
691
570
  pickMultipleObjects(params) {
692
- (0, import_core5.assert)(this._deck);
571
+ (0, import_core4.assert)(this._deck);
693
572
  return this._deck.pickMultipleObjects(params);
694
573
  }
695
574
  /** Forwards the Deck.pickObjects method */
696
575
  pickObjects(params) {
697
- (0, import_core5.assert)(this._deck);
576
+ (0, import_core4.assert)(this._deck);
698
577
  return this._deck.pickObjects(params);
699
578
  }
700
579
  /** Remove from map and releases all resources */
@@ -710,5 +589,16 @@ var MapboxOverlay = class {
710
589
  }
711
590
  return this._interleaved ? this._map.getCanvas() : this._deck.getCanvas();
712
591
  }
592
+ _getViews(map) {
593
+ if (!this._props.views) {
594
+ return getDefaultView(map);
595
+ }
596
+ const views = Array.isArray(this._props.views) ? this._props.views : [this._props.views];
597
+ const hasMapboxView = views.some((v) => v.id === MAPBOX_VIEW_ID);
598
+ if (hasMapboxView) {
599
+ return this._props.views;
600
+ }
601
+ return [getDefaultView(map), ...views];
602
+ }
713
603
  };
714
604
  //# sourceMappingURL=index.cjs.map