in examples/website/trips/app.js [58:135]
export default function App({
buildings = DATA_URL.BUILDINGS,
trips = DATA_URL.TRIPS,
trailLength = 180,
initialViewState = INITIAL_VIEW_STATE,
mapStyle = 'mapbox://styles/mapbox/dark-v9',
theme = DEFAULT_THEME,
loopLength = 1800, // unit corresponds to the timestamp in source data
animationSpeed = 1
}) {
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 PolygonLayer({
id: 'ground',
data: landCover,
getPolygon: f => f,
stroked: false,
getFillColor: [0, 0, 0, 0]
}),
new TripsLayer({
id: 'trips',
data: trips,
getPath: d => d.path,
getTimestamps: d => d.timestamps,
getColor: d => (d.vendor === 0 ? theme.trailColor0 : theme.trailColor1),
opacity: 0.3,
widthMinPixels: 2,
rounded: true,
trailLength,
currentTime: time,
shadowEnabled: false
}),
new PolygonLayer({
id: 'buildings',
data: buildings,
extruded: true,
wireframe: false,
opacity: 0.5,
getPolygon: f => f.polygon,
getElevation: f => f.height,
getFillColor: theme.buildingColor,
material: theme.material
})
];
return (
<DeckGL
layers={layers}
effects={theme.effects}
initialViewState={initialViewState}
controller={true}
>
<StaticMap
reuseMaps
mapStyle={mapStyle}
preventStyleDiffing={true}
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
</DeckGL>
);
}