[OpenLayers-Commits] r3582 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Layer lib/OpenLayers/Layer/MapServer lib/OpenLayers/Layer/WMS tests

commits at openlayers.org commits at openlayers.org
Thu Jul 5 10:04:52 EDT 2007


Author: euzuro
Date: 2007-07-05 10:04:51 -0400 (Thu, 05 Jul 2007)
New Revision: 3582

Modified:
   trunk/openlayers/lib/OpenLayers/Layer.js
   trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js
   trunk/openlayers/lib/OpenLayers/Layer/Markers.js
   trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js
   trunk/openlayers/lib/OpenLayers/Map.js
   trunk/openlayers/tests/test_Layer.html
Log:
fix for #795 - all layers now have a redraw() method that simply redraws them no matter whether the extent or parameters or zoom has changed. Big big thanks to tim schaub for not only taking the time to listen to my relentless (and often cracked) brainstorming about this ticket and for taking the time out to review the final patch.... but above and beyond the call of duty, adding *tests* for this patch. real ace. top knotch.

Modified: trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/lib/OpenLayers/Layer/MapServer/Untiled.js	2007-07-05 14:04:51 UTC (rev 3582)
@@ -241,7 +241,7 @@
      */
     setUrl: function(newUrl) {
         OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);
-        this.moveTo();
+        this.redraw();
     },
 
     /** 
@@ -254,8 +254,7 @@
     mergeNewParams:function(newParams) {
         OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, 
                                                                  [newParams]);
-        //redraw
-        this.moveTo(null, true);
+        this.redraw();
     },
     
     /** 

Modified: trunk/openlayers/lib/OpenLayers/Layer/Markers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Markers.js	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/lib/OpenLayers/Layer/Markers.js	2007-07-05 14:04:51 UTC (rev 3582)
@@ -72,7 +72,9 @@
         OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
 
         if (zoomChanged || !this.drawn) {
-            this.redraw();
+            for(i=0; i < this.markers.length; i++) {
+                this.drawMarker(this.markers[i]);
+            }
             this.drawn = true;
         }
     },
@@ -116,17 +118,6 @@
         }
     },
 
-    /**
-     * APIMethod: redraw
-     * Clear all the marker div's from the layer and then redraw all of them.
-     *    Use the map to recalculate new placement of markers.
-     */
-    redraw: function() {
-        for(i=0; i < this.markers.length; i++) {
-            this.drawMarker(this.markers[i]);
-        }
-    },
-
     /** 
      * Method: drawMarker
      * Calculate the pixel location for the marker, create it, and 

Modified: trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/lib/OpenLayers/Layer/WMS/Untiled.js	2007-07-05 14:04:51 UTC (rev 3582)
@@ -257,7 +257,7 @@
      */
     setUrl: function(newUrl) {
         OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments);
-        this.moveTo();
+        this.redraw();
     },
 
     /**
@@ -272,8 +272,7 @@
         var newArguments = [upperParams];
         OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, 
                                                                  newArguments);
-        //redraw
-        this.moveTo(null, true);
+        this.redraw();
     },
     
     /** 

Modified: trunk/openlayers/lib/OpenLayers/Layer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer.js	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/lib/OpenLayers/Layer.js	2007-07-05 14:04:51 UTC (rev 3582)
@@ -335,6 +335,31 @@
     },
 
     /**
+     * APIMethod: redraw
+     * Redraws the layer.  Returns true if the layer was redrawn, false if not.
+     *
+     * Return:
+     * {Boolean} The layer was redrawn.
+     */
+    redraw: function() {
+        var redrawn = false;
+        if (this.map) {
+
+            // min/max Range may have changed
+            this.inRange = this.calculateInRange();
+
+            // map's center might not yet be set
+            var extent = this.getExtent();
+
+            if (extent && this.inRange && this.visibility) {
+                this.moveTo(extent, true, false);
+                redrawn = true;
+            }
+        }
+        return redrawn;
+    },
+
+    /**
      * Method: moveTo
      * 
      * Parameters:
@@ -451,12 +476,7 @@
         if (visibility != this.visibility) {
             this.visibility = visibility;
             this.display(visibility);
-            if (visibility && this.map != null) {
-                var extent = this.map.getExtent();
-                if (extent != null) {
-                    this.moveTo(extent, true);
-                }
-            }
+            this.redraw();
             if ((this.map != null) && 
                 ((noEvent == null) || (noEvent == false))) {
                 this.map.events.triggerEvent("changelayer");

Modified: trunk/openlayers/lib/OpenLayers/Map.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Map.js	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/lib/OpenLayers/Map.js	2007-07-05 14:04:51 UTC (rev 3582)
@@ -518,9 +518,7 @@
                 layer.setVisibility(false);
             }
         } else {
-            if (this.getCenter() != null) {
-                layer.moveTo(this.getExtent(), true);   
-            }
+            layer.redraw();
         }
 
         this.events.triggerEvent("addlayer");

Modified: trunk/openlayers/tests/test_Layer.html
===================================================================
--- trunk/openlayers/tests/test_Layer.html	2007-07-05 13:36:38 UTC (rev 3581)
+++ trunk/openlayers/tests/test_Layer.html	2007-07-05 14:04:51 UTC (rev 3582)
@@ -165,6 +165,50 @@
 
     }
     
+    function test_Layer_redraw(t) {
+        t.plan(8)
+
+        var name = 'Test Layer';
+        var url = "http://octo.metacarta.com/cgi-bin/mapserv";
+        var params = { map: '/mapdata/vmap_wms.map', 
+                       layers: 'basic', 
+                       format: 'image/jpeg'};
+
+        var layer = new OpenLayers.Layer.WMS(name, url, params);
+        
+        t.ok(!layer.redraw(),
+             "redraw on an orphan layer returns false");
+        
+        var map = new OpenLayers.Map('map');
+        map.addLayer(layer);
+
+        t.ok(!layer.redraw(),
+             "redraw returns false if map does not yet have a center");
+        map.zoomToMaxExtent();
+        
+        t.ok(layer.redraw(),
+             "redraw returns true after map has a center");
+        
+        layer.setVisibility(false);
+        t.ok(!layer.redraw(),
+             "redraw returns false if a layer is not visible");
+        
+        layer.setVisibility(true);
+        t.ok(layer.redraw(),
+                "redraw returns true even if extent has not changed");
+        
+        layer.moveTo = function(bounds, zoomChanged, dragging) {
+            var extent = layer.map.getExtent();
+            t.ok(bounds.equals(extent),
+                 "redraw calls moveTo with the map extent");
+            t.ok(zoomChanged,
+                 "redraw calls moveTo with zoomChanged true");
+            t.ok(!dragging,
+                 "redraw calls moveTo with dragging false");
+        }
+        layer.redraw();
+        
+    }
     
 /******
  * 



More information about the Commits mailing list