Spaces:
Runtime error
Runtime error
Commit
·
2b18158
1
Parent(s):
09cd743
Make polyline vanish after distance marker gets dragged
Browse filesDistance marker gets dragged -> Polyline disppears -> Distane marker gets a new coordinate -> GeoPoints gets updated -> Distance api is triggered via api -> Polyline shows up with new distance results
frontend/src/components/Map.js
CHANGED
|
@@ -58,6 +58,8 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
| 58 |
const [geoSidebarOpen, setGeoSidebarOpen] = useState(false);
|
| 59 |
const [geoUnit, setGeoUnit] = useState('km');
|
| 60 |
|
|
|
|
|
|
|
| 61 |
const distanceCache = useRef({});
|
| 62 |
|
| 63 |
const handleMouseDown = (e) => {
|
|
@@ -345,12 +347,16 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
| 345 |
position={[pt.lat, pt.lon]}
|
| 346 |
draggable={true}
|
| 347 |
eventHandlers={{
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
}}
|
| 355 |
>
|
| 356 |
<Popup>
|
|
@@ -360,7 +366,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
| 360 |
))}
|
| 361 |
|
| 362 |
{/* Polyline if 2 points are selected and sidebar is open */}
|
| 363 |
-
{geoSidebarOpen && geoPoints.length === 2 && (
|
| 364 |
<Polyline
|
| 365 |
key={geoPoints.map(pt => `${pt.lat},${pt.lon}`).join('-')}
|
| 366 |
positions={generateGeodesicPoints(
|
|
|
|
| 58 |
const [geoSidebarOpen, setGeoSidebarOpen] = useState(false);
|
| 59 |
const [geoUnit, setGeoUnit] = useState('km');
|
| 60 |
|
| 61 |
+
const [isGeoMarkerDragging, setIsGeoMarkerDragging] = useState(false);
|
| 62 |
+
|
| 63 |
const distanceCache = useRef({});
|
| 64 |
|
| 65 |
const handleMouseDown = (e) => {
|
|
|
|
| 347 |
position={[pt.lat, pt.lon]}
|
| 348 |
draggable={true}
|
| 349 |
eventHandlers={{
|
| 350 |
+
dragstart: () => {
|
| 351 |
+
setIsGeoMarkerDragging(true);
|
| 352 |
+
},
|
| 353 |
+
dragend: (e) => {
|
| 354 |
+
const { lat, lng } = e.target.getLatLng();
|
| 355 |
+
const updated = [...geoPoints];
|
| 356 |
+
updated[index] = { lat, lon: lng };
|
| 357 |
+
setGeoPoints(updated); // Triggering the distance fetch via useEffect
|
| 358 |
+
setIsGeoMarkerDragging(false);
|
| 359 |
+
}
|
| 360 |
}}
|
| 361 |
>
|
| 362 |
<Popup>
|
|
|
|
| 366 |
))}
|
| 367 |
|
| 368 |
{/* Polyline if 2 points are selected and sidebar is open */}
|
| 369 |
+
{geoSidebarOpen && geoPoints.length === 2 && !isGeoMarkerDragging && (
|
| 370 |
<Polyline
|
| 371 |
key={geoPoints.map(pt => `${pt.lat},${pt.lon}`).join('-')}
|
| 372 |
positions={generateGeodesicPoints(
|