I'm new to using React-leaflet. I want to getBounds of my GeoJSON but I don't figure out how.
I want to use it instead of [48.832,2.623], [48.900, 2.800] in my code.
<MapContainer
zoom={10}
scrollWheelZoom={false}
maxZoom={14}
center={[48.832,2.623]}
whenReady={e => {
mapRef = e.target;
e.target.flyToBounds([
[48.832,2.623],
[48.900, 2.800]
]);
}}
>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{data && (
<GeoJSON data={data}
style={style}
onEachFeature={onEachFeature} />
)}
</MapContainer>
In the V2 and V3 I see on other questions that we can use mapRef.leafletElement.getBounds()
But no longer in tha V4 because when I use it, have got an error of: Uncaught TypeError: Cannot read properties of undefined (reading 'getBounds')
I try with the answer of this question, but it doesn't work either
Can someone help me do it in the new version of react-leaflet please?