-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
app.jsx
80 lines (76 loc) · 2.01 KB
/
app.jsx
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
/* global fetch */
import React, {useState, useMemo} from 'react';
import {createRoot} from 'react-dom/client';
import DeckGL from '@deck.gl/react';
import {COORDINATE_SYSTEM, OrthographicView} from '@deck.gl/core';
import {SolidPolygonLayer} from '@deck.gl/layers';
import {MaskExtension} from '@deck.gl/extensions';
/* eslint-disable react/no-deprecated */
export default function App() {
const [maskEnabled, setMaskEnabled] = useState(true);
const [showLayers, setShowLayers] = useState(true);
const layers = [
new SolidPolygonLayer({
id: 'mask',
operation: 'mask',
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
data: [
[
[-20, -200],
[-20, 200],
[20, 200],
[20, -200]
]
],
getPolygon: f => f,
getFillColor: [0, 255, 0]
}),
new SolidPolygonLayer({
id: 'square',
extensions: [new MaskExtension()],
maskId: maskEnabled && 'mask',
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
data: [
[
[-100, -100],
[-100, 100],
[100, 100],
[100, -100]
]
],
getPolygon: f => f,
getFillColor: [255, 0, 0]
})
];
const views = new OrthographicView();
const viewState = {
target: [0, 0, 0],
zoom: 0
};
return (
<>
<DeckGL
layers={showLayers ? layers : []}
initialViewState={viewState}
views={views}
controller={true}
></DeckGL>
<div style={{position: 'absolute', background: 'white', padding: 10}}>
<label>
<input
type="checkbox"
checked={maskEnabled}
onChange={() => setMaskEnabled(!maskEnabled)}
/>
Use mask
</label>
<label>
<input type="checkbox" checked={showLayers} onChange={() => setShowLayers(!showLayers)} />
Show layers
</label>
</div>
</>
);
}
const container = document.getElementById('app');
createRoot(container).render(<App />);