Skip to content

Commit 91b2284

Browse files
committed
featured checkins updates on move
1 parent c970ca6 commit 91b2284

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

pages/dev/test-site/explore/+Page.client.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useCallback, useEffect, useState } from "react";
2222
import { tileserverDomain } from "@macrostrat-web/settings";
2323
import "./main.styl";
2424
import { BlankImage, Image } from "../index";
25+
import { set } from "react-datepicker/dist/date_utils";
2526

2627
export function Page() {
2728
return h(
@@ -119,47 +120,29 @@ function FeatureDetails() {
119120
let checkins = [];
120121
let result;
121122

123+
122124

123125

124126
if(mapRef == null) {
125127
result = getCheckins(0, 100, 0, 100);
126128
} else {
127129
let map = mapRef.current;
128-
let bounds = map?.getBounds();
130+
131+
const [bounds, setBounds] = useState(map.getBounds());
129132

130133
// change use map coords
131134
result = getCheckins(bounds.getSouth(), bounds.getNorth(), bounds.getEast(), bounds.getWest());
132135

133-
// Define thresholds for movement
134-
const MOVE_THRESHOLD = 0.5; // 0.1 degrees change in center
135-
const ZOOM_THRESHOLD = 1; // 0.5 zoom level change
136-
137-
let lastCenter = map.getCenter();
138-
let lastZoom = map.getZoom();
139-
140-
// Attach the 'move' event listener with thresholding
141-
map.on('move', () => {
142-
const currentCenter = map.getCenter();
143-
const currentZoom = map.getZoom();
144-
145-
// Calculate the distance between last and current center coordinates
146-
const distance = Math.sqrt(
147-
Math.pow(currentCenter.lng - lastCenter.lng, 2) + Math.pow(currentCenter.lat - lastCenter.lat, 2)
148-
);
149-
150-
// Check if movement exceeds the threshold for position or zoom
151-
if (distance > MOVE_THRESHOLD || Math.abs(currentZoom - lastZoom) > ZOOM_THRESHOLD) {
152-
console.log('Map has moved significantly!');
153-
let bounds = mapRef.current?.getBounds();
154-
155-
// change use map coords
156-
// result = getCheckins(bounds.getSouth(), bounds.getNorth(), bounds.getEast(), bounds.getWest());
157-
158-
// Update the last known values
159-
lastCenter = currentCenter;
160-
lastZoom = currentZoom;
161-
}
162-
});
136+
// Update bounds on move
137+
useEffect(() => {
138+
const listener = () => {
139+
setBounds(map.getBounds());
140+
};
141+
map.on("moveend", listener);
142+
return () => {
143+
map.off("moveend", listener);
144+
};
145+
}, [bounds]);
163146
}
164147

165148
if (result == null) return h(Spinner);

0 commit comments

Comments
 (0)