@@ -118,8 +118,8 @@ function FeatureDetails() {
118118 let checkins = [];
119119 let result;
120120
121- if(mapRef == null ) {
122- result = getCheckins(0, 100, 0, 100);
121+ if(! mapRef.current ) {
122+ return h(Spinner)
123123 } else {
124124 let map = mapRef.current;
125125
@@ -241,15 +241,19 @@ function WeaverMap({
241241
242242 const [featuredCheckins, setFeaturedCheckin] = useState(h(Spinner));
243243
244+ // overlay
245+ const [isOpenSelected, setOpenSelected] = useState(true);
246+
244247 const [inspectPosition, setInspectPosition] =
245248 useState<mapboxgl.LngLat | null>(null);
246249
247250 const onSelectPosition = useCallback((position: mapboxgl.LngLat) => {
248251 setInspectPosition(position);
252+ setOpenSelected(true);
249253 }, []);
250254
251255 let detailElement = null;
252- let selectedCheckin = h('h1', { className: 'no-checkins' }, "No Checkin(s) Selected") ;
256+ let selectedCheckin = null ;
253257 let result = getCheckins(inspectPosition?.lat - .05, inspectPosition?.lat + .05, inspectPosition?.lng - .05, inspectPosition?.lng + .05);
254258 if (inspectPosition != null) {
255259 detailElement = h(
@@ -266,15 +270,28 @@ function WeaverMap({
266270 selectedCheckin = getSelectedCheckins(result);
267271 }
268272
269- // TODO: have run depend on changing mapRef
270273 let featuredCheckin = h(FeatureDetails);
274+ let overlay;
271275
272- let overlay = h(
273- "div.overlay-div",
274- [
275- h(ExpansionPanel, {title: "Selected Checkins"}, selectedCheckin),
276- h(ExpansionPanel, {title: "Featured Checkins"}, featuredCheckin),
276+ if (selectedCheckin == null || !isOpenSelected) {
277+ overlay = h("div.sidebox", [
278+ h('div.title', h("h1", "Featured Checkins")),
279+ h("div.overlay-div", featuredCheckin),
277280 ]);
281+ } else {
282+ overlay = h("div.sidebox", [
283+ h('div.title', [
284+ h("h1", "Selected Checkins"),
285+ h('h3', { className: "coordinates" }, formatCoordinates(inspectPosition.lat, inspectPosition.lng)),
286+ ]),
287+ h("button", {
288+ className: "close-btn",
289+ onClick: () => setOpenSelected(false)
290+ }, "X"),
291+ h("div.overlay-div", selectedCheckin)
292+ ]);
293+ }
294+
278295
279296 if(style == null) return null;
280297
@@ -346,4 +363,16 @@ function useMapStyle(type, mapboxToken) {
346363 }, []);
347364
348365 return actualStyle;
366+ }
367+
368+ function formatCoordinates(latitude, longitude) {
369+ // Round latitude and longitude to 4 decimal places
370+ const roundedLatitude = latitude.toFixed(4);
371+ const roundedLongitude = longitude.toFixed(4);
372+
373+ const latitudeDirection = latitude >= 0 ? 'N' : 'S';
374+ const longitudeDirection = longitude >= 0 ? 'E' : 'W';
375+
376+ // Return the formatted string with rounded values
377+ return `${Math.abs(roundedLatitude)}° ${latitudeDirection}, ${Math.abs(roundedLongitude)}° ${longitudeDirection}`;
349378}
0 commit comments