canvas2 = {
const context = DOM.context2d(width, height);
var UKcoords = d3.geoCentroid(EEZshapes.features[0])
var projection = d3.geoOrthographic()
.rotate([-UKcoords[0], -UKcoords[1]])
.scale(400)
.translate([width/2, height/2])
.clipAngle(15)
.precision(10);
const path = d3.geoPath(projection, context);
function render(focalEEZ) {
context.clearRect(0, 0, width, height);
context.beginPath(), path(land), context.fillStyle = "#ccc", context.fill();
for (const EEZ of EEZshapes.features) {
if (EEZ.properties.SOVEREIGN1 === focalEEZ) {
context.beginPath(), path(EEZ),context.fillStyle = "red",context.fill();
}
}
context.beginPath(), path(sphere), context.strokeStyle = "#000", context.lineWidth = 1.5, context.stroke();
return context.canvas;
}
let p;
for (const EEZ of EEZshapes.features) {
let name = EEZ.properties.SOVEREIGN1;
yield render(name);
p = d3.geoCentroid(EEZ);
const ip = d3.interpolate(projection.rotate(), [-p[0], -p[1]])
await d3.transition()
.duration(2000)
.tween("render", () => t => {
projection.rotate(ip(t));
render(name);
})
.end();
}
}