[OpenLayers-Users] how to tell user "this scale is not available for this layer"

Franz Buchinger fbuchinger at gmail.com
Wed Jun 29 03:43:47 EDT 2011


The cleanest thing would be to listen for zoom changes of the map and
remove/add the layers accordingly. This can be done by assigning an event
listener to each layer that checks if the map scale is still within the
layer's min/maxscale and drop it accordingly.

Something like this (untested):

function isLayerAvailable (event){
  if (!event.zoomChanged ) {
     return;
  }
  var layer = this;
  var mapScale = layer.map.getScale();
  if ( mapScale > layer.maxScale || mapScale < layer.minScale){
     layer.map.removeLayer(layer);
     //TODO: add the other layer here
  }
}

map.layers[0].events.on({
                 moveend: isLayerAvailable,
                 scope: this
            });

cheers,

Franz

2011/6/28 Alberto Valente <alb.valente at gmail.com>

> Hi, I have 2 layers and one is available (min-maxscale) from scale 1000 to
> 200000 and the other from 200000 to 400000 (sat and aerial photos).
> If the user changes the active layer from one to the other, the map becomes
> white (correctly since actual scale is not permitted for the other layer)
> but I'd like to tell user that the scale is not available for this layer.
>
> For example disabling the layer from layer chooser if the actual scale is
> not allowed for it
> or by switching to layer's nearest allowed scale
> or by auto-switching back to the other layer and launching an alert();
>
> How to do that?
>
> thank you
> alberto
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110629/2568543a/attachment.html


More information about the Users mailing list