Public
Edited
Apr 6, 2022
Insert cell
Insert cell
<div style="height:600px;"></div>
Insert cell
map = container.value = new mapboxgl.Map({
container,
center: [-78.476678, 38.029306], // Charlottesville downtown
zoom: 12,
style: "mapbox://styles/mapbox/streets-v11",
//scrollZoom: false
});
Insert cell
Insert cell
map.on('load', () => {
map.addSource('neighborhoods', {
'type': 'geojson',
'data': 'https://opendata.arcgis.com/datasets/c371ad0b81024822bad1147ff6bb24c4_51.geojson'
});

map.addLayer({
'id': 'neighborhoods',
'type': 'line',
'source': 'neighborhoods',
'layout': {},
'paint': {
'line-color': '#0000ff',
'line-width': 2
}
});
})
Insert cell
Insert cell
uscounties = FileAttachment("gz_2010_us_counties_00_20m.json").json()
Insert cell
map.on('load', () => {
map.addSource('uscounties', {
'type': 'geojson',
'data': uscounties
});

map.addLayer({
'id': 'uscounties',
'type': 'line',
'source': 'uscounties',
'layout': {},
'paint': {
'line-color': '#bbbbbb',
'line-width': 2
}
});
})
Insert cell
Insert cell
Insert cell
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl@2.2.0");
if (!gl.accessToken) {
// https://www.mapbox.com/help/how-access-tokens-work/
// you will need to get your own access token to put here in place of mine.
gl.accessToken = "pk.eyJ1IjoiZW1maWVsZCIsImEiOiJja25lb3hwbWEwMjRwMnBud29zcXQ4MG9nIn0.Ou1f9fNGHHcNiquxzXdz_g";
const href = await require.resolve("mapbox-gl@2.2.0/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
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