[Commits] r1596 - in sandbox/ahocevar/playground/ux/Printing: build build/Printing examples ux ux/data ux/widgets

commits at geoext.org commits at geoext.org
Sat Dec 19 22:51:42 CET 2009


Author: ahocevar
Date: 2009-12-19 22:51:42 +0100 (Sat, 19 Dec 2009)
New Revision: 1596

Added:
   sandbox/ahocevar/playground/ux/Printing/build/Printing/
   sandbox/ahocevar/playground/ux/Printing/build/Printing/examples/
   sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.html
   sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.js
   sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js
Modified:
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
   sandbox/ahocevar/playground/ux/Printing/ux/Printing.js
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
Log:
Streamlined units handling; started PrintMapPanel (not yet functional)

Added: sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.html
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.html	                        (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.html	2009-12-19 21:51:42 UTC (rev 1596)
@@ -0,0 +1,46 @@
+<html>
+    <head>
+        <title>Printing ux Example</title>
+
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/adapter/ext/ext-base.js"></script>
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/ext-all-debug.js"></script>
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
+        <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
+        <script type="text/javascript" src="/geoext/geoext/lib/GeoExt.js"></script>
+        
+        <script type="text/javascript" src="../ux/Printing.js"></script>
+        
+        <script type="text/javascript" src="PrintMapPanel.js"></script>
+
+        <!--
+        Using the script tag method to get the print service capabilities and
+        make them available in the printCapabilities variable.
+        The script tag below can be removed when configuring the printProvider
+        with url instead of capabilities
+        -->
+        <script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
+        
+    </head>
+    <body>
+        <h1>PrintProvider with a Simple Print Form</h1>
+        
+        <p>This example shows how to use GeoExt.ux.data.PrintProvider to talk
+        to the <a href="http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleInstallation">Mapfish print module</a>,
+        which is also available as
+        <a href="http://geoserver.org/display/GEOS/Printing+2.0+HOWTO">GeoServer print module</a>.</p>
+        
+        <p>The rectangle and handle on the map can be used to change center,
+        scale and rotation.</p>
+        
+        <p>Note that this example uses GET requests to communicate with the
+        print servlet (provided by the Mapfish demo server). This saves us a
+        proxy, but has limitations (URL length in Internet Explorer, and
+        character encoding issues). For production use, the POST method is
+        recommended.</p>
+        
+        <p>See <a href="PrintMapPanel.js">PrintMapPanel.js</a> for the source code.</p>
+        
+        <div id="content"></div>
+    </body>
+</html>


Property changes on: sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.html
___________________________________________________________________
Name: svn:keywords
   + Id Author Date Revision
Name: svn:eol-style
   + native

Added: sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.js	                        (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -0,0 +1,65 @@
+var printProvider, map;
+
+Ext.onReady(function() {
+
+    printProvider = new GeoExt.ux.data.PrintProvider({
+        // using get for remote service access without same origin restriction.
+        // For asynchronous requests, we would set method to "POST".
+        method: "GET",
+        //method: "POST",
+        
+        // capabilities from script tag in Printing.html. For asynchonous
+        // loading, we would configure url instead of capabilities.
+        capabilities: printCapabilities
+        //url: "/geoserver/pdf/"
+    });
+    
+    var mapPanel = new GeoExt.MapPanel({
+        renderTo: "content",
+        width: 600,
+        height: 350,
+        layers: [new OpenLayers.Layer.WMS("Global Imagery",
+            "http://labs.metacarta.com/wms/vmap0",
+            {layers: "basic"})] ,
+        center: [16,48],
+        zoom: 5,
+        bbar: [{
+            text: "Print",
+            handler: showPrintWindow
+        }]
+    });
+    
+    map = mapPanel.map;
+
+    // create a vector layer, which will also be printed.
+    var redline = new OpenLayers.Layer.Vector("vector", {
+        styleMap: new OpenLayers.StyleMap({
+            strokeColor: "red",
+            fillColor: "red",
+            fillOpacity: 0.7,
+            strokeWidth: 2,
+            pointRadius: 12,
+            externalGraphic: "http://openlayers.org/dev/img/marker-blue.png"
+        })
+    });
+    var geom = OpenLayers.Geometry.fromWKT, Vec = OpenLayers.Feature.Vector;
+    redline.addFeatures([
+        new Vec(geom("POLYGON(15 47, 16 48, 14 49)")),
+        new Vec(geom("LINESTRING(15 48, 16 47, 17 46)")),
+        new Vec(geom("POINT(16 46)"))
+    ]);
+    mapPanel.map.addLayer(redline);
+});
+
+function showPrintWindow() {
+    new Ext.Window({
+        title: "Print",
+        layout: "fit",
+        autoWidth: true,
+        autoHeight: true,
+        items: new GeoExt.PrintMapPanel({
+            sourceMap: map,
+            printProvider: printProvider
+        })
+    }).show();
+}


Property changes on: sandbox/ahocevar/playground/ux/Printing/examples/PrintMapPanel.js
___________________________________________________________________
Name: svn:keywords
   + Id Author Date Revision
Name: svn:eol-style
   + native

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-17 16:30:19 UTC (rev 1595)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-19 21:51:42 UTC (rev 1596)
@@ -2,11 +2,12 @@
     <head>
         <title>Printing ux Example</title>
 
-        <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/adapter/ext/ext-base.js"></script>
+        <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/ext-all-debug.js"></script>
         <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
         <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
         <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
-        <script type="text/javascript" src="http://api.geoext.org/0.6/script/GeoExt.js"></script>
+        <script type="text/javascript" src="/geoext/geoext/lib/GeoExt.js"></script>
         
         <script type="text/javascript" src="../ux/Printing.js"></script>
         
@@ -17,8 +18,8 @@
         make them available in the printCapabilities variable.
         The script tag below can be removed when configuring the printProvider
         with url instead of capabilities
+        <script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
         -->
-        <script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
         
     </head>
     <body>

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-17 16:30:19 UTC (rev 1595)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -5,20 +5,20 @@
     printProvider = new GeoExt.ux.data.PrintProvider({
         // using get for remote service access without same origin restriction.
         // For asynchronous requests, we would set method to "POST".
-        method: "GET",
-        //method: "POST",
+        //method: "GET",
+        method: "POST",
         
         // capabilities from script tag in Printing.html. For asynchonous
         // loading, we would configure url instead of capabilities.
-        capabilities: printCapabilities
-        //url: "/geoserver/pdf/"
+        //capabilities: printCapabilities
+        url: "/geoserver/pdf/"
     });
     
     var mapPanel = new GeoExt.MapPanel({
         region: "center",
         layers: [new OpenLayers.Layer.WMS("Global Imagery",
-            "http://labs.metacarta.com/wms/vmap0",
-            {layers: "basic"})] ,
+            "/geoserver/wms",
+            {layers: "nurc:Arc_Sample"})] ,
         center: [16,48],
         zoom: 5
     });
@@ -42,10 +42,18 @@
     ]);
     mapPanel.map.addLayer(redline);
     
+    var legend = new GeoExt.LegendPanel({
+        region: "west",
+        width: 200,
+        defaults: {style: "padding:5px"},
+        layerStore: mapPanel.layers
+    });
+
     // a simple print form
     printForm = new GeoExt.ux.form.SimplePrint({
         map: mapPanel,
         printProvider: printProvider,
+        printOptions: {legend: legend},
         bodyStyle: {padding: "5px"},
         labelWidth: 65,
         defaults: {width: 115},
@@ -79,24 +87,25 @@
         region: "east",
         width: 200
     });
-
+    
     new Ext.Panel({
         renderTo: "content",
         layout: "border",
         width: 800,
         height: 350,
-        items: [mapPanel, formCt]
+        items: [legend, mapPanel, formCt]
     });
     
     /* add the print form to its container and make sure that the print page
      * fits the max extent
-     */
     formCt.add(printForm);
     formCt.doLayout();
     printForm.pages[0].fitPage(mapPanel.map);
+     */
 
     /* use this code block instead of the above one if you configured the
      * printProvider with url instead of capabilities
+     */
     var myMask = new Ext.LoadMask(formCt.body, {msg:"Loading data..."});
     myMask.show();
     printProvider.on("loadcapabilities", function() {
@@ -105,6 +114,5 @@
         formCt.doLayout();
         printForm.pages[0].fitPage(mapPanel.map);
     });
-     */
     
 });

Modified: sandbox/ahocevar/playground/ux/Printing/ux/Printing.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/Printing.js	2009-12-17 16:30:19 UTC (rev 1595)
+++ sandbox/ahocevar/playground/ux/Printing/ux/Printing.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -56,6 +56,7 @@
         "data/PrintProvider.js",
         "plugins/PrintPageField.js",
         "plugins/PrintProviderField.js",
+        "widgets/PrintMapPanel.js",
         "widgets/form/PrintForm.js",
         "widgets/form/SimplePrint.js"
     );

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2009-12-17 16:30:19 UTC (rev 1595)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintPage.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -101,7 +101,7 @@
         if(config.layer) {
             config.layer.addFeatures([this.feature, this.handle]);
         }
-
+        
         this.printProvider.on({
             "layoutchange": function() {
                 this.updateByHandle();
@@ -123,13 +123,16 @@
     
     /** api: method[setScale]
      *  :param scale: ``Ext.data.Record`` The new scale record.
+     *  :param units: ``String`` map units to use for the scale calculation.
+     *      Optional if a ``layer`` that is added to a map was configured.
+     *      If neither is provided, "dd" will be assumed.
      * 
      *  Updates the page geometry to match a given scale. Since this takes the
      *  current layout of the printProvider into account, this can be used to
      *  update the page geometry feature when the layout has changed.
      */
-    setScale: function(scale) {
-        var bounds = this.calculatePageBounds(scale);
+    setScale: function(scale, units) {
+        var bounds = this.calculatePageBounds(scale, units);
         var geom = bounds.toGeometry();
         var rotation = this.rotation;
         if(rotation != 0) {
@@ -177,13 +180,16 @@
         this.suspendEvents();
         this.setCenter(map.getCenter());
         var extent = map.getExtent();
+        var units = map.baseLayer.units;
         var scale;
         this.printProvider.scales.each(function(rec) {
             scale = rec;
-            return !extent.containsBounds(this.calculatePageBounds(scale));
+            return !extent.containsBounds(
+                this.calculatePageBounds(scale, units)
+            );
         }, this)
         this.resumeEvents();
-        this.setScale(scale);
+        this.setScale(scale, units);
     },
 
     /** api: method[updateByHandle]
@@ -279,26 +285,23 @@
     /** private: method[calculatePageBounds]
      *  :param scale: ``Ext.data.Record`` Scale record to calculate the page
      *      bounds for.
+     *  :param units: ``String`` map units to use for the scale calculation.
+     *      Optional if a ``layer`` that is added to a map was configured. If
+     *      neither is provided, "dd" will be assumed.
      *  :return: ``OpenLayers.Bounds``
      *  
      *  Calculates the page bounds for a given scale.
      */
-    calculatePageBounds: function(scale) {
+    calculatePageBounds: function(scale, units) {
         var s = scale.get("value");
         var geom = this.feature.geometry;
         var center = geom.getBounds().getCenterLonLat();
 
-        // if the layer has a map, we have to care about the bounds, otherwise
-        // we just create bounds with zero extent around the center.
-        var w = 0, h = 0;
-        var map = this.feature.layer.map;
-        if(map) {
-            var size = this.printProvider.layout.get("size");
-            var unitsRatio = map ?
-                OpenLayers.INCHES_PER_UNIT[map.baseLayer.units] : 1;
-            var w = size.width / 72 / unitsRatio * s / 2;
-            var h = size.height / 72 / unitsRatio * s / 2;
-        }
+        var size = this.printProvider.layout.get("size");
+        var units = units || this.feature.layer.map.baseLayer.units || "dd";
+        var unitsRatio = OpenLayers.INCHES_PER_UNIT[units];
+        var w = size.width / 72 / unitsRatio * s / 2;
+        var h = size.height / 72 / unitsRatio * s / 2;
         
         return new OpenLayers.Bounds(center.lon - w, center.lat - h,
             center.lon + w, center.lat + h);

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-17 16:30:19 UTC (rev 1595)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -468,10 +468,10 @@
             }
         },
         "legends": {
-            "gx_legendwms": function(legend) {
+            "gx_wmslegend": function(legend) {
                 return this.encoders.legends.base.call(this, legend);
             },
-            "gx_legendurl": function(legend) {
+            "gx_urllegend": function(legend) {
                 return this.encoders.legends.base.call(this, legend);
             },
             "base": function(legend){

Added: sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js	                        (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js	2009-12-19 21:51:42 UTC (rev 1596)
@@ -0,0 +1,28 @@
+Ext.namespace("GeoExt");
+
+GeoExt.PrintMapPanel = Ext.extend(GeoExt.MapPanel, {
+    
+    sourceMap: null,
+    
+    printProvider: null,
+    
+    printPage: null,
+    
+    initComponent: function() {
+        this.layers = this.sourceMap.layers;
+        this.extent = this.sourceMap.getExtent();
+        
+        GeoExt.PrintMapPanel.superclass.initComponent.call(this);
+        
+        this.printPage = new GeoExt.ux.data.PrintPage({
+            printProvider: this.printProvider
+        });
+        this.printPage.fitPage(this.sourceMap);
+        var extent = this.printPage.feature.geometry.getBounds();
+        var resolution = this.map.getResolution();
+        this.setSize(
+            extent.getWidth() / resolution,
+            extent.getHeight() / resolution
+        );
+    }
+});


Property changes on: sandbox/ahocevar/playground/ux/Printing/ux/widgets/PrintMapPanel.js
___________________________________________________________________
Name: svn:keywords
   + Id Author Date Revision
Name: svn:eol-style
   + native



More information about the Commits mailing list