d3-geo-polygon
d3-geo-polygon copied to clipboard
Use clipPolygon for geoInterrupted
example code that works (at least in one test case):
var c = projection.lobes().map(d => d3.merge(d.map(q => {
var centroid = d3.geoCentroid({type:"MultiPoint", coordinates:q});
return q.map(p => d3.geoInterpolate(p,centroid)(1e-7)); // pull inside each lobe
})));
c = d3.merge([c[0], c[1].reverse()]); // north, south
projection.preclip(d3.geoClipPolygon({ type: "Polygon", coordinates: [c] }));
the projection was defined by:
var lobes = [
[
[[-180, 0], [-130, 90], [-95, 0]],
[[-95, 0], [-30, 90], [55, 0]],
[[55, 0], [120, 90], [180, 0]]
],
[
[[-180, 0], [-120, -90], [-60, 0]],
[[-60, 0], [20, -90], [85, 0]],
[[85, 0], [140, -90], [180, 0]]
]
];
projection = d3.geoInterrupt(d3.geoHomolosineRaw, lobes).rotate([-204, 0])
.fitExtent([[10, 10], [width-10, height-10]], {type: "Sphere"});
Solved in https://beta.observablehq.com/d/71ce78c6ae5001fa for all "interrupted" projections of d3-geo-projection, including HEALPix.
Have to think about how to integrate this — I'd rather not duplicate all the code from geo-projection, but for users I want it to be as simple as adding d3-geo-polygon to their sources (like we have for the polyhedral projections).