I'm trying to load different layers based on the user zoom level with OpenLayers. I've seen some similar questions in here, but they load the layer and then hide/show it based on the zoom level.
I don't want the layer to be loaded. I've managed to use some answers and came with a solution, but I don't like it that much. There must be an easier way. Can anybody point me in the right direction?
Here is the solution I've found so far.
map.events.on({ "zoomend": function (e) {
if (this.getZoom() > 8) {
// Setup single tiled layer
var untiled = new OpenLayers.Layer.WMS("cite:ly_parc - Untiled", "http://localhost:8082/geoserver/cite/wms",
{
LAYERS: 'cite:ly_parc',
STYLES: '',
format: 'image/png',
transparent: true
},
{
maxExtent: bounds,
isBaseLayer: false
}
);
this.addLayers([untiled]);
} else {
//TODO
}
}
});
Best Answer
There are parameters, but there's an issue with XYZ layers. But there is a patch.
All the info is here: https://stackoverflow.com/a/4294980/229875