Spaces:
Runtime error
Runtime error
Commit
·
09cd743
1
Parent(s):
7982b5b
Make popups/markers in distance feature draggable
Browse files
frontend/src/components/Map.js
CHANGED
@@ -231,7 +231,8 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
231 |
});
|
232 |
const data = await res.json();
|
233 |
setGeoDistance(data.distance);
|
234 |
-
distanceCache.current[cacheKey] = data.distance; //
|
|
|
235 |
}
|
236 |
catch (err) {
|
237 |
console.error('Failed to fetch distance:', err);
|
@@ -340,7 +341,18 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
340 |
|
341 |
{/* Only show geodistance markers/polyline if sidebar is open */}
|
342 |
{geoSidebarOpen && geoPoints.map((pt, index) => (
|
343 |
-
<Marker key={`geo-${index}`}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
<Popup>
|
345 |
Point {index + 1}: {pt.lat.toFixed(4)}, {pt.lon.toFixed(4)}
|
346 |
</Popup>
|
|
|
231 |
});
|
232 |
const data = await res.json();
|
233 |
setGeoDistance(data.distance);
|
234 |
+
distanceCache.current[cacheKey] = data.distance; // Setting up the cache here, forgot it in first attempt.
|
235 |
+
console.log("Distance fetched via useEffect:", data.distance);
|
236 |
}
|
237 |
catch (err) {
|
238 |
console.error('Failed to fetch distance:', err);
|
|
|
341 |
|
342 |
{/* Only show geodistance markers/polyline if sidebar is open */}
|
343 |
{geoSidebarOpen && geoPoints.map((pt, index) => (
|
344 |
+
<Marker key={`geo-${index}`}
|
345 |
+
position={[pt.lat, pt.lon]}
|
346 |
+
draggable={true}
|
347 |
+
eventHandlers={{
|
348 |
+
dragend: (e) => {
|
349 |
+
const { lat, lng } = e.target.getLatLng();
|
350 |
+
const updated = [...geoPoints];
|
351 |
+
updated[index] = { lat, lon: lng };
|
352 |
+
setGeoPoints(updated); // Triggering the distance fetch via useEffect
|
353 |
+
}
|
354 |
+
}}
|
355 |
+
>
|
356 |
<Popup>
|
357 |
Point {index + 1}: {pt.lat.toFixed(4)}, {pt.lon.toFixed(4)}
|
358 |
</Popup>
|