11import h from "@macrostrat/hyper" ;
22import { LngLatCoords } from "@macrostrat/map-interface" ;
3- import { useEffect , useState } from 'react' ;
3+ import { useEffect , useState , useRef } from 'react' ;
44import { usePageContext } from 'vike-react/usePageContext' ;
55import 'mapbox-gl/dist/mapbox-gl.css' ;
66import { BlankImage , Image , Footer } from "../index" ;
@@ -9,6 +9,12 @@ import { SETTINGS } from "@macrostrat-web/settings";
99import { DarkModeButton } from "@macrostrat/ui-components" ;
1010import "./main.sass" ;
1111import "@macrostrat/style-system" ;
12+ import { MapAreaContainer , MapView , MapMarker } from "@macrostrat/map-interface" ;
13+ import 'mapbox-gl/dist/mapbox-gl.css' ;
14+ import { checkIfClientRouting } from "vike/dist/esm/utils/assertRoutingType" ;
15+ import { MapPosition } from "@macrostrat/mapbox-utils" ;
16+ import { set } from "react-datepicker/dist/date_utils" ;
17+
1218
1319function imageExists ( image_url ) {
1420 var http = new XMLHttpRequest ( ) ;
@@ -25,6 +31,14 @@ export function Page() {
2531 const [ loading , setLoading ] = useState ( true ) ;
2632 const [ error , setError ] = useState ( null ) ;
2733 const [ checkinNum , setCheckin ] = useState ( null ) ;
34+ const [ overlayOpen , setOverlayOpen ] = useState ( false ) ;
35+ const [ overlayImage , setOverlayImage ] = useState ( null ) ;
36+ const [ overlayBody , setOverlayBody ] = useState ( null ) ;
37+ const [ showMap , setShowMap ] = useState ( false ) ;
38+ const [ center , setCenter ] = useState ( {
39+ lat : 0 ,
40+ lng : 0
41+ } ) ;
2842
2943 let stop ;
3044
@@ -35,7 +49,6 @@ export function Page() {
3549 } else {
3650 setCheckin ( 0 ) ;
3751 }
38- console . log ( `Fetching data for checkin ID: ` + stop ) ;
3952
4053 // Ensure trip ID is valid
4154 if ( isNaN ( stop ) ) {
@@ -52,9 +65,13 @@ export function Page() {
5265 return response . json ( ) ;
5366 } )
5467 . then ( data => {
55- console . log ( 'Fetched data:' , data ) ; // Log fetched data for debugging
5668 if ( data . success && data . success . data . length > 0 ) {
5769 setUserData ( data . success . data [ 0 ] ) ;
70+ setCenter ( {
71+ lat : data . success . data [ 0 ] . lat ,
72+ lng : data . success . data [ 0 ] . lng
73+ } ) ;
74+ console . log ( "Center: " , center ) ;
5875 } else {
5976 setUserData ( null ) ;
6077 }
@@ -95,7 +112,6 @@ export function Page() {
95112 }
96113
97114 let checkin = userData ;
98- console . log ( checkin )
99115
100116 let profile_pic = h ( BlankImage , { src : "https://rockd.org/api/v2/protected/gravatar/" + checkin . person_id , className : "profile-pic" } ) ;
101117
@@ -109,26 +125,24 @@ export function Page() {
109125 let observations = [ ] ;
110126
111127 // add checkin photo and notes
112- console . log ( "Checkin photo: " , checkin . photo != null ) ;
113- let headerImg ;
114- if ( imageExists ( "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo ) && checkin . photo != null ) {
115- headerImg = h ( BlankImage , { className : 'observation-img' , src : "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo } )
116- } else {
117- headerImg = h ( BlankImage , { className : 'observation-img' , src : "https://storage.macrostrat.org/assets/rockd/rockd.jpg" } )
118- }
128+ let headerImgUrl = imageExists ( "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo ) && checkin . photo != null ? "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo : "https://storage.macrostrat.org/assets/rockd/rockd.jpg" ;
129+ let headerBody = h ( 'h4' , { className : 'observation-header' } , checkin . notes ) ;
119130
120131 observations . push (
121132 h ( 'div' , { className : 'observation' } , [
122- headerImg ,
123- h ( 'h4' , { className : 'observation-header' } , checkin . notes ) ,
133+ h ( BlankImage , { className : 'observation-img' , src : headerImgUrl , onClick : ( ) => {
134+ setOverlayBody ( h ( 'div.observation-body' , headerBody ) ) ;
135+ setOverlayImage ( headerImgUrl ) ;
136+ setOverlayOpen ( ! overlayOpen ) ;
137+ }
138+ } ) ,
139+ headerBody ,
124140 ] )
125141 ) ;
126142
127143 // add observations
128144 for ( var i = 0 ; i < checkin . observations . length ; i ++ ) {
129145 let observation = checkin . observations [ i ] ;
130- console . log ( "Observation " + i ) ;
131- console . log ( observation ) ;
132146
133147 if ( Object . keys ( observation . rocks ) . length != 0 ) {
134148 // get liths
@@ -151,25 +165,52 @@ export function Page() {
151165 let imageSrc ;
152166 imageSrc = imageExists ( "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + observation . photo ) ? "https://rockd.org/api/v1/protected/image/" + checkin . person_id + "/thumb_large/" + observation . photo : "https://storage.macrostrat.org/assets/rockd/rockd.jpg" ;
153167 let obsAge = observation . age_est ? observation . age_est . name + " (" + observation . age_est . b_age + " - " + observation ?. age_est ?. t_age + ")" : null ;
168+ let observationBody = h ( 'div' , { className : 'observation-body' } , [
169+ h ( 'h4' , { className : 'observation-header' } , observation . rocks . strat_name ?. strat_name_long ) ,
170+ h ( 'div' , { className : 'observation-details' } , [
171+ h ( 'p' , { className : 'observation-detail' } , observation . rocks . strat_name ?. strat_name_long ) ,
172+ h ( 'p' , { className : 'observation-detail' } , observation . rocks . map_unit ?. unit_name ) ,
173+ h ( 'p' , { className : 'observation-detail' } , obsAge ) ,
174+ h ( 'p' , { className : 'observation-detail' } , liths ) ,
175+ h ( 'p' , { className : 'observation-detail' } , observation . orientation . feature ?. name ) ,
176+ LngLatCoords ( LngLatProps )
177+ ] ) ,
178+ ] ) ;
154179
155- console . log ( "PRINTING" , observation . age_est ) ;
156180 observations . push (
157181 h ( 'div' , { className : 'observation' } , [
158- h ( BlankImage , { className : 'observation-img' , src : imageSrc } ) ,
159- h ( 'h4' , { className : 'observation-header' } , observation . rocks . strat_name ?. strat_name_long ) ,
160- h ( 'div' , { className : 'observation-details' } , [
161- h ( 'p' , { className : 'observation-detail' } , observation . rocks . strat_name ?. strat_name_long ) ,
162- h ( 'p' , { className : 'observation-detail' } , observation . rocks . map_unit ?. unit_name ) ,
163- h ( 'p' , { className : 'observation-detail' } , obsAge ) ,
164- h ( 'p' , { className : 'observation-detail' } , liths ) ,
165- h ( 'p' , { className : 'observation-detail' } , observation . orientation . feature ?. name ) ,
166- LngLatCoords ( LngLatProps )
167- ] ) ,
182+ h ( BlankImage , { className : 'observation-img' , src : imageSrc , onClick : ( ) => {
183+ setOverlayImage ( imageSrc ) ;
184+ setOverlayBody ( observationBody ) ;
185+ setOverlayOpen ( ! overlayOpen ) ;
186+ } } ) ,
187+ observationBody ,
168188 ] )
169189 ) ;
170190 }
171191 }
172192
193+ const newMapPosition : MapPosition = {
194+ camera : {
195+ lat : center . lat , // Latitude
196+ lng : center . lng , // Longitude
197+ altitude : 300000 , // Altitude (height from the Earth's surface)
198+ } ,
199+ } ;
200+
201+ let map = h ( MapAreaContainer ,
202+ [
203+ h ( MapView , { style : 'mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i' , mapboxToken : SETTINGS . mapboxAccessToken , mapPosition : newMapPosition } , [
204+ h ( MapMarker , {
205+ position : center ,
206+ } ) ,
207+ ] ) ,
208+ h ( 'div' , { className : 'banner' , onClick : ( ) => {
209+ setShowMap ( ! showMap ) ;
210+ } } , h ( Image , { className : 'left-arrow' , src : "checkins/left-arrow.png" } ) ) ,
211+ ]
212+ ) ;
213+
173214 let LngLatProps = {
174215 position : {
175216 lat : checkin . lat ,
@@ -179,11 +220,23 @@ export function Page() {
179220 zoom : 10
180221 } ;
181222
182- return h ( 'div' , [
183- h ( 'div' , { className : 'main' } , [
223+ // overlay
224+ let overlay = h ( 'div' , { className : 'overlay' } , [
225+ h ( 'div' , { className : 'banner' , onClick : ( ) => {
226+ setOverlayOpen ( ! overlayOpen ) ;
227+ } } , h ( Image , { className : 'left-arrow' , src : "checkins/left-arrow.png" } ) ) ,
228+
229+ h ( 'div.overlay-body' , [
230+ h ( BlankImage , { className : 'observation-img' , src : overlayImage } ) ,
231+ overlayBody ,
232+ ] )
233+ ] ) ;
234+
235+ let main = h ( 'div' , [
236+ h ( 'div' , { className : showMap ? 'hide' : 'main' } , [
184237 h ( 'h1' , { className : "checkin-header" } , checkin . description ) ,
185238 h ( BlankImage , { className : "location-img" , src : "https://api.mapbox.com/styles/v1/jczaplewski/cje04mr9l3mo82spihpralr4i/static/geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B" + checkin . lng + "%2C" + checkin . lat + "%5D%7D)/" + checkin . lng + "," + checkin . lat + ",5,0/1200x400?access_token=" + SETTINGS . mapboxAccessToken } ) ,
186- h ( 'div' , { className : 'stop-header' } , [
239+ h ( 'div' , { className : 'stop-header' , onClick : ( ) => { setShowMap ( true ) ; console . log ( "center" , center ) } } , [
187240 profile_pic ,
188241 h ( 'div' , { className : 'stop-main-info' } , [
189242 h ( 'h3' , { className : 'name' } , checkin . first_name + " " + checkin . last_name ) ,
@@ -197,7 +250,13 @@ export function Page() {
197250 ] ) ,
198251 h ( 'div' , { className : 'observations' } , observations ) ,
199252 ] ) ,
200- h ( Footer ) ,
201- h ( DarkModeButton , { className : 'dark-mode-button' , showText : true } ) ,
253+ h ( 'div' , { className : showMap ? 'hide' : 'bottom' } , [
254+ h ( Footer ) ,
255+ h ( DarkModeButton , { className : 'dark-mode-button' , showText : true } ) ,
256+ ] ) ,
257+ h ( 'div' , { className : ! showMap ? 'hide' : 'map' } , map )
202258 ] )
203- }
259+
260+
261+ return overlayOpen ? overlay : main ;
262+ }
0 commit comments