Spaces:
Runtime error
Runtime error
Commit
·
662d63b
1
Parent(s):
09eff05
Added autozoom for nearby api, animation for zoom
Browse files- Man, it's really beautiful the way it zooms in just the right amount after the api is hit.
- Added autozoom for nearby api as well added animation (3 seconds) for the zooming process.
frontend/src/components/Map.js
CHANGED
@@ -87,14 +87,29 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
87 |
const [explorationLimit, setExplorationLimit] = useState(10);
|
88 |
const [explorationMarkers, setExplorationMarkers] = useState([]);
|
89 |
const [explorationSidebarOpen, setExplorationSidebarOpen] = useState(false);
|
|
|
90 |
|
91 |
-
|
|
|
92 |
const map = useMap();
|
93 |
useEffect(() => {
|
94 |
if (position && Array.isArray(position) && position.length === 2) {
|
95 |
map.setView(position, map.getZoom());
|
96 |
}
|
97 |
}, [map, position]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
return null;
|
99 |
};
|
100 |
|
@@ -246,6 +261,7 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
246 |
},
|
247 |
...markers
|
248 |
]);
|
|
|
249 |
console.log(`Found ${markers.length} nearby pages`); // Only backend results.
|
250 |
} else {
|
251 |
console.error('Failed to fetch nearby pages');
|
@@ -592,7 +608,11 @@ const Map = ( { onMapClick, searchQuery, contentType, setSearchQuery, setSubmitt
|
|
592 |
<ScaleControl position="bottomright" imperial={true} />
|
593 |
|
594 |
<ResizeHandler trigger={wikiWidth} />
|
595 |
-
<CenterMap
|
|
|
|
|
|
|
|
|
596 |
{baseLayer === "satellite" && (
|
597 |
<>
|
598 |
<TileLayer
|
|
|
87 |
const [explorationLimit, setExplorationLimit] = useState(10);
|
88 |
const [explorationMarkers, setExplorationMarkers] = useState([]);
|
89 |
const [explorationSidebarOpen, setExplorationSidebarOpen] = useState(false);
|
90 |
+
const [shouldZoom, setShouldZoom] = useState(false);
|
91 |
|
92 |
+
// Using CenterMap component to handle centering (for summary/full apis) and for zooming (for wiki/nearby api)
|
93 |
+
const CenterMap = ({ position, coordinates, shouldZoom }) => {
|
94 |
const map = useMap();
|
95 |
useEffect(() => {
|
96 |
if (position && Array.isArray(position) && position.length === 2) {
|
97 |
map.setView(position, map.getZoom());
|
98 |
}
|
99 |
}, [map, position]);
|
100 |
+
|
101 |
+
|
102 |
+
useEffect(() => {
|
103 |
+
if (coordinates && Array.isArray(coordinates) && coordinates.length > 0 && shouldZoom) {
|
104 |
+
const bounds = L.latLngBounds(coordinates);
|
105 |
+
map.flyToBounds(bounds, {
|
106 |
+
padding: [50, 50],
|
107 |
+
maxZoom: 16,
|
108 |
+
duration: 3
|
109 |
+
});
|
110 |
+
}
|
111 |
+
}, [coordinates, map, shouldZoom]);
|
112 |
+
|
113 |
return null;
|
114 |
};
|
115 |
|
|
|
261 |
},
|
262 |
...markers
|
263 |
]);
|
264 |
+
setShouldZoom(true);
|
265 |
console.log(`Found ${markers.length} nearby pages`); // Only backend results.
|
266 |
} else {
|
267 |
console.error('Failed to fetch nearby pages');
|
|
|
608 |
<ScaleControl position="bottomright" imperial={true} />
|
609 |
|
610 |
<ResizeHandler trigger={wikiWidth} />
|
611 |
+
<CenterMap
|
612 |
+
position={markerPosition}
|
613 |
+
coordinates={explorationMarkers.map((marker) => marker.position)}
|
614 |
+
shouldZoom={shouldZoom}
|
615 |
+
/>
|
616 |
{baseLayer === "satellite" && (
|
617 |
<>
|
618 |
<TileLayer
|