function getTestPolygon2(parent) {
const positions = [
[
[
[48, 44, 16, 17, 24, 22, 8, 12, 40, 39, 32, 34],
[46, 48, 20, 16, 23, 24, 10, 8, 36, 40, 33, 32]
],
[
[2400, 2200, 800, 850, 1200, 1100, 400, 600, 2000, 1950, 1600, 1700],
[2300, 2400, 1000, 800, 1150, 1200, 500, 400, 1800, 2000, 1650, 1600]
]
],
[
[
[40, 36, 8, 9, 16, 14, 32, 31, 24, 26],
[38, 40, 12, 8, 15, 16, 28, 32, 25, 24]
],
[
[2000, 1800, 400, 450, 800, 700, 1600, 1550, 1200, 1300],
[1900, 2000, 600, 400, 750, 800, 1400, 1600, 1250, 1200]
]
]
];
const earthRadiusKm = 6371.007180918475;
const parentRes = h3.getResolution(parent);
const edgeRes = Math.min(parentRes + 4, 15);
let resDiff = edgeRes - parentRes;
resDiff = resDiff < 2 ? resDiff : resDiff < 4 ? 2 : 4;
const [centerLat, centerLng] = h3.cellToLatLng(parent);
const offset = h3.radsToDegs(h3.getHexagonEdgeLengthAvg(parentRes + resDiff, h3.UNITS.km) / earthRadiusKm) * resDiff;
function applyOffset([lng, lat]) {
lat += offset * (lat < centerLat ? -1 : 1) * 1.5;
lng += offset * (lng < centerLng ? -1 : 1) * 1.5;
return [lng, lat];
}
function applyOffset2([lng, lat]) {
const dist = Math.sqrt(Math.pow(centerLat - lat, 2) + Math.pow(centerLng - lng, 2));
lat = lat + (lat - centerLat) / dist * offset * 3;
lng = lng + (lng - centerLng) / dist * offset * 3;
return [lng, lat];
}
const coordinates = [];
if (resDiff < 2) {
const boundary = h3.cellToBoundary(parent, true);
for (let i = 0; i < boundary.length; i++) {
coordinates.push(applyOffset(boundary[i]));
}
} else {
const pos = positions[h3.isPentagon(parent) ? 1 : 0][resDiff < 4 ? 0 : 1][parentRes % 2];
const children = h3.cellToChildren(parent, parentRes + resDiff);
const candidates = pos.map(p => children[p]);
for (let i = 0; i < candidates.length; i++) {
const [lat, lng] = h3.cellToLatLng(candidates[i]);
coordinates.push(applyOffset([lng, lat]));
}
coordinates.push(coordinates[0]);
}
return {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [coordinates]
}
};
}