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

Camera height calculation problem #11914

Open
wcwcwcwc opened this issue May 20, 2022 · 1 comment
Open

Camera height calculation problem #11914

wcwcwcwc opened this issue May 20, 2022 · 1 comment

Comments

@wcwcwcwc
Copy link

mapbox-gl-js version: 2.6.0

browser: Chrome 101.0.4951.54

Question

When I set to the maximum zoom and to the maximum Pitch, I get the camera height, and then set the same height. At this time, I find the camera height is inconsistent with that of the front and rear cameras.
here is my code:

 map.on('click', () => {
       const camera = map.getFreeCameraOptions();
       const coord = new mapboxgl.MercatorCoordinate(camera._position.x, camera._position.y,
       camera._position.z).toLngLat();
       const height = new mapboxgl.MercatorCoordinate(camera._position.x, camera._position.y,camera._position.z).toAltitude();
                
       console.log(height);
       camera.position = mapboxgl.MercatorCoordinate.fromLngLat([coord.lng, coord.lat],
       height);

       map.setFreeCameraOptions(camera);

       const camera2 = map.getFreeCameraOptions();
       const height_new = new mapboxgl.MercatorCoordinate(camera2._position.x, camera2._position.y,camera2._position.z).toAltitude();
       console.log(height_new);
     })  

and then the result:

image

Solution

image

I found there was a problem calculating the camera height in this method and distToCenter didn't take camera.forward() into account, so I changed it to this,And it worked:

image

@SnailBones
Copy link
Contributor

Thanks for the report and explaining your fix @wcwcwcwc! Would you be interested in opening a PR from your fork?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants