function featureFill(geoJson, res, expandOutward = false) {
let polygons;
if (geoJson.geometry.type === "Polygon") {
polygons = [geoJson.geometry.coordinates];
} else if (geoJson.geometry.type === "MultiPolygon") {
polygons = geoJson.geometry.coordinates;
} else {
throw new Error("Unable to fill geoJSON of type " + geoJson.type)
}
return [...new Set(polygons.map(polygon =>
[... new Set(h3.polyfill(polygon, res, true)
.flatMap(h3Index => {
if (expandOutward) {
return h3.kRing(h3Index, 1);
} else {
return [h3Index];
}
}))]
.filter(h3Index => {
if (expandOutward) {
const h3AsGeoJson = {
type: "Feature",
geometry: { type: "Polygon", coordinates: [h3.h3ToGeoBoundary(h3Index, true)] } };
const polygonAsSingleFeature = {
type: "Feature",
geometry: { type: "Polygon", coordinates: polygon } };
console.log(polygonAsSingleFeature)
return intersects(polygonAsSingleFeature, h3AsGeoJson)
}
return true;
})).flat())];
}