Public
Edited
Apr 3, 2022
1 fork
Insert cell
Insert cell
<svg width="1000" height="500">
<g id="countries"></g>
<g id="usstates"></g>
<g id="cville_neighborhoods"></g>
</svg>
Insert cell
map = d3.select(mapContainer)
Insert cell
import {getMapData, drawMapLayer} from "@emfielduva/dvlib_maps"
Insert cell
world = getMapData("world110m")
Insert cell
usstates = FileAttachment("gz_2010_us_states_00_20m.json").json()
Insert cell
cville_neighborhoods = getMapData("https://opendata.arcgis.com/datasets/c371ad0b81024822bad1147ff6bb24c4_51.geojson")
Insert cell
mapLayers = {
let mapLayers = [];
mapLayers["countries"] = drawMapLayer(map,"countries",world.features,world.idField);
mapLayers["usstates"] = drawMapLayer(map,"usstates",usstates.features,"properties.NAME");
mapLayers["cville_neighborhoods"] = drawMapLayer(map,"cville_neighborhoods",cville_neighborhoods.features,"properties.NAME");

mapLayers["countries"].on("click", zoomToBounds); // this is added here to enable zooming to a clicked feature element.
mapLayers["usstates"].on("click", zoomToBounds);

return mapLayers;
}
Insert cell
<style>
#countries path {fill: #eeeeee; stroke: #ccc}
#usstates path {fill: #bbb; stroke: #aaa; opacity: 0.5;}
#cville_neighborhoods {fill: none; stroke: #333}
</style>
Insert cell
Insert cell
Insert cell
Insert cell
import {zoomed, zoomToBounds} with {map} from "@emfielduva/dvlib_maps"
Insert cell
Insert cell
map.call(d3.zoom()
.scaleExtent([1,1000]) //how far to be able zoom out,in
.on("zoom", zoomed));
Insert cell
Insert cell
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