map = (projection) => {
const height = width/2
const context = DOM.context2d(width, height);
var path = d3.geoPath(projection, context);
var angle = projection.angle();
projection.fitExtent([[2,2],[width-2, height-2]], {type:"Sphere"});
context.clearRect(0,0,width, width/2);
countries.features.forEach((c, i) => {
context.beginPath();
path(c);
context.fillStyle = colors[i % colors.length];
context.fill();
context.strokeStyle = "#FFF",
context.stroke();
});
context.beginPath(),
path({type: "Sphere"});
context.lineWidth = 0.5;
context.setLineDash([3,4]);
context.strokeStyle = "#888";
context.stroke();
var rotate = projection.rotate();
projection.rotate([0,0,0]);
var sites = [], folds = [], i = 0;
function recurse(face) {
var site = d3.geoCentroid({type:"MultiPoint", coordinates:face.face});
site.id = face.id || i++;
sites.push(site);
if (face.children) {
face.children.forEach(function(child) {
folds.push({
type:"LineString",
coordinates: child.shared.map(
e => d3.geoInterpolate(e, face.centroid)(1e-5)
)
});
recurse(child);
});
}
}
recurse(projection.tree());
folds.forEach(fold => {
context.beginPath();
context.lineWidth = 0.5;
context.setLineDash([3,4]);
context.strokeStyle = "#888";
path(fold);
context.stroke();
context.setLineDash([]);
});
projection.rotate(rotate);
projection.angle(angle);
return context.canvas;
};