[Commits] r715 - sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend
commits at geoext.org
commits at geoext.org
Wed May 13 12:58:36 CEST 2009
Author: bartvde
Date: 2009-05-13 12:58:36 +0200 (Wed, 13 May 2009)
New Revision: 715
Modified:
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
Log:
update WMS legend class
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js 2009-05-13 09:49:13 UTC (rev 714)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js 2009-05-13 10:58:36 UTC (rev 715)
@@ -1,188 +1,81 @@
+/* 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 */
+
+/**
+ * @include GeoExt/widgets/legend/Image.js
+ */
+
+/** api: (define)
+ * module = GeoExt.legend
+ * class = WMS
+ */
Ext.namespace('GeoExt', 'GeoExt.legend');
+/** api: constructor
+ * .. class:: WMS(config)
+ *
+ * Show a legend image for a WMS layer.
+ */
GeoExt.legend.WMS = Ext.extend(Ext.Panel, {
- /**
- * APIProperty: wmsLegendFormat
- * {String} the format to use in the GetLegendGraphic requests, defaults
- * to image/png. The value should be a valid mime-type.
+ /** api: config[imageFormat]
+ * ``String``
+ * The image format to request the legend image in.
+ * Defaults to image/png.
*/
- wmsLegendFormat: "image/png",
+ imageFormat: "image/png",
- /**
- * Property: idPrefix
- * {String} the prefix to use for the id attribute value of the sub panels
- * (gxt for GeoExt and lp for LegendPanel)
- */
- idPrefix: 'gxt-lp-',
+ /** api: config[layer]
+ * ``OpenLayers.Layer.WMS``
+ * The WMS layer to request the legend for.
+ */
+ layer: null,
+ /** private: method[initComponent]
+ * Initializes the WMS legend. For group layers it will create multiple
+ * image box components.
+ */
initComponent: function() {
GeoExt.legend.WMS.superclass.initComponent.call(this);
- this.createLegend(this.layer);
+ this.createLegend();
},
- /**
- * Constructor: GeoExt.legend.WMSGenerator
- *
- * Parameters:
- * config - {Object}
- */
- constructor: function(config) {
- return GeoExt.legend.WMS.superclass.constructor.apply(this, arguments);
- },
-
- /**
- * 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
+ /** private: method[getLegendUrl]
+ * :param layer: ``OpenLayers.Layer.WMS`` The OpenLayers WMS layer object
+ * :param layerName: ``String`` The name of the layer
+ * (used in the LAYERS parameter)
+ * :return: ``String`` The url of the SLD WMS GetLegendGraphic request.
*
- * Parameters:
- * src - {String} the source of the image (url)
- * id - {String} the id (prefix) for the image object
- *
- * Returns:
- * {DOMElement}
+ * Get the url for the SLD WMS GetLegendGraphic request.
*/
- createImage: function(src, id) {
- var legendImage = document.createElement("img");
- Ext.EventManager.addListener(legendImage, 'error',
- this.onImageLoadError, legendImage);
- legendImage.src = src;
- legendImage.id = id+'_img';
- return legendImage;
+ getLegendUrl: function(layerName) {
+ return this.layer.getFullRequestString({
+ REQUEST: "GetLegendGraphic",
+ WIDTH: null,
+ HEIGHT: null,
+ EXCEPTIONS: "application/vnd.ogc.se_xml",
+ LAYER: layerName,
+ LAYERS: null,
+ SRS: null,
+ FORMAT: this.imageFormat
+ });
},
-
- /**
- * Method: getLegendUrl
- * Get the URL from which the legend image can be retrieved
- *
- * Parameters:
- * layer - {<OpenLayers.Layer.WMS>} the WMS layer
- * layerName - {String} one of the layers from the LAYERS parameter
- *
- * Returns:
- * {String}
- */
- getLegendUrl: function(layer, layerName) {
- return layer.getFullRequestString({
- REQUEST: "GetLegendGraphic",
- WIDTH: null,
- HEIGHT: null,
- EXCEPTIONS: "application/vnd.ogc.se_xml",
- LAYER: layerName,
- LAYERS: null,
- SRS: null,
- FORMAT: this.wmsLegendFormat
- });
- },
- /**
- * Method: createLegend
- * Create the legend panel for a layer
- *
- * Parameters:
- * layer - {<OpenLayers.Layer>} the layer object
+ /** private: method[createLegend]
+ * Add one BoxComponent per sublayer to this panel.
*/
- createLegend: function(layer) {
- var panel = null;
- if (layer.getVisibility()) {
- panel = this.createLegendPanel(
- this.generatePanelId(layer),
- layer.name,
- this.generateImageGroup(layer)
- );
- }
- this.add(panel);
- this.doLayout();
- },
-
- /**
- * Method: generatePanelId
- * Generate an id attribute value for the panel.
- * It is assumed that the combination of layer.params.LAYERS and
- * layer.id is unique.
- *
- * Parameters:
- * layer - {<OpenLayers.Layer.WMS>} the layer object
- *
- * Returns:
- * {String}
- */
- generatePanelId: function(layer) {
- if (layer) {
- return this.idPrefix + layer.id;
- }
- },
-
- /**
- * Method: createLegendPanel
- * Create a panel for every layer, it will contain a Label with the
- * layer's name and for every possible sub layer an image
- *
- * Parameters:
- * id - {String} the unique id to use for the panel
- * title - {String} the title of the layer
- * legImg - {Object} the legend image object
- *
- * Returns:
- * {<Ext.Panel>}
- */
- createLegendPanel: function(id, title, legImg) {
- // TODO: we probably need the ability to change the css class
- // of the label
- var panelConfig = {
- border: false,
- bodyBorder: false,
- id: id/*,
- bodyStyle: this.bodyStyle,
- items: [
- new Ext.form.Label({
- text: title,
- cls: 'x-form-item x-form-item-label' +
- (this.labelCls ? ' ' + this.labelCls : '')
- })
- ]*/
- };
-
- panelConfig = Ext.applyIf(panelConfig, this.childDefaults);
-
- var panel = new Ext.Panel(panelConfig);
- for (var i=0, len=legImg.length; i<len; i++) {
- panel.add(new Ext.BoxComponent({el: legImg[i]}));
- }
- return panel;
- },
-
- /**
- * Examine a layer and create an array of DOM nodes containing the legend
- * for the layer or its components (for example, a single
- * OpenLayers.Layer.WMS containing multiple layer names in its LAYERS
- * array).
- *
- * Parameters:
- * layer - {OpenLayers.Layer} The layer for which to produce legend
- * graphics.
- */
- generateImageGroup: function(layer) {
- var layers = layer.params.LAYERS.split(",");
- var legImg = [];
+ createLegend: function() {
+ var layers = this.layer.params.LAYERS.split(",");
for (var i = 0, len = layers.length; i < len; i++){
var layerName = layers[i];
- legImg.push(this.createImage(
- this.getLegendUrl(layer, layerName),
- this.generatePanelId(layer)+i
- ));
+ var legend = new GeoExt.legend.Image({url:
+ this.getLegendUrl(layerName)});
+ this.add(legend);
}
- return legImg;
}
});
More information about the Commits
mailing list