@@ -11,7 +11,7 @@ import { distance } from "fastest-levenshtein";
1111import type { FeatureCollection } from "geojson" ;
1212import "maplibre-gl/dist/maplibre-gl.css" ;
1313import { useMemo , useRef , useState } from "react" ;
14- import type { MapRef , StyleSpecification } from "react-map-gl/maplibre" ;
14+ import type { LngLatBoundsLike , MapRef , StyleSpecification } from "react-map-gl/maplibre" ;
1515import { AttributionControl , Map as MaplibreMap } from "react-map-gl/maplibre" ;
1616import { Mode } from "../enums" ;
1717import { shuffle } from "../utils/ArrayUtils" ;
@@ -49,10 +49,12 @@ export default function CityMapQuiz({ data, datasetName, onResetGame }: Props) {
4949
5050 const currentFeatureId = featureIds [ featureIds . length - 1 ] ;
5151 const currentFeature = data . features . find ( item => item . id === currentFeatureId ) || data ;
52- const [ initialMinLng , initialMinLat , initialMaxLng , initialMaxLat ] = bbox ( transformScale ( currentFeature , 0.65 ) ) ;
53- const [ minLng , minLat , maxLng , maxLat ] = bbox ( transformScale ( currentFeature , 2 ) ) ;
54- mapRef . current ?. fitBounds ( [ initialMinLng , initialMinLat , initialMaxLng , initialMaxLat ] , { padding : 0 , duration : 1000 } ) ;
55- mapRef . current ?. getMap ( ) . setMaxBounds ( [ minLng , minLat , maxLng , maxLat ] ) ;
52+
53+ // setMaxBounds must be called before fitBounds
54+ const maxBounds = bbox ( transformScale ( currentFeature , 2 ) ) as LngLatBoundsLike ;
55+ mapRef . current ?. getMap ( ) . setMaxBounds ( maxBounds ) ;
56+ const initialBounds = bbox ( transformScale ( currentFeature , 0.65 ) ) as LngLatBoundsLike ;
57+ mapRef . current ?. fitBounds ( initialBounds , { padding : 0 , duration : 1500 } ) ;
5658
5759 const handleTextInput = ( input : string ) => {
5860 setUserGuess ( input ) ;
@@ -79,9 +81,9 @@ export default function CityMapQuiz({ data, datasetName, onResetGame }: Props) {
7981 < div className = "h-screen flex items-center justify-center" >
8082 < MaplibreMap
8183 initialViewState = { {
82- bounds : [ initialMinLng , initialMinLat , initialMaxLng , initialMaxLat ]
84+ bounds : initialBounds
8385 } }
84- maxBounds = { [ minLng , minLat , maxLng , maxLat ] }
86+ maxBounds = { maxBounds }
8587 doubleClickZoom = { false }
8688 dragRotate = { false }
8789 touchPitch = { false }
0 commit comments