Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Layer setMinZoom and l.setMaxZoom not working after 5.5.x? #11386

Closed
leelx78 opened this issue Mar 5, 2018 · 10 comments
Closed

Layer setMinZoom and l.setMaxZoom not working after 5.5.x? #11386

leelx78 opened this issue Mar 5, 2018 · 10 comments
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl

Comments

@leelx78
Copy link

leelx78 commented Mar 5, 2018

Hi This code was working fine e.g. for limiting a bunch of layers between 2 zooms in version 5.1.x

for (Layer l : MAP.getLayers()) { l.setMinZoom(5); l.setMaxZoom(8); Log(String.format("&&LAYER %s\t%s\tzoom=(%f, %f)", l.toString(), l.getId(), l.getMinZoom(), l.getMaxZoom())); }

or

for (Layer l : MAP.getLayers()) { MAP.getLayer(l.getId()).setMaxZoom(8); MAP.getLayer(l.getId()).setMinZoom(SATELLITE_MAP_MAX_ZOOM); Log(String.format("&*&LAYER %s\t%s\tzoom=(%f, %f)", l.toString(), l.getId(), l.getMinZoom(), l.getMaxZoom())); }

..but in 5.5.x and 6.x it does nothing. Any ideas?

I'd expect ALL layers to disappear over lvl8 and under lvl5 or am I missing something?

@leelx78 leelx78 changed the title Layer Layer setMinZoom and l.setMaxZoom not working after 5.5.x? Mar 5, 2018
@leelx78
Copy link
Author

leelx78 commented Mar 5, 2018

EDIT: It DOES disable SOME of the layers but not ALL, as I was expecting. Looks like there are some "default" layers that are not disabled this way..

I'd expect a completely BLANK map outside that range.

I'll keep testing but if I'm missing something please let me know.

@leelx78
Copy link
Author

leelx78 commented Mar 5, 2018

OK I think I understand what's happening. I have loaded the map with a json file

mapView.setStyleUrl(MAP_STYLE_URL);

which works fine but once I disable all layers it seem to revert to the default map zoom levels instead of disabling the layer altogether. Is this intentional? I'd like to have the possibility of controlling the zoom levels entirely in the app instead of in the json

@LukasPaczos LukasPaczos added the Android Mapbox Maps SDK for Android label Mar 6, 2018
@LukasPaczos
Copy link
Contributor

Unfortunately, with #8929 Layer and other style components became immutable, meaning, that those type of operations are not supported anymore.

We should remove Layer#setMaxZoom and Layer#setMinZoom from the public API as the results of those methods are ignored.

@jfirebaugh
Copy link
Contributor

Unfortunately, with #8929 Layer and other style components became immutable, meaning, that those type of operations are not supported anymore.

I think that's a misunderstanding. Internally, gl-core uses immutable objects, but the public API is still mutable. There is no reason to remove setMin/MaxZoom that I know of.

@leelx78
Copy link
Author

leelx78 commented Mar 6, 2018

..I'm confused. So is it mutable or not?

if I can call setMinZoom on a layer I'd expect it to do something otherwise indeed it should be removed.

Any workaround for this? I think being able to programmatically alter min/max zooms can be very important in some cases.

@jfirebaugh
Copy link
Contributor

It's a bug if setMinZoom/setMaxZoom don't work.

@jfirebaugh jfirebaugh reopened this Mar 6, 2018
@leelx78
Copy link
Author

leelx78 commented Mar 6, 2018

good to see this reopened then! Thanks

@LukasPaczos
Copy link
Contributor

Thanks for clearing this up @jfirebaugh.

After testing it out a bit more it seems like in order to enforce new min/max zoom levels we need to re-add the Layer to the map. Is that the expected behavior @jfirebaugh?
Example code below works correctly:

for (Layer layer : mapboxMap.getLayers()) {
            mapboxMap.removeLayer(layer);
            layer.setMaxZoom(12);
            layer.setMinZoom(10);
            mapboxMap.addLayer(layer);
          }

@jfirebaugh jfirebaugh added the Core The cross-platform C++ core, aka mbgl label Mar 6, 2018
@jfirebaugh
Copy link
Contributor

No, expected behavior is that the new zoom level takes effect immediately, and the layer is hidden if the current zoom is outside the range, or shown if inside.

It may be that all that's needed to fix this is to add observer->onLayerChanged(*this); at the end of the setter implementations here:

void <%- camelize(type) %>Layer::setMinZoom(float minZoom) {
auto impl_ = mutableImpl();
impl_->minZoom = minZoom;
baseImpl = std::move(impl_);
}
void <%- camelize(type) %>Layer::setMaxZoom(float maxZoom) {
auto impl_ = mutableImpl();
impl_->maxZoom = maxZoom;
baseImpl = std::move(impl_);
}

And then regenerate the style code.

@LukasPaczos
Copy link
Contributor

Landed with #11399.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

3 participants