@deck.gl/mapbox 8.9.0-alpha.5 → 8.9.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/dist.dev.js +1131 -6108
- package/dist/es5/deck-utils.js +26 -16
- package/dist/es5/deck-utils.js.map +1 -1
- package/dist/es5/mapbox-overlay.js +8 -4
- package/dist/es5/mapbox-overlay.js.map +1 -1
- package/dist/es5/resolve-layers.js.map +1 -1
- package/dist/esm/deck-utils.js +23 -16
- package/dist/esm/deck-utils.js.map +1 -1
- package/dist/esm/mapbox-overlay.js +8 -4
- package/dist/esm/mapbox-overlay.js.map +1 -1
- package/dist/esm/resolve-layers.js.map +1 -1
- package/dist.min.js +4 -1
- package/package.json +4 -4
- package/src/deck-utils.ts +29 -15
- package/src/mapbox-overlay.ts +14 -11
- package/src/resolve-layers.ts +1 -0
- package/typed/deck-utils.d.ts +2 -1
- package/typed/deck-utils.d.ts.map +1 -1
- package/typed/deck-utils.js +185 -0
- package/typed/index.js +2 -0
- package/typed/mapbox-layer.js +37 -0
- package/typed/mapbox-overlay.d.ts +4 -4
- package/typed/mapbox-overlay.d.ts.map +1 -1
- package/typed/mapbox-overlay.js +139 -0
- package/typed/resolve-layers.d.ts.map +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-layers.d.ts","sourceRoot":"","sources":["../src/resolve-layers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAE,UAAU,EAAQ,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AAInC,iFAAiF;
|
|
1
|
+
{"version":3,"file":"resolve-layers.d.ts","sourceRoot":"","sources":["../src/resolve-layers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAE,UAAU,EAAQ,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AAInC,iFAAiF;AAEjF,wBAAgB,aAAa,CAC3B,GAAG,CAAC,EAAE,GAAG,EACT,IAAI,CAAC,EAAE,IAAI,EACX,SAAS,CAAC,EAAE,UAAU,EACtB,SAAS,CAAC,EAAE,UAAU,QA+EvB"}
|