[OpenLayers-Users] problem in getZoomForResolution

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Tue Sep 18 07:26:01 EDT 2007


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;
   },

Any ideas on this?

Best regards,
Bart

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








More information about the Users mailing list