Published
Edited
Oct 17, 2021
Insert cell
Insert cell
map = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
context.lineJoin = "round";
context.lineCap = "round";
context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);

context.beginPath();
path(sphere);
path(land);
context.lineWidth = 0.5;
context.stroke();
context.clip("evenodd");

context.save();
context.beginPath();
path(land);
context.filter = "blur(12px)";
context.fillStyle = "#aaa";
context.fill("evenodd");
context.restore();
context.beginPath();
path(graticule);
context.globalAlpha = 0.2;
context.strokeStyle = "#000";
context.stroke();

return context.canvas;
}
Insert cell
projection = d3.geoMercator()
.translate([width/2,height/2])
.scale(3000)
.rotate([-176,43]); // nz center
Insert cell
Insert cell
// world = d3.json("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-10m.json") // this map goes inversed
world = d3.json("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-50m.json")
// world = d3.json("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json")

Insert cell
land = topojson.feature(world, world.objects.countries.geometries[93] ) // just new zealand
// land = topojson.feature(world, world.objects.countries)
Insert cell
graticule = d3.geoGraticule10()
Insert cell
sphere = ({type: "Sphere"})
Insert cell
height = 1000
Insert cell
Insert cell
d3 = require('d3')
Insert cell
Insert cell
topojson = require("topojson-client")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more