[Commits] r1603 - sandbox/ahocevar/playground/ux/Printing/ux/data

commits at geoext.org commits at geoext.org
Wed Dec 23 02:01:47 CET 2009


Author: ahocevar
Date: 2009-12-23 02:01:46 +0100 (Wed, 23 Dec 2009)
New Revision: 1603

Modified:
   sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
Log:
modified legend encoders to use classes and the proposed icons property for print-lib (http://www.mapfish.org/trac/mapfish/ticket/511); also fixed comments and added examples.

Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-22 10:31:00 UTC (rev 1602)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js	2009-12-23 01:01:46 UTC (rev 1603)
@@ -13,6 +13,26 @@
  *  base_link = `Ext.util.Observable <http://extjs.com/deploy/dev/docs/?class=Ext.util.Observable>`_
  */
 
+/** api: example
+ *  Minimal code to print as much of the current map extent as possible as
+ *  soon as the print service capabilities are loaded:
+ * 
+ *  .. code-block:: javascript
+ *     
+ *      var printProvider = new GeoExt.ux.data.PrintProvider({
+ *          url: "/geoserver/pdf",
+ *          listeners: {
+ *              "loadcapabilities": function() {
+ *                  var printPage = new GeoExt.ux.data.PrintPage({
+ *                      printProvider: printProvider
+ *                  });
+ *                  printPage.fitPage(map);
+ *                  printProvider.print(map, [printPage]);
+ *              }
+ *          }
+ *      });
+ */
+
 /** api: constructor
  *  .. class:: PrintProvider
  * 
@@ -135,7 +155,7 @@
         }
 
         this.addEvents([
-            /** api: events[capabilitiesload]
+            /** api: events[loadcapabilities]
              *  Triggered when the capabilities have finished loading. This
              *  event will only fire when
              *  :ref:`GeoExt.ux.data.PrintProvider.capabilities` is not
@@ -146,7 +166,7 @@
              *    PrintProvider
              *  * capabilities - ``Object`` the capabilities
              */
-            "capabilitiesload",
+            "loadcapabilities",
             
             /** api: events[layoutchange]
              *  Triggered when the layout is changed.
@@ -227,8 +247,16 @@
      *      print.
      *  :param options: ``Object`` of additional options:
      *      * ``legend``: :class:`GeoExt.LegendPanel` If provided, the legend
-     *        will be added to the print document.
-     * 
+     *        will be added to the print document. For this to look like in
+     *        the MapPanel, the following settings in the ``!legends`` block
+     *        of the print module are recommended:
+     *        
+     *        .. code-block:: none
+     *        
+     *          maxIconWidth: 0
+     *          maxIconHeight: 0
+     *          classIndentation: 0
+     *
      *  Sends the print command to the print service and opens a new window
      *  with the resulting PDF.
      */
@@ -375,7 +403,7 @@
             "OSM": function(layer) {
                 var enc = this.encoders.layers.TileCache.call(this, layer);
                 return Ext.apply(enc, {
-                    type: 'Osm',
+                    type: 'OSM',
                     baseURL: enc.baseURL.substr(0, enc.baseURL.indexOf("$")),
                     extension: "png"
                 });
@@ -422,7 +450,7 @@
                 var nextId = 1;
                 var styleDict = {};
                 var feature, style, dictKey, dictItem;
-                for(var i = 0, len = features.length; i < len; ++i) {
+                for(var i=0, len=features.length; i<len; ++i) {
                     feature = features[i];
                     style = feature.style || layer.style ||
                     layer.styleMap.createSymbolizer(feature,
@@ -469,28 +497,30 @@
         },
         "legends": {
             "gx_wmslegend": function(legend) {
-                return this.encoders.legends.base.call(this, legend);
+                var enc = this.encoders.legends.base.call(this, legend);
+                var icons = [];
+                for(var i=1, len=legend.items.getCount(); i<len; ++i) {
+                    icons.push(this.getAbsoluteUrl(legend.items.get(i).url));
+                };
+                enc[0].classes[0] = {
+                    name: "",
+                    icons: icons
+                }
+                return enc;
             },
             "gx_urllegend": function(legend) {
-                return this.encoders.legends.base.call(this, legend);
+                var enc = this.encoders.legends.base.call(this, legend);
+                enc[0].classes.push({
+                    name: "",
+                    icon: this.getAbsoluteUrl(legend.items.get(1).url)
+                });
+                return enc;
             },
             "base": function(legend){
-                var enc = [];
-                legend.items.each(function(cmp) {
-                    if(cmp instanceof Ext.form.Label) {
-                        enc.push({
-                            name: cmp.text,
-                            classes: []
-                        });
-                    } else if(cmp instanceof GeoExt.LegendImage) {
-                        enc.push({
-                            name: "",
-                            icon: this.getAbsoluteUrl(cmp.url),
-                            classes: []
-                        });
-                    }
-                }, this);
-                return enc;
+                return [{
+                    name: legend.items.get(0).text,
+                    classes: []
+                }];
             }
         }
     }



More information about the Commits mailing list