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?

Thanks,

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.
Index: Layer.js
===================================================================
--- Layer.js	(revision 7555)
+++ Layer.js	(working copy)
@@ -797,8 +797,11 @@
 
         this.resolutions = confProps.resolutions;
         this.maxResolution = confProps.resolutions[0];
+	if (this.options.minScale == null) this.maxResolution = Number.POSITIVE_INFINITY;
         var lastIndex = confProps.resolutions.length - 1;
         this.minResolution = confProps.resolutions[lastIndex];
+        if (this.options.maxScale == null) this.minResolution = Number.NEGATIVE_INFINITY;
+
         
         this.scales = [];
         for(var i = 0; i < confProps.resolutions.length; i++) {
_______________________________________________
Dev mailing list
[email protected]
http://openlayers.org/mailman/listinfo/dev

Reply via email to