@@ -118,8 +118,8 @@ function FeatureDetails() {
118118 let checkins = [ ] ;
119119 let result ;
120120
121- if ( mapRef == null ) {
122- result = getCheckins ( 0 , 100 , 0 , 100 ) ;
121+ if ( mapRef ?. current == null ) {
122+ return h ( Spinner )
123123 } else {
124124 let map = mapRef . current ;
125125
@@ -140,7 +140,7 @@ function FeatureDetails() {
140140 } , [ bounds ] ) ;
141141 }
142142
143- if ( result == null ) return h ( Spinner ) ;
143+ if ( result == null ) return h ( "div.checkin-container" , Spinner ) ;
144144 result = result . success . data ;
145145 console . log ( "result:" , result )
146146
@@ -240,16 +240,20 @@ function WeaverMap({
240240 const style = useMapStyle ( type , mapboxToken ) ;
241241
242242 const [ featuredCheckins , setFeaturedCheckin ] = useState ( h ( Spinner ) ) ;
243+ // overlay
244+ const [ isOpenSelected , setOpenSelected ] = useState ( true ) ;
245+
243246
244247 const [ inspectPosition , setInspectPosition ] =
245248 useState < mapboxgl . LngLat | null > ( null ) ;
246249
247250 const onSelectPosition = useCallback ( ( position : mapboxgl . LngLat ) => {
248251 setInspectPosition ( position ) ;
252+ setOpenSelected ( true ) ;
249253 } , [ ] ) ;
250254
251255 let detailElement = null ;
252- let selectedCheckin = h ( 'h1' , { className : 'no-checkins' } , "No Checkin(s) Selected" ) ;
256+ let selectedCheckin = null ;
253257 let result = getCheckins ( inspectPosition ?. lat - .05 , inspectPosition ?. lat + .05 , inspectPosition ?. lng - .05 , inspectPosition ?. lng + .05 ) ;
254258 if ( inspectPosition != null ) {
255259 detailElement = h (
@@ -268,13 +272,26 @@ function WeaverMap({
268272
269273 // TODO: have run depend on changing mapRef
270274 let featuredCheckin = h ( FeatureDetails ) ;
275+ let overlay ;
271276
272- let overlay = h (
273- "div.overlay-div" ,
274- [
275- h ( ExpansionPanel , { title : "Selected Checkins" } , selectedCheckin ) ,
276- h ( ExpansionPanel , { title : "Featured Checkins" } , featuredCheckin ) ,
277+ if ( selectedCheckin == null || ! isOpenSelected ) {
278+ overlay = h ( "div.sidebox" , [
279+ h ( 'div.title' , h ( "h1" , "Featured Checkins" ) ) ,
280+ h ( "div.overlay-div" , featuredCheckin ) ,
277281 ] ) ;
282+ } else {
283+ overlay = h ( "div.sidebox" , [
284+ h ( 'div.title' , [
285+ h ( "h1" , "Selected Checkins" ) ,
286+ h ( 'h3' , { className : "coordinates" } , formatCoordinates ( inspectPosition . lat , inspectPosition . lng ) ) ,
287+ ] ) ,
288+ h ( "button" , {
289+ className : "close-btn" ,
290+ onClick : ( ) => setOpenSelected ( false )
291+ } , "X" ) ,
292+ h ( "div.overlay-div" , selectedCheckin )
293+ ] ) ;
294+ }
278295
279296 if ( style == null ) return null ;
280297
@@ -285,7 +302,6 @@ function WeaverMap({
285302 h (
286303 MapAreaContainer ,
287304 {
288- detailPanel : detailElement ,
289305 contextPanelOpen : isOpen ,
290306 } ,
291307 [
@@ -311,15 +327,15 @@ function getSelectedCheckins(result) {
311327
312328 // Selected checkin
313329 if ( result == null ) {
314- return h ( Spinner ) ;
330+ return null ;
315331 } else {
316332 result = result . success . data ;
317333 checkins = createCheckins ( result , mapRef , false ) ;
318334
319335 if ( checkins . length > 0 ) {
320336 return h ( "div" , { className : 'checkin-container' } , checkins ) ;
321337 } else {
322- return h ( 'h1' , { className : 'no-checkins' } , "No Checkin(s) Selected" ) ;
338+ return null ;
323339 }
324340 }
325341}
@@ -346,4 +362,16 @@ function useMapStyle(type, mapboxToken) {
346362 } , [ ] ) ;
347363
348364 return actualStyle ;
365+ }
366+
367+ function formatCoordinates ( latitude , longitude ) {
368+ // Round latitude and longitude to 4 decimal places
369+ const roundedLatitude = latitude . toFixed ( 4 ) ;
370+ const roundedLongitude = longitude . toFixed ( 4 ) ;
371+
372+ const latitudeDirection = latitude >= 0 ? 'N' : 'S' ;
373+ const longitudeDirection = longitude >= 0 ? 'E' : 'W' ;
374+
375+ // Return the formatted string with rounded values
376+ return `${ Math . abs ( roundedLatitude ) } ° ${ latitudeDirection } , ${ Math . abs ( roundedLongitude ) } ° ${ longitudeDirection } ` ;
349377}
0 commit comments