[OpenLayers-Users] add, remove base layers depending on zoom,
change baselayer
Attila Csipa
plists at prometheus.org.yu
Mon Jan 14 16:27:25 EST 2008
On Monday 14 January 2008 21:53:08 Maria Panagou wrote:
> map.events.register("zoomend", map, function() {
> if (map.getZoom()>0) {
> if (satellite.displayInLayerSwitcher== false) {
> satellite.displayInLayerSwitcher= true;
> map.setBaseLayer(satellite);
> satellite.setVisibility(true);
> //switcher.updateMap;
> }
> }
> else
> {
> satellite.displayInLayerSwitcher= false;
> map.setBaseLayer(nomoi);
> satellite.setVisibility(false);
> }
> });
>
> this works when zooming in and for a little while zooming back to first
> zoom but then nothing happens when I click the zoom out button in
> panzoombar and the browser stops responding. tried that with firefox and
> IE. no errors in firebug
From what I've seen in the examples you should use context properly, eg. in
your case, since you want to change layers:
map.events.register("zoomend", satellite, function(){
and then refer to satellite as this, so your calls would look like
this.displayInLayerSwitcher=false;
this.map.setBaseLayer... etc
You should avoid using global variables as much as possible to avoid confusion
as to what your context is at the moment (context related errors are
especially nasty as they are in essence logical errors and thus won't be
always obvious in firebug). This might not be the root of your problems, but
it did bite me a couple of times so you should clear that up, just in case,
YMMV.
More information about the Users
mailing list