openlayers - show/hide kml on defined zoom levels -


i´m trying hide/show own kml files (polygons) depending on zoom levels in openlayers - when reached zoom level 1 layer should hide , show. far found solution (how load layers depending on zoom level?), doesn´t seem working in case. i´m relatively new javascript , don´t know if i´m using right, made changes example:

map.events.register("zoomend", map, zoomchanged);   //inserted in function init()  function zoomchanged()     {       if (map.getzoom() == 18)       {       kml1.setvisibility (true);       kml2.setvisibility (false);       }       else if (map.getzoom() == 19)       {       kml1.setvisibility (false);       kml2.setvisibility (true);       }     } 

i tried solution hide kml1, in case layer isn´t drawn. layerswitcher works - layer unselectable in defined zoom levels, nothing visible when zoomed out (when layer selectable):

var kml1 = new openlayers.layer.vector("prehled",                  {minscale: 1000,},                                //1:1000                 {                 projection: map.displayprojection,                 strategies: [new openlayers.strategy.fixed()],                 protocol: new openlayers.protocol.http({                     url: "kml/zahrada.kml",                     format: new openlayers.format.kml({                         extractstyles: true,                         extractattributes: true,                     })                 })             });     map.addlayer(kml1); 

thanks response , advice on this.

try:

var kml1 = new openlayers.layer.vector("prehled", {             minresolution: map.getresolutionforzoom(18), // or desired maximum zoom             projection: map.displayprojection,             strategies: [new openlayers.strategy.fixed()],             protocol: new openlayers.protocol.http({                 url: "kml/zahrada.kml",                 format: new openlayers.format.kml({                     extractstyles: true,                     extractattributes: true                 })             })         }); map.addlayer(kml1); 

```


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -