[OpenLayers-Commits] r6033 - in trunk/openlayers: lib/OpenLayers/Format/WMC tests tests/Format tests/Format/WMC

commits at openlayers.org commits at openlayers.org
Thu Feb 7 16:06:08 EST 2008


Author: tschaub
Date: 2008-02-07 16:06:08 -0500 (Thu, 07 Feb 2008)
New Revision: 6033

Added:
   trunk/openlayers/tests/Format/WMC/
   trunk/openlayers/tests/Format/WMC/test_v1_1_0.html
Modified:
   trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js
   trunk/openlayers/tests/list-tests.html
Log:
Only write out min/max scale related properties if they are explicitly set on the layer.  Thanks for slapping Safari around a bit with this on crschmidt.  Works but still untested there.  r=crschmidt (closes #1314)

Modified: trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js	2008-02-07 20:50:24 UTC (rev 6032)
+++ trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js	2008-02-07 21:06:08 UTC (rev 6033)
@@ -89,17 +89,23 @@
         );
         
         // min/max scale denominator elements go before the 4th element in v1
-        var minSD = this.createElementNS(
-            this.namespaces.sld, "sld:MinScaleDenominator"
-        );
-        minSD.appendChild(this.createTextNode(layer.maxScale.toPrecision(10)));
-        node.insertBefore(minSD, node.childNodes[3]);
+        if(layer.options.resolutions || layer.options.scales ||
+           layer.options.minResolution || layer.options.maxScale) {
+            var minSD = this.createElementNS(
+                this.namespaces.sld, "sld:MinScaleDenominator"
+            );
+            minSD.appendChild(this.createTextNode(layer.maxScale.toPrecision(10)));
+            node.insertBefore(minSD, node.childNodes[3]);
+        }
         
-        var maxSD = this.createElementNS(
-            this.namespaces.sld, "sld:MaxScaleDenominator"
-        );
-        maxSD.appendChild(this.createTextNode(layer.minScale.toPrecision(10)));
-        node.insertBefore(maxSD, node.childNodes[4]);
+        if(layer.options.resolutions || layer.options.scales ||
+           layer.options.maxResolution || layer.options.minScale) {
+            var maxSD = this.createElementNS(
+                this.namespaces.sld, "sld:MaxScaleDenominator"
+            );
+            maxSD.appendChild(this.createTextNode(layer.minScale.toPrecision(10)));
+            node.insertBefore(maxSD, node.childNodes[4]);
+        }
         
         return node;
         

Added: trunk/openlayers/tests/Format/WMC/test_v1_1_0.html
===================================================================
--- trunk/openlayers/tests/Format/WMC/test_v1_1_0.html	                        (rev 0)
+++ trunk/openlayers/tests/Format/WMC/test_v1_1_0.html	2008-02-07 21:06:08 UTC (rev 6033)
@@ -0,0 +1,74 @@
+<html> 
+<head> 
+    <script src="../../../lib/OpenLayers.js"></script> 
+    <script type="text/javascript">
+    
+    function test_write_wmc_Layer(t) {
+        if (OpenLayers.Util.getBrowserName() == "safari") {
+            t.plan(0);
+            t.debug_print("Safari has wierd behavior with getElementsByTagNameNS: the result is that we can't run these tests there. Patches welcome.");
+            return;
+        }
+        t.plan(10);
+        
+        // direct construction of a parser for a unit test
+        var wmc = new OpenLayers.Format.WMC.v1_1_0();
+        var sldNS = wmc.namespaces["sld"];
+        
+        // test that Min/MaxScaleDenominator is not written out when no
+        // resolution related options are set
+        var layer = new OpenLayers.Layer.WMS(
+            "test", "http://foo", {},
+            {maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
+        );
+        var node = wmc.write_wmc_Layer(layer);
+        var minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
+        t.eq(minList.length, 0, "(none) node not written with MinScaleDenominator");
+        var maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
+        t.eq(maxList.length, 0, "(none) node not written with MaxScaleDenominator");
+
+        // test that Min/MaxScaleDenominator is written out for explicit
+        // resolutions array
+        layer = new OpenLayers.Layer.WMS(
+            "test", "http://foo", {},
+            {resolutions: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
+        );
+        layer.minScale = Math.random();
+        layer.maxScale = Math.random();
+        sldNS = wmc.namespaces["sld"];
+        node = wmc.write_wmc_Layer(layer);
+        minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
+        t.eq(minList.length, 1, "(resolutions) node written with MinScaleDenominator");
+        t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
+             "(resolutions) node written with correct MinScaleDenominator value");
+        maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
+        t.eq(maxList.length, 1, "(resolutions) node written with MaxScaleDenominator");
+        t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
+             "(resolutions) node written with correct MaxScaleDenominator value");
+        
+        layer = new OpenLayers.Layer.WMS(
+            "test", "http://foo", {},
+            {scales: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
+        );
+        layer.minScale = Math.random();
+        layer.maxScale = Math.random();
+        node = wmc.write_wmc_Layer(layer);
+        minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
+        var f = new OpenLayers.Format.XML();
+        t.eq(minList.length, 1, "(scales) node written with MinScaleDenominator");
+        t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
+             "(scales) node written with correct MinScaleDenominator value");
+        maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
+        t.eq(maxList.length, 1, "(scales) node written with MaxScaleDenominator");
+        t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
+             "(scales) node written with correct MaxScaleDenominator value");
+        
+    }
+    
+
+    </script> 
+</head> 
+<body>
+    <div id="map" style="width: 512px; height: 256px;"></div>
+</body> 
+</html> 

Modified: trunk/openlayers/tests/list-tests.html
===================================================================
--- trunk/openlayers/tests/list-tests.html	2008-02-07 20:50:24 UTC (rev 6032)
+++ trunk/openlayers/tests/list-tests.html	2008-02-07 21:06:08 UTC (rev 6033)
@@ -31,6 +31,7 @@
     <li>Format/test_SLD.html</li>
     <li>Format/test_WKT.html</li>
     <li>Format/test_WMC.html</li>
+    <li>Format/WMC/test_v1_1_0.html</li>
     <li>Format/test_XML.html</li>
     <li>test_Icon.html</li>
     <li>test_Marker.html</li>



More information about the Commits mailing list