@deck.gl/mapbox 8.8.0-alpha.5 → 8.8.0-beta.2

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.
@@ -4,6 +4,8 @@ import type {Deck, Layer} from '@deck.gl/core';
4
4
 
5
5
  export type MapboxLayerProps<LayerT extends Layer> = Partial<LayerT['props']> & {
6
6
  id: string;
7
+ renderingMode?: '2d' | '3d';
8
+ deck?: Deck;
7
9
  };
8
10
 
9
11
  export default class MapboxLayer<LayerT extends Layer> implements CustomLayerInterface {
@@ -5,28 +5,50 @@ import type {Map, IControl, MapMouseEvent} from 'mapbox-gl';
5
5
  import type {MjolnirGestureEvent, MjolnirPointerEvent} from 'mjolnir.js';
6
6
  import type {DeckProps} from '@deck.gl/core';
7
7
 
8
+ import {resolveLayers} from './resolve-layers';
9
+
10
+ export type MapboxOverlayProps = Omit<
11
+ DeckProps,
12
+ | 'width'
13
+ | 'height'
14
+ | 'gl'
15
+ | 'parent'
16
+ | 'canvas'
17
+ | '_customRender'
18
+ | 'viewState'
19
+ | 'initialViewState'
20
+ | 'controller'
21
+ >;
22
+
8
23
  /**
9
24
  * Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface
10
25
  * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera
11
26
  */
12
27
  export default class MapboxOverlay implements IControl {
13
- private _props: DeckProps;
28
+ private _props: MapboxOverlayProps;
14
29
  private _deck?: Deck;
15
30
  private _map?: Map;
16
31
  private _container?: HTMLDivElement;
32
+ private _interleaved: boolean;
17
33
 
18
- constructor(props: DeckProps) {
19
- this._props = {...props};
34
+ constructor(
35
+ props: MapboxOverlayProps & {
36
+ interleaved?: boolean;
37
+ }
38
+ ) {
39
+ const {interleaved = false, ...otherProps} = props;
40
+ this._interleaved = interleaved;
41
+ this._props = otherProps;
20
42
  }
21
43
 
22
44
  /** Update (partial) props of the underlying Deck instance. */
23
- setProps(props: DeckProps): void {
24
- Object.assign(this._props, props);
25
-
26
- if ('viewState' in this._props) {
27
- delete this._props.viewState;
45
+ setProps(props: MapboxOverlayProps): void {
46
+ if (this._interleaved && props.layers) {
47
+ resolveLayers(this._map, this._deck, this._props.layers, props.layers);
28
48
  }
29
49
 
50
+ Object.assign(this._props, props);
51
+
30
52
  if (this._deck) {
31
53
  this._deck.setProps(this._props);
32
54
  }
@@ -35,7 +57,10 @@ export default class MapboxOverlay implements IControl {
35
57
  /** Called when the control is added to a map */
36
58
  onAdd(map: Map): HTMLDivElement {
37
59
  this._map = map;
60
+ return this._interleaved ? this._onAddInterleaved(map) : this._onAddOverlaid(map);
61
+ }
38
62
 
63
+ private _onAddOverlaid(map: Map): HTMLDivElement {
39
64
  /* global document */
40
65
  const container = document.createElement('div');
41
66
  Object.assign(container.style, {
@@ -63,17 +88,29 @@ export default class MapboxOverlay implements IControl {
63
88
  return container;
64
89
  }
65
90
 
91
+ private _onAddInterleaved(map: Map): HTMLDivElement {
92
+ this._deck = new Deck({
93
+ ...this._props,
94
+ // @ts-ignore non-public map property
95
+ gl: map.painter.context.gl
96
+ });
97
+
98
+ map.on('styledata', this._handleStyleChange);
99
+ resolveLayers(map, this._deck, [], this._props.layers);
100
+
101
+ return document.createElement('div');
102
+ }
103
+
66
104
  /** Called when the control is removed from a map */
67
105
  onRemove(): void {
68
106
  const map = this._map;
69
107
 
70
108
  if (map) {
71
- map.off('resize', this._updateContainerSize);
72
- map.off('render', this._updateViewState);
73
- map.off('mousemove', this._handleMouseEvent);
74
- map.off('mouseout', this._handleMouseEvent);
75
- map.off('click', this._handleMouseEvent);
76
- map.off('dblclick', this._handleMouseEvent);
109
+ if (this._interleaved) {
110
+ this._onRemoveInterleaved(map);
111
+ } else {
112
+ this._onRemoveOverlaid(map);
113
+ }
77
114
  }
78
115
 
79
116
  this._deck?.finalize();
@@ -82,6 +119,20 @@ export default class MapboxOverlay implements IControl {
82
119
  this._container = undefined;
83
120
  }
84
121
 
122
+ private _onRemoveOverlaid(map: Map): void {
123
+ map.off('resize', this._updateContainerSize);
124
+ map.off('render', this._updateViewState);
125
+ map.off('mousemove', this._handleMouseEvent);
126
+ map.off('mouseout', this._handleMouseEvent);
127
+ map.off('click', this._handleMouseEvent);
128
+ map.off('dblclick', this._handleMouseEvent);
129
+ }
130
+
131
+ private _onRemoveInterleaved(map: Map): void {
132
+ map.off('styledata', this._handleStyleChange);
133
+ resolveLayers(map, this._deck, this._props.layers, []);
134
+ }
135
+
85
136
  getDefaultPosition() {
86
137
  return 'top-left';
87
138
  }
@@ -113,6 +164,10 @@ export default class MapboxOverlay implements IControl {
113
164
  }
114
165
  }
115
166
 
167
+ private _handleStyleChange = () => {
168
+ resolveLayers(this._map, this._deck, this._props.layers, this._props.layers);
169
+ };
170
+
116
171
  private _updateContainerSize = () => {
117
172
  if (this._map && this._container) {
118
173
  const {clientWidth, clientHeight} = this._map.getContainer();
@@ -0,0 +1,89 @@
1
+ import {_flatten as flatten} from '@deck.gl/core';
2
+ import MapboxLayer from './mapbox-layer';
3
+
4
+ import type {Deck, LayersList, Layer} from '@deck.gl/core';
5
+ import type {Map} from 'mapbox-gl';
6
+
7
+ const UNDEFINED_BEFORE_ID = '__UNDEFINED__';
8
+
9
+ /** Insert Deck layers into the mapbox Map according to the user-defined order */
10
+ export function resolveLayers(
11
+ map?: Map,
12
+ deck?: Deck,
13
+ oldLayers?: LayersList,
14
+ newLayers?: LayersList
15
+ ) {
16
+ // Wait until map style is loaded
17
+ // @ts-ignore non-public map property
18
+ if (!map || !deck || !map.style || !map.style._loaded) {
19
+ return;
20
+ }
21
+
22
+ const layers = flatten(newLayers, Boolean) as Layer[];
23
+
24
+ if (oldLayers !== newLayers) {
25
+ // Step 1: remove layers that no longer exist
26
+ const prevLayers = flatten(oldLayers, Boolean) as Layer[];
27
+ const prevLayerIds = new Set<string>(prevLayers.map(l => l.id));
28
+
29
+ for (const layer of layers) {
30
+ prevLayerIds.delete(layer.id);
31
+ }
32
+
33
+ for (const id of prevLayerIds) {
34
+ if (map.getLayer(id)) {
35
+ map.removeLayer(id);
36
+ }
37
+ }
38
+ }
39
+
40
+ // Step 2: add missing layers
41
+ for (const layer of layers) {
42
+ if (!map.getLayer(layer.id)) {
43
+ map.addLayer(
44
+ new MapboxLayer({id: layer.id, deck}),
45
+ // @ts-expect-error beforeId is not defined in LayerProps
46
+ layer.props.beforeId
47
+ );
48
+ }
49
+ }
50
+
51
+ // Step 3: check the order of layers
52
+ // If beforeId is defined, the deck layer should always render before the mapbox layer [beforeId]
53
+ // If beforeId is not defined, the deck layer should appear after all mapbox layers
54
+ // When two deck layers share the same beforeId, they are rendered in the order that is passed into Deck props.layers
55
+ // @ts-ignore non-public map property
56
+ const mapLayers: string[] = map.style._order;
57
+
58
+ // Group deck layers by beforeId
59
+ const layerGroups: Record<string, string[]> = {};
60
+ for (const layer of layers) {
61
+ // @ts-expect-error beforeId is not defined in LayerProps
62
+ let {beforeId} = layer.props;
63
+ if (!beforeId || !mapLayers.includes(beforeId)) {
64
+ beforeId = UNDEFINED_BEFORE_ID;
65
+ }
66
+ layerGroups[beforeId] = layerGroups[beforeId] || [];
67
+ layerGroups[beforeId].push(layer.id);
68
+ }
69
+
70
+ for (const beforeId in layerGroups) {
71
+ const layerGroup = layerGroups[beforeId];
72
+ let lastLayerIndex =
73
+ beforeId === UNDEFINED_BEFORE_ID ? mapLayers.length : mapLayers.indexOf(beforeId);
74
+ let lastLayerId = beforeId === UNDEFINED_BEFORE_ID ? undefined : beforeId;
75
+ for (let i = layerGroup.length - 1; i >= 0; i--) {
76
+ const layerId = layerGroup[i];
77
+ const layerIndex = mapLayers.indexOf(layerId);
78
+ if (layerIndex !== lastLayerIndex - 1) {
79
+ map.moveLayer(layerId, lastLayerId);
80
+ if (layerIndex > lastLayerIndex) {
81
+ // The last layer's index have changed
82
+ lastLayerIndex++;
83
+ }
84
+ }
85
+ lastLayerIndex--;
86
+ lastLayerId = layerId;
87
+ }
88
+ }
89
+ }
@@ -15,5 +15,11 @@ export declare function updateLayer(deck: Deck, layer: MapboxLayer<any>): void;
15
15
  export declare function drawLayer(deck: Deck, map: Map, layer: MapboxLayer<any>): void;
16
16
  export declare function getViewState(map: Map): MapViewState & {
17
17
  repeat: boolean;
18
+ padding: {
19
+ left: number;
20
+ right: number;
21
+ top: number;
22
+ bottom: number;
23
+ };
18
24
  };
19
25
  //# sourceMappingURL=deck-utils.d.ts.map
@@ -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,CAgEP;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,CAAC,GAAG,IAAI,CAGrE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAAI,CAErE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,IAA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C;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAaA"}
@@ -0,0 +1,185 @@
1
+ import { Deck, WebMercatorViewport, MapView, _flatten as flatten } from '@deck.gl/core';
2
+ export function getDeckInstance({ map, gl, deck }) {
3
+ // Only create one deck instance per context
4
+ if (map.__deck) {
5
+ return map.__deck;
6
+ }
7
+ const customRender = deck?.props._customRender;
8
+ const deckProps = {
9
+ useDevicePixels: true,
10
+ _customRender: (reason) => {
11
+ map.triggerRepaint();
12
+ // customRender may be subscribed by DeckGL React component to update child props
13
+ // make sure it is still called
14
+ customRender?.(reason);
15
+ },
16
+ // TODO: import these defaults from a single source of truth
17
+ parameters: {
18
+ depthMask: true,
19
+ depthTest: true,
20
+ blend: true,
21
+ blendFunc: [gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA],
22
+ polygonOffsetFill: true,
23
+ depthFunc: gl.LEQUAL,
24
+ blendEquation: gl.FUNC_ADD
25
+ },
26
+ views: (deck && deck.props.views) || [new MapView({ id: 'mapbox' })]
27
+ };
28
+ if (!deck || deck.props.gl === gl) {
29
+ // deck is using the WebGLContext created by mapbox
30
+ // block deck from setting the canvas size
31
+ Object.assign(deckProps, {
32
+ gl,
33
+ width: null,
34
+ height: null,
35
+ touchAction: 'unset',
36
+ viewState: getViewState(map)
37
+ });
38
+ // If using the WebGLContext created by deck (React use case), we use deck's viewState to drive the map.
39
+ // Otherwise (pure JS use case), we use the map's viewState to drive deck.
40
+ map.on('move', () => onMapMove(deck, map));
41
+ }
42
+ if (deck) {
43
+ deck.setProps(deckProps);
44
+ deck.userData.isExternal = true;
45
+ }
46
+ else {
47
+ deck = new Deck(deckProps);
48
+ map.on('remove', () => {
49
+ deck.finalize();
50
+ map.__deck = null;
51
+ });
52
+ }
53
+ deck.userData.mapboxLayers = new Set();
54
+ deck.userData.mapboxVersion = getMapboxVersion(map);
55
+ map.__deck = deck;
56
+ map.on('render', () => {
57
+ // @ts-expect-error (2445) protected property
58
+ if (deck.layerManager)
59
+ afterRender(deck, map);
60
+ });
61
+ return deck;
62
+ }
63
+ export function addLayer(deck, layer) {
64
+ deck.userData.mapboxLayers.add(layer);
65
+ updateLayers(deck);
66
+ }
67
+ export function removeLayer(deck, layer) {
68
+ deck.userData.mapboxLayers.delete(layer);
69
+ updateLayers(deck);
70
+ }
71
+ export function updateLayer(deck, layer) {
72
+ updateLayers(deck);
73
+ }
74
+ export function drawLayer(deck, map, layer) {
75
+ let { currentViewport } = deck.userData;
76
+ if (!currentViewport) {
77
+ // This is the first layer drawn in this render cycle.
78
+ // Generate viewport from the current map state.
79
+ currentViewport = getViewport(deck, map, true);
80
+ deck.userData.currentViewport = currentViewport;
81
+ }
82
+ // @ts-expect-error (2445) protected property
83
+ if (!deck.layerManager) {
84
+ return;
85
+ }
86
+ deck._drawLayers('mapbox-repaint', {
87
+ viewports: [currentViewport],
88
+ layerFilter: ({ layer: deckLayer }) => layer.id === deckLayer.id,
89
+ clearCanvas: false
90
+ });
91
+ }
92
+ export function getViewState(map) {
93
+ const { lng, lat } = map.getCenter();
94
+ return {
95
+ // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian
96
+ // https://github.com/visgl/deck.gl/issues/6894
97
+ longitude: ((lng + 540) % 360) - 180,
98
+ latitude: lat,
99
+ zoom: map.getZoom(),
100
+ bearing: map.getBearing(),
101
+ pitch: map.getPitch(),
102
+ repeat: map.getRenderWorldCopies()
103
+ };
104
+ }
105
+ function getMapboxVersion(map) {
106
+ // parse mapbox version string
107
+ let major = 0;
108
+ let minor = 0;
109
+ // @ts-ignore (2339) undefined property
110
+ const version = map.version;
111
+ if (version) {
112
+ [major, minor] = version.split('.').slice(0, 2).map(Number);
113
+ }
114
+ return { major, minor };
115
+ }
116
+ function getViewport(deck, map, useMapboxProjection = true) {
117
+ const { mapboxVersion } = deck.userData;
118
+ return new WebMercatorViewport(Object.assign({
119
+ id: 'mapbox',
120
+ x: 0,
121
+ y: 0,
122
+ width: deck.width,
123
+ height: deck.height
124
+ }, getViewState(map), useMapboxProjection
125
+ ? {
126
+ // match mapbox's projection matrix
127
+ // A change of near plane was made in 1.3.0
128
+ // https://github.com/mapbox/mapbox-gl-js/pull/8502
129
+ nearZMultiplier: (mapboxVersion.major === 1 && mapboxVersion.minor >= 3) || mapboxVersion.major >= 2
130
+ ? 0.02
131
+ : 1 / (deck.height || 1)
132
+ }
133
+ : {
134
+ // use deck.gl's own default
135
+ nearZMultiplier: 0.1
136
+ }));
137
+ }
138
+ function afterRender(deck, map) {
139
+ const { mapboxLayers, isExternal } = deck.userData;
140
+ if (isExternal) {
141
+ // Draw non-Mapbox layers
142
+ const mapboxLayerIds = Array.from(mapboxLayers, layer => layer.id);
143
+ const deckLayers = flatten(deck.props.layers, Boolean);
144
+ const hasNonMapboxLayers = deckLayers.some(layer => layer && !mapboxLayerIds.includes(layer.id));
145
+ let viewports = deck.getViewports();
146
+ const mapboxViewportIdx = viewports.findIndex(vp => vp.id === 'mapbox');
147
+ const hasNonMapboxViews = viewports.length > 1 || mapboxViewportIdx < 0;
148
+ if (hasNonMapboxLayers || hasNonMapboxViews) {
149
+ if (mapboxViewportIdx >= 0) {
150
+ viewports = viewports.slice();
151
+ viewports[mapboxViewportIdx] = getViewport(deck, map, false);
152
+ }
153
+ deck._drawLayers('mapbox-repaint', {
154
+ viewports,
155
+ layerFilter: params => (!deck.props.layerFilter || deck.props.layerFilter(params)) &&
156
+ (params.viewport.id !== 'mapbox' || !mapboxLayerIds.includes(params.layer.id)),
157
+ clearCanvas: false
158
+ });
159
+ }
160
+ }
161
+ // End of render cycle, clear generated viewport
162
+ deck.userData.currentViewport = null;
163
+ }
164
+ function onMapMove(deck, map) {
165
+ deck.setProps({
166
+ viewState: getViewState(map)
167
+ });
168
+ // Camera changed, will trigger a map repaint right after this
169
+ // Clear any change flag triggered by setting viewState so that deck does not request
170
+ // a second repaint
171
+ deck.needsRedraw({ clearRedrawFlags: true });
172
+ }
173
+ function updateLayers(deck) {
174
+ if (deck.userData.isExternal) {
175
+ return;
176
+ }
177
+ const layers = [];
178
+ let layerIndex = 0;
179
+ deck.userData.mapboxLayers.forEach(deckLayer => {
180
+ const LayerType = deckLayer.props.type;
181
+ const layer = new LayerType(deckLayer.props, { _offset: layerIndex++ });
182
+ layers.push(layer);
183
+ });
184
+ deck.setProps({ layers });
185
+ }
package/typed/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as MapboxLayer } from './mapbox-layer';
2
2
  export { default as MapboxOverlay } from './mapbox-overlay';
3
+ export type { MapboxOverlayProps } from './mapbox-overlay';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE1D,YAAY,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC"}
package/typed/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as MapboxLayer } from './mapbox-layer';
2
+ export { default as MapboxOverlay } from './mapbox-overlay';
@@ -2,6 +2,8 @@ import type { Map, CustomLayerInterface } from 'mapbox-gl';
2
2
  import type { Deck, Layer } from '@deck.gl/core/typed';
3
3
  export declare type MapboxLayerProps<LayerT extends Layer> = Partial<LayerT['props']> & {
4
4
  id: string;
5
+ renderingMode?: '2d' | '3d';
6
+ deck?: Deck;
5
7
  };
6
8
  export default class MapboxLayer<LayerT extends Layer> implements CustomLayerInterface {
7
9
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mapbox-layer.d.ts","sourceRoot":"","sources":["../src/mapbox-layer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,GAAG,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAE/C,oBAAY,gBAAgB,CAAC,MAAM,SAAS,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG;IAC9E,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,WAAW,CAAC,MAAM,SAAS,KAAK,CAAE,YAAW,oBAAoB;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAChB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;gBAGpB,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAe3C,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,qBAAqB,GAAG,IAAI;IAMhD,QAAQ,IAAI,IAAI;IAMhB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;IASxC,MAAM;CAGP"}
1
+ {"version":3,"file":"mapbox-layer.d.ts","sourceRoot":"","sources":["../src/mapbox-layer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,GAAG,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AAE/C,oBAAY,gBAAgB,CAAC,MAAM,SAAS,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG;IAC9E,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,WAAW,CAAC,MAAM,SAAS,KAAK,CAAE,YAAW,oBAAoB;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAChB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;gBAGpB,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAe3C,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,qBAAqB,GAAG,IAAI;IAMhD,QAAQ,IAAI,IAAI;IAMhB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;IASxC,MAAM;CAGP"}
@@ -0,0 +1,37 @@
1
+ import { getDeckInstance, addLayer, removeLayer, updateLayer, drawLayer } from './deck-utils';
2
+ export default class MapboxLayer {
3
+ /* eslint-disable no-this-before-super */
4
+ constructor(props) {
5
+ if (!props.id) {
6
+ throw new Error('Layer must have an unique id');
7
+ }
8
+ this.id = props.id;
9
+ this.type = 'custom';
10
+ this.renderingMode = props.renderingMode || '3d';
11
+ this.map = null;
12
+ this.deck = null;
13
+ this.props = props;
14
+ }
15
+ /* Mapbox custom layer methods */
16
+ onAdd(map, gl) {
17
+ this.map = map;
18
+ this.deck = getDeckInstance({ map, gl, deck: this.props.deck });
19
+ addLayer(this.deck, this);
20
+ }
21
+ onRemove() {
22
+ if (this.deck) {
23
+ removeLayer(this.deck, this);
24
+ }
25
+ }
26
+ setProps(props) {
27
+ // id cannot be changed
28
+ Object.assign(this.props, props, { id: this.id });
29
+ // safe guard in case setProps is called before onAdd
30
+ if (this.deck) {
31
+ updateLayer(this.deck, this);
32
+ }
33
+ }
34
+ render() {
35
+ drawLayer(this.deck, this.map, this);
36
+ }
37
+ }
@@ -1,6 +1,7 @@
1
1
  import { Deck } from '@deck.gl/core/typed';
2
2
  import type { Map, IControl } from 'mapbox-gl';
3
3
  import type { DeckProps } from '@deck.gl/core/typed';
4
+ export declare type MapboxOverlayProps = Omit<DeckProps, 'width' | 'height' | 'gl' | 'parent' | 'canvas' | '_customRender' | 'viewState' | 'initialViewState' | 'controller'>;
4
5
  /**
5
6
  * Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface
6
7
  * Renders deck.gl layers over the base map and automatically synchronizes with the map's camera
@@ -10,13 +11,20 @@ export default class MapboxOverlay implements IControl {
10
11
  private _deck?;
11
12
  private _map?;
12
13
  private _container?;
13
- constructor(props: DeckProps);
14
+ private _interleaved;
15
+ constructor(props: MapboxOverlayProps & {
16
+ interleaved?: boolean;
17
+ });
14
18
  /** Update (partial) props of the underlying Deck instance. */
15
- setProps(props: DeckProps): void;
19
+ setProps(props: MapboxOverlayProps): void;
16
20
  /** Called when the control is added to a map */
17
21
  onAdd(map: Map): HTMLDivElement;
22
+ private _onAddOverlaid;
23
+ private _onAddInterleaved;
18
24
  /** Called when the control is removed from a map */
19
25
  onRemove(): void;
26
+ private _onRemoveOverlaid;
27
+ private _onRemoveInterleaved;
20
28
  getDefaultPosition(): string;
21
29
  /** Forwards the Deck.pickObject method */
22
30
  pickObject(params: Parameters<Deck['pickObject']>[0]): ReturnType<Deck['pickObject']>;
@@ -26,6 +34,7 @@ export default class MapboxOverlay implements IControl {
26
34
  pickObjects(params: Parameters<Deck['pickObjects']>[0]): ReturnType<Deck['pickObjects']>;
27
35
  /** Remove from map and releases all resources */
28
36
  finalize(): void;
37
+ private _handleStyleChange;
29
38
  private _updateContainerSize;
30
39
  private _updateViewState;
31
40
  private _handleMouseEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"mapbox-overlay.d.ts","sourceRoot":"","sources":["../src/mapbox-overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAS,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAC,GAAG,EAAE,QAAQ,EAAgB,MAAM,WAAW,CAAC;AAE5D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,QAAQ;IACpD,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAC,CAAO;IACrB,OAAO,CAAC,IAAI,CAAC,CAAM;IACnB,OAAO,CAAC,UAAU,CAAC,CAAiB;gBAExB,KAAK,EAAE,SAAS;IAI5B,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAYhC,gDAAgD;IAChD,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc;IA8B/B,oDAAoD;IACpD,QAAQ,IAAI,IAAI;IAkBhB,kBAAkB;IAIlB,0CAA0C;IAC1C,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAKrF,mDAAmD;IACnD,mBAAmB,CACjB,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,GACjD,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAK1C,2CAA2C;IAC3C,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAKxF,iDAAiD;IACjD,QAAQ;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