-
-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fitBounds
broken
#5375
Comments
Thanks for taking the time to report this issue! map.fitBounds([
[9.031869499999999, 46.8322365],
[9.289097166666666, 47.19989433333333]
], {
padding: 50,
maxZoom: 14,
}); |
The docs says A LngLatBounds object, an array of LngLatLike objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order. so I guess you are right. But the change in behavior is still a bit inconvenient when updating the MapLibre version. If I understand correctly the old behavior was give me two points and I will make the map show both. So not exactly bounds but very convenient... |
If I take two points and put them in an order, they might have one of the following four meanings for bounding box corners
If only the first option should be given to fitBounds, how can I convert the other 3 to the first? |
OK I can just do this myself with something like this: const getBoundingBox = (point1, point2) => {
const [lng1, lat1] = point1;
const [lng2, lat2] = point2;
const sw = [Math.min(lng1, lng2), Math.min(lat1, lat2)];
const ne = [Math.max(lng1, lng2), Math.max(lat1, lat2)];
return [sw, ne];
}; and then I call map.fitBounds(getBoundingBox(point1, point2)); That gives me roughly the v4.6.0 behavior I think. |
Exactly. |
Feel free to close this issue @HarelM. But maybe we can add a link to this workaround in the changelog. What do you think? |
I think adding some code example is a better approach, or adding an example in the examples with this code and linking to it. |
But then again the above function does not work across the antimeridian. So tricky... |
maplibre-gl-js version: 4.7.0
browser: chrome on ubuntu
Link to Demonstration
Correct behavior in v4.6.0:
https://jsbin.com/rexiseyeve/1/edit?html,output
Broken behavior in v4.7.0 (zooms to wrong location):
https://jsbin.com/ninokegeto/edit?html,output
Expected Behavior
Should zoom to bounds
Actual Behavior
Zooms somewhere else, maybe the antimeridian?
Probably related to #4620
The text was updated successfully, but these errors were encountered: