Skip to content

Commit 7565df9

Browse files
authored
Merge pull request #260 from UW-Macrostrat/user_features
User features - saved locations
2 parents b92882e + dc6afd9 commit 7565df9

File tree

5 files changed

+36
-79
lines changed

5 files changed

+36
-79
lines changed

pages/dev/map/saved-locations/+Page.client.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
} from "@macrostrat/map-interface";
1919
import hyper from "@macrostrat/hyper";
2020
import styles from "./main.module.sass";
21-
import { DetailsPanel } from "./details-panel";
22-
import Legend from "./legend-text.mdx";
21+
import { DetailsPanel, SpotsPanel } from "./details-panel";
2322
import { useInDarkMode } from "@macrostrat/ui-components";
2423
import { usePageContext } from "vike-react/usePageContext";
2524
import {
@@ -36,7 +35,7 @@ const baseURL = "/dev/map/saved-locations";
3635

3736
export function Page() {
3837
const [inspectPosition, onSelectPosition] = useMapLocationManager();
39-
38+
const [mapInstance, setMapInstance] = useState(null);
4039
const style = useSavedLocationsStyle();
4140
const inDarkMode = useInDarkMode();
4241

@@ -58,8 +57,10 @@ export function Page() {
5857
contextPanel: h(
5958
PanelCard,
6059
{ className: "context-panel" },
61-
h(Legend, {
60+
h(SpotsPanel, {
6261
colors: getColors(inDarkMode),
62+
onSelectPosition,
63+
map: mapInstance,
6364
})
6465
),
6566
detailPanel: h(DetailsPanel, {
@@ -79,6 +80,7 @@ export function Page() {
7980
mapboxToken: mapboxAccessToken,
8081
mapPosition: inspectPosition,
8182
bounds: [-125, 24, -66, 49],
83+
onMapLoaded: (map) => setMapInstance(map),
8284
onMapMoved(pos, map) {
8385
setURL(inspectPosition, map);
8486
},
@@ -129,6 +131,13 @@ function useMapLocationManager(): [MapPosition, PositionBuilder] {
129131
(position: mapboxgl.LngLat | null, map: mapboxgl.Map | undefined) => {
130132
setInspectPosition(position);
131133
setURL(position, map);
134+
if (map) {
135+
console.log("MAP!!", map)
136+
map.flyTo({
137+
center: [position.lng, position.lat],
138+
zoom: position.zoom || 12,
139+
});
140+
}
132141
},
133142
[]
134143
);
@@ -155,7 +164,7 @@ function setURL(position: mapboxgl.LngLat, map: mapboxgl.Map) {
155164

156165
function buildHashParams(map, selectedPosition) {
157166
if (selectedPosition == null) return "";
158-
const z = map.getZoom();
167+
const z = map.getZoom() ?? 7;
159168
// Parse hash and add zoom level
160169
let q = new URLSearchParams(window.location.hash.slice(1));
161170
q.set("z", z.toFixed(0));

pages/dev/map/saved-locations/details-panel.ts

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { getColors } from "#/dev/map/rockd-strabospot/map-style";
1010
import { useInDarkMode } from "@macrostrat/ui-components";
1111
import { SaveLocationForm } from "./save-location";
12+
import mapboxgl from "mapbox-gl";
1213
import React, { useState, useEffect } from "react";
1314

1415

@@ -17,7 +18,7 @@ import React, { useState, useEffect } from "react";
1718
const h = hyper.styled(styles);
1819
export function DetailsPanel({ position, nearbyFeatures, onClose }) {
1920
if (position == null) return null;
20-
let count = 22;
21+
let count = 24;
2122

2223
return h(
2324
LocationPanel,
@@ -26,34 +27,13 @@ export function DetailsPanel({ position, nearbyFeatures, onClose }) {
2627
position,
2728
},
2829
[
29-
h(SaveLocationForm, { position, count }),
30-
//h(CheckinsPanel, { nearbyFeatures }),
31-
h(SpotsPanel, {
32-
nearbyFeatures,
33-
}),
30+
h(SaveLocationForm, { position, count })
31+
//h(CheckinsPanel, { nearbyFeatures })
3432
]
3533
);
3634
}
3735

38-
//implement tileserver api to reorient user to an exact location
39-
/*
40-
export function CheckinsPanel({ nearbyFeatures }) {
41-
const checkins = useNearbyCheckins(nearbyFeatures);
42-
const titleComponent = () =>
43-
h(PanelHeader, {
44-
title: "Checkins",
45-
sourceLink: h(SystemLink, { href: "https://rockd.org" }, "Rockd"),
46-
hasData: checkins.length != 0,
47-
});
48-
49-
return h(FeatureTypePanel, {
50-
features: checkins,
51-
titleComponent,
52-
featureComponent: CheckinFeature,
53-
});
54-
}
55-
*/
56-
export function SpotsPanel({ nearbyFeatures }) {
36+
export function SpotsPanel({ onSelectPosition, map }) {
5737
const [features, setFeatures] = useState([]); // State to store features
5838
const [loading, setLoading] = useState(true); // State to track loading
5939
const [error, setError] = useState(null); // State to track errors
@@ -79,11 +59,19 @@ export function SpotsPanel({ nearbyFeatures }) {
7959
fetchFeatures();
8060
}, []);
8161

82-
console.log("features!!", features)
83-
84-
const FeatureComponent = ({ data }) => {
62+
const FeatureComponent = ({ data, onSelectPosition, map }) => {
63+
const handleLinkClick = () => {
64+
if (onSelectPosition) {
65+
onSelectPosition({ lng: data.longitude, lat: data.latitude, zoom: 7 }, map);
66+
}
67+
};
8568
return h("div.feature", [
86-
h("h3.feature-title", data.location_name),
69+
h("h3.feature-title",
70+
{
71+
style: { cursor: "pointer", textDecoration: "bold", color: "purple" }, // Optional styling for a clickable look
72+
onClick: handleLinkClick,
73+
},
74+
data.location_name),
8775
h("p.feature-description", data.location_description),
8876
h("p.feature-coordinates", [
8977
`Latitude: ${data.latitude}, Longitude: ${data.longitude}`,
@@ -107,7 +95,7 @@ export function SpotsPanel({ nearbyFeatures }) {
10795
titleComponent,
10896
loading,
10997
error,
110-
featureComponent: FeatureComponent,
98+
featureComponent: (props) => h(FeatureComponent, { ...props, onSelectPosition, map }),
11199
});
112100
}
113101

@@ -166,40 +154,6 @@ function SystemLink({ href, children }) {
166154
]);
167155
}
168156

169-
export function LegendList() {
170-
const darkMode = useInDarkMode();
171-
const colors = getColors(darkMode);
172-
return h("ul.legend-list", [
173-
h(
174-
LegendItem,
175-
{
176-
color: colors.checkins,
177-
name: "My saved locations",
178-
},
179-
"Will show the user locations on the map. Need to build it within the tileserver."
180-
),
181-
]);
182-
}
183-
184-
function LegendItem({ color, name, sourceLink, children }) {
185-
let child = children;
186-
if (typeof children === "string") {
187-
child = h("p.description", children);
188-
}
189-
190-
return h("li.legend-item", [
191-
h(LegendHeader, { color, name, sourceLink }),
192-
h("div.legend-body", child),
193-
]);
194-
}
195-
196-
function LegendHeader({ color, name, sourceLink = null }) {
197-
return h("div.legend-header", [
198-
h(Swatch, { color }),
199-
h("h4", name),
200-
sourceLink,
201-
]);
202-
}
203157

204158
function Swatch({ color }) {
205159
return h("span.swatch", { style: { backgroundColor: color } });

pages/dev/map/saved-locations/legend-text.mdx

Lines changed: 0 additions & 9 deletions
This file was deleted.

pages/dev/map/saved-locations/main.module.sass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
color: var(--secondary-color)
5151

5252
.context-panel
53+
overflow-y: auto
54+
max-height: 100vh
55+
width: fit-content
5356

5457
h3
5558
margin-bottom: 0.5em

pages/dev/map/saved-locations/save-location.module.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
max-width: 180px
4242

4343
select
44-
max-width: 100px
44+
max-width: 140px
4545
font-size: 0.9em
4646

4747
.button-container

0 commit comments

Comments
 (0)