[OpenLayers-Users] Display a layer at the specified zoom
Mario Danelli
mario.danelli at gmail.com
Tue Oct 23 08:19:39 PDT 2012
adidas <xkadidas at ...> writes:
>
> Hello! How to display a layer at the specified zoom? For example, the
> layer is displayed at a zoom more than 14 and etc.
> Thanks for answer.
>
If the layer is a tile layer a solution, probably not the best, could be this:
- Create a new layer called "special layer"
var layer = new OpenLayers.Layer.OSM( "special_layer", "./tiles/special_layer/",
{ type: 'png',
getURL: get_my_url_special_layer,
isBaseLayer: false
});
- Specify "special layer" as additional layer over the base layer
map.addLayers([mapnik, special_layer]);
- Implement a "get_my_url_special_layer" function that return null if the level
is less the one specified with "your_layer" and the tile png in other cases.
function get_my_url_special_layer(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left)
/ (res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top)
/ (res * this.tileSize.h));
var z = this.map.getZoom();
if (y < your_limit) {
return null;
} else {
url = this.url;
path= "speciallayer/" + z + "/" + x + "/" + y + "." + this.type;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
return url+path;
}
}
If instead, the layer is simply a marker layer you can implement a function that
handle the zoomend event:
map.events.register('zoomend', this, function(e) {
var x = map.getZoom();
if (x < your_layer){
special_layer.setVisibility(false);
} else {
special_layer.setVisibility(true);
}
});
More information about the Users
mailing list