Set bounds on map init

This commit is contained in:
Timothy Armes
2023-07-05 16:29:50 +02:00
parent 67a6bcd365
commit caaad4e229
+7
View File
@@ -31,6 +31,7 @@ const MapEvents = () => {
export default function TournamentMap() { export default function TournamentMap() {
const tournaments = useAtomValue(tournamentsAtom); const tournaments = useAtomValue(tournamentsAtom);
const setMapBounds = useSetAtom(mapBoundsAtom);
const center: LatLngLiteral = { lat: 47.0844, lng: 2.3964 }; const center: LatLngLiteral = { lat: 47.0844, lng: 2.3964 };
const createLayerGroups = ( const createLayerGroups = (
@@ -64,6 +65,7 @@ export default function TournamentMap() {
"green", "green",
tournaments tournaments
); );
const rapidMarkers = createLayerGroups("Rapide", "blue", tournaments); const rapidMarkers = createLayerGroups("Rapide", "blue", tournaments);
const blitzMarkers = createLayerGroups("Blitz", "yellow", tournaments); const blitzMarkers = createLayerGroups("Blitz", "yellow", tournaments);
const otherMarkers = createLayerGroups("1h KO", "red", tournaments); const otherMarkers = createLayerGroups("1h KO", "red", tournaments);
@@ -77,6 +79,11 @@ export default function TournamentMap() {
style={{ style={{
height: "100%", height: "100%",
}} }}
ref={(map) => {
if (map) {
setMapBounds(map.getBounds());
}
}}
> >
<MapEvents /> <MapEvents />
<TileLayer <TileLayer