Skip to content
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

fitScreenCoordinates results in bounding box occupying only appr 1/9th of map view #13347

Open
enzedonline opened this issue Dec 12, 2024 · 0 comments

Comments

@enzedonline
Copy link

When trying to use map.fitScreenCoordinates() to fit a point pair to the map view, the results end up with the bounding box for the pair only occupying the central 9th of the map view (approximately), roughly a a zoom order of 1 lower than it should be and not quite centred correctly.

mapbox-gl-js version: 3.8

browser: Firefox/Chrome latest

Steps to Trigger Behavior

p0 = map.project(topLeft)
     t {x: 171.65250512712697, y: 71.05358673362583}
p1 = map.project(bottomRight)
     t {x: 941.7523262852809, y: 529.5638120381566}
map.fitScreenCoordinates(p0, p1, mapBlock.map.getBearing(), {
    padding: 0,
    pitch: mapBlock.map.getPitch()
});
map.project(topLeft)
     t {x: 293.2161599189392, y: 215.4263917725453} 
map.project(bottomRight)
     t {x: 650.604679888928, y: 435.9973409725512}

Screenshot 2024-12-12 163148

The bounding box is drawn in red with p0 being the top left corner, p1 the bottom right.

The issue is there whether the pitch and/or bearing are zero or not and unrelated to initial position or zoom level before issuing fitScreenCoordinates().

map.getPadding() confirms the padding is zero and not related to the issue.

I've seen the related issue #11795 that states this can be related to using the globe projection in place of mercator. I changed the style projection to mercator and passed this in the Map options (confirmed with map.getProjection()) - this made no difference.

Codepen

https://codepen.io/enzedonline/pen/emOdGbx
NB: use your token in the code to get working example

Expected Behavior

Zoom and map position should be such that the bounding box fills the map view area taking any padding into consideration.

Actual Behavior

Map is not properly centred, zoom level is approximately an order of 1 smaller than it should be to fill the map view area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant