[OpenLayers-Commits] r7311 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Format lib/OpenLayers/Layer tests

commits at openlayers.org commits at openlayers.org
Thu Jun 5 16:37:40 EDT 2008


Author: tschaub
Date: 2008-06-05 16:37:40 -0400 (Thu, 05 Jun 2008)
New Revision: 7311

Modified:
   trunk/openlayers/lib/OpenLayers/Format/KML.js
   trunk/openlayers/lib/OpenLayers/Layer/KaMap.js
   trunk/openlayers/lib/OpenLayers/Layer/MapServer.js
   trunk/openlayers/lib/OpenLayers/Layer/WFS.js
   trunk/openlayers/lib/OpenLayers/Layer/WorldWind.js
   trunk/openlayers/lib/OpenLayers/Map.js
   trunk/openlayers/lib/OpenLayers/Util.js
   trunk/openlayers/tests/Util.html
Log:
Adding a bit of flexibility to extend and applyDefaults.  First argument can now be undefined.  r=pspencer,elemoine (closes #1564)

Modified: trunk/openlayers/lib/OpenLayers/Format/KML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/KML.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Format/KML.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -550,9 +550,9 @@
                 if (inlineStyleNode) {
                     var inlineStyle= this.parseStyle(inlineStyleNode);
                     if (inlineStyle) {
-                        feature.style = OpenLayers.Util.extend({}, 
-                                            feature.style);
-                        OpenLayers.Util.extend(feature.style, inlineStyle);
+                        feature.style = OpenLayers.Util.extend(
+                            feature.style, inlineStyle
+                        );
                     }
                 }
 

Modified: trunk/openlayers/lib/OpenLayers/Layer/KaMap.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/KaMap.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Layer/KaMap.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -64,13 +64,9 @@
         var newArguments = [];
         newArguments.push(name, url, params, options);
         OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
-        this.params = (params ? params : {});
-        if (params) {
-            OpenLayers.Util.applyDefaults(
-                           this.params, 
-                           this.DEFAULT_PARAMS
-                           );
-        }
+        this.params = OpenLayers.Util.applyDefaults(
+            this.params, this.DEFAULT_PARAMS
+        );
     },
 
     /**

Modified: trunk/openlayers/lib/OpenLayers/Layer/MapServer.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/MapServer.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Layer/MapServer.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -42,12 +42,9 @@
         newArguments.push(name, url, params, options);
         OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
 
-        if (arguments.length > 0) {
-            OpenLayers.Util.applyDefaults(
-                           this.params,
-                           this.DEFAULT_PARAMS
-                           );
-        }
+        this.params = OpenLayers.Util.applyDefaults(
+            this.params, this.DEFAULT_PARAMS
+        );
 
         // unless explicitly set in options, if the layer is transparent, 
         // it will be an overlay

Modified: trunk/openlayers/lib/OpenLayers/Layer/WFS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/WFS.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Layer/WFS.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -138,11 +138,10 @@
             this.options.geometry_column = "the_geom";
         }    
         
-        this.params = params;
-        OpenLayers.Util.applyDefaults(
-                       this.params, 
-                       OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
-                       );
+        this.params = OpenLayers.Util.applyDefaults(
+            params, 
+            OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
+        );
         this.url = url;
     },    
     

Modified: trunk/openlayers/lib/OpenLayers/Layer/WorldWind.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/WorldWind.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Layer/WorldWind.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -54,13 +54,9 @@
         var newArguments = [];
         newArguments.push(name, url, params, options);
         OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
-        this.params = (params ? params : {});
-        if (params) {
-            OpenLayers.Util.applyDefaults(
-                           this.params, 
-                           this.DEFAULT_PARAMS
-                           );
-        }
+        this.params = OpenLayers.Util.applyDefaults(
+            this.params, this.DEFAULT_PARAMS
+        );
     },
     /**
      * Method: addTile

Modified: trunk/openlayers/lib/OpenLayers/Map.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Map.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Map.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -1335,11 +1335,7 @@
      *    false.
      */
     pan: function(dx, dy, options) {
-        // this should be pushed to applyDefaults and extend
-        if (!options) {
-            options = {};
-        }
-        OpenLayers.Util.applyDefaults(options, {
+        options = OpenLayers.Util.applyDefaults(options, {
             animate: true,
             dragging: false
         });

Modified: trunk/openlayers/lib/OpenLayers/Util.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Util.js	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/lib/OpenLayers/Util.js	2008-06-05 20:37:40 UTC (rev 7311)
@@ -49,7 +49,8 @@
  * {Object} The destination object.
  */
 OpenLayers.Util.extend = function(destination, source) {
-    if(destination && source) {
+    destination = destination || {};
+    if(source) {
         for(var property in source) {
             var value = source[property];
             if(value !== undefined) {
@@ -522,7 +523,7 @@
  *     in place and returned by this function.
  */
 OpenLayers.Util.applyDefaults = function (to, from) {
-
+    to = to || {};
     /*
      * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative
      * prototype object" when calling hawOwnProperty if the source object is an

Modified: trunk/openlayers/tests/Util.html
===================================================================
--- trunk/openlayers/tests/Util.html	2008-06-05 15:51:06 UTC (rev 7310)
+++ trunk/openlayers/tests/Util.html	2008-06-05 20:37:40 UTC (rev 7311)
@@ -169,7 +169,7 @@
 
     function test_Util_applyDefaults(t) {
     
-        t.plan(10);
+        t.plan(11);
         
         var to = { 
             'a': "abra",
@@ -198,6 +198,12 @@
         t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret");
         t.eq(to.toString(), "works", "correctly applies custom toString");
         t.eq(to.n, null, "correctly preserves null");
+        
+        var to;
+        var from = {rand: Math.random()};
+        
+        var ret = OpenLayers.Util.applyDefaults(to, from);
+        t.eq(ret.rand, from.rand, "works with undefined to");
     }
 
     function test_Util_getParameterString(t) {
@@ -709,7 +715,7 @@
     }
 
     function tests_Util_extend(t) {
-        t.plan(6);
+        t.plan(7);
 
         var source = {
             num: Math.random(),
@@ -736,6 +742,12 @@
         t.eq(destination.nada, "untouched",
              "undefined source properties don't clobber existing properties");
         t.eq(window.property, undefined, "Property variable not clobbered.");
+        
+        var destination;
+        var source = {rand: Math.random()};
+        var ret = OpenLayers.Util.extend(destination, source);
+        t.eq(destination.rand, source.rand, "works with undefined destination");
+        
     }
     
     function test_XX_Util_Try(t) {



More information about the Commits mailing list