diff options
Diffstat (limited to 'app/geometry.js')
| -rw-r--r-- | app/geometry.js | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/app/geometry.js b/app/geometry.js index b9cac4f..9b89106 100644 --- a/app/geometry.js +++ b/app/geometry.js @@ -134,10 +134,9 @@ export class Geometry { /** * Deserialize geometry from GeoJSON * @param {{type: string, coordinates?: any, [key: string]: any}} geojson - * @returns {Geometry|null} + * @returns {Point|LineString|Polygon|MultiLineString} */ static fromGeoJSON(geojson) { - if (!geojson?.type) return null; switch (geojson.type) { case "Point": return Point.fromGeoJSON(geojson); @@ -154,7 +153,7 @@ export class Geometry { /** * Compute geometry bounds - * @param {Geometry} geometry - Input geometry + * @param {Point|LineString|Polygon} geometry - Input geometry * @returns {Bounds} Geometry bounds */ static bounds(geometry) { @@ -169,8 +168,7 @@ export class Geometry { if (geometry instanceof Polygon) { return Geometry.calculateBoundsFromCoords(geometry.rings[0]); } - - throw new Error(`Unsupported geometry type: ${geometry.type}`); + throw new Error(`Unsupported geometry type: ${geometry}`); } /** @@ -1057,10 +1055,6 @@ export class Feature { * @param {Object} geojson - GeoJSON feature * @returns {Feature|null} */ - /** - * @param {{geometry: object, properties?: object, id?: string|number}} geojson - * @returns {Feature|null} - */ static fromGeoJSON(geojson) { if (!geojson?.geometry) return null; @@ -1073,7 +1067,7 @@ export class Feature { export class Collection { /** - * @param {Feature[]} [features=[]] - Feature array + * @param {Feature[]} features - Feature array */ constructor(features = []) { this.type = "FeatureCollection"; @@ -1101,7 +1095,7 @@ export class Collection { * @returns {Collection} */ static fromGeoJSON(geojson) { - const features = geojson.features ?? []; + const features = geojson.features.map(Feature.fromGeoJSON).filter((x) => x !== null); return new Collection(features); } |
