[OpenLayers-Users] max/minScale Values

Erik Uzureau erik.uzureau at metacarta.com
Mon Jul 9 15:59:17 EDT 2007


Hi Jochen,

I've taken a look at this, stepped through the initialization of a
layer with miin/max scale properties, and I think I have a reasonable
explanation for you:

When you run your code, you should notice that the maxScale property
*does* get set as you had desired, but the minScale will probably be
modified.

The reason for this is because of zoom levels.

The way initResolutions() works is that it takes all the information
that has been provided (as options to the layer or options to the map)
and tries to create a resolutions array.

Since you specify min&max Scale, what it does is first to convert
those two values into the corresponding resolution values
(maxResolution/minResolution).

Then, in order to create the resolutions array, it executes the following code:

            // determine numZoomLevels
            if (confProps.minResolution != null) {
                var ratio = confProps.maxResolution / confProps.minResolution;
                confProps.numZoomLevels =
                    Math.floor(Math.log(ratio) / Math.log(2)) + 1;
            }

Basically, unless you explicitly specify a resolutions or scales
array, OpenLayers works on a power of two principle (like google,
yahoo, others) for determining the zoom levels. Thus it will start
from the maxResolution and progressively build up from there. In order
to determine when to stop, it takes a ratio between the min and the
max and uses that to set numZoomLevels.

Hopefully that makes sense. If you want to be precise about your max
and min scale values, the best thing to do would be to specify a
scales array with all the intermediate levels you wish to display in
between min and max.

If someone has an alternative way of programmatically defining those
intermediate steps betweeen min and max scale/resolution, please write
in to the list with some suggestions -- we're certainly open to
hearing them... this power of two bit is just a default that has
worked well in general.

Cheers,
Erik


On 6/28/07, Jochen Grefe <jochen.grefe at ingenieurteam2.com> wrote:
> Hello,
> At first I'm new to OL so please forgive my ignorance of anything obvisious.
> I want to set max/minScale Values on initialization of a Layer:
> new OpenLayers.Layer.KaMap('B1','...uri...',{g: 'B1',map: 'map',i: 'png'},{minScale: 499,maxScale: 3001})
> But if I add this layer to the map via: map.addLayers(layers);
> the layer values are overwritten by the map values for max/minScale
> on initResolution of OpenLayers.Layer (Called by addLayer/Map -> setMap/Grid ->setMap/Layer)
> Since I don't know the desired handling, I assume that the layer settings should
> only be overwritten if they are not set. In lib/layer.js that would guide me to:
> 546,547c546,549
> <         this.minScale = this.scales[0];
> <         this.maxScale = this.scales[this.scales.length - 1];
> ---
> >         if (this.minScale == null)
> >          this.minScale = this.scales[0];
> >         if (this.maxScale == null)
> >          this.maxScale = this.scales[this.scales.length - 1];
>
> Best regards,
> Jochen
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list