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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more