mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
10.9k stars 2.19k forks source link

Camera "look at" with adjustable height #12563

Closed Bulisor closed 1 year ago

Bulisor commented 1 year ago

Motivation

Hi, I am using Mapbox with babylonjs to display 3d buildings on map. It is working very well so far. I was wondering if there is a way to set the camera "look at" position at a different height, or to change the height of the camera target. Currently, it seems that the camera always looks at the target at 0 height

The ability to set the camera height for the "look at" feature would provide more flexibility and enhance the user experience for all who are using 3d on mapbox.

https://prnt.sc/ql8hlW1CMFAU

Thanks

stepankuzmin commented 1 year ago

Hi @Bulisor,

Thank you for using mapbox-gl-js. You can change the camera altitude with FreeCameraOptions:

const camera = map.getFreeCameraOptions();

const position = [138.72649, 35.33974];
const altitude = 3000;

camera.position = mapboxgl.MercatorCoordinate.fromLngLat(position, altitude);
camera.lookAtPoint([138.73036, 35.36197]);

map.setFreeCameraOptions(camera);

I'll close the issue, but feel free to reopen if you have any questions.

Bulisor commented 1 year ago

Hi @stepankuzmin , thank you for your response. Unfortunately, this is not what I'm seeking. When using this option, the camera simply zooms out on the target, and I do not desire that. Instead, I would like the same zoom level, but positioned at a specific distance above the ground along the Y-axis. I hope I have explained it more accurately.

artu-ole commented 1 year ago

Hi there, this looks like a duplicate of https://github.com/mapbox/mapbox-gl-js/issues/3552 to me?

stepankuzmin commented 1 year ago

Yes, this is a duplicate of #3552.