[OpenLayers-Users] Displaying layers depending on the zoom

Arthur Delorme delorme.ipgp at gmail.com
Thu Jul 16 05:02:37 EDT 2009


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



More information about the Users mailing list