Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "stac-js", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "JS drop-in classes with utilities for STAC", | ||
@@ -5,0 +5,0 @@ "author": "Matthias Mohr", |
@@ -9,3 +9,3 @@ # stac-js | ||
- **Package version:** 0.1.0 | ||
- **Package version:** 0.1.1 | ||
- **STAC versions:** >= 0.6.0 (through [stac-migrate](https://github.com/stac-utils/stac-migrate)). | ||
@@ -12,0 +12,0 @@ - **Documentation:** <https://m-mohr.github.io/stac-js/latest/> |
@@ -5,3 +5,3 @@ import Asset from './asset.js'; | ||
import { isoToDate } from './datetime.js'; | ||
import { isBoundingBox, toGeoJSON } from './geo.js'; | ||
import { bbox2D, isBoundingBox, toGeoJSON } from './geo.js'; | ||
import { hasText } from './utils.js'; | ||
@@ -78,3 +78,3 @@ | ||
/** | ||
* Returns a single union bounding box for the whole collection. | ||
* Returns a single union 2D bounding box for the whole collection. | ||
* | ||
@@ -86,3 +86,3 @@ * @returns {BoundingBox|null} | ||
if (bboxes.length > 0 && isBoundingBox(bboxes[0])) { | ||
return bboxes[0]; | ||
return bbox2D(bboxes[0]); | ||
} | ||
@@ -93,3 +93,3 @@ return null; | ||
/** | ||
* Returns the individual bounding boxes for the collection, | ||
* Returns the individual 2D bounding boxes for the collection, | ||
* without the union bounding box if multiple bounding boxes are given. | ||
@@ -100,10 +100,11 @@ * | ||
getBoundingBoxes() { | ||
let bboxes = this.getRawBoundingBoxes(); | ||
if (bboxes.length === 1 && isBoundingBox(bboxes[0])) { | ||
return bboxes; | ||
let raw = this.getRawBoundingBoxes(); | ||
let bboxes = []; | ||
if (raw.length === 1 && isBoundingBox(raw[0])) { | ||
bboxes = raw; | ||
} | ||
else if (bboxes.length > 1) { | ||
return bboxes.filter((bbox, i) => i > 0 && isBoundingBox(bbox)); | ||
else if (raw.length > 1) { | ||
bboxes = raw.filter((bbox, i) => i > 0 && isBoundingBox(bbox)); | ||
} | ||
return []; | ||
return bboxes.map(bbox => bbox2D(bbox)); | ||
} | ||
@@ -110,0 +111,0 @@ |
@@ -68,3 +68,3 @@ import Collection from './collection.js'; | ||
/** | ||
* Returns a single bounding box for all the STAC collections. | ||
* Returns a single 2D bounding box for all the STAC collections. | ||
* | ||
@@ -78,3 +78,3 @@ * @returns {BoundingBox|null} | ||
/** | ||
* Returns a list of bounding boxes for all the STAC collections. | ||
* Returns a list of 2D bounding boxes for all the STAC collections. | ||
* | ||
@@ -81,0 +81,0 @@ * @returns {Array.<BoundingBox>} |
@@ -114,2 +114,18 @@ function toObject(bbox) { | ||
/** | ||
* Converts a bounding box to be two-dimensional. | ||
* | ||
* @param {BoundingBox} bbox | ||
* @returns {BoundingBox} | ||
*/ | ||
export function bbox2D(bbox) { | ||
if (bbox.length === 4) { | ||
return bbox; | ||
} | ||
else { | ||
let { west, east, south, north } = toObject(bbox); | ||
return [west, south, east, north]; | ||
} | ||
} | ||
/** | ||
* Checks whether the given thing is a valid bounding box. | ||
@@ -137,2 +153,8 @@ * | ||
/** | ||
* Checks whether the given bounding box crosses the antimeridian. | ||
* | ||
* @param {BoundingBox} bbox | ||
* @returns {boolean} | ||
*/ | ||
export function isAntimeridianBoundingBox(bbox) { | ||
@@ -139,0 +161,0 @@ if (!isBoundingBox(bbox)) { |
import Asset from './asset.js'; | ||
import { centerDateTime, isoToDate } from './datetime.js'; | ||
import { isBoundingBox } from './geo.js'; | ||
import { bbox2D, isBoundingBox } from './geo.js'; | ||
import { hasText } from './utils.js'; | ||
@@ -60,3 +60,3 @@ import STAC from './stac.js'; | ||
/** | ||
* Returns a single bounding box for the item. | ||
* Returns a single 2D bounding box for the item. | ||
* | ||
@@ -66,7 +66,7 @@ * @returns {BoundingBox|null} | ||
getBoundingBox() { | ||
return isBoundingBox(this.bbox) ? this.bbox : null; | ||
return isBoundingBox(this.bbox) ? bbox2D(this.bbox) : null; | ||
} | ||
/** | ||
* Returns bounding boxes for the item. | ||
* Returns 2D bounding boxes for the item. | ||
* | ||
@@ -76,3 +76,4 @@ * @returns {Array.<BoundingBox>} | ||
getBoundingBoxes() { | ||
return isBoundingBox(this.bbox) ? [this.bbox] : []; | ||
const bbox = this.getBoundingBox(); | ||
return bbox ? [bbox] : []; | ||
} | ||
@@ -79,0 +80,0 @@ |
@@ -54,3 +54,3 @@ import { unionDateTime } from './datetime.js'; | ||
/** | ||
* Returns a single bounding box for all the STAC items. | ||
* Returns a single 2D bounding box for all the STAC items. | ||
* | ||
@@ -64,3 +64,3 @@ * @returns {BoundingBox|null} | ||
/** | ||
* Returns a list of bounding boxes for all the STAC items. | ||
* Returns a list of 2D bounding boxes for all the STAC items. | ||
* | ||
@@ -67,0 +67,0 @@ * @returns {Array.<BoundingBox>} |
83041
2433