-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.jsx
104 lines (90 loc) · 2.26 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* global window */
import React, { useState, useEffect } from "react";
import { Map } from "react-map-gl";
import maplibregl from 'maplibre-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:
"/routes.json", // eslint-disable-line
};
const ambientLight = new AmbientLight({
color: [255, 255, 255],
intensity: 1.0,
});
const pointLight = new PointLight({
color: [255, 255, 255],
intensity: 2.0,
position: [174.76, -36.8, 8000],
});
const lightingEffect = new LightingEffect({ ambientLight, pointLight });
const material = {
ambient: 0.1,
diffuse: 0.6,
shininess: 32,
specularColor: [60, 64, 70],
};
const DEFAULT_THEME = {
material,
effects: [lightingEffect],
};
const INITIAL_VIEW_STATE = {
longitude: 174.76485,
latitude: -36.86103,
zoom: 14,
pitch: 45,
bearing: 0,
};
const MAP_STYLE =
"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json";
export default function App({
trips = DATA_URL.TRIPS,
trailLength = 500,
initialViewState = INITIAL_VIEW_STATE,
mapStyle = MAP_STYLE,
theme = DEFAULT_THEME,
loopLength = 231800, // unit corresponds to the timestamp in source data
animationSpeed = 15,
}) {
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 = [
new TripsLayer({
id: "trips",
data: trips,
getPath: (d) => d.path,
getTimestamps: (d) => d.timestamps,
getColor: [253, 128, 93],
opacity: 0.4,
widthMinPixels: 2,
rounded: true,
trailLength,
currentTime: time,
}),
];
return (
<DeckGL
layers={layers}
effects={theme.effects}
initialViewState={initialViewState}
controller={true}
>
<Map
reuseMaps
mapLib={maplibregl}
mapStyle={mapStyle}
preventStyleDiffing={true}
/>
</DeckGL>
);
}