-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
98 lines (84 loc) · 2.25 KB
/
app.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
/* global window */
import React, {useState, useEffect} from 'react';
import {render} from 'react-dom';
import {StaticMap} from 'react-map-gl';
import {AmbientLight, PointLight, LightingEffect} from '@deck.gl/core';
import DeckGL from '@deck.gl/react';
import {TripsLayer} from '@deck.gl/geo-layers';
// Source data CSV
const DATA_URL = {
TRIPS: './bin/data_processed.json'
};
const ambientLight = new AmbientLight({
color: [255, 255, 255],
intensity: 1.0
});
const pointLight = new PointLight({
color: [255, 255, 255],
intensity: 2.0,
position: [-74.05, 40.7, 8000]
});
const lightingEffect = new LightingEffect({ambientLight, pointLight});
const DEFAULT_THEME = {
effects: [lightingEffect]
};
const INITIAL_VIEW_STATE = {
longitude: 114.027465,
latitude: 22.632468,
zoom: 10,
pitch: 40,
bearing: -10
};
const MAP_STYLE = 'https://basemaps.cartocdn.com/gl/dark-matter-nolabels-gl-style/style.json';
export default function App({
trips = DATA_URL.TRIPS,
trailLength = 150,
initialViewState = INITIAL_VIEW_STATE,
mapStyle = MAP_STYLE,
theme = DEFAULT_THEME,
loopLength = 3600*5, // unit corresponds to the timestamp in source data
animationSpeed = 1.5
}) {
const [time, setTime] = useState(0);
const [animation] = useState({});
const animate = () => {
setTime(t => (t + animationSpeed) % loopLength);
animation.id = window.requestAnimationFrame(animate);
};
useEffect(
() => {
animation.id = window.requestAnimationFrame(animate);
return () => window.cancelAnimationFrame(animation.id);
},
[animation]
);
const layers = [
// This is only needed when using shadow effects
new TripsLayer({
id: 'trips',
data: trips,
getPath: d => d.path,
getTimestamps: d => d.timestamps,
getColor: d => d.color,
opacity: 0.8,
widthMinPixels: 2,
rounded: true,
trailLength,
currentTime: time+3600*6,
shadowEnabled: false
})
];
return (
<DeckGL
layers={layers}
effects={theme.effects}
initialViewState={initialViewState}
controller={true}
>
<StaticMap reuseMaps mapStyle={mapStyle} preventStyleDiffing={true} />
</DeckGL>
);
}
export function renderToDOM(container) {
render(<App />, container);
}