@deck.gl/mapbox 8.8.0-beta.1 → 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.
- package/dist/dist.dev.js +155 -13
- package/dist/es5/deck-utils.js +1 -0
- package/dist/es5/deck-utils.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mapbox-overlay.js +55 -11
- package/dist/es5/mapbox-overlay.js.map +1 -1
- package/dist/es5/resolve-layers.js +134 -0
- package/dist/es5/resolve-layers.js.map +1 -0
- package/dist/esm/deck-utils.js +1 -0
- package/dist/esm/deck-utils.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mapbox-overlay.js +49 -12
- package/dist/esm/mapbox-overlay.js.map +1 -1
- package/dist/esm/resolve-layers.js +73 -0
- package/dist/esm/resolve-layers.js.map +1 -0
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/deck-utils.ts +10 -1
- package/src/index.ts +2 -0
- package/src/mapbox-overlay.ts +69 -14
- package/src/resolve-layers.ts +89 -0
- package/typed/deck-utils.d.ts +6 -0
- package/typed/deck-utils.d.ts.map +1 -1
- package/typed/index.d.ts +1 -0
- package/typed/index.d.ts.map +1 -1
- package/typed/mapbox-overlay.d.ts +11 -2
- package/typed/mapbox-overlay.d.ts.map +1 -1
- package/typed/resolve-layers.d.ts +5 -0
- package/typed/resolve-layers.d.ts.map +1 -0
|
@@ -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
|
+
}
|
package/typed/deck-utils.d.ts
CHANGED
|
@@ -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,IAAI,CAmB7E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,GAAG;
|
|
1
|
+
{"version":3,"file":"deck-utils.d.ts","sourceRoot":"","sources":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
|
@@ -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"}
|
|
@@ -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
|
-
|
|
14
|
+
private _interleaved;
|
|
15
|
+
constructor(props: MapboxOverlayProps & {
|
|
16
|
+
interleaved?: boolean;
|
|
17
|
+
});
|
|
14
18
|
/** Update (partial) props of the underlying Deck instance. */
|
|
15
|
-
setProps(props:
|
|
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;
|
|
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;AAI7C,oBAAY,kBAAkB,GAAG,IAAI,CACnC,SAAS,EACP,OAAO,GACP,QAAQ,GACR,IAAI,GACJ,QAAQ,GACR,QAAQ,GACR,eAA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AAO,CAAC,gBAAgB,CAQtB;IAEF,OAAO,CAAC,iBAAiB,CA4CvB;CACH"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Deck, LayersList } from '@deck.gl/core/typed';
|
|
2
|
+
import type { Map } from 'mapbox-gl';
|
|
3
|
+
/** Insert Deck layers into the mapbox Map according to the user-defined order */
|
|
4
|
+
export declare function resolveLayers(map?: Map, deck?: Deck, oldLayers?: LayersList, newLayers?: LayersList): void;
|
|
5
|
+
//# sourceMappingURL=resolve-layers.d.ts.map
|
|
@@ -0,0 +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;AACjF,wBAAgB,aAAa,CAC3B,GAAG,CAAC,EAAE,GAAG,EACT,IAAI,CAAC,EAAE,IAAI,EACX,SAAS,CAAC,EAAE,UAAU,EACtB,SAAS,CAAC,EAAE,UAAU,QA2EvB"}
|