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?
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.
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
Unfortunately, with https://github.com/mapbox/mapbox-gl-native/pull/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.
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.
..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.
It's a bug if setMinZoom/setMaxZoom don't work.
good to see this reopened then! Thanks
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);
}
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:
And then regenerate the style code.
Most helpful comment
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:https://github.com/mapbox/mapbox-gl-native/blob/82de856c94bbc090ba30186011610da5e233e277/src/mbgl/style/layers/layer.cpp.ejs#L107-L117
And then regenerate the style code.