Published
Edited
Aug 31, 2019
3 forks
14 stars
Insert cell
Insert cell
map = {
const context = DOM.context2d(width, height);
const path = d3.geoPath(projection, context);
context.beginPath(), path(graticule), context.strokeStyle = "#ccc", context.stroke();
context.beginPath(), path(land), context.fillStyle = "#000", context.fill();
context.beginPath(), path({type: "Point", coordinates: sun}), context.fillStyle = "#f00", context.fill();
context.beginPath(), path(sphere), context.strokeStyle = "#000", context.stroke();
return context.canvas;
}
Insert cell
height = width
Insert cell
projection = d3.geoOrthographic()
.rotate([-sun[0], -sun[1]])
.fitExtent([[1, 1], [width - 1, height - 1]], sphere)
.precision(0.1)
Insert cell
sun = {
const now = new Date;
const day = new Date(+now).setUTCHours(0, 0, 0, 0);
const t = solar.century(now);
const x = (day - now) / 864e5 * 360 - 180 - solar.equationOfTime(t) / 4;
const y = solar.declination(t);
return [x % 360, y];
}
Insert cell
sphere = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
world = fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/land-50m.json").then(response => response.json())
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3-geo@1")
Insert cell
solar = require("solar-calculator@0.3/dist/solar-calculator.min.js")
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