[OpenLayers-Dev] Layer switch depending on zoom level

Alexandre Dube adube at mapgears.com
Wed Jan 27 08:28:42 EST 2010


Dominic,

  You could try to set a maxScale [1] value to your layer, then try to 
register a map "moveend" event to check if you layer is inRange with the 
layer.calculateInRange() method.  If it's not, change your base layer.

  BTW, this kind of question is more suitable for the 'users' mailing list.

  Kind regards,

Alexandre

[1] 
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.maxScale

Dom Lehr wrote:
> Hey guys,
>
> I managed to handle the "zoom changed" event now. What I m trying to 
> do is to combine prerendered tiles with tiles gettin rendered "on the 
> fly". So I only want to rerender the tiles with a zoom greater than 
> let s say 14. I did
>
>
> layerEntry0.events.on({
>                       moveend: function(e) {
>                         if (e.zoomChanged) {
>                             var zoom = parseInt(map.zoom);
>                             if(zoom >= 14){
>                                    map.setBaseLayer(map.layers[1]);    
>                    
>                             }
>                         }
>                       }
>                     });         
>
> The issue that I got with this solution is, that the event gets fired 
> AFTER the zoom changed (which makes sense, D'ooh) ... so whenever I 
> switch the layer, it first displays the current base layer with e.g. 
> zoom 14, than switches the layers and displays the tiles with zoom 14 
> again, using a different base layer. Now is there a way to change the 
> base layer BEFORE new tiles are requested?
>
> Thanks in advance!
>
> Dom
> ------------------------------------------------------------------------
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Dev mailing list