@@ -8,14 +8,19 @@ import useStacChildren from "./hooks/stac-children";
88import useStacValue from "./hooks/stac-value" ;
99import type { BBox2D , Color } from "./types/map" ;
1010import type { DatetimeBounds , StacValue } from "./types/stac" ;
11- import { getItemDatetimes } from "./utils/stac" ;
11+ import {
12+ isCollectionInBbox ,
13+ isCollectionInDatetimeBounds ,
14+ isItemInBbox ,
15+ isItemInDatetimeBounds ,
16+ } from "./utils/stac" ;
1217
1318// TODO make this configurable by the user.
1419const lineColor : Color = [ 207 , 63 , 2 , 100 ] ;
1520const fillColor : Color = [ 207 , 63 , 2 , 50 ] ;
1621
1722export default function App ( ) {
18- // State
23+ // User state
1924 const [ href , setHref ] = useState < string | undefined > ( getInitialHref ( ) ) ;
2025 const fileUpload = useFileUpload ( { maxFiles : 1 } ) ;
2126 const [ userCollections , setCollections ] = useState < StacCollection [ ] > ( ) ;
@@ -195,73 +200,3 @@ function getInitialHref() {
195200 }
196201 return href ;
197202}
198-
199- function isCollectionInBbox ( collection : StacCollection , bbox : BBox2D ) {
200- if ( bbox [ 2 ] - bbox [ 0 ] >= 360 ) {
201- // A global bbox always contains every collection
202- return true ;
203- }
204- const collectionBbox = collection ?. extent ?. spatial ?. bbox ?. [ 0 ] ;
205- if ( collectionBbox ) {
206- return (
207- ! (
208- collectionBbox [ 0 ] < bbox [ 0 ] &&
209- collectionBbox [ 1 ] < bbox [ 1 ] &&
210- collectionBbox [ 2 ] > bbox [ 2 ] &&
211- collectionBbox [ 3 ] > bbox [ 3 ]
212- ) &&
213- ! (
214- collectionBbox [ 0 ] > bbox [ 2 ] ||
215- collectionBbox [ 1 ] > bbox [ 3 ] ||
216- collectionBbox [ 2 ] < bbox [ 0 ] ||
217- collectionBbox [ 3 ] < bbox [ 1 ]
218- )
219- ) ;
220- } else {
221- return false ;
222- }
223- }
224-
225- function isCollectionInDatetimeBounds (
226- collection : StacCollection ,
227- bounds : DatetimeBounds
228- ) {
229- const interval = collection . extent . temporal . interval [ 0 ] ;
230- const start = interval [ 0 ] ? new Date ( interval [ 0 ] ) : null ;
231- const end = interval [ 1 ] ? new Date ( interval [ 1 ] ) : null ;
232- return ! ( ( end && end < bounds . start ) || ( start && start > bounds . end ) ) ;
233- }
234-
235- function isItemInBbox ( item : StacItem , bbox : BBox2D ) {
236- if ( bbox [ 2 ] - bbox [ 0 ] >= 360 ) {
237- // A global bbox always contains every item
238- return true ;
239- }
240- const itemBbox = item . bbox ;
241- if ( itemBbox ) {
242- return (
243- ! (
244- itemBbox [ 0 ] < bbox [ 0 ] &&
245- itemBbox [ 1 ] < bbox [ 1 ] &&
246- itemBbox [ 2 ] > bbox [ 2 ] &&
247- itemBbox [ 3 ] > bbox [ 3 ]
248- ) &&
249- ! (
250- itemBbox [ 0 ] > bbox [ 2 ] ||
251- itemBbox [ 1 ] > bbox [ 3 ] ||
252- itemBbox [ 2 ] < bbox [ 0 ] ||
253- itemBbox [ 3 ] < bbox [ 1 ]
254- )
255- ) ;
256- } else {
257- return false ;
258- }
259- }
260-
261- function isItemInDatetimeBounds ( item : StacItem , bounds : DatetimeBounds ) {
262- const datetimes = getItemDatetimes ( item ) ;
263- return ! (
264- ( datetimes . end && datetimes . end < bounds . start ) ||
265- ( datetimes . start && datetimes . start > bounds . end )
266- ) ;
267- }
0 commit comments