[Commits] r2311 - in core/trunk/geoext: lib/GeoExt/data lib/GeoExt/plugins lib/GeoExt/widgets tests/lib/GeoExt/data tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Fri Sep 3 09:47:45 CEST 2010


Author: ahocevar
Date: 2010-09-03 09:47:45 +0200 (Fri, 03 Sep 2010)
New Revision: 2311

Modified:
   core/trunk/geoext/lib/GeoExt/data/PrintPage.js
   core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js
   core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
   core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
   core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
   core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
Log:
revert changes for #318 and #321 that were accidently committed with r2304


Modified: core/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/lib/GeoExt/data/PrintPage.js	2010-09-03 07:47:45 UTC (rev 2311)
@@ -166,23 +166,15 @@
     /** api: method[fit]
      *  :param fitTo: :class:`GeoExt.MapPanel` or ``OpenLayers.Map`` or ``OpenLayers.Feature.Vector``
      *      The map or feature to fit the page to.
-     *  :param options: ``Object`` Additional options to determine how to fit
-     *
+     *  :param loose: ``Boolean`` If true, the closest matching print extent
+     *      will be chosen. If set to false, the chosen print extent will
+     *      be the closest one that entirely fits into the visible map extent.
+     *      Default is false.
+     * 
      *  Fits the page layout to a map or feature extent. If the map extent has
      *  not been centered yet, this will do nothing.
-     * 
-     *  Available options:
-     *
-     *  * mode - ``String`` How to calculate the print extent? If "closest",
-     *    the closest matching print extent will be chosen. If "printer", the
-     *    chosen print extent will be the closest one that can show the entire
-     *    ``fitTo`` extent on the printer. If "screen", it will be the closest
-     *    one that is entirely visible inside the ``fitTo`` extent. Default is
-     *    "printer".
-     * 
      */
-    fit: function(fitTo, options) {
-        options = options || {};
+    fit: function(fitTo, loose) {
         var map = fitTo, extent;
         if(fitTo instanceof GeoExt.MapPanel) {
             map = fitTo.map;
@@ -201,30 +193,33 @@
         this.setCenter(center);
         var units = map.getUnits();
         var scale = this.printProvider.scales.getAt(0);
-        var closest = Number.POSITIVE_INFINITY;
+        var closest = {
+            diff: Number.POSITIVE_INFINITY,
+            scale: scale
+        };
         var mapWidth = extent.getWidth();
         var mapHeight = extent.getHeight();
         this.printProvider.scales.each(function(rec) {
             var bounds = this.calculatePageBounds(rec, units);
-            if (options.mode == "closest") {
-                var diff = 
-                    Math.abs(bounds.getWidth() - mapWidth) +
-                    Math.abs(bounds.getHeight() - mapHeight);
-                if (diff < closest) {
-                    closest = diff;
-                    scale = rec;
+            var contains = bounds.containsBounds(extent);
+            if (contains) {
+                scale = rec;
+            }
+            if (loose) {
+                var diff = Math.min(
+                    Math.abs(bounds.getWidth() - mapWidth),
+                    Math.abs(bounds.getHeight() - mapHeight)
+                );
+                if (diff < closest.diff) {
+                    closest.diff = diff;
+                    closest.scale = rec;
                 }
             } else {
-                var contains = options.mode == "screen" ?
-                    !extent.containsBounds(bounds) :
-                    bounds.containsBounds(extent);
-                if (contains || (options.mode == "screen" && !contains)) {
-                    scale = rec;
-                }
+                // no need to continue if not contained and not loose
                 return contains;
             }
         }, this);
-        this.setScale(scale, units);
+        this.setScale(loose ? closest.scale : scale, units);
         delete this._updating;
         this.updateFeature(this.feature.geometry, {
             center: center,

Modified: core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js	2010-09-03 07:47:45 UTC (rev 2311)
@@ -88,9 +88,9 @@
     control: null,
     
     /** api: config[pages]
-     *  Array of :class:`GeoExt.data.PrintPage` The pages that this plugin
+     *  Array of :class:`GeoExt.data.PrintPage` The pages that this form
      *  controls. Optional. If not provided, it will be created with one page
-     *  that is completely contained within the visible map extent.
+     *  that fits the current map extent.
      *  
      *  .. note:: All pages must use the same PrintProvider.
      */
@@ -335,7 +335,7 @@
                             e.center.toShortString()
                         ));
                     } else {
-                        page.fit(e.object.box, {mode: "closest"});
+                        page.fit(e.object.box);
                         var minScale = this.printProvider.scales.getAt(0);
                         var maxScale = this.printProvider.scales.getAt(
                             this.printProvider.scales.getCount() - 1);
@@ -363,7 +363,7 @@
      */
     fitPage: function() {
         if(this.page) {
-            this.page.fit(this.map, {mode: "screen"});
+            this.page.fit(this.map);
         }
     },
 

Modified: core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2010-09-03 07:47:45 UTC (rev 2311)
@@ -343,6 +343,9 @@
         if(this.ownerCt) {
             this.ownerCt.un("move", this.updateMapSize, this);
         }
+        GeoExt.MapPanel.superclass.beforeDestroy.apply(this, arguments);
+        // if the map panel was passed a map instance, this map instance
+        // is under the user's responsibility
         if(this.map && this.map.events) {
             this.map.events.un({
                 "moveend": this.onMoveend,
@@ -350,8 +353,6 @@
                 scope: this
             });
         }
-        // if the map panel was passed a map instance, this map instance
-        // is under the user's responsibility
         if(!this.initialConfig.map ||
            !(this.initialConfig.map instanceof OpenLayers.Map)) {
             // we created the map, we destroy it
@@ -360,7 +361,6 @@
             }
         }
         delete this.map;
-        GeoExt.MapPanel.superclass.beforeDestroy.apply(this, arguments);
     }
     
 });

Modified: core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js	2010-09-03 07:47:45 UTC (rev 2311)
@@ -201,7 +201,7 @@
         
         GeoExt.PrintMapPanel.superclass.initComponent.call(this);
 
-        this.printProvider.on("layoutchange", this.syncSize, this);
+        this.printProvider.on("layoutchange", this.updateExtent, this);
         this.printPage.on("change", this.fitZoom, this);
         this.map.events.register("moveend", this, this.updatePage);
     },
@@ -211,28 +211,12 @@
      */
     afterRender: function() {
         GeoExt.PrintMapPanel.superclass.afterRender.apply(this, arguments);
-        this.syncSize();
-        if (this.initialConfig.limitScales === true) {
-            if (!this.ownerCt) {
-                this.calculatePreviewScales()
-            } else {
-                this.ownerCt.on({
-                    "afterlayout": {
-                        fn: this.calculatePreviewScales,
-                        scope: this,
-                        single: true
-                    }
-                });
-            }
-            this.on("resize", this.calculatePreviewScales, this);
-        }
+        this.updateExtent();
     },
     
     /** private: method[adjustSize]
-     *  :param width: ``Number`` If not provided or 0, initialConfig.width will
-     *      be used.
-     *  :param height: ``Number`` If not provided or 0, initialConfig.height
-     *      will be used.
+     *  :param width: ``Number``
+     *  :param height: ``Number``
      *  Private override - sizing this component always takes the aspect ratio
      *  of the print page into account.
      */
@@ -243,10 +227,8 @@
         // aspect ratio - do not exceed either, but don't take values for
         // granted if container is configured with autoWidth or autoHeight.
         var ownerCt = this.ownerCt;
-        var targetWidth = (ownerCt && ownerCt.autoWidth) ? 0 :
-            (width || this.initialConfig.width);
-        var targetHeight = (ownerCt && ownerCt.autoHeight) ? 0 :
-            (height || this.initialConfig.height);
+        var targetWidth = (ownerCt && ownerCt.autoWidth) ? 0 : width;
+        var targetHeight = (ownerCt && ownerCt.autoHeight) ? 0 : height;
         if (targetWidth) {
             height = targetWidth / ratio;
             if (targetHeight && height > targetHeight) {
@@ -263,6 +245,17 @@
         return {width: width, height: height};
     },
     
+    /** private: method[updateExtent]
+     *  Makes sure that this :class:`PrintMapPanel` gets the aspect ratio that
+     *  matches the print page, and update the previewable scales.
+     */
+    updateExtent: function() {
+        this.syncSize();
+        if (this.initialConfig.limitScales === true) {
+            this.calculatePreviewScales();
+        }
+    },
+    
     /** private: method[fitZoom]
      *  Fits this PrintMapPanel's zoom to the print scale.
      */
@@ -363,7 +356,7 @@
     beforeDestroy: function() {
         this.map.events.unregister("moveend", this, this.updatePage);
         this.printPage.un("change", this.fitZoom, this);
-        this.printProvider.un("layoutchange", this.syncSize, this);
+        this.printProvider.un("layoutchange", this.updateExtent, this);
         GeoExt.PrintMapPanel.superclass.beforeDestroy.apply(this, arguments);
     }
 });

Modified: core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html	2010-09-03 07:47:45 UTC (rev 2311)
@@ -79,14 +79,14 @@
         }
         
         function test_fit(t) {
-            t.plan(4);
+            t.plan(3);
             
             var center = new OpenLayers.LonLat(146.56, -41.56);
             var mapPanel = new GeoExt.MapPanel({
                 renderTo: "map",
-                width: 272,
-                height: 272,
-                layers: [new OpenLayers.Layer("empty", {isBaseLayer: true})],
+                width: 400,
+                height: 300,
+                layers: [new OpenLayers.Layer.WMS("wms", "http://demo.opengeo.org/geoserver/wms", {layers: "topp:tasmania_water_bodies"})],
                 center: center,
                 zoom: 7
             });
@@ -97,15 +97,12 @@
                 })
             });
 
-            printPage.fit(mapPanel, {mode: "printer"});
+            printPage.fit(mapPanel);
             t.eq(printPage.center.toString(), center.toString(), "Print page centered correctly.");
-            t.eq(printPage.scale.get("value"), 4000000, "Print scale set correctly.");
+            t.eq(printPage.scale.get("value"), 2000000, "Print scale set correctly.");
 
-            printPage.fit(mapPanel, {mode: "closest"});
-            t.eq(printPage.scale.get("value"), 2000000, "Print scale for 'closest' mode set correctly.");
-
-            printPage.fit(mapPanel, {mode: "screen"});
-            t.eq(printPage.scale.get("value"), 1000000, "Print scale for 'screen' mode set correctly.");
+            printPage.fit(mapPanel, true);
+            t.eq(printPage.scale.get("value"), 4000000, "Print scale for 'loose' option set correctly.");
             
             printPage.destroy();
             mapPanel.destroy();

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html	2010-09-03 07:42:16 UTC (rev 2310)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html	2010-09-03 07:47:45 UTC (rev 2311)
@@ -16,9 +16,9 @@
                 renderTo: "mappanel",
                 width: 256,
                 height: 256,
-                layers: [new OpenLayers.Layer("Empty",
-                    {isBaseLayer: true}
-                )],
+                layers: [new OpenLayers.Layer.WMS("Tasmania State Boundaries",
+                    "http://demo.opengeo.org/geoserver/wms",
+                    {layers: "topp:tasmania_state_boundaries"}, {singleTile: true})],
                 center: [146.56, -41.56],
                 zoom: 7
             });
@@ -42,7 +42,7 @@
             });
             
             var printSize = printMapPanel.printProvider.layout.get("size");
-            var size = printMapPanel.map.getSize();
+            var size = printMapPanel.getSize();
             var center = mapPanel.map.getCenter();
             var pageCenter = printMapPanel.printPage.center;
             
@@ -50,7 +50,7 @@
             t.ok(printMapPanel.map.controls[0] instanceof OpenLayers.Control.PanPanel, "which is a PanPanel.");
             t.eq(printMapPanel.map.layers[0].name, mapPanel.map.layers[0].name, "Preview map has the same visible layer as the source map.");
             t.eq(log.preaddlayer.name, printMapPanel.map.layers[0].name, "preaddlayer listener noticed addition of the layer.");
-            t.eq((size.w/size.h).toPrecision(2), (printSize.width/printSize.height).toPrecision(2), "Aspect ratio of the preview map is the same as of the print layout.");
+            t.eq((size.width/size.height).toPrecision(2), (printSize.width/printSize.height).toPrecision(2), "Aspect ratio of the preview map is the same as of the print layout.");
             t.ok(Math.abs(center.lon - pageCenter.lon) < 0.0000001 && Math.abs(center.lat - pageCenter.lat) < 0.0000001, "Print page has the same center as the source map.");
 
             printMapPanel.destroy();



More information about the Commits mailing list