-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathdeck-only-component.tsx
More file actions
80 lines (73 loc) · 2.33 KB
/
Copy pathdeck-only-component.tsx
File metadata and controls
80 lines (73 loc) · 2.33 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
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import React, {useMemo, useCallback} from 'react';
import DeckGL from '@deck.gl/react';
import {MapView, _GlobeView as GlobeView} from '@deck.gl/core';
import type {Config} from '../../types';
import {getBaseMapViewState} from '../../config';
type DeckOnlyComponentProps = {
config: Config;
};
export default function DeckOnlyComponent({config}: DeckOnlyComponentProps) {
const {
initialViewState,
layers,
multiView,
views,
layerFilter,
globe,
useDevicePixels,
onViewStateChange
} = config;
const handleViewStateChange = useCallback(
({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
});
}
},
[onViewStateChange]
);
// For multi-view, use the mapbox view state as the main view
const viewState = getBaseMapViewState(initialViewState);
// Compute effective views based on globe and multiView settings
const effectiveViews = useMemo(() => {
if (globe) {
const globeView = new GlobeView({id: 'globe'});
if (multiView && views) {
// Combine GlobeView with other views
return [globeView, ...views];
}
return globeView;
}
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});
return [mainView, ...views];
}
return undefined;
}, [globe, multiView, views]);
return (
<div style={{width: '100%', height: '100%', position: 'relative', background: '#1a1a2e'}}>
<DeckGL
width="100%"
height="100%"
initialViewState={multiView ? initialViewState : viewState}
controller={true}
layers={layers}
views={effectiveViews}
useDevicePixels={useDevicePixels}
layerFilter={multiView ? layerFilter : undefined}
onViewStateChange={handleViewStateChange}
/>
</div>
);
}