Skip to content

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jul 25, 2024
1 parent 7af6a23 commit 9bab2be
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions client/src/services/geoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,19 @@ export function getFeatureCutouts(
): Feature {
const polygons: Polygon[] = []

if (feature.geometry.type === 'Polygon') {
feature.geometry.coordinates.forEach((polygon, i) => {
if (i > 0) {
polygons.push({
type: 'Polygon',
coordinates: [polygon],
})
}
const push = (positions: Position[], index: number) =>
index > 0 &&
polygons.push({
type: 'Polygon',
coordinates: [positions],
})

if (feature.geometry.type === 'Polygon') {
feature.geometry.coordinates.forEach(push)
} else if (feature.geometry.type === 'MultiPolygon') {
feature.geometry.coordinates.forEach((multi) => {
multi.forEach((polygon, i) => {
if (i > 0) {
polygons.push({
type: 'Polygon',
coordinates: [polygon],
})
}
})
})
feature.geometry.coordinates.forEach((multi) => multi.forEach(push))
}

return {
type: 'Feature',
id: `${feature.id}-cutouts`,
Expand Down

0 comments on commit 9bab2be

Please sign in to comment.