Published
Edited
May 17, 2018
1 fork
Insert cell
Insert cell
world = d3.json("https://unpkg.com/world-atlas@1/world/110m.json")
Insert cell
Insert cell
landTopo = topojson.feature(world, world.objects.land)
Insert cell
countryTopos = topojson.feature(world, world.objects.countries).features
Insert cell
function countryTopoById(id) {
return countryTopos.filter(c => c.id == id)[0];
}
Insert cell
botswanaTopo = countryTopoById(72)
Insert cell
countryBordersTopo = topojson.mesh(world, world.objects.countries)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
projection = d3.geoNaturalEarth1()
.fitExtent([
[mapPad, mapPad], // top left
[mapWidth - mapPad, mapHeight - mapPad] // bottom right
],
{type: "Sphere"}) // shape to fit
.precision(0.1) // controls the smoothness of curves
Insert cell
path = d3.geoPath(projection)
Insert cell
svg`
<svg width=${mapWidth} height=${mapHeight}>
<path d="${path({type: "Sphere"})}" fill="none" stroke="#000"></path>
<path d="${path(landTopo)}" fill="rgba(0,200,50,0.6)"></path>
<path d="${path(countryBordersTopo)}" fill="none" stroke="#fff" stroke-width="0.5px"></path>
<path d="${path(botswanaTopo)}" fill="rgba(0,123,230,0.5)"></path>
</svg>
`
Insert cell
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