[Commits] r2386 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Wed Sep 22 09:17:39 CEST 2010


Author: elemoine
Date: 2010-09-22 09:17:39 +0200 (Wed, 22 Sep 2010)
New Revision: 2386

Modified:
   core/trunk/geoext/lib/GeoExt/data/PrintPage.js
   core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
Log:
Error in PrintPage when working without a scales field, r=ahocevar (closes #344)

Modified: core/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-09-22 06:50:33 UTC (rev 2385)
+++ core/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-09-22 07:17:39 UTC (rev 2386)
@@ -96,6 +96,18 @@
         this.feature = new OpenLayers.Feature.Vector(
             OpenLayers.Geometry.fromWKT("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"));
 
+        if(this.printProvider.capabilities) {
+            this.setScale(this.printProvider.scales.getAt(0));
+        } else {
+            this.printProvider.on({
+                "loadcapabilities": function() {
+                    this.setScale(this.printProvider.scales.getAt(0));
+                },
+                scope: this,
+                single: true
+            });
+        }
+
         this.printProvider.on({
             "layoutchange": this.onLayoutChange,
             scope: this
@@ -299,7 +311,11 @@
         if(this.printProvider.layout.get("rotation") === false) {
             this.setRotation(0, true);
         }
-        this.setScale(this.scale);
+        // at init time the print provider triggers layoutchange
+        // before loadcapabilities, i.e. before we set this.scale
+        // to the first scale in the scales store, we need to
+        // guard against that
+        this.scale && this.setScale(this.scale);
     },
     
     /** private: method[destroy]

Modified: core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html	2010-09-22 06:50:33 UTC (rev 2385)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html	2010-09-22 07:17:39 UTC (rev 2386)
@@ -29,7 +29,42 @@
             
             printPage.destroy();
         }
-        
+
+        function test_init_setScale(t) {
+
+            // tests to check printPage.scale is set when the printProvider
+            // has received the print capabilities
+            // http://trac.geoext.org/ticket/344
+
+            t.plan(3);
+
+            var printProvider, printPage;
+
+            // test #1
+            printProvider = new GeoExt.data.PrintProvider({
+                capabilities: printCapabilities
+            });
+            printPage = new GeoExt.data.PrintPage({
+                printProvider: printProvider
+            });
+            t.eq(printPage.scale.get("name"), "1:4,000,000", "first scale set in page");
+            printPage.destroy();
+
+            // test #2
+            printProvider = new GeoExt.data.PrintProvider({
+                url: "foo", autoLoad: false
+            });
+            printPage = new GeoExt.data.PrintPage({
+                printProvider: printProvider
+            });
+            t.eq(printPage.scale, null,
+                 "scale is null in page if provider hasn't received the caps");
+            printProvider.capabilities = printCapabilities;
+            printProvider.loadStores();
+            t.eq(printPage.scale.get("name"), "1:4,000,000", "first scale set in page");
+            printPage.destroy();
+        }
+
         function test_setCenter(t) {
             t.plan(1);
             
@@ -110,7 +145,6 @@
             printPage.destroy();
             mapPanel.destroy();
         }
-        
     </script>
   </head>  
   <body>



More information about the Commits mailing list