Published
Edited
Jan 24, 2021
Insert cell
Insert cell
Insert cell
container = html `<div style="height:500px"></div>`
Insert cell
deckgl = {
// In the event this cell is re-run, clear previously generated content.
invalidation.then(() => container.innerHTML = '');

return new deck.DeckGL({
container: container,

// Mapbox settings
// set `map: false` to turn off Mapbox base map
map: mapboxgl,
mapStyle: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json',

// Viewport settings
initialViewState: {
longitude: -122.4,
latitude: 37.78,
zoom: 11,
pitch: 30,
bearing: 0
},
controller: true
});
}
Insert cell
colorScale = {
// Convert from height to RGB values
const linearScale = d3.scaleLinear().domain([0, 500]).range([1, 0]);
return height => {
const color = d3.color(d3.interpolateRdYlGn(linearScale(height)));
return [color.r, color.g, color.b];
}
}
Insert cell
layer = {
const layer = new deck.GeoJsonLayer({
// This is an Observable hack - changing the id will force the layer to refresh when the cell reevaluates
id: `geojson-${Date.now()}`,
data: sfBuildings,
extruded: true,
getFillColor: f => colorScale(f.properties.gen_hght * 1),
getElevation: f => f.properties.gen_hght < 2000 ? f.properties.gen_hght * 1 : 0,
pickable: true,
onClick: evt => info.innerHTML = evt.object.properties.gen_hght
});
deckgl.setProps({layers: [layer]});
return layer;
}
Insert cell
Insert cell
Insert cell
Insert cell
deck = require.alias({
h3: {},
s2Geometry: {}
})('deck.gl@^8.0.0/dist.min.js')
Insert cell
Insert cell
mapboxgl = require('mapbox-gl@1.13.0/dist/mapbox-gl.js')
Insert cell
Insert cell
d3 = require("https://d3js.org/d3.v5.min.js")
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