-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathdeck-only.ts
More file actions
81 lines (71 loc) · 2.28 KB
/
Copy pathdeck-only.ts
File metadata and controls
81 lines (71 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import {Deck, MapView, _GlobeView as GlobeView} from '@deck.gl/core';
import type {Config} from '../../types';
import {getBaseMapViewState} from '../../config';
export function mount(container: HTMLElement, config: Config): () => void {
const {
initialViewState,
layers,
multiView,
views,
layerFilter,
globe,
useDevicePixels,
onViewStateChange
} = config;
// Create a wrapper div for Deck to render into
const wrapper = document.createElement('div');
wrapper.style.cssText = 'width: 100%; height: 100%; position: relative; background: #1a1a2e;';
container.appendChild(wrapper);
// For multi-view, use the mapbox view state as the main view
const viewState = getBaseMapViewState(initialViewState);
const deckConfig: any = {
parent: wrapper,
width: '100%',
height: '100%',
initialViewState: viewState,
controller: true,
layers,
useDevicePixels
};
// Use GlobeView for globe projection
if (globe) {
const globeView = new GlobeView({id: 'globe'});
if (multiView && views) {
// Combine GlobeView with other views
deckConfig.views = [globeView, ...views];
deckConfig.initialViewState = initialViewState;
} else {
deckConfig.views = globeView;
}
} else if (multiView && views) {
// For deck-only multi-view, add a main MapView since there's no basemap
// Use 'mapbox' as ID to match the view state key in MultiViewState
const mainView = new MapView({id: 'mapbox', controller: true});
deckConfig.views = [mainView, ...views];
deckConfig.initialViewState = initialViewState;
}
if (multiView && layerFilter) {
deckConfig.layerFilter = layerFilter;
}
if (onViewStateChange) {
deckConfig.onViewStateChange = ({viewState: vs}: {viewState: any}) => {
// Only report view state if it has lat/lng (skip ortho view state changes)
if (vs.latitude !== undefined && vs.longitude !== undefined) {
onViewStateChange({
latitude: vs.latitude,
longitude: vs.longitude,
zoom: vs.zoom,
bearing: vs.bearing,
pitch: vs.pitch
});
}
};
}
const deck = new Deck(deckConfig);
return () => {
deck.finalize();
};
}