[OpenLayers-Dev] [OpenLayers-Users] problem in getZoomForResolution

Christopher Schmidt crschmidt at metacarta.com
Tue Sep 18 07:43:20 EDT 2007


On Tue, Sep 18, 2007 at 01:26:01PM +0200, Bart van den Eijnden (OSGIS) wrote:
> We are experiencing a problem in Layer.js's getZoomForResolution in that
> it's return value is sometimes 1 off. This is similar to TileCache's seed
> problems and deals with precision.
> 
> This problem was also in previous OL versions, but is still present in
> 2.5RC1 unfortunately. It happens to us when we switch baselayers, which are
> both WMS Tiled layers. The scales are only set on the Map, so basically the
> layers share the same set of resolutions.
> 
> If we use a different approach (find the minimal difference) it works fine:
> 
>     getZoomForResolution: function(resolution) {
>         var lastDiff = null;
>         var zoom = null;
>         for(var i=1; i < this.resolutions.length; i++) {
>           diff = Math.abs(this.resolutions[i]-resolution);
>           if (lastDiff && (diff < lastDiff))
>           {
>             zoom = i;
>           }
>           lastDiff = diff;
>        }
>        return zoom;
>    },
> 

This seems low cost and unlikely to break things, but I'd prefer to get
more buyin -- I think Tim is in favor of this (I know he was for
TileCache, which is why this is what it does these days). It's also high
benefit, if it actually fixes the problem.

I'm moving this one to the dev list, since I think it's more appropriate
for there -- any time you're talking about changing internals of the
library, it's generally best to send to the dev list (though I'll admit
I haven't bothered to make the distinction particularly clear: my bad).

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list