[OpenLayers-Commits] r6003 - in sandbox/pagameba/transition-resize: examples lib/OpenLayers lib/OpenLayers/Control lib/OpenLayers/Layer tests tests/Control tests/Layer

commits at openlayers.org commits at openlayers.org
Tue Feb 5 21:18:04 EST 2008


Author: pagameba
Date: 2008-02-05 21:18:04 -0500 (Tue, 05 Feb 2008)
New Revision: 6003

Added:
   sandbox/pagameba/transition-resize/examples/fractional-zoom.html
   sandbox/pagameba/transition-resize/tests/Control/test_Navigation.html
Modified:
   sandbox/pagameba/transition-resize/lib/OpenLayers/Control/Navigation.js
   sandbox/pagameba/transition-resize/lib/OpenLayers/Layer.js
   sandbox/pagameba/transition-resize/lib/OpenLayers/Layer/WFS.js
   sandbox/pagameba/transition-resize/lib/OpenLayers/Map.js
   sandbox/pagameba/transition-resize/tests/Layer/test_WFS.html
   sandbox/pagameba/transition-resize/tests/list-tests.html
   sandbox/pagameba/transition-resize/tests/test_Layer.html
   sandbox/pagameba/transition-resize/tests/test_Map.html
Log:
merge 5981 to trunk HEAD

Copied: sandbox/pagameba/transition-resize/examples/fractional-zoom.html (from rev 6002, trunk/openlayers/examples/fractional-zoom.html)
===================================================================
--- sandbox/pagameba/transition-resize/examples/fractional-zoom.html	                        (rev 0)
+++ sandbox/pagameba/transition-resize/examples/fractional-zoom.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -0,0 +1,69 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <style type="text/css">
+        #map {
+            width: 512px;
+            height: 256px;
+            border: 1px solid gray;
+        }
+    </style>
+    <script src="../lib/OpenLayers.js"></script>
+    <script type="text/javascript">
+        var map;
+
+        function init() {
+            map = new OpenLayers.Map('map');
+            var wms = new OpenLayers.Layer.WMS(
+                "OpenLayers WMS",
+                "http://labs.metacarta.com/wms/vmap0",
+                {layers: 'basic'}
+            );
+            map.addLayers([wms]);
+
+            map.events.register("moveend", null, displayZoom);
+            map.addControl( new OpenLayers.Control.LayerSwitcher() );
+
+            map.zoomToMaxExtent();
+            
+            update(document.getElementById("fractional"));
+            
+        }
+        
+        function displayZoom() {
+            document.getElementById("zoom").innerHTML = map.zoom.toFixed(4);
+        }
+        
+        function update(input) {
+            map.fractionalZoom = input.checked;
+        }
+    </script>
+  </head>
+  <body onload="init()">
+	<h1 id="title">Fractional Zoom Example</h1>
+
+	<div id="tags">
+	</div>
+	<p id="shortdesc">
+            Shows the use of a map with fractional (or non-discrete) zoom levels.
+	</p>
+
+	<div id="map"></div>
+        <input type="checkbox" name="fractional"
+               id="fractional" checked="checked" onclick="update(this)" />
+        <label for="fractional">Fractional Zoom</label>
+        (zoom: <span id="zoom"></span>)
+        <br /><br />
+	<div id="docs">
+            <p>
+            Setting the map.fractionalZoom property to true allows zooming to
+            an arbitrary level (between the min and max resolutions).  This
+            can be demonstrated by shift-dragging a box to zoom to an arbitrary
+            extent.
+            </p>
+	</div>
+  </body>
+</html>
+
+
+
+

Modified: sandbox/pagameba/transition-resize/lib/OpenLayers/Control/Navigation.js
===================================================================
--- sandbox/pagameba/transition-resize/lib/OpenLayers/Control/Navigation.js	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/lib/OpenLayers/Control/Navigation.js	2008-02-06 02:18:04 UTC (rev 6003)
@@ -62,11 +62,28 @@
      */
     destroy: function() {
         OpenLayers.Control.prototype.destroy.apply(this,arguments);
+
         this.deactivate();
-        this.dragPan.destroy();
-        this.wheelHandler.destroy();
-        this.clickHandler.destroy();
-        this.zoomBox.destroy();
+
+        if (this.dragPan) {
+            this.dragPan.destroy();
+        }
+        this.dragPan = null;
+
+        if (this.wheelHandler) {
+            this.wheelHandler.destroy();
+        }
+        this.wheelHandler = null;
+
+        if (this.clickHandler) {
+            this.clickHandler.destroy();
+        }
+        this.clickHandler = null;
+        
+        if (this.zoomBox) {
+            this.zoomBox.destroy();
+        }
+        this.zoomBox = null;
     },
     
     /**
@@ -137,7 +154,7 @@
         var size    = this.map.getSize();
         var deltaX  = size.w/2 - evt.xy.x;
         var deltaY  = evt.xy.y - size.h/2;
-        var newRes  = this.map.baseLayer.resolutions[newZoom];
+        var newRes  = this.map.baseLayer.getResolutionForZoom(newZoom);
         var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
         var newCenter = new OpenLayers.LonLat(
                             zoomPoint.lon + deltaX * newRes,

Modified: sandbox/pagameba/transition-resize/lib/OpenLayers/Layer/WFS.js
===================================================================
--- sandbox/pagameba/transition-resize/lib/OpenLayers/Layer/WFS.js	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/lib/OpenLayers/Layer/WFS.js	2008-02-06 02:18:04 UTC (rev 6003)
@@ -156,6 +156,24 @@
         } else {    
             OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
         }    
+        if (this.tile) {
+            this.tile.destroy();
+        }
+        this.tile = null;
+
+        this.ratio = null;
+        this.featureClass = null;
+        this.format = null;
+
+        if (this.formatObject && this.formatObject.destroy) {
+            this.formatObject.destroy();
+        }
+        this.formatObject = null;
+        
+        this.formatOptions = null;
+        this.vectorMode = null;
+        this.encodeBBOX = null;
+        this.extractAttributes = null;
     },
     
     /**

Modified: sandbox/pagameba/transition-resize/lib/OpenLayers/Layer.js
===================================================================
--- sandbox/pagameba/transition-resize/lib/OpenLayers/Layer.js	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/lib/OpenLayers/Layer.js	2008-02-06 02:18:04 UTC (rev 6003)
@@ -769,7 +769,7 @@
      */
     getResolution: function() {
         var zoom = this.map.getZoom();
-        return this.resolutions[zoom];
+        return this.getResolutionForZoom(zoom);
     },
 
     /** 
@@ -824,6 +824,29 @@
     },
 
     /**
+     * APIMethod: getResolutionForZoom
+     * 
+     * Parameter:
+     * zoom - {Float}
+     * 
+     * Returns:
+     * {Float} A suitable resolution for the specified zoom.
+     */
+    getResolutionForZoom: function(zoom) {
+        zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1));
+        var resolution;
+        if(this.map.fractionalZoom) {
+            var low = Math.floor(zoom);
+            var high = Math.ceil(zoom);
+            resolution = this.resolutions[high] +
+                ((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
+        } else {
+            resolution = this.resolutions[Math.round(zoom)];
+        }
+        return resolution;
+    },
+
+    /**
      * APIMethod: getZoomForResolution
      * 
      * Parameters:
@@ -842,22 +865,50 @@
      *     value and the 'closest' specification.
      */
     getZoomForResolution: function(resolution, closest) {
-        var diff;
-        var minDiff = Number.POSITIVE_INFINITY;
-        for(var i=0; i < this.resolutions.length; i++) {            
-            if (closest) {
-                diff = Math.abs(this.resolutions[i] - resolution);
-                if (diff > minDiff) {
+        var zoom;
+        if(this.map.fractionalZoom) {
+            var lowZoom = 0;
+            var highZoom = this.resolutions.length - 1;
+            var highRes = this.resolutions[lowZoom];
+            var lowRes = this.resolutions[highZoom];
+            var res;
+            for(var i=0; i<this.resolutions.length; ++i) {
+                res = this.resolutions[i];
+                if(res >= resolution) {
+                    highRes = res;
+                    lowZoom = i;
+                }
+                if(res <= resolution) {
+                    lowRes = res;
+                    highZoom = i;
                     break;
                 }
-                minDiff = diff;
+            }
+            var dRes = highRes - lowRes;
+            if(dRes > 0) {
+                zoom = lowZoom + ((resolution - lowRes) / dRes);
             } else {
-                if (this.resolutions[i] < resolution) {
-                    break;
+                zoom = lowZoom;
+            }
+        } else {
+            var diff;
+            var minDiff = Number.POSITIVE_INFINITY;
+            for(var i=0; i < this.resolutions.length; i++) {            
+                if (closest) {
+                    diff = Math.abs(this.resolutions[i] - resolution);
+                    if (diff > minDiff) {
+                        break;
+                    }
+                    minDiff = diff;
+                } else {
+                    if (this.resolutions[i] < resolution) {
+                        break;
+                    }
                 }
             }
+            zoom = Math.max(0, i-1);
         }
-        return Math.max(0, i-1);
+        return zoom;
     },
     
     /**

Modified: sandbox/pagameba/transition-resize/lib/OpenLayers/Map.js
===================================================================
--- sandbox/pagameba/transition-resize/lib/OpenLayers/Map.js	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/lib/OpenLayers/Map.js	2008-02-06 02:18:04 UTC (rev 6003)
@@ -67,6 +67,14 @@
     id: null,
     
     /**
+     * Property: fractionalZoom
+     * {Boolean} For a base layer that supports it, allow the map resolution
+     *     to be set to a value between one of the values in the resolutions
+     *     array.  Default is false.
+     */
+    fractionalZoom: false,
+    
+    /**
      * APIProperty: events
      * {<OpenLayers.Events>} An events object that handles all 
      *                       events on the map
@@ -1266,10 +1274,7 @@
             if(zoom == null) { 
                 zoom = this.getZoom(); 
             }
-            var resolution = null;
-            if(this.baseLayer != null) {
-                resolution = this.baseLayer.resolutions[zoom];
-            }
+            var resolution = this.getResolutionForZoom(zoom);
             var extent = this.calculateBounds(lonlat, resolution); 
             if(!this.restrictedExtent.containsBounds(extent)) {
                 var maxCenter = this.restrictedExtent.getCenterLonLat(); 
@@ -1326,7 +1331,7 @@
 
             if (zoomChanged) {
                 this.zoom = zoom;
-                this.resolution = this.baseLayer.getResolution();
+                this.resolution = this.getResolutionForZoom(zoom);
                 // zoom level has changed, increment viewRequestID.
                 this.viewRequestID++;
             }    
@@ -1595,6 +1600,24 @@
     },
 
     /**
+     * APIMethod: getResolutionForZoom
+     * 
+     * Parameter:
+     * zoom - {Float}
+     * 
+     * Returns:
+     * {Float} A suitable resolution for the specified zoom.  If no baselayer
+     *     is set, returns null.
+     */
+    getResolutionForZoom: function(zoom) {
+        var resolution = null;
+        if(this.baseLayer) {
+            resolution = this.baseLayer.getResolutionForZoom(zoom);
+        }
+        return resolution;
+    },
+
+    /**
      * APIMethod: getZoomForResolution
      * 
      * Parameter:

Copied: sandbox/pagameba/transition-resize/tests/Control/test_Navigation.html (from rev 6002, trunk/openlayers/tests/Control/test_Navigation.html)
===================================================================
--- sandbox/pagameba/transition-resize/tests/Control/test_Navigation.html	                        (rev 0)
+++ sandbox/pagameba/transition-resize/tests/Control/test_Navigation.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -0,0 +1,69 @@
+<html>
+<head>
+  <script src="../../lib/OpenLayers.js"></script>
+  <script type="text/javascript">
+
+    function test_Control_Navigation_constructor (t) {
+        t.plan( 2 );
+    	var temp = OpenLayers.Control.prototype.initialize;
+    	OpenLayers.Control.prototype.initialize = function() {
+    		t.ok(true, "OpenLayers.Control's constructor called");
+    	};
+
+        var control = new OpenLayers.Control.Navigation();
+        t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" );
+
+		OpenLayers.Control.prototype.initialize = temp;
+    }
+
+    function test_Control_Navigation_destroy (t) {
+        t.plan(10);
+		
+    	var temp = OpenLayers.Control.prototype.destroy;
+    	OpenLayers.Control.prototype.destroy = function() {
+    		t.ok(true, "OpenLayers.Control's destroy called");
+    	};
+
+		var control = {
+			'deactivate': function() {
+				t.ok(true, "navigation control deactivated before being destroyed");
+			},
+			'dragPan': {
+				'destroy': function() {
+					t.ok(true, "dragPan destroyed");
+				}
+			},
+			'zoomBox': {
+				'destroy': function() {
+					t.ok(true, "zoomBox destroyed");
+				}
+			},
+			'wheelHandler': {
+				'destroy': function() {
+					t.ok(true, "wheelHandler destroyed");
+				}
+			},
+			'clickHandler': {
+				'destroy': function() {
+					t.ok(true, "clickHandler destroyed");
+				}
+			}
+		};
+
+		//this will also trigger one test by calling OpenLayers.Control's destroy
+		// and three more for the destruction of dragPan, zoomBox, and wheelHandler
+		OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
+
+		t.eq(control.dragPan, null, "'dragPan' set to null");
+		t.eq(control.zoomBox, null, "'zoomBox' set to null");
+		t.eq(control.wheelHandler, null, "'wheelHandler' set to null");
+		t.eq(control.clickHandler, null, "'clickHandler' set to null");
+
+		OpenLayers.Control.prototype.destroy = temp;
+    }
+
+  </script>
+</head>
+<body>
+</body>
+</html>
\ No newline at end of file

Modified: sandbox/pagameba/transition-resize/tests/Layer/test_WFS.html
===================================================================
--- sandbox/pagameba/transition-resize/tests/Layer/test_WFS.html	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/tests/Layer/test_WFS.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -14,6 +14,68 @@
         t.ok(layer.renderer.CLASS_NAME, "layer has a renderer");
 
     }
+    
+    function test_Layer_WFS_destroy(t) {
+    	t.plan(13);
+    	
+		var tVectorDestroy = OpenLayers.Layer.Vector.prototype.destroy;
+		OpenLayers.Layer.Vector.prototype.destroy = function() {
+			g_VectorDestroyed = true;
+		}
+
+		var tMarkersDestroy = OpenLayers.Layer.Markers.prototype.destroy;
+		OpenLayers.Layer.Markers.prototype.destroy = function() {
+			g_MarkersDestroyed = true;
+		}
+
+    	var layer = {
+    		'vectorMode': true,
+    		'tile': {
+    			'destroy': function() {
+    				t.ok(true, "wfs layer's tile is destroyed");
+				}
+			},
+			'ratio': {},
+			'featureClass': {},
+			'format': {},
+			'formatObject': {
+				'destroy': function() {
+					t.ok(true, "wfs layer's format object is destroyed");
+				}
+			},
+			'formatOptions': {},
+			'encodeBBOX': {},
+			'extractAttributes': {}
+		};
+		
+		//this call should set off two tests (destroys for tile and format object)
+		g_VectorDestroyed = null;
+		g_MarkersDestroyed = null;		
+		OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);		
+
+		t.ok(g_VectorDestroyed && !g_MarkersDestroyed, "when vector mode is set to true, the default vector layer's destroy() method is called");
+		t.eq(layer.vectorMode, null, "'vectorMode' property nullified");
+		t.eq(layer.tile, null, "'tile' property nullified");
+		t.eq(layer.ratio, null, "'ratio' property nullified");
+		t.eq(layer.featureClass, null, "'featureClass' property nullified");
+		t.eq(layer.format, null, "'format' property nullified");
+		t.eq(layer.formatObject, null, "'formatObject' property nullified");
+		t.eq(layer.formatOptions, null, "'formatOptions' property nullified");
+		t.eq(layer.encodeBBOX, null, "'encodeBBOX' property nullified");
+		t.eq(layer.extractAttributes, null, "'extractAttributes' property nullified");
+
+		layer.vectorMode = false;
+
+		//this call will *not* set off two tests (tile and format object are null)
+		g_VectorDestroyed = null;
+		g_MarkersDestroyed = null;		
+		OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);		
+		t.ok(!g_VectorDestroyed && g_MarkersDestroyed, "when vector mode is set to false, the default markers layer's destroy() method is called");
+		
+		OpenLayers.Layer.Vector.prototype.destroy = tVectorDestroy;
+		OpenLayers.Layer.Markers.prototype.destroy = tMarkersDestroy;
+    }
+    
     function test_Layer_WFS_mapresizevector(t) {
         t.plan(2);
 

Modified: sandbox/pagameba/transition-resize/tests/list-tests.html
===================================================================
--- sandbox/pagameba/transition-resize/tests/list-tests.html	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/tests/list-tests.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -84,6 +84,7 @@
     <li>Control/test_ModifyFeature.html</li>
     <li>Control/test_MousePosition.html</li>
     <li>Control/test_MouseToolbar.html</li>
+    <li>Control/test_Navigation.html</li>
     <li>Control/test_NavToolbar.html</li>
     <li>Control/test_OverviewMap.html</li>
     <li>Control/test_Panel.html</li>

Modified: sandbox/pagameba/transition-resize/tests/test_Layer.html
===================================================================
--- sandbox/pagameba/transition-resize/tests/test_Layer.html	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/tests/test_Layer.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -176,10 +176,11 @@
 
     function test_06_Layer_getZoomForResolution(t) {
 
-        t.plan(8);
+        t.plan(12);
 
         var layer = new OpenLayers.Layer('Test Layer');
-            
+        layer.map = {};
+        
         //make some dummy resolutions
         layer.resolutions = [128, 64, 32, 16, 8, 4, 2];
         
@@ -193,6 +194,16 @@
 
         t.eq(layer.getZoomForResolution(65, true), 1, "closest res");
         t.eq(layer.getZoomForResolution(63, true), 1, "closest res");
+        
+        layer.map.fractionalZoom = true;
+        t.eq(layer.getZoomForResolution(64), 1,
+             "(fractionalZoom) correct zoom for res in array");
+        t.eq(layer.getZoomForResolution(48).toPrecision(6), (1.5).toPrecision(6),
+             "(fractionalZoom) linear scaling for res between entries");
+        t.eq(layer.getZoomForResolution(200).toPrecision(6), (0).toPrecision(6),
+             "(fractionalZoom) doesn't return zoom below zero");
+        t.eq(layer.getZoomForResolution(1).toPrecision(6), (layer.resolutions.length - 1).toPrecision(6),
+             "(fractionalZoom) doesn't return zoom above highest index");
 
     }
     
@@ -301,6 +312,41 @@
         t.ok(layer.imageOffset.equals(desiredImageOffset), "image offset correctly calculated");
         t.ok(layer.imageSize.equals(desiredImageSize), "image size correctly calculated");
     }
+    
+    function test_Layer_getResolution(t) {
+        t.plan(1);
+        var layer = new OpenLayers.Layer("test");
+        layer.map = {
+            getZoom: function() {return "foo";}
+        };
+        layer.getResolutionForZoom = function(zoom) {
+            t.eq(zoom, "foo", "getResolution calls getResolutionForZoom");
+        }
+        layer.getResolution();
+        layer.map = null;
+        layer.destroy();
+    }
+    
+    function test_Layer_getResolutionForZoom(t) {
+        t.plan(5);
+        var layer = new OpenLayers.Layer("test");
+        layer.map = {fractionalZoom: false};
+        layer.resolutions = ["zero", "one", "two"];
+        t.eq(layer.getResolutionForZoom(0), "zero",
+             "(fractionalZoom false) returns resolution for given index");
+        t.eq(layer.getResolutionForZoom(0.9), "one",
+             "(fractionalZoom false) returns resolution for float index");
+        
+        layer.resolutions = [2, 4, 6, 8];
+        layer.map.fractionalZoom = true;
+        t.eq(layer.getResolutionForZoom(1).toPrecision(6), (4).toPrecision(6),
+             "(fractionalZoom true) returns resolution for integer zoom");
+        t.eq(layer.getResolutionForZoom(1.5).toPrecision(6), (5).toPrecision(6),
+             "(fractionalZoom true) returns resolution for float zoom");             
+        t.eq(layer.getResolutionForZoom(3.5).toPrecision(6), (8).toPrecision(6),
+             "(fractionalZoom true) returns resolution for zoom beyond res length - 1");
+        
+    }
 
 
 

Modified: sandbox/pagameba/transition-resize/tests/test_Map.html
===================================================================
--- sandbox/pagameba/transition-resize/tests/test_Map.html	2008-02-05 21:29:00 UTC (rev 6002)
+++ sandbox/pagameba/transition-resize/tests/test_Map.html	2008-02-06 02:18:04 UTC (rev 6003)
@@ -958,6 +958,22 @@
              se.toString(),
              "map extent not restricted with null restrictedExtent for se");
     }
+    
+    function test_Map_getResolutionForZoom(t) {
+        t.plan(2);
+        var map = new OpenLayers.Map("map");
+        var res = map.getResolutionForZoom();
+        t.eq(res, null, "getResolutionForZoom returns null for no base layer");
+        map.fractionalZoom = true;
+        var layer = new OpenLayers.Layer("test", {isBaseLayer: true});
+        layer.getResolutionForZoom = function() {
+            t.ok(true, "getResolutionForZoom calls base layer getResolutionForZoom");
+        }
+        map.addLayer(layer);
+        var res = map.getResolutionForZoom();
+        layer.destroy();
+        map.destroy();
+    }
 
     function test_99_Map_destroy (t) {
         t.plan( 3 );    



More information about the Commits mailing list