[OpenLayers-Users] map resolutions and layers resolution

Christopher Schmidt crschmidt at metacarta.com
Wed Sep 10 07:11:19 EDT 2008


On Wed, Sep 10, 2008 at 11:32:27AM +0200, Guillaume Sueur wrote:
> Hi,
> 
> It seems that when layer's minResolution and maxResolution are set, the 
> map's resolution are overriden and goes then from maxResolution to 
> minResolution by x2 steps.
> Is it a normal behaviour or am I missing something ?

This is normal behavior.

OpenLayers has two different kind of layes: Base Layers, and Overlays.
Base layer resolutions control the resolutions available to the map:
when the base layer is switched, the available resolutions to zoom to
change. 

Overlays don't really care about hteir 'list' of resolutions: this list
is *only* used to determine whether a layer is in range or not. (In 2.7,
unless you pass layer-related resolution options *explicitly*, a layer
is always in range; this is a break from the past.) 

The map resolution options are used as a fallback to the layer
resolution options. When creating a layer, the initResolutions function
loops through all the resolution-relate properties, checking first if
the layer has such a property, then checking if the map has such a
property. In this way, it creates a 'complete' hash of all the
resolution related options.

It then acts as if the layer has passed all those resolution options in
directly -- so, the map resolution parameters are just a fallback, which
is overridden by the layer.

So, it is completely expected behavior that a layer will take the
feedback from the map, override it with its own settings, and call it
done.

An easy way to prevent misbehavior is to simply always pass a list of
resolutions into your layer. Resolutions are the 'core' res properties
in OpenLayers, and override naything else set on the map or layer. you
don't *need* to go this far -- OpenLayers does a fair amount for you --
but if you do that, you can never go wrong.

(This isn't the first time a resolution-related question has been asked
which demosntrates a lack of understanding of this phenomen; This is
just a general response to the more general qustions we get.)

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list