mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

fitBounds doesn't work with the alternate projections

Open LarryZhu-dev opened this issue 1 year ago • 6 comments

Other coordinate systems will have significant offsets

LarryZhu-dev avatar Sep 13 '23 09:09 LarryZhu-dev

Hi @LarryZhu-dev,

Thank you for using mapbox-gl-js. It's unclear to me what the issue is about. Could you please add more details on the subject? You can also provide a minimal, complete, verified demonstration of the issue to help the maintainers and community understand and address the problem accurately. We recommend using https://jsbin.com/.

Also, for future "how do I" questions like this, you can refer to our help documentation, and if you can't find the answer there, contact support. This issue tracker is for reporting bugs and feature requests.

You might also consider posting your question to https://stackoverflow.com/questions/tagged/mapbox-gl-js to ask the community for help.

stepankuzmin avatar Sep 18 '23 08:09 stepankuzmin

That is to say, the fitBounds() method only correctly moves the perspective in the Mercator coordinate system, for example, in the wgs84 coordinate system, the more northward the incoming rect is, the more severely the method shifts

LarryZhu-dev avatar Oct 12 '23 02:10 LarryZhu-dev

I can confirm that when using Equal Earth projection the fitbounds function doesn't fit all markers to the viewport.

asktomi avatar Oct 16 '23 13:10 asktomi

Hi @LarryZhu-dev,

Thank you for using mapbox-gl-js. It's unclear to me what the issue is about. Could you please add more details on the subject? You can also provide a minimal, complete, verified demonstration of the issue to help the maintainers and community understand and address the problem accurately. We recommend using https://jsbin.com/.

Also, for future "how do I" questions like this, you can refer to our help documentation, and if you can't find the answer there, contact support. This issue tracker is for reporting bugs and feature requests.

You might also consider posting your question to https://stackoverflow.com/questions/tagged/mapbox-gl-js to ask the community for help.

Can you confirm the cause of the problem now

LarryZhu-dev avatar Dec 11 '23 03:12 LarryZhu-dev

Yes, thanks for the clarification. This is a known issue, related to https://github.com/mapbox/mapbox-gl-js/issues/12913, https://github.com/mapbox/mapbox-gl-js/issues/11284, https://github.com/mapbox/mapbox-gl-js/issues/12565

stepankuzmin avatar Dec 11 '23 12:12 stepankuzmin

I have the same problem - adding to the chorus on this "known issue". Using globe/web Mercator, fitBounds with the following coordinates works in the globe/default projection and fails in "naturalEarth" - it incorrectly zooms to eastern North America. For example:

bbox = [
     [-29.1, 30.4],
     [58.0, 85.0]
];
map.fitBounds(bbox, {
        padding: {top: 10, bottom:25, left: 15, right: 5}
});

jmersonuo avatar Jan 11 '24 23:01 jmersonuo