@deck.gl/mapbox 8.8.19 → 8.8.21

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/src/deck-utils.ts CHANGED
@@ -3,6 +3,8 @@ import type {DeckProps, MapViewState, Layer} from '@deck.gl/core';
3
3
  import type MapboxLayer from './mapbox-layer';
4
4
  import type {Map} from 'mapbox-gl';
5
5
 
6
+ import GL from '@luma.gl/constants';
7
+
6
8
  type UserData = {
7
9
  isExternal: boolean;
8
10
  currentViewport?: WebMercatorViewport | null;
@@ -24,10 +26,11 @@ export function getDeckInstance({
24
26
  return map.__deck;
25
27
  }
26
28
 
29
+ // Only initialize certain props once per context
27
30
  const customRender = deck?.props._customRender;
28
31
 
29
- const deckProps: DeckProps = {
30
- useDevicePixels: true,
32
+ const deckProps = getInterleavedProps({
33
+ ...deck?.props,
31
34
  _customRender: () => {
32
35
  map.triggerRepaint();
33
36
  // customRender may be subscribed by DeckGL React component to update child props
@@ -35,19 +38,8 @@ export function getDeckInstance({
35
38
  // Hack - do not pass a redraw reason here to prevent the React component from clearing the context
36
39
  // Rerender will be triggered by MapboxLayer's render()
37
40
  customRender?.('');
38
- },
39
- // TODO: import these defaults from a single source of truth
40
- parameters: {
41
- depthMask: true,
42
- depthTest: true,
43
- blend: true,
44
- blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
45
- polygonOffsetFill: true,
46
- depthFunc: gl.LEQUAL,
47
- blendEquation: gl.FUNC_ADD
48
- },
49
- views: (deck && deck.props.views) || [new MapView({id: 'mapbox'})]
50
- };
41
+ }
42
+ });
51
43
 
52
44
  let deckInstance: Deck;
53
45
 
@@ -88,6 +80,29 @@ export function getDeckInstance({
88
80
  return deckInstance;
89
81
  }
90
82
 
83
+ export function getInterleavedProps(currProps: DeckProps) {
84
+ const useDevicePixels = 'useDevicePixels' in currProps ? currProps.useDevicePixels : true;
85
+
86
+ const nextProps: DeckProps = {
87
+ ...currProps,
88
+ useDevicePixels,
89
+ // TODO: import these defaults from a single source of truth
90
+ parameters: {
91
+ depthMask: true,
92
+ depthTest: true,
93
+ blend: true,
94
+ blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA],
95
+ polygonOffsetFill: true,
96
+ depthFunc: GL.LEQUAL,
97
+ blendEquation: GL.FUNC_ADD,
98
+ ...currProps.parameters
99
+ },
100
+ views: currProps.views || [new MapView({id: 'mapbox'})]
101
+ };
102
+
103
+ return nextProps;
104
+ }
105
+
91
106
  export function addLayer(deck: Deck, layer: MapboxLayer<any>): void {
92
107
  (deck.userData as UserData).mapboxLayers.add(layer);
93
108
  updateLayers(deck);
@@ -1,5 +1,5 @@
1
1
  import {Deck, assert} from '@deck.gl/core';
2
- import {getViewState} from './deck-utils';
2
+ import {getViewState, getDeckInstance, getInterleavedProps} from './deck-utils';
3
3
 
4
4
  import type {Map, IControl, MapMouseEvent} from 'mapbox-gl';
5
5
  import type {MjolnirGestureEvent, MjolnirPointerEvent} from 'mjolnir.js';
@@ -50,7 +50,7 @@ export default class MapboxOverlay implements IControl {
50
50
  Object.assign(this._props, props);
51
51
 
52
52
  if (this._deck) {
53
- this._deck.setProps(this._props);
53
+ this._deck.setProps(this._interleaved ? getInterleavedProps(this._props) : this._props);
54
54
  }
55
55
  }
56
56
 
@@ -89,10 +89,15 @@ export default class MapboxOverlay implements IControl {
89
89
  }
90
90
 
91
91
  private _onAddInterleaved(map: Map): HTMLDivElement {
92
- this._deck = new Deck({
93
- ...this._props,
92
+ this._deck = getDeckInstance({
93
+ map,
94
94
  // @ts-ignore non-public map property
95
- gl: map.painter.context.gl
95
+ gl: map.painter.context.gl,
96
+ deck: new Deck({
97
+ ...this._props,
98
+ // @ts-ignore non-public map property
99
+ gl: map.painter.context.gl
100
+ })
96
101
  });
97
102
 
98
103
  map.on('styledata', this._handleStyleChange);
@@ -1,5 +1,5 @@
1
1
  import { Deck } from '@deck.gl/core/typed';
2
- import type { MapViewState } from '@deck.gl/core/typed';
2
+ import type { DeckProps, MapViewState } from '@deck.gl/core/typed';
3
3
  import type MapboxLayer from './mapbox-layer';
4
4
  import type { Map } from 'mapbox-gl';
5
5
  export declare function getDeckInstance({ map, gl, deck }: {
@@ -9,6 +9,7 @@ export declare function getDeckInstance({ map, gl, deck }: {
9
9
  gl: WebGLRenderingContext;
10
10
  deck?: Deck;
11
11
  }): Deck;
12
+ export declare function getInterleavedProps(currProps: DeckProps): DeckProps;
12
13
  export declare function addLayer(deck: Deck, layer: MapboxLayer<any>): void;
13
14
  export declare function removeLayer(deck: Deck, layer: MapboxLayer<any>): void;
14
15
  export declare function updateLayer(deck: Deck, layer: MapboxLayer<any>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"deck-utils.d.ts","sourceRoot":"","sources":["../src/deck-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAoD,MAAM,eAAe,CAAC;AACtF,OAAO,KAAK,EAAY,YAAY,EAAQ,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AASnC,wBAAgB,eAAe,CAAC,EAC9B,GAAG,EACH,EAAE,EACF,IAAI,EACL,EAAE;IACD,GAAG,EAAE,GAAG,GAAG;QAAC,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;KAAC,CAAC;IAClC,EAAE,EAAE,qBAAqB,CAAC;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GAAG,IAAI,CAoEP;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAGlE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CA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