function poi(g, projection = d3.geoIdentity().reflectY(true), alpha = 2) {
const polygons = [];
const holes = [];
let ring;
const context = {
arc(x, y) {},
moveTo(x, y) {
ring = [[x, -alpha * y]];
},
lineTo(x, y) {
ring.push([x, -alpha * y]);
},
closePath() {
ring.push(ring[0]);
if (d3.polygonArea(ring) > 0) polygons.push([ring]);
else holes.push(ring);
}
};
d3.geoPath(projection, context)(g);
for (const h of holes)
polygons.find(([ring]) => d3.polygonContains(ring, h[0]))?.push(h);
const a = d3.greatest(
polygons.map((d) => polylabel(d, 0.01)),
(d) => d.distance
);
if (a) {
[a[0], a[1]] = projection.invert([a[0], -a[1] / alpha]);
return a;
}
return d3.geoPath(projection).centroid(g);
}