mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Zoom controls don't work if onZoom is calling

Open anna-visarsoft opened this issue 2 years ago • 2 comments

mapbox-gl-js version: "^2.9.1"

browser: Version 106.0.5249.119 (Official Build) (x86_64)

Steps to Trigger Behavior

  1. have zoom controls on the map
  2. use onZoom for adding pitch on zoom action

Link to Demonstration

https://codepen.io/anna-visarsoft/pen/jOxojJv?editors=0010

Expected Behavior

controls work fine

Actual Behavior

controls don't work

anna-visarsoft avatar Oct 19 '22 14:10 anna-visarsoft

Yeah, this looks like a bug. The underlying issue is that all map view setters like setPitch first stop animations with map.stop() before doing the change, but apparently this interferes with zoom if done on the zoom event. A temporary workaround for you (while we look for a way to fix this) is to change the code like this:

function onZoom () {
  map.transform.pitch = lerp(0, 70, smoothstep(10, 15, map.getZoom())); // instead of `map.setPitch`
}

mourner avatar Oct 19 '22 15:10 mourner

@mourner thanks! map.transform.pitch works for me =)

anna-visarsoft avatar Dec 15 '22 09:12 anna-visarsoft