[Commits] r711 - in sandbox/bartvde/legend/geoext/lib: . GeoExt/widgets GeoExt/widgets/legend

commits at geoext.org commits at geoext.org
Wed May 13 09:56:25 CEST 2009


Author: bartvde
Date: 2009-05-13 09:56:24 +0200 (Wed, 13 May 2009)
New Revision: 711

Added:
   sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js
Modified:
   sandbox/bartvde/legend/geoext/lib/GeoExt.js
   sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
   sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
Log:
more updates for legend, work in progress

Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js	2009-05-13 07:48:50 UTC (rev 710)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js	2009-05-13 07:56:24 UTC (rev 711)
@@ -1,36 +1,13 @@
 Ext.namespace('GeoExt', 'GeoExt.legend');
 
-GeoExt.legend.generateIconBox = function(options) {
-    if (options.layer instanceof OpenLayers.Layer.Vector) {
-        var legend = GeoExt.legend.Vector(options);
-        return legend;
-    } else {
-        return null;
-    }
-};
-
-GeoExt.legend.generateLegendImage = function(options) {
-    if (options.layer instanceof OpenLayers.Layer.WMS) {
-        return options.layer.getFullRequestString({
-            REQUEST: "GetLegendGraphic",
-            WIDTH: options.width,
-            HEIGHT: options.height,
-            EXCEPTIONS: "application/vnd.ogc.se_xml",
-            LAYER: options.layer.params.LAYERS,
-            LAYERS: null,
-            SRS: null,
-            FORMAT: 'image/png'
-        });
-    }
-};
-
 GeoExt.LegendPanel = Ext.extend(Ext.Panel, {
 
     /**
-     * APIProperty: layers
-     * {<GeoExt.data.LayerStore>} 
+     * APIProperty: layerStore
+     * {<GeoExt.data.LayerStore>} The layer store containing layers to be
+     *     displayed in the container.
      */
-    layers: null,
+    layerStore: null,
 
     /**
      * Method: initComponent
@@ -46,18 +23,55 @@
      */
     onRender: function(ct, position) {
         GeoExt.LegendPanel.superclass.onRender.call(this, ct, position);
-        this.layers.each(function(record) { 
-            var layer = record.get('layer');
-            // use the right legend generator for this layer type
+        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();
+    },
+
+    onStoreAdd: function() {
+    },
+
+    onStoreRemove: function() {
+    },
+
+    /**
+     * Method: onDestroy
+     */
+    onDestroy: function() {
+        if(this.layerStore) {
+            this.layerStore.un("add", this.onStoreAdd, this);
+            this.layerStore.un("remove", this.onStoreRemove, this);
+        }
+        GeoExt.LegendPanel.superclass.onDestroy.apply(this, arguments);
+    },
+
+    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);
+            this.add(mainPanel);
+        } else {
             var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
                 'OpenLayers.Layer.', '')];
-
-            var mainPanel = this.createTitlePanel(layer, layer.name);
             var legend = new legendGenerator({layer: layer});
             mainPanel.add(legend);
             this.add(mainPanel);
-        }, this);
-        this.doLayout();
+        }
     },
 
     createTitlePanel: function(layer, title) {

Added: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js	                        (rev 0)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js	2009-05-13 07:56:24 UTC (rev 711)
@@ -0,0 +1,50 @@
+Ext.namespace('GeoExt', 'GeoExt.legend');
+
+GeoExt.legend.Image = Ext.extend(Ext.BoxComponent, {
+
+    url: null,
+
+    /**
+     * Constructor: GeoExt.legend.Image
+     * 
+     * Parameters:
+     * config - {Object}
+     */
+    constructor: function(config) {
+        GeoExt.legend.Image.superclass.constructor.apply(this, arguments);
+    },
+
+    initComponent: function() {
+        GeoExt.legend.Image.superclass.initComponent.call(this);
+        this.el = this.createImage(this.url);
+    },
+    
+    /**
+     * Method: onImageLoadError
+     *     When the image fails loading (e.g. when the server returns an XML
+     *     exception) we need to set the src to a blank image otherwise IE
+     *     will show the infamous red cross.
+     */
+    onImageLoadError: function() {
+        this.src = Ext.BLANK_IMAGE_URL;
+    },
+
+    /**
+     * Method: createImage
+     *     Create an image object for the legend image
+     *
+     * Parameters:
+     * src - {String} the source of the image (url)
+     *
+     * Returns:
+     * {DOMElement}
+     */
+    createImage: function(src) {
+        var legendImage = document.createElement("img");
+        Ext.EventManager.addListener(legendImage, 'error', 
+            this.onImageLoadError, legendImage);
+        legendImage.src = src;
+        return legendImage;
+    }
+    
+});

Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js	2009-05-13 07:48:50 UTC (rev 710)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js	2009-05-13 07:56:24 UTC (rev 711)
@@ -1,11 +1,7 @@
-Ext.namespace('GeoExt.legend');
+Ext.namespace('GeoExt', 'GeoExt.legend');
 
-GeoExt.legend.WMS = function(config) {
-    return new GeoExt.legend.WMSGenerator(config);
-};
+GeoExt.legend.WMS = Ext.extend(Ext.Panel, {
 
-GeoExt.legend.WMSGenerator = Ext.extend(Ext.Panel, {
-
     /**
      * APIProperty: wmsLegendFormat
      * {String} the format to use in the GetLegendGraphic requests, defaults
@@ -21,9 +17,19 @@
     idPrefix: 'gxt-lp-',
 
     initComponent: function() {
-        GeoExt.legend.WMSGenerator.superclass.initComponent.call(this);
+        GeoExt.legend.WMS.superclass.initComponent.call(this);
         this.createLegend(this.layer);
     },
+
+    /**
+     * Constructor: GeoExt.legend.WMSGenerator
+     * 
+     * Parameters:
+     * config - {Object}
+     */
+    constructor: function(config) {
+        return GeoExt.legend.WMS.superclass.constructor.apply(this, arguments);
+    },
     
     /**
      * Method: onImageLoadError

Modified: sandbox/bartvde/legend/geoext/lib/GeoExt.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt.js	2009-05-13 07:48:50 UTC (rev 710)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt.js	2009-05-13 07:56:24 UTC (rev 711)
@@ -70,6 +70,7 @@
             "GeoExt/data/ProtocolProxy.js",
             "GeoExt/widgets/FeatureRenderer.js",
             "GeoExt/widgets/legend/Vector.js",
+            "GeoExt/widgets/legend/Image.js",
             "GeoExt/widgets/legend/WMS.js",
             "GeoExt/widgets/LegendPanel.js",
             "GeoExt/widgets/MapPanel.js",



More information about the Commits mailing list