[OpenLayers-Users] Displaying layers depending on the zoom

Adrian Popa adrian_gh.popa at romtelecom.ro
Thu Jul 16 06:26:41 EDT 2009


Hello Arthur,

You can use minResolution and maxResolution for your layer. I see that 
your example already has that. Your layer should be grayed out outside 
the min-max resolution range and should become selectable (and visible) 
inside that range.
You should tune your range by using firebug and looking at your layer's 
properties for the correct values.
For instance, for my layer I use a minResolution of 1 and a 
maxResolution of 38 to select an area about 10-20 km in length

Good luck,
Adrian



Arthur Delorme wrote:
> Hello,
>
> I need your help : I am just beginning using OpenLayers and I cannot 
> find how to hide a layer and display it when zoom is big enough. I did a 
> script with a map layer and a GML layer (parsing KML). Here is my code :
>
> function init()
> {
>      var map = new OpenLayers.Map('map');
>
>      var wms = new OpenLayers.Layer.WMS("OpenLayers WMS",
>          "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'
>          });
>
>      var optionsSRTM = {resolutions: 
> [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125],
>          maxResolution: 0.17578125,minResolution: 0.0439453125};
>
>      var srtm = new OpenLayers.Layer.GML("KML", "./test.kml", {
>          format: OpenLayers.Format.KML}, optionsSRTM);
>
> //            srtm.setVisibility(false);
> //            if (map.getZoom() > 2)
> //            {
> //                srtm.setVisibility(true);
> //            }
>
>      map.addLayers([wms, srtm]);
>
>      map.zoomToMaxExtent();
>
>      map.addControl(new OpenLayers.Control.LayerSwitcher());
>      map.addControl(new OpenLayers.Control.MousePosition());
> }
>
> I tried two things : using the resolutions options in the layer's 
> declaration and playing with setVisibility. Both are not working : for 
> the first I don't know why and for the second I think it might be 
> because the layer is not reloaded when I zoom / unzoom. The div for my 
> map is 512px*256px.
>
> I tried to follow these instructions 
> (http://trac.openlayers.org/wiki/SettingZoomLevels) but without success.
>
> Thanks a lot !
>
> Arthur Delorme
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>   





More information about the Users mailing list