Public
Edited
Oct 24, 2023
6 stars
Insert cell
Insert cell
projection = d3.geoModifiedStereographicGs50()
Insert cell
{
const context = DOM.context2d(w, h);
const path = d3.geoPath(projection.fitSize([w,h], outline), context);
context.save();
context.beginPath(), path(outline), context.clip(), context.fillStyle = "#fff", context.fillRect(0, 0, w, h);
context.beginPath(), path(graticule), context.lineWidth = 0.5, context.strokeStyle = "#ccc", context.stroke();
context.beginPath(), path(land), context.fillStyle = "#a8a8a8", context.fill();
context.beginPath(), path(us), context.fillStyle = "#cecece", context.fill();
context.beginPath(), path(countries), context.lineWidth = 1, context.strokeStyle = "#333", context.stroke();
context.restore();
context.beginPath(), path(outline), context.strokeStyle = "#000", context.stroke();
return context.canvas;
}
Insert cell
// Outline from https://www.jasondavies.com/maps/modified-stereographic/gs50/
outline = {
return {
type: "Polygon",
coordinates: [
[[-180, 30]]
.concat(parallel(75, -180, -60))
.concat([
[-60, 70],
[-50, 70],
[-50, 40],
[-60, 40],
[-60, 30],
[-65, 30]
])
.concat(parallel(15, -65, -165))
.concat([[-165, 30], [-180, 30]])
]
};

function parallel(y, x0, x1) {
var dx = x0 < x1 ? 5 : -5;
return d3.range(x0, x1 + dx / 2, dx).map(x => [x, y]);
}
}
Insert cell
graticule = d3
.geoGraticule()
.extent([[-180, 0], [-50, 80 + 1e-6]])
.step([5, 5])()
Insert cell
w = width
Insert cell
h = (width * (710 / 960)) | 0
Insert cell
world = d3.json("https://unpkg.com/world-atlas@2.0.2/countries-50m.json")
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
countries = topojson.mesh(world, world.objects.countries)
Insert cell
us = topojson.feature(world, world.objects.countries).features.filter(d => d.id === "840")[0]
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@6", "d3-geo-projection@3")
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