@@ -12,17 +12,13 @@ import { useRockdAPI, Image, pageCarousel, createCheckins } from "~/components/g
1212import "@macrostrat/style-system" ;
1313import { MapPosition } from "@macrostrat/mapbox-utils" ;
1414import { ClientOnly } from "vike-react/ClientOnly" ;
15+ import {
16+ MapAreaContainer ,
17+ MapMarker ,
18+ MapView ,
19+ } from "@macrostrat/map-interface" ;
20+ import { mapboxAccessToken } from "@macrostrat-web/settings" ;
1521
16- function MapContainer ( props ) {
17- return h (
18- ClientOnly ,
19- {
20- load : ( ) => import ( "./map.client" ) . then ( ( d ) => d . WeaverMapContainer ) ,
21- fallback : h ( "div.loading" , "Loading map..." ) ,
22- } ,
23- ( component ) => h ( component , props )
24- ) ;
25- }
2622
2723export function Page ( ) {
2824 return h (
@@ -674,3 +670,92 @@ function renderSection(label, key, resultList, setFn, existingIds, setAutocomple
674670 ] )
675671 : null ;
676672}
673+
674+
675+ export function MapContainer ( { style, mapPosition, onSelectPosition, setSelectedCheckin, overlay} ) {
676+ return h (
677+ "div.map-container" ,
678+ [
679+ // The Map Area Container
680+ h (
681+ MapAreaContainer ,
682+ {
683+ className : "map-area-container" ,
684+ style : { "paddingLeft" : "calc(30% + 14px)" , } ,
685+ } ,
686+ [
687+ h ( MapView , { style, mapboxToken : mapboxAccessToken , mapPosition } , [
688+ h ( MapMarker , {
689+ setPosition : onSelectPosition ,
690+ } ) ,
691+ ] ) ,
692+
693+ // The Overlay Div
694+ overlay ,
695+ h ( ClickedCheckins , { setSelectedCheckin} ) ,
696+ ]
697+ ) ,
698+ ]
699+ ) ;
700+ }
701+
702+
703+ function ClickedCheckins ( { setSelectedCheckin} ) {
704+ const mapRef = useMapRef ( ) ;
705+ const map = mapRef . current ;
706+
707+ useEffect ( ( ) => {
708+ if ( ! map ) return ;
709+
710+ const handleClick = ( e ) => {
711+ const cluster = map . queryRenderedFeatures ( e . point , {
712+ layers : [ 'clusters' ]
713+ } ) ;
714+
715+ if ( cluster . length > 0 ) {
716+ const zoom = cluster [ 0 ] . properties . expansion_zoom ;
717+ console . log ( "cluster" , cluster [ 0 ] ) ;
718+
719+ console . log ( "zoom" , zoom ) ;
720+
721+ map . flyTo ( {
722+ center : cluster [ 0 ] . geometry . coordinates ,
723+ zoom : zoom + 2 ,
724+ speed : 0.5 ,
725+ } ) ;
726+ }
727+
728+ const features = map . queryRenderedFeatures ( e . point , {
729+ layers : [ 'unclustered-point' ]
730+ } ) ;
731+
732+ if ( features . length > 0 ) {
733+ const checkinId = features [ 0 ] . properties . id ;
734+
735+ // add marker
736+ const coord = features [ 0 ] . geometry . coordinates . slice ( ) ;
737+ console . log ( "coordinates" , coord ) ;
738+
739+ const el = document . createElement ( 'div' ) ;
740+ el . className = 'selected_pin' ;
741+
742+ new mapboxgl . Marker ( el )
743+ . setLngLat ( coord )
744+ . addTo ( map ) ;
745+
746+ console . log ( "data" , features [ 0 ] ) ;
747+ setSelectedCheckin ( checkinId ) ;
748+ } else {
749+ setSelectedCheckin ( null ) ;
750+ }
751+ } ;
752+
753+ map . on ( 'click' , handleClick ) ;
754+
755+ return ( ) => {
756+ map . off ( 'click' , handleClick ) ;
757+ } ;
758+ } , [ map ] ) ;
759+
760+ return null ;
761+ }
0 commit comments