[Commits] r714 - in sandbox/bartvde/legend/geoext: examples lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Wed May 13 11:49:13 CEST 2009


Author: bartvde
Date: 2009-05-13 11:49:13 +0200 (Wed, 13 May 2009)
New Revision: 714

Modified:
   sandbox/bartvde/legend/geoext/examples/legendpanel.html
   sandbox/bartvde/legend/geoext/examples/legendpanel.js
   sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
Log:
more legend changes

Modified: sandbox/bartvde/legend/geoext/examples/legendpanel.html
===================================================================
--- sandbox/bartvde/legend/geoext/examples/legendpanel.html	2009-05-13 08:28:01 UTC (rev 713)
+++ sandbox/bartvde/legend/geoext/examples/legendpanel.html	2009-05-13 09:49:13 UTC (rev 714)
@@ -7,6 +7,12 @@
         <script type="text/javascript" src="../../ext/ext-all.js"></script>
         <script type="text/javascript" src="../lib/GeoExt.js"></script>
         <script type="text/javascript" src="legendpanel.js"></script>
+        <style type="text/css">
+        .mylabel {
+            font-weight: bold;
+            color: red;
+        }
+        </style>
     </head>
     <body>
         <h1>GeoExt.LegendPanel with an Existing OpenLayers.Map</h1>

Modified: sandbox/bartvde/legend/geoext/examples/legendpanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/examples/legendpanel.js	2009-05-13 08:28:01 UTC (rev 713)
+++ sandbox/bartvde/legend/geoext/examples/legendpanel.js	2009-05-13 09:49:13 UTC (rev 714)
@@ -31,7 +31,8 @@
         zoom: 7});
 
     legendPanel = new GeoExt.LegendPanel({
-        layers: mapPanel.layers, 
+        labelCls: 'mylabel',
+        bodyStyle: 'padding:5px',
         width: 200,
         autoScroll: true,
         region: 'west'});

Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js	2009-05-13 08:28:01 UTC (rev 713)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js	2009-05-13 09:49:13 UTC (rev 714)
@@ -1,52 +1,90 @@
-Ext.namespace('GeoExt', 'GeoExt.legend');
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ *
+ * pending approval */
 
+/** api: (define)
+ *  module = GeoExt
+ *  class = LegendPanel
+ */
+
+Ext.namespace('GeoExt');
+
+/** api: constructor
+ *  .. class:: LegendPanel(config)
+ *
+ *  A panel showing legends of all layers in a layer store.
+ *  Depending on the layer type, a legend renderer will be chosen.
+ */
 GeoExt.LegendPanel = Ext.extend(Ext.Panel, {
 
-    /**
-     * APIProperty: layerStore
-     * {<GeoExt.data.LayerStore>} The layer store containing layers to be
-     *     displayed in the container.
+    /** api: config[showTitle]
+     *  ``Boolean``
+     *  Whether or not to show the title of a layer. This can be a global
+     *  setting for the whole panel, or it can be overridden on the LayerStore 
+     *  record using the hideInLegend property.
      */
+    showTitle: true,
+
+    /** api: config[labelCls]
+     *  ``String``
+     *  Optional css class to use for the layer title labels.
+     */
+    labelCls: null,
+
+    /** api:config[bodyStyle]
+     *  ``String``
+     *  Optional style to apply to the body of the legend panels.
+     */
+    bodyStyle: '',
+
+    /** api: config[layerStore]
+     *  ``GeoExt.data.LayerStore``
+     *  The layer store containing layers to be displayed in the legend 
+     *  container. If not provided it will be taken from the MapPanel.
+     */
     layerStore: null,
 
-    /**
-     * Method: initComponent
-     *      Initialize the component and register the map property if provided.
+    /** private: method[initComponent]
+     *  Initializes the legend panel.
      */
     initComponent: function() {
         GeoExt.LegendPanel.superclass.initComponent.call(this);
     },
 
-    /**
-     * Method: onRender
-     *      This function is called when the component renders.
+    /** private: method[onRender]
+     *  Private method called when the legend panel is being rendered.
      */
     onRender: function(ct, position) {
         GeoExt.LegendPanel.superclass.onRender.call(this, ct, position);
         if(!this.layerStore) {
             this.layerStore = GeoExt.MapPanel.guess().layers;
         }
-        var legendURL = 'http://www.geoext.org//trac/geoext/chrome/site/img/GeoExt.png';
-        var firstRecord = this.layerStore.getAt(0);
-        firstRecord.set('legendURL', legendURL);
         this.layerStore.each(this.addLegend, this);
         this.layerStore.on({
             "add": this.onStoreAdd,
             "remove": this.onStoreRemove,
             scope: this
         });
-        this.layerStore.each(this.addLegend, this);
         this.doLayout();
     },
 
+    /** private: method[onStoreAdd]
+     *  Private method called when a layer is added to the store.
+     */
     onStoreAdd: function() {
     },
 
+    /** private: method[onStoreRemove]
+     *  Private method called when a layer is removed from the store.
+     */
     onStoreRemove: function() {
     },
 
-    /**
-     * Method: onDestroy
+    /** private: method[onDestroy]
+     *  Private method called during the destroy sequence.
      */
     onDestroy: function() {
         if(this.layerStore) {
@@ -56,25 +94,47 @@
         GeoExt.LegendPanel.superclass.onDestroy.apply(this, arguments);
     },
 
+    /** private: method[addLegend]
+     *  Add a legend for the layer.
+     *
+     *  :param record: ``Ext.data.Record`` The record object from the layer 
+     *      store.
+     */
     addLegend: function(record) {
         var layer = record.get('layer');
-        var mainPanel = this.createTitlePanel(layer, layer.name);
-        // user can override the default legend by specifying a legendURL 
-        // property
-        if (record.get('legendURL')) {
-            var legend = new GeoExt.legend.Image({url: record.get('legendURL')});
-            mainPanel.add(legend);
+        // a layer can be excluded from the legend by setting the hideInLegend
+        // property to true
+        var hideInLegend = record.get('hideInLegend');
+        // only show visible layers
+        if (layer && layer.getVisibility() && !hideInLegend) {
+            var mainPanel = this.createMainPanel(record);
+            // the default legend can be overridden by specifying a 
+            // legendURL property
+            if (record.get('legendURL')) {
+                var legend = new GeoExt.legend.Image({url: 
+                    record.get('legendURL')});
+                mainPanel.add(legend);
+                this.add(mainPanel);
+            } else {
+                var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
+                    'OpenLayers.Layer.', '')];
+                if (legendGenerator) {
+                    var legend = new legendGenerator({layer: layer});
+                    mainPanel.add(legend);
+                }
+            }
             this.add(mainPanel);
-        } else {
-            var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
-                'OpenLayers.Layer.', '')];
-            var legend = new legendGenerator({layer: layer});
-            mainPanel.add(legend);
-            this.add(mainPanel);
         }
     },
 
-    createTitlePanel: function(layer, title) {
+    /** private: method[createMainPanel]
+     *  Creates the main panel with a title for the layer.
+     *
+     *  :param record: ``Ext.data.Record`` The record object from the layer
+     *      store.
+     */
+    createMainPanel: function(record) {
+        var layer = record.get('layer');
         var panelConfig = {
             id: layer.id,
             border: false,
@@ -82,15 +142,13 @@
             bodyStyle: this.bodyStyle,
             items: [
                 new Ext.form.Label({
-                    text: title,
+                    text: (this.showTitle && !record.get('hideTitle')) ? 
+                        layer.name : '',
                     cls: 'x-form-item x-form-item-label' +
                         (this.labelCls ? ' ' + this.labelCls : '')
                 })
             ]
         };
-
-        panelConfig = Ext.applyIf(panelConfig, this.childDefaults);
-
         var panel = new Ext.Panel(panelConfig);
         return panel;
     }



More information about the Commits mailing list