Spaces:
Runtime error
Runtime error
Commit
·
f86d829
1
Parent(s):
8db209d
Add slider to control zoom delay seconds in exploration mode
Browse files- User controls zoom delay duration (0-5 sec, with step of 1)
- If delay>0, use `flyToBounds`, else use `fitBounds`
frontend/src/components/Map.js
CHANGED
@@ -90,9 +90,10 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
90 |
const [explorationMarkers, setExplorationMarkers] = useState([]);
|
91 |
const [explorationSidebarOpen, setExplorationSidebarOpen] = useState(false);
|
92 |
const [shouldZoom, setShouldZoom] = useState(false);
|
|
|
93 |
|
94 |
// Using CenterMap component to handle centering (for summary/full apis) and for zooming (for wiki/nearby api)
|
95 |
-
const CenterMap = ({ position, coordinates, shouldZoom, setShouldZoom }) => {
|
96 |
const map = useMap();
|
97 |
useEffect(() => {
|
98 |
if (position && Array.isArray(position) && position.length === 2) {
|
@@ -104,14 +105,22 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
104 |
useEffect(() => {
|
105 |
if (coordinates && Array.isArray(coordinates) && coordinates.length > 1 && shouldZoom) {
|
106 |
const bounds = L.latLngBounds(coordinates);
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
setShouldZoom(false);
|
113 |
}
|
114 |
-
}, [coordinates, map, shouldZoom, setShouldZoom]);
|
115 |
|
116 |
return null;
|
117 |
};
|
@@ -616,6 +625,7 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
616 |
coordinates={explorationMarkers.map((marker) => marker.position)}
|
617 |
shouldZoom={shouldZoom}
|
618 |
setShouldZoom={setShouldZoom}
|
|
|
619 |
/>
|
620 |
{baseLayer === "satellite" && (
|
621 |
<>
|
@@ -1042,6 +1052,25 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
1042 |
</div>
|
1043 |
</div>
|
1044 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1045 |
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
1046 |
<input
|
1047 |
type="checkbox"
|
|
|
90 |
const [explorationMarkers, setExplorationMarkers] = useState([]);
|
91 |
const [explorationSidebarOpen, setExplorationSidebarOpen] = useState(false);
|
92 |
const [shouldZoom, setShouldZoom] = useState(false);
|
93 |
+
const [zoomDelaySeconds, setZoomDelaySeconds] = useState(3); // Default zoom delay in seconds
|
94 |
|
95 |
// Using CenterMap component to handle centering (for summary/full apis) and for zooming (for wiki/nearby api)
|
96 |
+
const CenterMap = ({ position, coordinates, shouldZoom, setShouldZoom, zoomDelaySeconds }) => {
|
97 |
const map = useMap();
|
98 |
useEffect(() => {
|
99 |
if (position && Array.isArray(position) && position.length === 2) {
|
|
|
105 |
useEffect(() => {
|
106 |
if (coordinates && Array.isArray(coordinates) && coordinates.length > 1 && shouldZoom) {
|
107 |
const bounds = L.latLngBounds(coordinates);
|
108 |
+
console.log("Delay:", zoomDelaySeconds);
|
109 |
+
if (zoomDelaySeconds > 0) {
|
110 |
+
map.flyToBounds(bounds, {
|
111 |
+
padding: [50, 50],
|
112 |
+
maxZoom: 16,
|
113 |
+
duration: zoomDelaySeconds
|
114 |
+
});
|
115 |
+
} else {
|
116 |
+
map.fitBounds(bounds, {
|
117 |
+
padding: [50, 50],
|
118 |
+
maxZoom: 16
|
119 |
+
});
|
120 |
+
}
|
121 |
setShouldZoom(false);
|
122 |
}
|
123 |
+
}, [coordinates, map, shouldZoom, setShouldZoom, zoomDelaySeconds]);
|
124 |
|
125 |
return null;
|
126 |
};
|
|
|
625 |
coordinates={explorationMarkers.map((marker) => marker.position)}
|
626 |
shouldZoom={shouldZoom}
|
627 |
setShouldZoom={setShouldZoom}
|
628 |
+
zoomDelaySeconds={zoomDelaySeconds}
|
629 |
/>
|
630 |
{baseLayer === "satellite" && (
|
631 |
<>
|
|
|
1052 |
</div>
|
1053 |
</div>
|
1054 |
|
1055 |
+
|
1056 |
+
<div>
|
1057 |
+
<label style={{ fontWeight: 500, marginBottom: 8, display: 'block' }}>
|
1058 |
+
Zoom Delay (seconds):
|
1059 |
+
</label>
|
1060 |
+
<input
|
1061 |
+
type="range"
|
1062 |
+
min="0"
|
1063 |
+
max="5"
|
1064 |
+
step="1"
|
1065 |
+
value={zoomDelaySeconds}
|
1066 |
+
onChange={(e) => setZoomDelaySeconds(parseInt(e.target.value))}
|
1067 |
+
style={{ width: '100%' }}
|
1068 |
+
/>
|
1069 |
+
<div style={{ textAlign: 'center', marginTop: 4 }}>
|
1070 |
+
{zoomDelaySeconds} sec. zoom duration
|
1071 |
+
</div>
|
1072 |
+
</div>
|
1073 |
+
|
1074 |
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
1075 |
<input
|
1076 |
type="checkbox"
|