Skip to content

Commit

Permalink
Handle MultiPolygons when splitting polygons from points
Browse files Browse the repository at this point in the history
  • Loading branch information
rybesh committed Oct 20, 2023
1 parent e69ccb4 commit 5cc9710
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/periodo-ui/src/components/WorldMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ const mesh2bbox = mesh => {

const geometryOf = feature => 'geometry' in feature ? feature.geometry.geometries[0] : null

const coordinatesOf = geometry => geometry.type == "Polygon" ? geometry.coordinates[0] : geometry.coordinates[0].flat()

const splitIntoPolygonsAndPoints = features => {
const polygons = []
const points = []
for (const feature of features) {
const geometry = geometryOf(feature)
if (geometry) {
// change small polygons to points
if (geometry.type == "Polygon") {
if (geometry.type == "Polygon" || geometry.type == "MultiPolygon") {
let minLon = 180
let maxLon = -180
let minLat = 90
let maxLat = -90
for (const [lon, lat] of geometry.coordinates[0]) {
for (const [lon, lat] of coordinatesOf(geometry)) {
if (lon < minLon) {
minLon = lon
}
Expand Down

0 comments on commit 5cc9710

Please sign in to comment.