[Commits] r1719 - in sandbox/ahocevar/playground/ux/Printing/ux: data widgets

commits at geoext.org commits at geoext.org
Tue Jan 12 15:40:43 CET 2010


Author: ahocevar
Date: 2010-01-12 15:40:43 +0100 (Tue, 12 Jan 2010)
New Revision: 1719

Modified:
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintPreview.js
Log:
added mapOverlay, fixed scale issues

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2010-01-12 14:24:53 UTC (rev 1718)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2010-01-12 14:40:43 UTC (rev 1719)
@@ -182,14 +182,15 @@
         this.resumeEvents();
         var extent = map.getExtent();
         var units = map.baseLayer.units;
-        var scale, looseScale;
+        var scale, looseScale, contains;
         this.printProvider.scales.each(function(rec) {
             looseScale = scale || rec;
             scale = rec;
-            return !extent.containsBounds(
+            contains = extent.containsBounds(
                 this.calculatePageBounds(scale, units));
+            return !contains
         }, this);
-        this.setScale(loose === true ? looseScale : scale, units);
+        this.setScale(loose && contains ? looseScale : scale, units);
     },
 
     /** api: method[updateByHandle]

Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js	2010-01-12 14:24:53 UTC (rev 1718)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js	2010-01-12 14:40:43 UTC (rev 1719)
@@ -113,6 +113,13 @@
             resolutions: resolutions,
             numZoomLevels: resolutions.length
         });
+
+        // set an initial size with the same aspect ratio as the print page.
+        // This is crucial for the first fitMap call to determine the correct
+        // resolution, otherwise we may be one zoom level off.
+        var size = this.printProvider.layout.get("size");
+        this.width = size.width;
+        this.height = size.height;
         
         GeoExt.ux.PrintMapPanel.superclass.initComponent.call(this);
         
@@ -123,13 +130,19 @@
     },
     
     /** private: method[fitMap]
-     *  Fits this PrintMapPanel's size to the print extent.
+     *  Fits this PrintMapPanel's width and height to the print extent. This
+     *  calculation is based on the print extent for the first available scale,
+     *  which means that the print view extent is only guaranteed to be
+     *  accurate at that scale. The aspect ratio, however, can be taken for
+     *  granted at any scale.
      */
     fitMap: function() {
-        this.updatePage();
+        this.printPage.setScale(this.printProvider.scales.getAt(0),
+            this.sourceMap.units);
+        this.printPage.setCenter(this.sourceMap.getCenter());
         var extent = this.printPage.feature.geometry.getBounds();
-        var zoom = this.sourceMap.getZoomForExtent(extent);
-        var resolution = this.sourceMap.getResolutionForZoom(zoom);
+        var zoom = this.map.getZoomForExtent(extent);
+        var resolution = this.map.getResolutionForZoom(zoom);
         this.setSize(
             extent.getWidth() / resolution,
             extent.getHeight() / resolution
@@ -140,21 +153,22 @@
      *  Fits this PrintMapPanel's zoom to the print scale.
      */
     fitZoom: function() {
-        if(this.map) {
-            var zoom = this.map.getZoomForResolution(
-                OpenLayers.Util.getResolutionFromScale(
-                    this.printPage.scale.get("value"),
-                    this.map.baseLayer.units));
-            this.map && this.map.getZoom() != zoom && this.map.zoomTo(zoom);
-        }
+        var zoom = this.map.getZoomForResolution(
+            OpenLayers.Util.getResolutionFromScale(
+                this.printPage.scale.get("value"),
+                this.map.baseLayer.units));
+        this._updating = true;
+        this.map.getZoom() != zoom && this.map.zoomTo(zoom);
+        delete this._updating;
     },
     
     /** private: method[updatePage]
      *  updates the print page to match this PrintMapPanel's center and scale.
      */
     updatePage: function() {
-        this.printPage.fitPage(this.rendered ? this.map : this.sourceMap,
-            this.rendered);
+        if(!this._updating) {
+            this.printPage.fitPage(this.map, true);
+        }
     },
     
     /** api: method[print]

Modified: sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintPreview.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintPreview.js	2010-01-12 14:24:53 UTC (rev 1718)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintPreview.js	2010-01-12 14:40:43 UTC (rev 1719)
@@ -50,6 +50,8 @@
     
     mapOptions: null,
     
+    addMapOverlay: true,
+    
     /** api: config[busyMask]
      *  ``Ext.LoadMask`` A LoadMask to use while the print document is
      *  prepared. Optional, will be auto-created with ``creatingPdfText` if
@@ -89,7 +91,7 @@
         
         this.add(this.form);
         this.add(this.printMapPanel);
-        this.printMapPanel.add(this.createMapOverlay());
+        this.addMapOverlay && this.printMapPanel.add(this.createMapOverlay());
 
         this.on({
             "render": function() {
@@ -109,7 +111,7 @@
     },
     
     createToolbar: function() {
-        return [this.paperSizeText, {
+        return new Ext.Toolbar([this.paperSizeText, {
             xtype: "combo",
             width: 98,
             plugins: new GeoExt.ux.plugins.PrintProviderField({
@@ -148,7 +150,7 @@
                     {legend: this.legend});
             },
             scope: this
-        }];
+        }]);
     },
     
     createForm: function() {
@@ -228,6 +230,7 @@
         return new Ext.Panel({
             cls: "gx-map-overlay",
             layout: "column",
+            width: 235,
             bodyStyle: "padding:5px",
             items: [{
                 xtype: "box",
@@ -235,11 +238,14 @@
                 width: scaleLine.maxWidth
             }, {
                 xtype: "container",
-                style: "padding: .2em 5px 0 5px",
-                cls: "x-small-editor",
+                layout: "form",
+                style: "padding: .2em 5px 0 0;",
+                columnWidth: 1,
+                cls: "x-small-editor x-form-item",
                 items: {
                     xtype: "combo",
-                    width: 85,
+                    anchor: "100%",
+                    hideLabel: true,
                     store: this.printProvider.scales,
                     displayField: "name",
                     typeAhead: true,



More information about the Commits mailing list