Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function h3SetToFeature(hexagons, properties = {}) {
const polygons = h3.h3SetToMultiPolygon(hexagons, true);
// See if we can unwrap to a simple Polygon.
const isMultiPolygon = polygons.length > 1;
const type = isMultiPolygon ? MULTI_POLYGON : POLYGON;
// MultiPolygon, single polygon, or empty array for an empty hex set
const coordinates = isMultiPolygon ? polygons : polygons[0] || [];
return {
type: FEATURE,
properties,
geometry: {
type,
coordinates
}
};
}
updateState({props, oldProps, changeFlags}) {
if (
changeFlags.dataChanged ||
(changeFlags.updateTriggers && changeFlags.updateTriggers.getHexagons)
) {
const {data, getHexagons} = props;
const polygons = [];
const {iterable, objectInfo} = createIterable(data);
for (const object of iterable) {
objectInfo.index++;
const hexagons = getHexagons(object, objectInfo);
const multiPolygon = h3SetToMultiPolygon(hexagons, true);
for (const polygon of multiPolygon) {
polygons.push(this.getSubLayerRow({polygon}, object, objectInfo.index));
}
}
this.setState({polygons});
}
}