@deck.gl/mapbox 8.9.10 → 8.9.11
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/package.json +2 -2
- package/typed/deck-utils.js +0 -185
- package/typed/index.js +0 -2
- package/typed/mapbox-layer.js +0 -37
- package/typed/mapbox-overlay.js +0 -139
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/mapbox",
|
|
3
3
|
"description": "Use deck.gl layers as custom mapbox-gl-js layers",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.9.
|
|
5
|
+
"version": "8.9.11",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@deck.gl/core": "^8.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "ec059b9b2bde01fecc8017ed39b9898d85794561"
|
|
39
39
|
}
|
package/typed/deck-utils.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
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.js
DELETED
package/typed/mapbox-layer.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
package/typed/mapbox-overlay.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { Deck, assert } from '@deck.gl/core';
|
|
2
|
-
import { getViewState } from './deck-utils';
|
|
3
|
-
/**
|
|
4
|
-
* Implements Mapbox [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) interface
|
|
5
|
-
* Renders deck.gl layers over the base map and automatically synchronizes with the map's camera
|
|
6
|
-
*/
|
|
7
|
-
export default class MapboxOverlay {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
this._updateContainerSize = () => {
|
|
10
|
-
if (this._map && this._container) {
|
|
11
|
-
const { clientWidth, clientHeight } = this._map.getContainer();
|
|
12
|
-
Object.assign(this._container.style, {
|
|
13
|
-
width: `${clientWidth}px`,
|
|
14
|
-
height: `${clientHeight}px`
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
this._updateViewState = () => {
|
|
19
|
-
const deck = this._deck;
|
|
20
|
-
if (deck) {
|
|
21
|
-
// @ts-ignore (2345) map is always defined if deck is
|
|
22
|
-
deck.setProps({ viewState: getViewState(this._map) });
|
|
23
|
-
// Redraw immediately if view state has changed
|
|
24
|
-
deck.redraw();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
this._handleMouseEvent = (event) => {
|
|
28
|
-
const deck = this._deck;
|
|
29
|
-
if (!deck) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const mockEvent = {
|
|
33
|
-
type: event.type,
|
|
34
|
-
offsetCenter: event.point,
|
|
35
|
-
srcEvent: event
|
|
36
|
-
};
|
|
37
|
-
switch (event.type) {
|
|
38
|
-
case 'click':
|
|
39
|
-
mockEvent.tapCount = 1;
|
|
40
|
-
// Hack: because we do not listen to pointer down, perform picking now
|
|
41
|
-
deck._onPointerDown(mockEvent);
|
|
42
|
-
deck._onEvent(mockEvent);
|
|
43
|
-
break;
|
|
44
|
-
case 'dblclick':
|
|
45
|
-
mockEvent.type = 'click';
|
|
46
|
-
mockEvent.tapCount = 2;
|
|
47
|
-
deck._onEvent(mockEvent);
|
|
48
|
-
break;
|
|
49
|
-
case 'mousemove':
|
|
50
|
-
mockEvent.type = 'pointermove';
|
|
51
|
-
deck._onPointerMove(mockEvent);
|
|
52
|
-
break;
|
|
53
|
-
case 'mouseout':
|
|
54
|
-
mockEvent.type = 'pointerleave';
|
|
55
|
-
deck._onPointerMove(mockEvent);
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
this._props = { ...props };
|
|
62
|
-
}
|
|
63
|
-
/** Update (partial) props of the underlying Deck instance. */
|
|
64
|
-
setProps(props) {
|
|
65
|
-
Object.assign(this._props, props);
|
|
66
|
-
if ('viewState' in this._props) {
|
|
67
|
-
delete this._props.viewState;
|
|
68
|
-
}
|
|
69
|
-
if (this._deck) {
|
|
70
|
-
this._deck.setProps(this._props);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** Called when the control is added to a map */
|
|
74
|
-
onAdd(map) {
|
|
75
|
-
this._map = map;
|
|
76
|
-
/* global document */
|
|
77
|
-
const container = document.createElement('div');
|
|
78
|
-
Object.assign(container.style, {
|
|
79
|
-
position: 'absolute',
|
|
80
|
-
left: 0,
|
|
81
|
-
top: 0,
|
|
82
|
-
pointerEvents: 'none'
|
|
83
|
-
});
|
|
84
|
-
this._container = container;
|
|
85
|
-
this._deck = new Deck({
|
|
86
|
-
...this._props,
|
|
87
|
-
parent: container,
|
|
88
|
-
viewState: getViewState(map)
|
|
89
|
-
});
|
|
90
|
-
map.on('resize', this._updateContainerSize);
|
|
91
|
-
map.on('render', this._updateViewState);
|
|
92
|
-
map.on('mousemove', this._handleMouseEvent);
|
|
93
|
-
map.on('mouseout', this._handleMouseEvent);
|
|
94
|
-
map.on('click', this._handleMouseEvent);
|
|
95
|
-
map.on('dblclick', this._handleMouseEvent);
|
|
96
|
-
this._updateContainerSize();
|
|
97
|
-
return container;
|
|
98
|
-
}
|
|
99
|
-
/** Called when the control is removed from a map */
|
|
100
|
-
onRemove() {
|
|
101
|
-
const map = this._map;
|
|
102
|
-
if (map) {
|
|
103
|
-
map.off('resize', this._updateContainerSize);
|
|
104
|
-
map.off('render', this._updateViewState);
|
|
105
|
-
map.off('mousemove', this._handleMouseEvent);
|
|
106
|
-
map.off('mouseout', this._handleMouseEvent);
|
|
107
|
-
map.off('click', this._handleMouseEvent);
|
|
108
|
-
map.off('dblclick', this._handleMouseEvent);
|
|
109
|
-
}
|
|
110
|
-
this._deck?.finalize();
|
|
111
|
-
this._deck = undefined;
|
|
112
|
-
this._map = undefined;
|
|
113
|
-
this._container = undefined;
|
|
114
|
-
}
|
|
115
|
-
getDefaultPosition() {
|
|
116
|
-
return 'top-left';
|
|
117
|
-
}
|
|
118
|
-
/** Forwards the Deck.pickObject method */
|
|
119
|
-
pickObject(params) {
|
|
120
|
-
assert(this._deck);
|
|
121
|
-
return this._deck.pickObject(params);
|
|
122
|
-
}
|
|
123
|
-
/** Forwards the Deck.pickMultipleObjects method */
|
|
124
|
-
pickMultipleObjects(params) {
|
|
125
|
-
assert(this._deck);
|
|
126
|
-
return this._deck.pickMultipleObjects(params);
|
|
127
|
-
}
|
|
128
|
-
/** Forwards the Deck.pickObjects method */
|
|
129
|
-
pickObjects(params) {
|
|
130
|
-
assert(this._deck);
|
|
131
|
-
return this._deck.pickObjects(params);
|
|
132
|
-
}
|
|
133
|
-
/** Remove from map and releases all resources */
|
|
134
|
-
finalize() {
|
|
135
|
-
if (this._map) {
|
|
136
|
-
this._map.removeControl(this);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|