[Commits] r1842 - sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Fri Jan 29 18:24:20 CET 2010


Author: ahocevar
Date: 2010-01-29 18:24:19 +0100 (Fri, 29 Jan 2010)
New Revision: 1842

Modified:
   sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js
Log:
event handling fixes

Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js	2010-01-29 00:36:35 UTC (rev 1841)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js	2010-01-29 17:24:19 UTC (rev 1842)
@@ -135,14 +135,14 @@
         this.map = mapPanel.map;
         this.initLayer();
         this.initControl();
-        this.printProvider.on("layoutchange", this.onLayoutChange, this);
+        this.printProvider.on("layoutchange", this.updateBox, this);
 
         if(!this.initialConfig.pages) {
             this.map.getCenter() ?
-                this.pages[0].fit(this.map) :
+                this.fitPage() :
                 mapPanel.on({
-                    "afterlayout": this.pages[0].fit,
-                    scope: this.pages[0],
+                    "afterlayout": this.fitPage,
+                    scope: this,
                     single: true
                 });
         }
@@ -152,7 +152,7 @@
      *  :param mapPanel: class:`GeoExt.MapPanel`
      */
     removeFromMapPanel: function(mapPanel) {
-        this.printProvider.un("layoutchange", this.onLayoutChange, this);
+        this.printProvider.un("layoutchange", this.updateBox, this);
         this.control.deactivate();
         this.map.removeControl(this.control);
         for(var i=0, len=this.pages.length; i<len; ++i) {
@@ -188,11 +188,6 @@
         var pages = this.pages;
 
         if(!this.control) {
-            var updateHandles = function() {
-                for(var i=0, len=pages.length; i<len; ++i) {
-                    pages[i].updateHandles();
-                };
-            }
             this.control = new OpenLayers.Control.TransformFeature(this.layer, {
                 preserveAspectRatio: true,
                 eventListeners: {
@@ -225,17 +220,12 @@
                             var tooSmall = page.scale === maxScale &&
                                 pageBounds.containsBounds(boxBounds);
                             if(tooLarge === true || tooSmall === true) {
-                                e.object.setFeature(this.currentPage.feature,
-                                    {rotation: this.currentPage.rotation});
+                                this.updateBox();
                             }
                         }
                         return false;
                     },
-                    "transformcomplete": function(e) {
-                        this.control.setFeature(this.currentPage.feature, {
-                            rotation: -this.currentPage.rotation
-                        });
-                    },
+                    "transformcomplete": this.updateBox,
                     scope: this
                 }
             });
@@ -244,23 +234,28 @@
         this.map.addControl(this.control);
     },
     
-    /** private: method[onLayoutChange]
-     *  Handler for the printProvider's layoutchange event.
+    /** private: method[fitPage]
+     *  Fits the current print page to the map.
      */
-    onLayoutChange: function(printProvider, layout) {
-        this.control.setFeature(this.currentPage.feature, {
-            rotation: -this.currentPage.rotation
-        });
+    fitPage: function() {
+        this.currentPage.fit(this.map);
     },
     
+    /** private: method[updateBox]
+     *  Updates the transformation box after setting a new scale or
+     *  layout, or to fit the box to the extent feature after a tranform.
+     */
+    updateBox: function() {
+        var page = this.currentPage;
+        this.control.setFeature(page.feature, {rotation: -page.rotation});
+    },
+    
     /** private: method[onPageChange]
      *  Handler for a page's change event.
      */
     onPageChange: function(page, mods) {
-        if(this.control.feature !== page.feature) {
-            this.control.setFeature(page.feature, {
-                rotation: -page.rotation
-            });
+        if(mods.scale || this.control.feature !== page.feature) {
+            this.control.setFeature(page.feature, {rotation: -page.rotation});
         }
     },
     



More information about the Commits mailing list