@deck.gl/mapbox 9.3.0-alpha.5 → 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;
@@ -242,8 +306,9 @@ function getViewport(deck, map, renderParameters) {
242
306
  });
243
307
  }
244
308
  function afterRender(deck, map) {
245
- const deckLayers = (0, import_core._flatten)(deck.props.layers, Boolean);
246
- const hasNonMapboxLayers = deckLayers.some((layer) => layer && !map.getLayer(layer.id));
309
+ var _a, _b, _c, _d;
310
+ const deckLayers = (0, import_core3._flatten)(deck.props.layers, Boolean);
311
+ const hasNonMapboxLayers = deckLayers.some((layer) => layer && !map.getLayer(getLayerGroupId(layer)));
247
312
  let viewports = deck.getViewports();
248
313
  const mapboxViewportIdx = viewports.findIndex((vp) => vp.id === MAPBOX_VIEW_ID);
249
314
  const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
@@ -259,9 +324,14 @@ function afterRender(deck, map) {
259
324
  }
260
325
  deck._drawLayers("mapbox-repaint", {
261
326
  viewports,
262
- 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))),
263
328
  clearCanvas: false
264
329
  });
330
+ } else {
331
+ const device = deck.device;
332
+ const gl = device == null ? void 0 : device.gl;
333
+ (_b = (_a = deck.props).onBeforeRender) == null ? void 0 : _b.call(_a, { device, gl });
334
+ (_d = (_c = deck.props).onAfterRender) == null ? void 0 : _d.call(_c, { device, gl });
265
335
  }
266
336
  deck.userData.currentViewport = null;
267
337
  }
@@ -272,188 +342,6 @@ function onMapMove(deck, map) {
272
342
  deck.needsRedraw({ clearRedrawFlags: true });
273
343
  }
274
344
 
275
- // dist/resolve-layers.js
276
- var import_core2 = require("@deck.gl/core");
277
-
278
- // dist/mapbox-layer.js
279
- var MapboxLayer = class {
280
- /* eslint-disable no-this-before-super */
281
- constructor(props) {
282
- if (!props.id) {
283
- throw new Error("Layer must have an unique id");
284
- }
285
- this.id = props.id;
286
- this.type = "custom";
287
- this.renderingMode = props.renderingMode || "3d";
288
- this.slot = props.slot;
289
- this.map = null;
290
- this.props = props;
291
- }
292
- /* Mapbox custom layer methods */
293
- onAdd(map, gl) {
294
- this.map = map;
295
- }
296
- onRemove() {
297
- this.map = null;
298
- }
299
- setProps(props) {
300
- Object.assign(this.props, props, { id: this.id });
301
- }
302
- render(gl, renderParameters) {
303
- if (!this.map)
304
- return;
305
- drawLayer(this.map.__deck, this.map, this, renderParameters);
306
- }
307
- };
308
-
309
- // dist/resolve-layers.js
310
- var UNDEFINED_BEFORE_ID = "__UNDEFINED__";
311
- function resolveLayers(map, deck, oldLayers, newLayers) {
312
- if (!map || !deck || !map.style || !map.style._loaded) {
313
- return;
314
- }
315
- const layers = (0, import_core2._flatten)(newLayers, Boolean);
316
- if (oldLayers !== newLayers) {
317
- const prevLayers = (0, import_core2._flatten)(oldLayers, Boolean);
318
- const prevLayerIds = new Set(prevLayers.map((l) => l.id));
319
- for (const layer of layers) {
320
- prevLayerIds.delete(layer.id);
321
- }
322
- for (const id of prevLayerIds) {
323
- if (map.getLayer(id)) {
324
- map.removeLayer(id);
325
- }
326
- }
327
- }
328
- for (const layer of layers) {
329
- const mapboxLayer = map.getLayer(layer.id);
330
- if (mapboxLayer) {
331
- const layerInstance = mapboxLayer.implementation || mapboxLayer;
332
- layerInstance.setProps(layer.props);
333
- } else {
334
- map.addLayer(
335
- new MapboxLayer({
336
- id: layer.id,
337
- // @ts-expect-error slot is not defined in LayerProps
338
- slot: layer.props.slot
339
- }),
340
- // @ts-expect-error beforeId is not defined in LayerProps
341
- layer.props.beforeId
342
- );
343
- }
344
- }
345
- const mapLayers = map.style._order;
346
- const layerGroups = {};
347
- for (const layer of layers) {
348
- let { beforeId } = layer.props;
349
- if (!beforeId || !mapLayers.includes(beforeId)) {
350
- beforeId = UNDEFINED_BEFORE_ID;
351
- }
352
- layerGroups[beforeId] = layerGroups[beforeId] || [];
353
- layerGroups[beforeId].push(layer.id);
354
- }
355
- for (const beforeId in layerGroups) {
356
- const layerGroup = layerGroups[beforeId];
357
- let lastLayerIndex = beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
358
- let lastLayerId = beforeId === UNDEFINED_BEFORE_ID ? void 0 : beforeId;
359
- for (let i = layerGroup.length - 1; i >= 0; i--) {
360
- const layerId = layerGroup[i];
361
- const layerIndex = mapLayers.indexOf(layerId);
362
- if (layerIndex !== lastLayerIndex - 1) {
363
- map.moveLayer(layerId, lastLayerId);
364
- if (layerIndex > lastLayerIndex) {
365
- lastLayerIndex++;
366
- }
367
- }
368
- lastLayerIndex--;
369
- lastLayerId = layerId;
370
- }
371
- }
372
- }
373
-
374
- // dist/resolve-layer-groups.js
375
- var import_core4 = require("@deck.gl/core");
376
-
377
- // dist/mapbox-layer-group.js
378
- var import_core3 = require("@deck.gl/core");
379
- var MapboxLayerGroup = class {
380
- /* eslint-disable no-this-before-super */
381
- constructor(props) {
382
- (0, import_core3.assert)(props.id, "id is required");
383
- this.id = props.id;
384
- this.type = "custom";
385
- this.renderingMode = props.renderingMode || "3d";
386
- this.slot = props.slot;
387
- this.beforeId = props.beforeId;
388
- this.map = null;
389
- }
390
- /* Mapbox custom layer methods */
391
- onAdd(map, gl) {
392
- this.map = map;
393
- }
394
- render(gl, renderParameters) {
395
- if (!this.map)
396
- return;
397
- drawLayerGroup(this.map.__deck, this.map, this, renderParameters);
398
- }
399
- };
400
-
401
- // dist/resolve-layer-groups.js
402
- var UNDEFINED_BEFORE_ID2 = "__UNDEFINED__";
403
- function getLayerGroupId(layer) {
404
- if (layer.props.beforeId) {
405
- return `deck-layer-group-before:${layer.props.beforeId}`;
406
- } else if (layer.props.slot) {
407
- return `deck-layer-group-slot:${layer.props.slot}`;
408
- }
409
- return "deck-layer-group-last";
410
- }
411
- function resolveLayerGroups(map, oldLayers, newLayers) {
412
- if (!map || !map.style || !map.style._loaded) {
413
- return;
414
- }
415
- const layers = (0, import_core4._flatten)(newLayers, Boolean);
416
- if (oldLayers !== newLayers) {
417
- const prevLayers = (0, import_core4._flatten)(oldLayers, Boolean);
418
- const prevLayerGroupIds = new Set(prevLayers.map((l) => getLayerGroupId(l)));
419
- const newLayerGroupIds = new Set(layers.map((l) => getLayerGroupId(l)));
420
- for (const groupId of prevLayerGroupIds) {
421
- if (!newLayerGroupIds.has(groupId)) {
422
- if (map.getLayer(groupId)) {
423
- map.removeLayer(groupId);
424
- }
425
- }
426
- }
427
- }
428
- const layerGroups = {};
429
- for (const layer of layers) {
430
- const groupId = getLayerGroupId(layer);
431
- const mapboxGroup = map.getLayer(groupId);
432
- if (mapboxGroup) {
433
- const groupInstance = mapboxGroup.implementation || mapboxGroup;
434
- layerGroups[groupId] = groupInstance;
435
- } else {
436
- const newGroup = new MapboxLayerGroup({
437
- id: groupId,
438
- slot: layer.props.slot,
439
- beforeId: layer.props.beforeId
440
- });
441
- layerGroups[groupId] = newGroup;
442
- map.addLayer(newGroup, layer.props.beforeId);
443
- }
444
- }
445
- const mapLayers = map.style._order;
446
- for (const [groupId, group] of Object.entries(layerGroups)) {
447
- const beforeId = group.beforeId || UNDEFINED_BEFORE_ID2;
448
- const expectedGroupIndex = beforeId === UNDEFINED_BEFORE_ID2 ? mapLayers.length : mapLayers.indexOf(beforeId);
449
- const currentGropupIndex = mapLayers.indexOf(groupId);
450
- if (currentGropupIndex !== expectedGroupIndex - 1) {
451
- const moveBeforeId = beforeId === UNDEFINED_BEFORE_ID2 ? void 0 : beforeId;
452
- map.moveLayer(groupId, moveBeforeId);
453
- }
454
- }
455
- }
456
-
457
345
  // dist/mapbox-overlay.js
458
346
  var MapboxOverlay = class {
459
347
  constructor(props) {
@@ -463,8 +351,8 @@ var MapboxOverlay = class {
463
351
  if (!this._map)
464
352
  return;
465
353
  const projection = getProjection(this._map);
466
- if (projection && !this._props.views) {
467
- (_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) });
468
356
  }
469
357
  };
470
358
  this._updateContainerSize = () => {
@@ -481,7 +369,7 @@ var MapboxOverlay = class {
481
369
  const map = this._map;
482
370
  if (deck && map) {
483
371
  deck.setProps({
484
- views: this._props.views || getDefaultView(map),
372
+ views: this._getViews(map),
485
373
  viewState: getViewState(map)
486
374
  });
487
375
  if (deck.isInitialized) {
@@ -552,7 +440,6 @@ var MapboxOverlay = class {
552
440
  };
553
441
  const { interleaved = false } = props;
554
442
  this._interleaved = interleaved;
555
- this._renderLayersInGroups = props._renderLayersInGroups || false;
556
443
  this._props = this.filterProps(props);
557
444
  }
558
445
  /** Filter out props to pass to Deck **/
@@ -572,6 +459,7 @@ var MapboxOverlay = class {
572
459
  if (this._deck && this._map) {
573
460
  this._deck.setProps({
574
461
  ...this._props,
462
+ views: this._getViews(this._map),
575
463
  parameters: {
576
464
  ...getDefaultParameters(this._map, this._interleaved),
577
465
  ...this._props.parameters
@@ -596,11 +484,11 @@ var MapboxOverlay = class {
596
484
  pointerEvents: "none"
597
485
  });
598
486
  this._container = container;
599
- this._deck = new import_core5.Deck({
487
+ this._deck = new import_core4.Deck({
600
488
  ...this._props,
601
489
  parent: container,
602
490
  parameters: { ...getDefaultParameters(map, false), ...this._props.parameters },
603
- views: this._props.views || getDefaultView(map),
491
+ views: this._getViews(map),
604
492
  viewState: getViewState(map)
605
493
  });
606
494
  map.on("resize", this._updateContainerSize);
@@ -619,12 +507,13 @@ var MapboxOverlay = class {
619
507
  _onAddInterleaved(map) {
620
508
  const gl = map.painter.context.gl;
621
509
  if (gl instanceof WebGLRenderingContext) {
622
- 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")();
623
511
  }
624
512
  this._deck = getDeckInstance({
625
513
  map,
626
- deck: new import_core5.Deck({
514
+ deck: new import_core4.Deck({
627
515
  ...this._props,
516
+ views: this._getViews(map),
628
517
  gl,
629
518
  parameters: { ...getDefaultParameters(map, true), ...this._props.parameters }
630
519
  })
@@ -633,12 +522,8 @@ var MapboxOverlay = class {
633
522
  this._resolveLayers(map, this._deck, [], this._props.layers);
634
523
  return document.createElement("div");
635
524
  }
636
- _resolveLayers(map, deck, prevLayers, newLayers) {
637
- if (this._renderLayersInGroups) {
638
- resolveLayerGroups(map, prevLayers, newLayers);
639
- } else {
640
- resolveLayers(map, deck, prevLayers, newLayers);
641
- }
525
+ _resolveLayers(map, _deck, prevLayers, newLayers) {
526
+ resolveLayerGroups(map, prevLayers, newLayers);
642
527
  }
643
528
  /** Called when the control is removed from a map */
644
529
  onRemove() {
@@ -678,17 +563,17 @@ var MapboxOverlay = class {
678
563
  }
679
564
  /** Forwards the Deck.pickObject method */
680
565
  pickObject(params) {
681
- (0, import_core5.assert)(this._deck);
566
+ (0, import_core4.assert)(this._deck);
682
567
  return this._deck.pickObject(params);
683
568
  }
684
569
  /** Forwards the Deck.pickMultipleObjects method */
685
570
  pickMultipleObjects(params) {
686
- (0, import_core5.assert)(this._deck);
571
+ (0, import_core4.assert)(this._deck);
687
572
  return this._deck.pickMultipleObjects(params);
688
573
  }
689
574
  /** Forwards the Deck.pickObjects method */
690
575
  pickObjects(params) {
691
- (0, import_core5.assert)(this._deck);
576
+ (0, import_core4.assert)(this._deck);
692
577
  return this._deck.pickObjects(params);
693
578
  }
694
579
  /** Remove from map and releases all resources */
@@ -704,5 +589,16 @@ var MapboxOverlay = class {
704
589
  }
705
590
  return this._interleaved ? this._map.getCanvas() : this._deck.getCanvas();
706
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
+ }
707
603
  };
708
604
  //# sourceMappingURL=index.cjs.map