map = (projection) => {
const height = width / 2;
const svg = d3.select(DOM.svg(width, height));
var path = d3.geoPath(projection, svg);
let geoGenerator = d3.geoPath().projection(projection);
var angle = projection.angle();
projection.fitExtent(
[
[2, 2],
[width - 2, height - 2]
],
{ type: "Sphere" }
);
let u = svg
.append("g")
.selectAll("path")
.data(countries.features)
.join("path")
.attr("d", geoGenerator)
.attr("fill", "#dedede")
.attr("stroke", "#eeeeee");
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) => {
svg
.append("g")
.selectAll("path")
.data(fold)
.enter()
.append("path")
.attr("d", path)
.attr("stroke", "#cc0000")
.attr("stroke-width", "2px");
});
projection.rotate(rotate);
projection.angle(angle);
return svg.node();
}