@@ -2,7 +2,7 @@ import h from "@macrostrat/hyper";
22import { LngLatCoords } from "@macrostrat/map-interface" ;
33import { useEffect , useState , useRef } from 'react' ;
44import 'mapbox-gl/dist/mapbox-gl.css' ;
5- import { BlankImage , Image , Footer , apiURL , useRockdAPI , imageExists } from "../index" ;
5+ import { BlankImage , imageExists , Footer , apiURL , apiURLOld , useRockdAPI } from "../index" ;
66import { Icon } from "@blueprintjs/core" ;
77import "../main.sass" ;
88import { SETTINGS } from "@macrostrat-web/settings" ;
@@ -12,6 +12,7 @@ import "@macrostrat/style-system";
1212import { MapAreaContainer , MapView , MapMarker } from "@macrostrat/map-interface" ;
1313import 'mapbox-gl/dist/mapbox-gl.css' ;
1414import { MapPosition } from "@macrostrat/mapbox-utils" ;
15+ import { PanelCard } from "@macrostrat/map-interface" ;
1516
1617export function Checkins ( { checkinID} ) {
1718 const checkinData = useRockdAPI ( "protected/checkins?checkin_id=" + checkinID ) ;
@@ -28,7 +29,8 @@ export function Checkins({checkinID}) {
2829
2930 if ( checkinData . success . data . length == 0 ) {
3031 return h ( "div" , { className : 'error' } , [
31- h ( "h1" , "Checkin " + checkinID + " not found" ) ,
32+ h ( BlankImage , { className : "error-img" , src : "https://rockd.org/assets/img/404.jpg" } ) ,
33+ h ( "h1" , "Checkin " + checkinID + " not found!" ) ,
3234 ] ) ;
3335 }
3436
@@ -53,13 +55,13 @@ export function Checkins({checkinID}) {
5355 let observations = [ ] ;
5456
5557 // add checkin photo and notes
56- const showImage = checkin . photo ;
57- const headerImgUrl = showImage ? apiURL + "protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo : "https://storage.macrostrat.org/assets/rockd/rockd.jpg" ;
58+ const imageSrc = apiURL + "protected/image/" + checkin . person_id + "/thumb_large/" + checkin . photo ;
59+ const headerImgUrl = checkin . photo && imageExists ( imageSrc ) ? imageSrc : null ;
5860 const headerBody = h ( 'h4' , { className : 'observation-header' } , checkin . notes ) ;
5961
6062 observations . push (
6163 h ( 'div' , { className : 'observation' } , [
62- showImage ? h ( BlankImage , { className : 'observation-img' , src : headerImgUrl , onClick : ( ) => {
64+ headerImgUrl ? h ( BlankImage , { className : 'observation-img' , src : headerImgUrl , onClick : ( ) => {
6365 setOverlayBody ( h ( 'div.observation-body' , headerBody ) ) ;
6466 setOverlayImage ( headerImgUrl ) ;
6567 setOverlayOpen ( ! overlayOpen ) ;
@@ -74,13 +76,13 @@ export function Checkins({checkinID}) {
7476 console . log ( "obs" , observation . photo , observation ) ;
7577 if ( Object . keys ( observation . rocks ) . length != 0 ) {
7678 // if photo exists
77- const showImage = observation . photo ;
78- const imageSrc = showImage ? apiURL + "/protected/image/" + checkin . person_id + "/thumb_large/" + observation . photo : "https://storage.macrostrat.org/assets/rockd/rockd.jpg" ;
79+ const imageSrc = apiURL + "protected/image/" + checkin . person_id + "/thumb_large/" + observation . photo ;
80+ const observationURL = observation . photo && imageExists ( imageSrc ) ? imageSrc : null ;
7981 let observationBody = observationFooter ( observation ) ;
8082
8183 observations . push (
8284 h ( 'div' , { className : 'observation' } , [
83- showImage ? h ( BlankImage , { className : 'observation-img' , src : imageSrc , onClick : ( ) => {
85+ observationURL ? h ( BlankImage , { className : 'observation-img' , src : observationURL , onClick : ( ) => {
8486 setOverlayImage ( imageSrc ) ;
8587 setOverlayBody ( observationBody ) ;
8688 setOverlayOpen ( ! overlayOpen ) ;
@@ -91,29 +93,6 @@ export function Checkins({checkinID}) {
9193 }
9294 } ) ;
9395
94- const newMapPosition : MapPosition = {
95- camera : {
96- lat : center . lat , // Latitude
97- lng : center . lng , // Longitude
98- altitude : 300000 , // Altitude (height from the Earth's surface)
99- } ,
100- } ;
101-
102- let map = h ( "div.map" , [
103- h ( MapAreaContainer , { style : { height : "93vh" , top : "7vh" } } ,
104- [
105- h ( MapView , { style : 'mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i' , mapboxToken : SETTINGS . mapboxAccessToken , mapPosition : newMapPosition } , [
106- h ( MapMarker , {
107- position : center ,
108- } ) ,
109- ] ) ,
110- ]
111- ) ,
112- h ( 'div' , { className : 'banner' , onClick : ( ) => {
113- setShowMap ( ! showMap ) ;
114- } } , h ( Icon , { className : "left-arrow banner-arrow" , icon : "arrow-left" , iconSize : "4vh" , style : { color : 'black' } } ) ) ,
115- ] )
116-
11796 let LngLatProps = {
11897 position : {
11998 lat : checkin . lat ,
@@ -138,6 +117,8 @@ export function Checkins({checkinID}) {
138117 ] )
139118 ] ) ;
140119
120+ const map = h ( Map , { center, showMap, setShowMap} ) ;
121+
141122 let main = h ( 'div' , { className : "container" } , [
142123 h ( 'div' , { className : showMap ? 'hide' : 'main' } , [
143124 h ( 'div' , { className : "checkin-header" } , [
@@ -204,4 +185,46 @@ function observationFooter(observation) {
204185 h ( 'p' , { className : "notes" } , rocks . notes ) ,
205186 ] ) ,
206187 ] ) ;
188+ }
189+
190+ function Map ( { center, showMap, setShowMap} ) {
191+ const [ style , setStyle ] = useState ( "mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i" ) ;
192+ const [ styleText , setStyleText ] = useState ( "Show Satelite" ) ;
193+
194+ const newMapPosition : MapPosition = {
195+ camera : {
196+ lat : center . lat , // Latitude
197+ lng : center . lng , // Longitude
198+ altitude : 300000 , // Altitude (height from the Earth's surface)
199+ } ,
200+ } ;
201+
202+ const sateliteStyle = 'mapbox://styles/mapbox/satellite-v9' ;
203+ const whiteStyle = "mapbox://styles/jczaplewski/cje04mr9l3mo82spihpralr4i" ;
204+ const whiteText = "Show White" ;
205+ const sateliteText = "Show Satelite" ;
206+
207+ let map = h ( "div.map" , [
208+ h ( MapAreaContainer , { style : { height : "93vh" , top : "7vh" } } ,
209+ [
210+ h ( MapView , { style : style , mapboxToken : SETTINGS . mapboxAccessToken , mapPosition : newMapPosition } , [
211+ h ( MapMarker , {
212+ position : center ,
213+ } ) ,
214+ ] ) ,
215+ ]
216+ ) ,
217+ h ( 'div' , { className : 'banner' } , [
218+ h ( Icon , { className : "left-arrow banner-arrow" , icon : "arrow-left" , iconSize : "4vh" , style : { color : 'black' } , onClick : ( ) => {
219+ setShowMap ( ! showMap ) ;
220+ } } ) ,
221+ h ( PanelCard , { className : "banner-button" , onClick : ( ) => {
222+ console . log ( "clicked" ) ;
223+ setStyle ( style == whiteStyle ? sateliteStyle : whiteStyle ) ;
224+ setStyleText ( styleText == whiteText ? sateliteText : whiteText ) ;
225+ } } , styleText ) ,
226+ ] ) ,
227+ ] )
228+
229+ return map ;
207230}
0 commit comments