noahflk/railtrack

When navigating from another page to the dashboard the map doesn't center on the content

noahflk opened this issue · 2 comments

It only centers after manually reloading the page.

CleanShot.2022-12-11.at.23.39.23.mp4

I was able to fix this in two ways:

  • by wrapping this
    if (journeys.length !== 0) {
    const [minLng, minLat, maxLng, maxLat] = bbox(geoData);
    mapRef?.current?.fitBounds(
    [
    [minLng, minLat],
    [maxLng, maxLat],
    ],
    { padding: 60, duration: 0 }
    );
    }

    in useCallback and use it with onLoad
  • by using reuseMaps, the only problem with this solution is that Mapbox will remembers the last state of the map so if the user zoomed in/out or dragged the map it will remember that last position

@mocherfaoui thank you! Just commited a fix using the onLoad