[OpenLayers-Dev] Roundoff error disables overlays with no minScale when fully zoomed in

David Fuhry dfuhry at acm.org
Sat Aug 23 15:52:35 EDT 2008

My OpenLayers map was disabling layers with no minScale only at the most 
zoomed-in level.  Some firebug debugging showed that at that level, in 
OpenLayers.Layer.calculateRange, this.map.getResolution() returns 
0.14999999999999977 while this.minResolution is 0.15.  My map 
initialization parameters include { minResolution: 0.15 } so it would 
seem paradoxical that this.map.getResolution() can return a value < 0.15.

Obviously there is a small roundoff problem here, which could be brushed 
over by putting a very small tolerance (epsilon) value into the 
calculateRange calculation:

inRange = ( (resolution >= this.minResolution /* - tolerance */) && 
                   (resolution <= this.maxResolution /* + tolerance */) );

My approach was to change the layer's minResolution from 0.15 to 
Number.NEGATIVE_INFINITY.  It unfortunately accomplishes this specious 
task in a rather blunt way, clobbering the value of any 
{min,max}Resolution parameters passed to Layer constructors.

Maybe this.map.getResolution() should just be tweaked to snap its value 
to {min,max}Resolution if it's ever-so-slightly beyond one.  Any 
thoughts on the best course of action?


Dave Fuhry

P.S. Full map initialization params are:  { maxExtent: new 
OpenLayers.Bounds(-20000000,-20000000,20000000,20000000), maxResolution: 
10000, minResolution: 0.15, numZoomLevels: 16, units: "m" }.  I'm using 
a spherical mercator projection.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ol_minmax_res_inf.patch
Type: text/x-patch
Size: 673 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20080823/c5795ac3/ol_minmax_res_inf.bin

More information about the Dev mailing list