Public
Edited
May 29, 2024
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
deck = require('deck.gl@6.2.3/deckgl.min.js')
Insert cell
mapboxgl = require('mapbox-gl@~0.50.0/dist/mapbox-gl.js')
Insert cell
d3 = require('d3')
Insert cell
nycRoadAccidents = d3.csv('https://raw.githubusercontent.com/nharrisanalyst/deckgl_sacjs/master/NYPD_Motor_crashes.csv', d=>({
lat: +d.LATITUDE,
long: +d.LONGITUDE,
}))
Insert cell
deckgl = {
const container = html`<div style="height:500px;">`;
yield container;
new deck.DeckGL({
// The HTML container to render into
container,

// Mapbox settings
// set `map: false` to turn off Mapbox base map
map: mapboxgl,
// This token is for demo-purpose only and rotated regularly. Get your token at https://www.mapbox.com
mapboxApiAccessToken: 'pk.eyJ1IjoidWJlcmRhdGEiLCJhIjoiY2pudzRtaWloMDAzcTN2bzN1aXdxZHB5bSJ9.2bkj3IiRC8wj3jLThvDGdA',
mapStyle: 'mapbox://styles/mapbox/dark-v9',

// Viewport settings
longitude: -73.9712,
latitude: 40.7831,
zoom: 11,
pitch: 30,
bearing: -30,
layers: [hexegonLayer()]
});
}
Insert cell
scatterPlot = () => new deck.ScatterplotLayer({
data:nycRoadAccidents,
getColor:[255, 0, 0],
getPosition: d => [d.long,d.lat],
radiusScale:10,
})
Insert cell
hexegonLayer = () => new deck.HexagonLayer({
data:nycRoadAccidents,
upperPercentile:99,
pickable: true,
extruded: true,
radius: 200,
elevationScale: 4,
getPosition: d => [d.long,d.lat],
onHover: ({object, x, y}) => {
const tooltip = `${object.centroid.join(', ')}\nCount: ${object.points.length}`;
},

})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more