Skip to content

Commit

Permalink
Geometry may be a polygon or multipolygon
Browse files Browse the repository at this point in the history
... or something else?
  • Loading branch information
Bruno Besson committed Feb 9, 2022
1 parent a58e80e commit 0d7540b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/map/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,16 @@ export default {
)
);
extent = areas
.flatMap((response) =>
geoJSONFormat.readGeometry(JSON.parse(response.data.geometry.geom_detail)).getPolygons()
)
.flatMap((response) => {
const geometry = geoJSONFormat.readGeometry(JSON.parse(response.data.geometry.geom_detail));
const type = geometry.getType();
if (type === 'Polygon') {
return [geometry];
} else if (type === 'MultiPolygon') {
return geometry.getPolygons();
}
return [];
})
.flatMap((polygon) => polygon.getCoordinates())
.map((coords) => ol.extent.boundingExtent(coords))
.reduce((acc, ext) => ol.extent.extend(acc, ext));
Expand Down

0 comments on commit 0d7540b

Please sign in to comment.