Calculate viewport bounds when searching for a place #543
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #389 .
Center is in Mercator space, thanks to Ethan for explaining how to get it in #389 (comment) .
getZoom and getBoundsForScreenSize are AI generated and appear to work. I don't quite understand especially the project/unproject helper functions and their relation to latLngToMercator/mercatorToLatLng .
I could check that the centre works by logging the bounds used, as well as google's getBounds() in src/redux/mapSlice.js .
To check center, I compared the calculated center to fitBounds + getCenter.
For zoom, I just checked a few examples at a few different scales and it matched - I originally had the zoom wrong and I've dismantled the testing jig that logged values for me. Can't be too far off!
As a bonus I've found a bug in the API when testing something - falling-fruit/falling-fruit-api#43 - but then I've realised I used the wrong code for calculating bounds (the implementation with padding around the viewport did not seem to correctly work, but getting the bounds for zoom + center + width + height seems to be reliable).