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

Default minzoom of -2 prevents NavigationControl button from being disabled #9172

Open
sgurin opened this issue Jan 10, 2020 · 5 comments
Open
Labels

Comments

@sgurin
Copy link

sgurin commented Jan 10, 2020

Hi, guys.

On the example, https://docs.mapbox.com/mapbox-gl-js/example/navigation/ disable state is stetted on the zoom-in button when you rich the limit https://prnt.sc/qlwb9i but when you zoom out https://prnt.sc/qlwby0 nothing happened with zoom out button. So, how we can disable the zoom out button?

@ryanhamley
Copy link
Contributor

ryanhamley commented Jan 10, 2020

Good catch. This is a little tricky. As of #9028, the map's default minZoom is actually -2, not 0. You can reset that by calling map.setMinZoom(0) if you don't need the ability to show your map on small viewports. However, the amount you can zoom out on a map is determined in part by the size of the viewport, even when it's large. Unless the map is displayed at an exact multiple of a 512x512 square, it will be impossible to hit exactly z0 so the zoom out button won't be disabled.

I can think of a couple ways to solve this:

  1. we could have a concept of "effective min zoom" which is the zoom that the map is actually able to reach at its current size and disable the zoom out button when that limit is reached

  2. we could provide a method to manually disable the zoom buttons so developers can disable them as necessary. something like navControl.zoomOutButton.disable(). this one is technically possible now via a "private" method but we could expose and document it

@sgurin
Copy link
Author

sgurin commented Jan 11, 2020

Hi @ryanhamley

Thanks a lot for such a detail explanation.

So, there are no methods to disable the zoom out button when your rich min zoom?

From my point zoom out button should have the same behavior as zoom in. It is confusing users when you click on it and nothing happens.

@ryanhamley
Copy link
Contributor

ryanhamley commented Jan 13, 2020

So, there are no methods to disable the zoom out button when your rich min zoom?
From my point zoom out button should have the same behavior as zoom in. It is confusing users when you click on it and nothing happens.

The zoom out button does behave the same as the zoom in button. The problem is that it's not always (or even usually) possible to actually reach the map's minZoom. If you were to set maxZoom: 22 and minZoom: 15 for example, you'd see the buttons being disabled as expected when you reach the appropriate zoom levels. It's always possible to reach the maxZoom since it's not determined by viewport size, but since the minZoom is determined in part by viewport size, it's not guaranteed that the map's minZoom is actually reachable. That's the source of this particular bug.

@sgurin
Copy link
Author

sgurin commented Jan 14, 2020

Hi, @ryanhamley

I see. Thanks for clarification.

What about boundaries? Will the bug be the same when we rich the limits of the area?

@ryanhamley
Copy link
Contributor

ryanhamley commented Jan 14, 2020

Setting a boundary area wouldn't automatically change the behavior of the zoom buttons.

_updateZoomButtons() {
const zoom = this._map.getZoom();
this._zoomInButton.disabled = zoom === this._map.getMaxZoom();
this._zoomOutButton.disabled = zoom === this._map.getMinZoom();
}

This is the code in question. You can see that the only determining factor in disabling the buttons is whether or not the current map zoom equals the map's minZoom or maxZoom. A bounding box doesn't change the map's min and max zoom. However, if you had a bounding box and set the map's min and max zoom to be equal to the min and max zoom levels that showed the entire bounded area, then yes, you could set up the controls to automatically disable the zoom out button when the maximum extent of the area is shown.

In general, the bug you've shown here only exhibits itself if the minZoom is very low, probably less than 2 in most cases. So if your map has a higher zoom level, you likely wouldn't experience this bug.

@ryanhamley ryanhamley changed the title Zoom out [disable attr] Default minzoom of -2 prevents NavigationControl button from being disabled Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants