UNPKG

@polar/plugin-draw

Version:

Draw plugin for POLAR that adds draw interactions to the map, allowing users to place various shapes and texts.

28 lines (26 loc) 826 B
import { FeatureCollection, Feature as GeoJsonFeature, MultiPolygon, Polygon, } from 'geojson' import { cleanCoords } from '@turf/clean-coords' import { unkinkPolygon } from '@turf/unkink-polygon' import { GeometryType } from '../../types' export const autofixFeatureCollection = ( revisedFeatureCollection: FeatureCollection<GeometryType> ) => ({ ...revisedFeatureCollection, features: revisedFeatureCollection.features.reduce((accumulator, feature) => { if (['Polygon', 'MultiPolygon'].includes(feature.geometry.type)) { accumulator.push( ...unkinkPolygon( cleanCoords(feature) as GeoJsonFeature<Polygon | MultiPolygon> ).features ) } else { accumulator.push(cleanCoords(feature)) } return accumulator }, [] as GeoJsonFeature<GeometryType>[]), })