DebasishDhal99 commited on
Commit
09cd743
·
1 Parent(s): 7982b5b

Make popups/markers in distance feature draggable

Browse files
Files changed (1) hide show
  1. frontend/src/components/Map.js +14 -2
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; // Using cachig here, forgot it in first attempt.
 
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}`} position={[pt.lat, pt.lon]}>
 
 
 
 
 
 
 
 
 
 
 
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>