examples/website/screen-grid/app.js (72 lines of code) (raw):
import React from 'react';
import {render} from 'react-dom';
import {StaticMap} from 'react-map-gl';
import DeckGL from '@deck.gl/react';
import {ScreenGridLayer} from '@deck.gl/aggregation-layers';
import {isWebGL2} from '@luma.gl/core';
// Set your mapbox token here
const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-line
// Source data CSV
const DATA_URL =
'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/screen-grid/uber-pickup-locations.json'; // eslint-disable-line
const INITIAL_VIEW_STATE = {
longitude: -73.75,
latitude: 40.73,
zoom: 9.6,
maxZoom: 16,
pitch: 0,
bearing: 0
};
const colorRange = [
[255, 255, 178, 25],
[254, 217, 118, 85],
[254, 178, 76, 127],
[253, 141, 60, 170],
[240, 59, 32, 212],
[189, 0, 38, 255]
];
export default function App({
data = DATA_URL,
cellSize = 20,
gpuAggregation = true,
aggregation = 'SUM',
disableGPUAggregation,
mapStyle = 'mapbox://styles/mapbox/dark-v9'
}) {
const layers = [
new ScreenGridLayer({
id: 'grid',
data,
opacity: 0.8,
getPosition: d => [d[0], d[1]],
getWeight: d => d[2],
cellSizePixels: cellSize,
colorRange,
gpuAggregation,
aggregation
})
];
const onInitialized = gl => {
if (!isWebGL2(gl)) {
console.warn('GPU aggregation is not supported'); // eslint-disable-line
if (disableGPUAggregation) {
disableGPUAggregation();
}
}
};
return (
<DeckGL
layers={layers}
initialViewState={INITIAL_VIEW_STATE}
onWebGLInitialized={onInitialized}
controller={true}
>
<StaticMap
reuseMaps
mapStyle={mapStyle}
preventStyleDiffing={true}
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
</DeckGL>
);
}
export function renderToDOM(container) {
render(<App />, container);
}