Pitch camera while zooming

Viewed 146

I'm trying to change the pitch of the mapbox camera while zooming. I know I can set a default/max pitch level and that the user is able to change the pitch of the camera by themselves, I'm however looking for a way to map a zoom level range to a pitch range. While scrolling/zooming I want the pitch to change according to this range.

I've tried the following:

function onMapboxZoom(e: MapboxEvent) {
  const zoom = e.target.getZoom();
  const pitch = mapRange(zoom, 6, 10, 0, 65);
  e.target.setPitch(pitch);
}

The problem I'm having with this approach is that I think the zoom interpolation that mapbox uses to create a smooth zooming effect is cancelled by my manual pitch change. The result is that the smoothness of zooming is gone and that it requires a lot of scroll events to zoom in properly. Which makes sense I guess. I was wondering if anyone has tackled this problem before and if/how this can be achieved while maintaining a smooth zoom behavior.

Thanks!

0 Answers
Related