Joan Ramos
Joan Ramos

Reputation: 21

How can I get Camera Altitude in MapBox GL JS?

I know that using

const camera = map.getFreeCameraOptions();

const cameraPosition = camera._position.toLngLat();

I can get at cameraPosition the longitude and latitude from the camera, but what about the elevation/altitude? What exactly is then, following the previous code:

const elevation = camera._elevation;

And why is always with the value undefined?

How can I get the correct altitude value?

Thanks in advance,

Joan.

Upvotes: 1

Views: 486

Answers (1)

Here:

const altitude = camera._position.toAltitude();

In the future, you can do console.log(camera._position); and inspect the available methods and attributes that show up in the console for the specified object. This is how I found it.

Upvotes: 0

Related Questions