[Commits] r1559 - in sandbox/ahocevar/playground/ux/Printing: examples ux/data ux/plugins

commits at geoext.org commits at geoext.org
Sat Dec 5 03:00:59 CET 2009


Author: ahocevar
Date: 2009-12-05 03:00:57 +0100 (Sat, 05 Dec 2009)
New Revision: 1559

Modified:
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
   sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
   sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js
Log:
better example documentation and comments

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-04 23:12:41 UTC (rev 1558)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.html	2009-12-05 02:00:57 UTC (rev 1559)
@@ -18,8 +18,34 @@
         
         <script type="text/javascript" src="Printing.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="Printing.js">Printing.js</a> for the source code.</p>
+        
+        <div id="content"></div>
     </body>
 </html>

Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-04 23:12:41 UTC (rev 1558)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.js	2009-12-05 02:00:57 UTC (rev 1559)
@@ -3,11 +3,27 @@
 Ext.onReady(function() {
 
     printProvider = new GeoExt.ux.data.PrintProvider({
-        // capabilities from script tag in Printing.html
-        capabilities: printCapabilities,
-        method: "GET"
+        // 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({
+        region: "center",
+        layers: [new OpenLayers.Layer.WMS("Global Imagery",
+            "http://labs.metacarta.com/wms/vmap0",
+            {layers: "basic"})] ,
+        center: [16,48],
+        zoom: 5
+    });
+
+    // create a vector layer, which will also be printed.
     var redline = new OpenLayers.Layer.Vector("vector", {
         styleMap: new OpenLayers.StyleMap({
             strokeColor: "red",
@@ -24,41 +40,21 @@
         new Vec(geom("LINESTRING(15 48, 16 47, 17 46)")),
         new Vec(geom("POINT(16 46)"))
     ]);
-    
-    var mapPanel = new GeoExt.MapPanel({
-        region: "center",
-        layers: [new OpenLayers.Layer.WMS("Global Imagery",
-            "http://labs.metacarta.com/wms/vmap0",
-            {layers: "basic"}), redline] ,
-        center: [16,48],
-        zoom: 5
-    });
     mapPanel.map.addLayer(redline);
     
-    var pageLayer = new OpenLayers.Layer.Vector(null, {displayInLayerSwitcher: false});
-    var pageFeature = new OpenLayers.Feature.Vector(null, {layout: null});
-    pageLayer.addFeatures(pageFeature);
-    var fit = false;
-    mapPanel.map.events.on({
-        "zoomend": function() {
-            if(!fit && mapPanel.map.getZoom() == mapPanel.initialConfig.zoom) {
-                fit = true;
-                printForm.pages[0].fitPage(mapPanel.map);
-            }
-        }
-    });
-    
+    // a simple print form
     printForm = new GeoExt.ux.form.SimplePrint({
         map: mapPanel,
         printProvider: printProvider,
-        layer: pageLayer,
-        pageFeature: pageFeature,
         bodyStyle: {padding: "5px"},
         labelWidth: 65,
         defaults: {width: 115},
         region: "east",
+        border: false,
         width: 200
     });
+
+    // add custom fields to the form
     printForm.insert(0, {
         xtype: "textfield",
         name: "mapTitle",
@@ -77,14 +73,38 @@
             page: printForm.pages[0]
         })
     });
-    printForm.doLayout();
+    
+    var formCt = new Ext.Panel({
+        layout: "fit",
+        region: "east",
+        width: 200
+    });
 
     new Ext.Panel({
-        renderTo: document.body,
+        renderTo: "content",
         layout: "border",
         width: 800,
         height: 350,
-        items: [mapPanel, printForm]
+        items: [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() {
+        myMask.hide();
+        formCt.add(printForm);
+        formCt.doLayout();
+        printForm.pages[0].fitPage(mapPanel.map);
+    });
+     */
+    
 });

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-04 23:12:41 UTC (rev 1558)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-05 02:00:57 UTC (rev 1559)
@@ -25,10 +25,8 @@
      *  :ref:`GeoExt.ux.data.PrintProvider.capabilities` is not provided. This
      *  is usually something like ``http://path/to/mapfish/print`` for Mapfish,
      *  and ``http://path/to/geoserver/pdf`` for GeoServer with the printing
-     *  extension installed. This property is useful when the print service is
-     *  at the same origin as the application (or accessible via proxy), and
-     *  the request method is set to ``POST`` (see
-     *  :ref:`GeoExt.ux.data.PrintProvider.method`).
+     *  extension installed. This property requires that the print service is
+     *  at the same origin as the application (or accessible via proxy).
      */
     
     /** private:  property[url]
@@ -37,34 +35,6 @@
      */
     url: null,
     
-    /** api: config[units]
-     *  ``String`` Map units to use with this printProvider. These can e.g. be
-     *  taken from an ``OpenLayers.Map``:
-     *  
-     *  .. code-block:: javascript
-     *      units: map.baseLayer.units,
-     */
-    
-    /** api: property[units]
-     *  ``String`` Map units to use with this printProvider. Must be set
-     *  before print pages can be created. If a
-     *  :class:`GeoExt.ux.form.PrintForm` is configured with this
-     *  printProvider, this will be taken care of properly.
-     */
-    units: null,
-    
-    /** api: property[dpi]
-     *  ``String`` the name of the currently used layout. Read-only, use
-     *      :ref:`GeoExt.ux.data.PrintProvider.setDpi` to set the value.
-     */
-    dpi: null,
-
-    /** api: property[layout]
-     *  ``String`` the name of the currently used layout. Read-only, use
-     *      :ref:`GeoExt.ux.data.PrintProvider.setLayout` to set the value.
-     */
-    layout: null,
-
     /** api: config[capabilities]
      *  ``Object`` Capabilities of the print service. Only required if
      *  :ref:`GeoExt.ux.data.PrintProvider.url` is not provided. This is the
@@ -72,9 +42,8 @@
      *  and is usually obtained by including a script tag pointing to
      *  ``http://path/to/printservice/info.json?var=myvar`` in the head of the
      *  html document, making the capabilities accessible as ``window.myvar``.
-     *  This property is useful when accessing a remote print service with no
-     *  proxy available, using the ``GET`` method (see
-     *  :ref:`GeoExt.ux.data.PrintProvider.method`).
+     *  This property should be used when no local print service or proxy is
+     *  available.
      */
     
     /** private: property[capabilities]
@@ -84,19 +53,35 @@
     
     /** api: config[method]
      *  ``String`` Either ``POST`` or ``GET`` (case-sensitive). Method to use
-     *  when talking to the servlet. If the print service is at the same
-     *  origin as the application (or accessible via proxy), then ``POST``
-     *  is recommended. Use ``GET`` when accessing a remote print service with
-     *  no proxy available, but expect issues with character encoding and URLs
-     *  exceeding the maximum length. Default is ``POST``.
+     *  when sending print requests to the servlet. If the print service is at
+     *  the same origin as the application (or accessible via proxy), then
+     *  ``POST`` is recommended. Use ``GET`` when accessing a remote print
+     *  service with no proxy available, but expect issues with character
+     *  encoding and URLs exceeding the maximum length. Default is ``POST``.
      */
     
     /** private: property[method]
      *  ``String`` Either ``POST`` or ``GET`` (case-sensitive). Method to use
-     *  when talking to the servlet.
+     *  when sending print requests to the servlet.
      */
     method: "POST",
 
+    /** api: config[units]
+     *  ``String`` Map units to use with this printProvider. These can e.g. be
+     *  taken from an ``OpenLayers.Map``:
+     *  
+     *  .. code-block:: javascript
+     *      units: map.baseLayer.units,
+     */
+    
+    /** api: property[units]
+     *  ``String`` Map units to use with this printProvider. Must be set
+     *  before print pages can be created. If a
+     *  :class:`GeoExt.ux.form.PrintForm` is configured with this
+     *  printProvider, this will be taken care of properly.
+     */
+    units: null,
+    
     /** api: config[customParams]
      *  ``Object`` Key-value pairs of custom data to be sent to the print
      *  service. Optional. This is e.g. useful for complex layout definitions
@@ -141,6 +126,18 @@
      */
     layouts: null,
     
+    /** api: property[dpi]
+     *  ``String`` the name of the currently used layout. Read-only, use
+     *      :ref:`GeoExt.ux.data.PrintProvider.setDpi` to set the value.
+     */
+    dpi: null,
+
+    /** api: property[layout]
+     *  ``String`` the name of the currently used layout. Read-only, use
+     *      :ref:`GeoExt.ux.data.PrintProvider.setLayout` to set the value.
+     */
+    layout: null,
+
     /** private:  method[constructor]
      *  Private constructor override.
      */

Modified: sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js	2009-12-04 23:12:41 UTC (rev 1558)
+++ sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintProviderField.js	2009-12-05 02:00:57 UTC (rev 1559)
@@ -36,8 +36,8 @@
      */
     init: function(target) {
         target.on({
+            "render": this.onRender,
             "valid": this.onFieldChange,
-            "render": this.onRender,
             scope: this
         });
     },



More information about the Commits mailing list