Skip to content

Commit 864d1bc

Browse files
committed
Settings and filter show up
1 parent b94bee6 commit 864d1bc

File tree

2 files changed

+95
-101
lines changed

2 files changed

+95
-101
lines changed

pages/explore/+Page.client.ts

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import { useRockdAPI, Image, pageCarousel, createCheckins } from "~/components/g
1212
import "@macrostrat/style-system";
1313
import { MapPosition } from "@macrostrat/mapbox-utils";
1414
import { 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

2723
export 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+
}

pages/explore/map.client.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -9,94 +9,3 @@ import { mapboxAccessToken } from "@macrostrat-web/settings";
99
import mapboxgl from "mapbox-gl";
1010
import { useEffect } from "react";
1111
import { useMapRef } from "@macrostrat/mapbox-react";
12-
13-
export function WeaverMapContainer({style, mapPosition, onSelectPosition, setSelectedCheckin, overlay}) {
14-
// Ensure the mapbox access token is setconsole
15-
console.log("overla")
16-
17-
return h(
18-
"div.map-container",
19-
[
20-
// The Map Area Container
21-
h(
22-
MapAreaContainer,
23-
{
24-
className: "map-area-container",
25-
style: { "paddingLeft": "calc(30% + 14px)",},
26-
},
27-
[
28-
h(MapView, { style, mapboxToken: mapboxAccessToken, mapPosition }, [
29-
h(MapMarker, {
30-
setPosition: onSelectPosition,
31-
}),
32-
]),
33-
34-
// The Overlay Div
35-
overlay,
36-
h(ClickedCheckins, {setSelectedCheckin}),
37-
]
38-
),
39-
]
40-
);
41-
}
42-
43-
44-
function ClickedCheckins({setSelectedCheckin}) {
45-
const mapRef = useMapRef();
46-
const map = mapRef.current;
47-
48-
useEffect(() => {
49-
if (!map) return;
50-
51-
const handleClick = (e) => {
52-
const cluster = map.queryRenderedFeatures(e.point, {
53-
layers: ['clusters']
54-
});
55-
56-
if(cluster.length > 0) {
57-
const zoom = cluster[0].properties.expansion_zoom;
58-
console.log("cluster", cluster[0]);
59-
60-
console.log("zoom", zoom);
61-
62-
map.flyTo({
63-
center: cluster[0].geometry.coordinates,
64-
zoom: zoom + 2,
65-
speed: 0.5,
66-
});
67-
}
68-
69-
const features = map.queryRenderedFeatures(e.point, {
70-
layers: ['unclustered-point']
71-
});
72-
73-
if (features.length > 0) {
74-
const checkinId = features[0].properties.id;
75-
76-
// add marker
77-
const coord = features[0].geometry.coordinates.slice();
78-
console.log("coordinates", coord);
79-
80-
const el = document.createElement('div');
81-
el.className = 'selected_pin';
82-
83-
new mapboxgl.Marker(el)
84-
.setLngLat(coord)
85-
.addTo(map);
86-
87-
console.log("data", features[0]);
88-
setSelectedCheckin(checkinId);
89-
} else {
90-
setSelectedCheckin(null);
91-
}
92-
};
93-
94-
map.on('click', handleClick);
95-
96-
return () => {
97-
map.off('click', handleClick);
98-
};
99-
}, [map]);
100-
101-
return null;
102-
}

0 commit comments

Comments
 (0)