Public
Edited
Oct 24, 2023
8 forks
Importers
52 stars
Insert cell
Insert cell
chart = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);

function render(land) {
context.clearRect(0, 0, width, height);
context.beginPath(), path(sphere), context.fillStyle = "#fff", context.fill();
const r = projection.rotate();
projection.reflectX(true).rotate([r[0] + 180, -r[1], -r[2]]);
context.beginPath(), path(land), context.fillStyle = "rgba(0,0,0,0.1)", context.fill();
projection.reflectX(false).rotate(r);
context.beginPath(), path(land), context.fillStyle = "#000", context.fill();
context.beginPath(), path(sphere), context.stroke();
}

return d3.select(context.canvas)
.call(zoom(projection)
.on("zoom.render", () => render(land110))
.on("end.render", () => render(land50)))
.call(() => render(land50))
.node();
}
Insert cell
projection = d3.geoOrthographic()
.rotate([160, 0])
.precision(0.1)
.fitSize([width, height], sphere)
Insert cell
height = Math.floor(width * 0.6)
Insert cell
sphere = ({type: "Sphere"})
Insert cell
land50 = FileAttachment("land-50m.json").json().then(world => topojson.feature(world, world.objects.land))
Insert cell
land110 = FileAttachment("land-110m.json").json().then(world => topojson.feature(world, world.objects.land))
Insert cell
import {zoom} from "@d3/versor-zooming@322"
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