-
Notifications
You must be signed in to change notification settings - Fork 165
/
example.js
107 lines (99 loc) · 2.87 KB
/
example.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* eslint-env browser */
import * as React from 'react';
import DeckGL from '@deck.gl/react';
import { EditableGeoJsonLayer } from '@nebula.gl/layers';
import { Toolbox, OverlappingSelection } from '@nebula.gl/editor';
import { SelectMode } from '@nebula.gl/edit-modes';
import { StaticMap } from 'react-map-gl';
const MAPBOX_ACCESS_TOKEN =
'pk.eyJ1IjoiZ2Vvcmdpb3MtdWJlciIsImEiOiJjanZidTZzczAwajMxNGVwOGZrd2E5NG90In0.gdsRu_UeU_uPi9IulBruXA';
const initialViewState = {
longitude: -122.43,
latitude: 37.775,
zoom: 12,
};
export function Example() {
const [geoJson, setGeoJson] = React.useState({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
name: 'My feature 1',
},
geometry: {
type: 'Polygon',
coordinates: [
[
[-122.46212548792364, 37.79026033616934],
[-122.48435831844807, 37.77160302698496],
[-122.45884849905971, 37.74414218845571],
[-122.42863676726826, 37.76266965836386],
[-122.46212548792364, 37.79026033616934],
],
],
},
},
{
type: 'Feature',
properties: {
name: 'My feature 2',
},
geometry: {
type: 'Polygon',
coordinates: [
[
[-122.4136573004723, 37.78826678755718],
[-122.44875601708893, 37.782670574261324],
[-122.43793598592286, 37.74322062447909],
[-122.40836932539945, 37.75125290412125],
[-122.4136573004723, 37.78826678755718],
],
],
},
},
],
});
const [selection, setSelection] = React.useState({ selectedIndexes: [0] });
const [mode, setMode] = React.useState(() => SelectMode);
const [modeConfig, setModeConfig] = React.useState({});
const layer = new EditableGeoJsonLayer({
data: geoJson,
mode,
modeConfig,
selectedFeatureIndexes: selection.selectedIndexes,
onEdit: ({ updatedData }) => {
setGeoJson(updatedData);
},
onSelectionChanged: setSelection,
});
return (
<>
<DeckGL
initialViewState={initialViewState}
controller={{
doubleClickZoom: false,
}}
layers={[layer]}
getCursor={layer.getCursor.bind(layer)}
>
<StaticMap mapboxApiAccessToken={MAPBOX_ACCESS_TOKEN} />
</DeckGL>
<Toolbox
geoJson={geoJson}
mode={mode}
modeConfig={modeConfig}
onSetMode={setMode}
onSetModeConfig={setModeConfig}
onImport={(imported) =>
setGeoJson({
...geoJson,
features: [...geoJson.features, ...imported.features],
})
}
onSetGeoJson={setGeoJson}
/>
<OverlappingSelection data={geoJson} selection={selection} onSetSelection={setSelection} />
</>
);
}