Spaces:
Runtime error
Runtime error
Commit
·
ab8ba8e
1
Parent(s):
8b80ab0
Make distance feature an option within the GeoTools sidebar
Browse filesEarlier distance feature was the default option, when you clicked on the map, the distance function started working. Not ideal. Now you click on GeoTools, select "Measure distane", then only the distance feature will work. Planning to add more geo features.
- frontend/src/components/Map.js +99 -54
frontend/src/components/Map.js
CHANGED
@@ -56,6 +56,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
56 |
const [geoDistance, setGeoDistance] = useState(null);
|
57 |
|
58 |
const [geoSidebarOpen, setGeoSidebarOpen] = useState(false);
|
|
|
59 |
const [geoUnit, setGeoUnit] = useState('km');
|
60 |
|
61 |
const [isGeoMarkerDragging, setIsGeoMarkerDragging] = useState(false);
|
@@ -350,7 +351,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
350 |
)}
|
351 |
|
352 |
{/* Only show geodistance markers/polyline if sidebar is open */}
|
353 |
-
{geoSidebarOpen && geoPoints.map((pt, index) => (
|
354 |
<Marker key={`geo-${index}`}
|
355 |
position={[pt.lat, pt.lon]}
|
356 |
draggable={true}
|
@@ -380,7 +381,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
380 |
))}
|
381 |
|
382 |
{/* Polyline if 2 points are selected and sidebar is open */}
|
383 |
-
{geoSidebarOpen && geoPoints.length === 2 && (
|
384 |
<Polyline
|
385 |
key={geoPoints.map(pt => `${pt.lat},${pt.lon}`).join('-')}
|
386 |
positions={generateGeodesicPoints(
|
@@ -453,59 +454,103 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
453 |
gap: 16,
|
454 |
border: '1px solid #eee'
|
455 |
}}>
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
)}
|
490 |
-
<button
|
491 |
-
onClick={() => {
|
492 |
-
setGeoSidebarOpen(false);
|
493 |
-
setGeoPoints([]);
|
494 |
-
setGeoDistance(null);
|
495 |
-
}}
|
496 |
-
style={{
|
497 |
-
marginTop: 8,
|
498 |
-
padding: '6px 0',
|
499 |
-
borderRadius: 4,
|
500 |
-
border: '1px solid #1976d2',
|
501 |
-
background: '#1976d2',
|
502 |
-
color: 'white',
|
503 |
-
fontWeight: 500,
|
504 |
-
cursor: 'pointer'
|
505 |
-
}}
|
506 |
-
>
|
507 |
-
Clear & Collapse
|
508 |
-
</button>
|
509 |
</div>
|
510 |
)}
|
511 |
|
|
|
56 |
const [geoDistance, setGeoDistance] = useState(null);
|
57 |
|
58 |
const [geoSidebarOpen, setGeoSidebarOpen] = useState(false);
|
59 |
+
const [geoToolMode, setGeoToolMode] = useState("menu"); // "menu" | "distance"
|
60 |
const [geoUnit, setGeoUnit] = useState('km');
|
61 |
|
62 |
const [isGeoMarkerDragging, setIsGeoMarkerDragging] = useState(false);
|
|
|
351 |
)}
|
352 |
|
353 |
{/* Only show geodistance markers/polyline if sidebar is open */}
|
354 |
+
{geoSidebarOpen && geoToolMode === "distance" && geoPoints.map((pt, index) => (
|
355 |
<Marker key={`geo-${index}`}
|
356 |
position={[pt.lat, pt.lon]}
|
357 |
draggable={true}
|
|
|
381 |
))}
|
382 |
|
383 |
{/* Polyline if 2 points are selected and sidebar is open */}
|
384 |
+
{geoSidebarOpen && geoToolMode === "distance" && geoPoints.length === 2 && (
|
385 |
<Polyline
|
386 |
key={geoPoints.map(pt => `${pt.lat},${pt.lon}`).join('-')}
|
387 |
positions={generateGeodesicPoints(
|
|
|
454 |
gap: 16,
|
455 |
border: '1px solid #eee'
|
456 |
}}>
|
457 |
+
{geoToolMode === "menu" && (
|
458 |
+
<>
|
459 |
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
460 |
+
<strong>Geo Tools</strong>
|
461 |
+
<button
|
462 |
+
onClick={() => {
|
463 |
+
setGeoSidebarOpen(false);
|
464 |
+
setGeoPoints([]);
|
465 |
+
setGeoDistance(null);
|
466 |
+
setGeoToolMode("menu");
|
467 |
+
}}
|
468 |
+
style={{
|
469 |
+
background: 'none',
|
470 |
+
border: 'none',
|
471 |
+
fontSize: 18,
|
472 |
+
cursor: 'pointer',
|
473 |
+
color: '#888'
|
474 |
+
}}
|
475 |
+
title="Close"
|
476 |
+
>×</button>
|
477 |
+
</div>
|
478 |
+
<button
|
479 |
+
style={{
|
480 |
+
marginTop: 16,
|
481 |
+
padding: '10px 0',
|
482 |
+
borderRadius: 4,
|
483 |
+
border: '1px solid #1976d2',
|
484 |
+
background: '#1976d2',
|
485 |
+
color: 'white',
|
486 |
+
fontWeight: 500,
|
487 |
+
cursor: 'pointer'
|
488 |
+
}}
|
489 |
+
onClick={() => setGeoToolMode("distance")}
|
490 |
+
>
|
491 |
+
Measure distance
|
492 |
+
</button>
|
493 |
+
{/* Add more tool buttons here in the future */}
|
494 |
+
</>
|
495 |
+
)}
|
496 |
+
|
497 |
+
{geoToolMode === "distance" && (
|
498 |
+
<>
|
499 |
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
500 |
+
<strong>Geodistance</strong>
|
501 |
+
<button
|
502 |
+
onClick={() => {
|
503 |
+
setGeoToolMode("menu");
|
504 |
+
setGeoPoints([]);
|
505 |
+
setGeoDistance(null);
|
506 |
+
}}
|
507 |
+
style={{
|
508 |
+
background: 'none',
|
509 |
+
border: 'none',
|
510 |
+
fontSize: 18,
|
511 |
+
cursor: 'pointer',
|
512 |
+
color: '#888'
|
513 |
+
}}
|
514 |
+
title="Back"
|
515 |
+
>←</button>
|
516 |
+
</div>
|
517 |
+
<div>
|
518 |
+
<label style={{ fontWeight: 500, marginRight: 8 }}>Unit:</label>
|
519 |
+
<select
|
520 |
+
value={geoUnit}
|
521 |
+
onChange={e => setGeoUnit(e.target.value)}
|
522 |
+
style={{ padding: '4px 8px', borderRadius: 4, border: '1px solid #ccc' }}
|
523 |
+
>
|
524 |
+
<option value="km">Kilometers</option>
|
525 |
+
<option value="mi">Miles</option>
|
526 |
+
</select>
|
527 |
+
</div>
|
528 |
+
{geoDistance !== null && (
|
529 |
+
<div style={{ fontSize: 20, fontWeight: 600, color: '#1976d2' }}>
|
530 |
+
{geoDistance.toFixed(2)} {geoUnit}
|
531 |
+
</div>
|
532 |
+
)}
|
533 |
+
<button
|
534 |
+
onClick={() => {
|
535 |
+
setGeoToolMode("menu");
|
536 |
+
setGeoPoints([]);
|
537 |
+
setGeoDistance(null);
|
538 |
+
}}
|
539 |
+
style={{
|
540 |
+
marginTop: 8,
|
541 |
+
padding: '6px 0',
|
542 |
+
borderRadius: 4,
|
543 |
+
border: '1px solid #1976d2',
|
544 |
+
background: '#1976d2',
|
545 |
+
color: 'white',
|
546 |
+
fontWeight: 500,
|
547 |
+
cursor: 'pointer'
|
548 |
+
}}
|
549 |
+
>
|
550 |
+
Clear & Back
|
551 |
+
</button>
|
552 |
+
</>
|
553 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
</div>
|
555 |
)}
|
556 |
|