@@ -15,7 +15,6 @@ import {
1515 Select ,
1616 Stack ,
1717 Switch ,
18- Text ,
1918} from "@chakra-ui/react" ;
2019import { useEffect , useState } from "react" ;
2120import { LuPause , LuPlay , LuSearch , LuX } from "react-icons/lu" ;
@@ -34,7 +33,7 @@ export default function ItemSearch({
3433 collection : StacCollection ;
3534 links : StacLink [ ] ;
3635} ) {
37- const { setItems, setPicked } = useStacMap ( ) ;
36+ const { setItems } = useStacMap ( ) ;
3837 const [ search , setSearch ] = useState < StacSearch > ( ) ;
3938 const [ link , setLink ] = useState < StacLink | undefined > ( links [ 0 ] ) ;
4039 const [ datetime , setDatetime ] = useState < string > ( ) ;
@@ -44,9 +43,8 @@ export default function ItemSearch({
4443 useEffect ( ( ) => {
4544 if ( ! search ) {
4645 setItems ( undefined ) ;
47- setPicked ( undefined ) ;
4846 }
49- } , [ search , setItems , setPicked ] ) ;
47+ } , [ search , setItems ] ) ;
5048
5149 const methods = createListCollection ( {
5250 items : links . map ( ( link ) => {
@@ -82,8 +80,6 @@ export default function ItemSearch({
8280 < Switch . Control > </ Switch . Control >
8381 </ Switch . Root >
8482
85- < Text > </ Text >
86-
8783 < Datetime
8884 interval = { collection . extent ?. temporal ?. interval [ 0 ] }
8985 setDatetime = { setDatetime }
@@ -132,7 +128,14 @@ export default function ItemSearch({
132128 datetime,
133129 bbox :
134130 useViewportBounds && map
135- ? map . getBounds ( ) . toArray ( ) . flat ( )
131+ ? normalizeBbox (
132+ map . getBounds ( ) . toArray ( ) . flat ( ) as [
133+ number ,
134+ number ,
135+ number ,
136+ number ,
137+ ] ,
138+ )
136139 : undefined ,
137140 } )
138141 }
@@ -356,3 +359,26 @@ function DatetimeInput({
356359 </ Field . Root >
357360 ) ;
358361}
362+
363+ function normalizeBbox ( bbox : [ number , number , number , number ] ) {
364+ if ( bbox [ 2 ] - bbox [ 0 ] >= 360 ) {
365+ return [ - 180 , bbox [ 1 ] , 180 , bbox [ 3 ] ] ;
366+ } else if ( bbox [ 0 ] < - 180 ) {
367+ return normalizeBbox ( [ bbox [ 0 ] + 360 , bbox [ 1 ] , bbox [ 2 ] + 360 , bbox [ 3 ] ] ) ;
368+ } else if ( bbox [ 0 ] > 180 ) {
369+ return normalizeBbox ( [ bbox [ 0 ] - 360 , bbox [ 1 ] , bbox [ 2 ] - 360 , bbox [ 3 ] ] ) ;
370+ } else if ( bbox [ 2 ] > 180 ) {
371+ // Antimeridian-crossing
372+ toaster . create ( {
373+ type : "info" ,
374+ title : "Viewport crosses the antimeridian" ,
375+ description :
376+ "The viewport crosses the antimeridian, and many STAC API servers do not support bounding boxes that cross +/- 180° longitude. We're narrowing the viewport to only search to only one side." ,
377+ } ) ;
378+ if ( ( bbox [ 0 ] + bbox [ 2 ] ) / 2 > 180 ) {
379+ return [ - 180 , bbox [ 1 ] , bbox [ 2 ] - 360 , bbox [ 3 ] ] ;
380+ } else {
381+ return [ bbox [ 0 ] , bbox [ 1 ] , 180 , bbox [ 3 ] ] ;
382+ }
383+ }
384+ }
0 commit comments