[OpenLayers-Users] zooming out when changing base layer

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Wed Dec 27 11:37:43 EST 2006


I have debugged this problem a little bit and "patched" my local version.

My base layers are all WMS Untiled.

What I understand from it, WMS Untiled does not inherit from
FixedZoomLevels, so does not have any zoom levels.

The behaviour I see (i.e. when changing base layer sometimes the map zooms
out) is caused by the following call in changeBaseLayer (Map.js):

this.zoomToExtent(oldBaseLayer.getExtent());

The getExtent call does give back to correct extent btw of the current map.

I made the following adjustment by checking on class name, but there is
probably a nicer solution to this problem:

                    } else {
                        if (!newBaseLayer.CLASS_NAME ==
'OpenLayers.Layers.WMS.Untiled')
                        this.zoomToExtent(oldBaseLayer.getExtent());
                    }

Does anybody have a better idea on how to tackle this? Can we for instance
check if the BaseLayer inherits from FixedZoomLevels?

Best regards,
Bart

--
Bart van den Eijnden
OSGIS, Open Source GIS
http://www.osgis.nl


--------- Oorspronkelijk bericht --------
Van: Bart van den Eijnden OSGIS <bartvde at osgis.nl>
Naar: Erik Uzureau <euzuro at gmail.com>, Bart van den Eijnden OSGIS
<bartvde at osgis.nl>
Cc: users at openlayers.org
Onderwerp: Re: [OpenLayers-Users] zooming out when changing base layer
Datum: 11/12/06 11:40

> 
> Hi Erik,
> 
> but with WMS Untiled, I do not specify an extent nor a resolution for a
> layer.
> 
> How does this relate then to WMS Untiled? Is there a way around it?
> 
> This is my code:
> 
>         function mapinit(){
>             map = new OpenLayers.Map( $('map'), { controls: [],
> 'projection': 'EPSG:28992', 'units':'meters', 'maxExtent': new
> OpenLayers.Bounds(-157973.103596, 300670.145842, 472056.321374,
> 678687.800824) , 'maxResolution':'auto'});            var layer = new
> OpenLayers.Layer.WMS.Untiled( &quot;Topografische kaart Nederland&quot;,
>                
>
&quot;http://intranet.rijkswaterstaat.nl/services/geoservices/basispakket/topografie?&quot;,
> {layers: 'AAA126,AAA127,AAA134', 'format':'image/jpeg',
> 'transparent':'true'}, {'ratio':1, isBaseLayer: true} );
> 
>             map.addLayers([layer]);            var layer = new
> OpenLayers.Layer.WMS.Untiled( &quot;Luchtfoto's Nederland&quot;,
>                
>
&quot;http://intranet.rijkswaterstaat.nl/services/geoservices/basispakket/luchtfoto?&quot;,
> {layers: 'AAA216', 'format':'image/jpeg', 'transparent':'true'},
{'ratio':1,
> isBaseLayer: true} );
> 
>             map.addLayers([layer]);            var layer = new
> OpenLayers.Layer.WMS.Untiled( &quot;Nationaal Wegen Bestand Wegen
wegvakken&quot;,
>                
>
&quot;http://intranet.rijkswaterstaat.nl/services/geoservices/basispakket/nationaalwegenbestand?&quot;,
> {layers: 'AAA70', 'format':'image/gif', 'transparent':'true'}, {'ratio':1,
> isBaseLayer: false} );
> 
>             map.addLayers([layer]);            var layer = new
> OpenLayers.Layer.WMS.Untiled( &quot;Top250namen&quot;,
>                
>
&quot;http://intranet.rijkswaterstaat.nl/services/geoservices/basispakket/topografie?&quot;,
> {layers: 'AAA133', 'format':'image/gif', 'transparent':'true'},
{'ratio':1,
> isBaseLayer: false} );
> 
>             map.addLayers([layer]);            if (!map.getCenter())
> map.zoomToMaxExtent();
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             map.addControl(new OpenLayers.Control.PanZoomBar());
>             map.addControl(new OpenLayers.Control.MouseDefaults());
>         }
> 
> Best regards,
> Bart
> 
> --
> Bart van den Eijnden
> OSGIS, Open Source GIS
> http://www.osgis.nl
> 
> 
> --------- Oorspronkelijk bericht --------
> Van: Erik Uzureau &lt;euzuro at gmail.com&gt;
> Naar: Bart van den Eijnden OSGIS &lt;bartvde at osgis.nl&gt;
> Cc: users at openlayers.org
> Onderwerp: Re: [OpenLayers-Users] zooming out when changing base layer
> Datum: 11/12/06 09:16
> 
> &gt; When you switch between base layers, OpenLayers tries to find the
> &gt; nearest approximate
> &gt; zoom for the new base layer.
> &gt; 
> &gt; So what is happening is that when you switch from baselayer A to
baselayer
> B
> &gt; 
> &gt; 1) records current extent of map in baselayer A
> &gt; 2) switches to base layer B
> &gt; 3) calls zoomToExtent() on stored extent from base layer A
> &gt; 
> &gt; if the resolutions/scales array for your two base layers are not the
same,
> &gt; this would explain the behaviour.
> &gt; 
> &gt; Note that with the commercial layers (google, yahoo, etc) we have
> specifically
> &gt; hard coded the resolutions array so that it will be more consistent
with
> wms
> &gt; layers (due to projection differences).
> &gt; 
> &gt; On 12/11/06, Bart van den Eijnden (OSGIS)
&amp;lt;bartvde at osgis.nl&amp;gt; wrote:
> &gt; &amp;gt; Hi list,
> &gt; &amp;gt;
> &gt; &amp;gt; I have 2 base layers and several overlays, all are WMS
Untiled.
> &gt; &amp;gt;
> &gt; &amp;gt; When I change the base layer, the application zooms out.
> &gt; &amp;gt;
> &gt; &amp;gt; Is this a bug?
> &gt; &amp;gt;
> &gt; &amp;gt; Best regards,
> &gt; &amp;gt; Bart
> &gt; &amp;gt;
> &gt; &amp;gt; --
> &gt; &amp;gt; Bart van den Eijnden
> &gt; &amp;gt; OSGIS, Open Source GIS
> &gt; &amp;gt; http://www.osgis.nl
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt;
> &gt; &amp;gt; _______________________________________________
> &gt; &amp;gt; Users mailing list
> &gt; &amp;gt; Users at openlayers.org
> &gt; &amp;gt; http://openlayers.org/mailman/listinfo/users
> &gt; &amp;gt;
> &gt; 
> &gt; 
> 
> 






More information about the Users mailing list