[Commits] r828 - in sandbox/opengeo/geoexplorer: examples lib lib/GeoExt/widgets lib/GeoExt/widgets/legend tests tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed May 20 01:40:21 CEST 2009
Author: tschaub
Date: 2009-05-20 01:40:21 +0200 (Wed, 20 May 2009)
New Revision: 828
Modified:
sandbox/opengeo/geoexplorer/examples/legendpanel.html
sandbox/opengeo/geoexplorer/examples/legendpanel.js
sandbox/opengeo/geoexplorer/lib/GeoExt.js
sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/LegendPanel.js
sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/Image.js
sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/WMS.js
sandbox/opengeo/geoexplorer/tests/lib/GeoExt/widgets/LegendPanel.html
sandbox/opengeo/geoexplorer/tests/list-tests.html
Log:
Applying newer patch for #2
Modified: sandbox/opengeo/geoexplorer/examples/legendpanel.html
===================================================================
--- sandbox/opengeo/geoexplorer/examples/legendpanel.html 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/examples/legendpanel.html 2009-05-19 23:40:21 UTC (rev 828)
@@ -1,7 +1,7 @@
<html>
<head>
<script type="text/javascript" src="http://dev.geoext.org/trunk/ext/adapter/ext/ext-base.js"></script>
- <script type="text/javascript" src="http://dev.geoext.org/trunk/ext/ext-all.js"></script>
+ <script type="text/javascript" src="http://dev.geoext.org/trunk/ext/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="http://extjs.com/deploy/dev/examples/shared/examples.css"></link>
<script src="http://openlayers.org/api/2.8-rc2/OpenLayers.js"></script>
Modified: sandbox/opengeo/geoexplorer/examples/legendpanel.js
===================================================================
--- sandbox/opengeo/geoexplorer/examples/legendpanel.js 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/examples/legendpanel.js 2009-05-19 23:40:21 UTC (rev 828)
@@ -22,6 +22,7 @@
strokeWidth: 2
}) }) })
]);
+ map.addControl(new OpenLayers.Control.LayerSwitcher());
addLayer = function() {
var wmslayer = new OpenLayers.Layer.WMS("Bodies of Water",
@@ -47,6 +48,9 @@
mapPanel.layers.getAt(1).set("hideInLegend", true);
};
+ updateLegendUrl = function() {
+ mapPanel.layers.getAt(0).set("legendURL", "http://www.geoext.org//trac/geoext/chrome/site/img/GeoExt.png");
+ };
mapPanel = new GeoExt.MapPanel({
region: 'center',
@@ -58,16 +62,16 @@
legendPanel = new GeoExt.LegendPanel({
labelCls: 'mylabel',
- ascending: false,
bodyStyle: 'padding:5px',
- width: 300,
+ width: 350,
tbar: new Ext.Toolbar({items: [
new Ext.Button({text: 'add', handler: addLayer}),
new Ext.Button({text: 'remove', handler: removeLayer}),
new Ext.Button({text: 'movetotop', handler: function() { moveLayer(10); } }),
new Ext.Button({text: 'moveup', handler: function() { moveLayer(1); } }),
new Ext.Button({text: 'togglevis', handler: toggleVisibility}),
- new Ext.Button({text: 'hide', handler: updateHideInLegend})
+ new Ext.Button({text: 'hide', handler: updateHideInLegend}),
+ new Ext.Button({text: 'legendurl', handler: updateLegendUrl})
]}),
autoScroll: true,
region: 'west'});
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/LegendPanel.js 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/LegendPanel.js 2009-05-19 23:40:21 UTC (rev 828)
@@ -20,21 +20,13 @@
*/
GeoExt.LegendPanel = Ext.extend(Ext.Panel, {
- /** api: config[ascending]
+ /** api: config[dynamic]
* ``Boolean``
- * If true the layers in the legend will show the bottom OpenLayers
- * layer on top and the top OpenLayers layer on the bottom.
- * If false, this is inverted. Default value is true.
+ * If false the LegendPanel will not listen to the add, remove and change
+ * events of the LayerStore. So it will load with the initial state of
+ * the LayerStore and not change anymore.
*/
- ascending: true,
-
- /** api: config[autoUpdate]
- * ``Boolean``
- * If true the LegendPanel will listen to the add, remove and change
- * events of the LayerStore. If false, it will load with the initial
- * state of the LayerStore and not change anymore.
- */
- autoUpdate: true,
+ dynamic: true,
/** api: config[showTitle]
* ``Boolean``
@@ -78,11 +70,12 @@
if(!this.layerStore) {
this.layerStore = GeoExt.MapPanel.guess().layers;
}
- this.layerStore.each(this.addLegend, this);
- if (this.autoUpdate) {
+ this.layerStore.each(function(record) {
+ this.addLegend(record);
+ }, this);
+ if (this.dynamic) {
this.layerStore.on({
"add": this.onStoreAdd,
- "move": this.onStoreMove,
"remove": this.onStoreRemove,
"update": this.onStoreUpdate,
scope: this
@@ -91,6 +84,33 @@
this.doLayout();
},
+ /** private: method[recordIndexToPanelIndex]
+ * Private method to get the panel index for a layer represented by a
+ * record.
+ *
+ * :param index ``Integer`` The index of the record in the store.
+ *
+ * :return: ``Integer`` The index of the sub panel in this panel.
+ */
+ recordIndexToPanelIndex: function(index) {
+ var store = this.layerStore;
+ var count = store.getCount();
+ var panelIndex = -1;
+ for(var i=count-1; i>=0; --i) {
+ var layer = store.getAt(i).get("layer");
+ var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
+ 'OpenLayers.Layer.', '')];
+ if(layer.displayInLayerSwitcher && legendGenerator &&
+ (store.getAt(i).get("hideInLegend") !== true)) {
+ ++panelIndex;
+ if(index === i) {
+ break;
+ }
+ }
+ };
+ return panelIndex;
+ },
+
/** private: method[onStoreUpdate]
* Update a layer within the legend panel. Gets called when the store
* fires the update event. This usually means the visibility of the layer
@@ -106,45 +126,17 @@
var layer = record.get('layer');
var legend = this.getComponent(layer.id);
if (legend) {
- legend.setVisible(layer.getVisibility() && !record.get('hideInLegend'));
+ legend.setVisible(layer.getVisibility() &&
+ layer.displayInLayerSwitcher && !record.get('hideInLegend'));
+ if (record.get('legendURL')) {
+ var items = legend.findByType('gx_legendimage');
+ for (var i=0, len=items.length; i<len; i++) {
+ items[i].setUrl(record.get('legendURL'));
+ }
+ }
}
},
- /** private: method[onStoreMove]
- * Relocate a layer within the legend panel. Gets called when the store
- * fires the move event.
- *
- * :param store: ``Ext.data.Store`` The store in which the record was
- * moved.
- * :param record: ``Ext.data.Record`` The record object corresponding
- * to the moved layer.
- * :param from: ``Integer`` The previous index of the moved record.
- * :param to: ``Integer`` The new index of the moved record.
- */
- onStoreMove: function(store, record, from, to) {
- this.moveLegend(record, to);
- },
-
- /** private: method[moveLegend]
- * Relocate a layer within the legend panel. Removes the existing panel
- * and then inserts it at the right index.
- *
- * :param record: ``Ext.data.Record`` The record object(s) corresponding
- * to the moved layer.
- * :param index: ``Integer`` The new index of the moved record.
- */
- moveLegend: function(record, index) {
- var legend = this.getComponent(record.get('layer').id);
- this.remove(legend);
- var newLegend = this.createLegendSubpanel(record);
- if (this.ascending) {
- this.insert(index, newLegend);
- } else {
- this.insert((this.items.length-index), newLegend);
- }
- this.doLayout();
- },
-
/** private: method[onStoreAdd]
* Private method called when a layer is added to the store.
*
@@ -155,8 +147,9 @@
* :param index: ``Integer`` The index of the inserted record.
*/
onStoreAdd: function(store, records, index) {
+ var panelIndex = this.recordIndexToPanelIndex(index);
for (var i=0, len=records.length; i<len; i++) {
- this.addLegend(records[i]);
+ this.addLegend(records[i], panelIndex);
}
this.doLayout();
},
@@ -182,7 +175,7 @@
removeLegend: function(record) {
var legend = this.getComponent(record.get('layer').id);
if (legend) {
- legend.hide();
+ this.remove(legend, true);
this.doLayout();
}
},
@@ -192,22 +185,26 @@
*
* :param record: ``Ext.data.Record`` The record object from the layer
* store.
+ *
+ * :return: ``Ext.Panel`` The created panel per layer
*/
createLegendSubpanel: function(record) {
var layer = record.get('layer');
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);
- } else {
- var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
- 'OpenLayers.Layer.', '')];
- if (legendGenerator) {
- var legend = new legendGenerator({layer: layer});
+ if (mainPanel !== null) {
+ // 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);
+ } else {
+ var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
+ 'OpenLayers.Layer.', '')];
+ if (legendGenerator) {
+ var legend = new legendGenerator({layer: layer});
+ mainPanel.add(legend);
+ }
}
}
return mainPanel;
@@ -218,18 +215,15 @@
*
* :param record: ``Ext.data.Record`` The record object from the layer
* store.
+ * :param index: ``Integer`` The position at which to add the legend.
*/
- addLegend: function(record) {
+ addLegend: function(record, index) {
+ index = index || 0;
var layer = record.get('layer');
- // a layer can be excluded from the legend by setting the hideInLegend
- // property to true
- var hideInLegend = record.get('hideInLegend');
var legendSubpanel = this.createLegendSubpanel(record);
- legendSubpanel.setVisible((layer && layer.getVisibility() && !hideInLegend));
- if (this.ascending) {
- this.add(legendSubpanel);
- } else {
- this.insert(0, legendSubpanel);
+ if (legendSubpanel !== null) {
+ legendSubpanel.setVisible(layer.getVisibility());
+ this.insert(index, legendSubpanel);
}
},
@@ -238,24 +232,32 @@
*
* :param record: ``Ext.data.Record`` The record object from the layer
* store.
+ *
+ * :return: ``Ext.Panel`` The created main panel with a label.
*/
createMainPanel: function(record) {
var layer = record.get('layer');
- var panelConfig = {
- id: layer.id,
- border: false,
- bodyBorder: false,
- bodyStyle: this.bodyStyle,
- items: [
- new Ext.form.Label({
- text: (this.showTitle && !record.get('hideTitle')) ?
- layer.name : '',
- cls: 'x-form-item x-form-item-label' +
- (this.labelCls ? ' ' + this.labelCls : '')
- })
- ]
- };
- var panel = new Ext.Panel(panelConfig);
+ var panel = null;
+ var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
+ 'OpenLayers.Layer.', '')];
+ if (layer.displayInLayerSwitcher && !record.get('hideInLegend') &&
+ legendGenerator) {
+ var panelConfig = {
+ id: layer.id,
+ border: false,
+ bodyBorder: false,
+ bodyStyle: this.bodyStyle,
+ items: [
+ new Ext.form.Label({
+ text: (this.showTitle && !record.get('hideTitle')) ?
+ layer.name : '',
+ cls: 'x-form-item x-form-item-label' +
+ (this.labelCls ? ' ' + this.labelCls : '')
+ })
+ ]
+ };
+ panel = new Ext.Panel(panelConfig);
+ }
return panel;
},
@@ -272,4 +274,4 @@
});
-Ext.reg('gx_legend', GeoExt.LegendPanel);
\ No newline at end of file
+Ext.reg('gx_legendpanel', GeoExt.LegendPanel);
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/Image.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/Image.js 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/Image.js 2009-05-19 23:40:21 UTC (rev 828)
@@ -1,66 +1,79 @@
-/* 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.legend
- * class = Image
- */
-
-Ext.namespace('GeoExt', 'GeoExt.legend');
-
-/** api: constructor
- * .. class:: Image(config)
- *
- * Show a legend image in a BoxComponent and make sure load errors are dealt
- * with.
- */
-GeoExt.legend.Image = Ext.extend(Ext.BoxComponent, {
-
- /** api: config[url]
- * ``String`` The url of the image to load
- */
- url: null,
-
- /** api: config[imgCls]
- * ``String`` Optional css class to apply to img tag
- */
- imgCls: null,
-
- /** private: method[initComponent]
- * Initializes the legend image component.
- */
- initComponent: function() {
- GeoExt.legend.Image.superclass.initComponent.call(this);
- this.autoEl = {tag: 'img',
- 'class': (this.imgCls ? this.imgCls : ''), src: this.url};
- },
-
- /** private: method[onRender]
- * Private method called when the legend image component is being
- * rendered.
- */
- onRender: function(ct, position) {
- GeoExt.legend.Image.superclass.onRender.call(this, ct, position);
- this.getEl().on('error', this.onImageLoadError, this);
- },
-
- /** private: method[onDestroy]
- * Private method called during the destroy sequence.
- */
- onDestroy: function() {
- this.getEl().un('error', this.onImageLoadError, this);
- GeoExt.legend.Image.superclass.onDestroy.apply(this, arguments);
- },
-
- /** private: method[onImageLoadError]
- * Private method called if the legend image fails loading.
- */
- onImageLoadError: function() {
- this.getEl().dom.src = Ext.BLANK_IMAGE_URL;
- }
-
-});
+/* 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.legend
+ * class = Image
+ */
+
+Ext.namespace('GeoExt', 'GeoExt.legend');
+
+/** api: constructor
+ * .. class:: Image(config)
+ *
+ * Show a legend image in a BoxComponent and make sure load errors are dealt
+ * with.
+ */
+GeoExt.legend.Image = Ext.extend(Ext.BoxComponent, {
+
+ /** api: config[url]
+ * ``String`` The url of the image to load
+ */
+ url: null,
+
+ /** api: config[imgCls]
+ * ``String`` Optional css class to apply to img tag
+ */
+ imgCls: null,
+
+ /** private: method[initComponent]
+ * Initializes the legend image component.
+ */
+ initComponent: function() {
+ GeoExt.legend.Image.superclass.initComponent.call(this);
+ this.autoEl = {tag: 'img',
+ 'class': (this.imgCls ? this.imgCls : ''), src: this.url};
+ },
+
+ /** public: method[setUrl]
+ * Sets the url of the image.
+ *
+ * :param url: ``String`` The new url of the image.
+ */
+ setUrl: function(url) {
+ if (this.getEl()) {
+ this.getEl().dom.src = url;
+ }
+ },
+
+ /** private: method[onRender]
+ * Private method called when the legend image component is being
+ * rendered.
+ */
+ onRender: function(ct, position) {
+ GeoExt.legend.Image.superclass.onRender.call(this, ct, position);
+ this.getEl().on('error', this.onImageLoadError, this);
+ },
+
+ /** private: method[onDestroy]
+ * Private method called during the destroy sequence.
+ */
+ onDestroy: function() {
+ this.getEl().un('error', this.onImageLoadError, this);
+ GeoExt.legend.Image.superclass.onDestroy.apply(this, arguments);
+ },
+
+ /** private: method[onImageLoadError]
+ * Private method called if the legend image fails loading.
+ */
+ onImageLoadError: function() {
+ this.getEl().dom.src = Ext.BLANK_IMAGE_URL;
+ }
+
+});
+
+Ext.reg('gx_legendimage', GeoExt.legend.Image);
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/WMS.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/WMS.js 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/widgets/legend/WMS.js 2009-05-19 23:40:21 UTC (rev 828)
@@ -1,87 +1,87 @@
-/* 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, {
-
- /** api: config[imageFormat]
- * ``String``
- * The image format to request the legend image in.
- * Defaults to image/png.
- */
- imageFormat: "image/gif",
-
- /** api: config[layer]
- * ``OpenLayers.Layer.WMS``
- * The WMS layer to request the legend for.
- */
- layer: null,
-
- /** api: config[bodyBorder]
- * ``Boolean``
- * Show a border around the legend image or not. Default is false.
- */
- bodyBorder: false,
-
- /** 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();
- },
-
- /** 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.
- *
- * Get the url for the SLD WMS GetLegendGraphic request.
- */
- 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
- });
- },
-
- /** private: method[createLegend]
- * Add one BoxComponent per sublayer to this panel.
- */
- createLegend: function() {
- var layers = this.layer.params.LAYERS.split(",");
- for (var i = 0, len = layers.length; i < len; i++){
- var layerName = layers[i];
- var legend = new GeoExt.legend.Image({url:
- this.getLegendUrl(layerName)});
- this.add(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 */
+
+/**
+ * @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, {
+
+ /** api: config[imageFormat]
+ * ``String``
+ * The image format to request the legend image in.
+ * Defaults to image/png.
+ */
+ imageFormat: "image/gif",
+
+ /** api: config[layer]
+ * ``OpenLayers.Layer.WMS``
+ * The WMS layer to request the legend for.
+ */
+ layer: null,
+
+ /** api: config[bodyBorder]
+ * ``Boolean``
+ * Show a border around the legend image or not. Default is false.
+ */
+ bodyBorder: false,
+
+ /** 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();
+ },
+
+ /** 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.
+ *
+ * Get the url for the SLD WMS GetLegendGraphic request.
+ */
+ 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
+ });
+ },
+
+ /** private: method[createLegend]
+ * Add one BoxComponent per sublayer to this panel.
+ */
+ createLegend: function() {
+ var layers = this.layer.params.LAYERS.split(",");
+ for (var i = 0, len = layers.length; i < len; i++){
+ var layerName = layers[i];
+ var legend = new GeoExt.legend.Image({url:
+ this.getLegendUrl(layerName)});
+ this.add(legend);
+ }
+ }
+
+});
Modified: sandbox/opengeo/geoexplorer/lib/GeoExt.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt.js 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt.js 2009-05-19 23:40:21 UTC (rev 828)
@@ -82,13 +82,13 @@
"GeoExt/widgets/form/SearchAction.js",
"GeoExt/widgets/form/BasicForm.js",
"GeoExt/widgets/form/FormPanel.js",
+ "GeoExt/widgets/tree/LayerNode.js",
+ "GeoExt/widgets/tree/LayerContainer.js",
+ "GeoExt/widgets/tree/BaseLayerContainer.js",
+ "GeoExt/widgets/tree/OverlayLayerContainer.js",
"GeoExt/widgets/legend/Image.js",
"GeoExt/widgets/legend/WMS.js",
"GeoExt/widgets/LegendPanel.js"
- "GeoExt/widgets/tree/LayerNode.js",
- "GeoExt/widgets/tree/LayerContainer.js",
- "GeoExt/widgets/tree/BaseLayerContainer.js",
- "GeoExt/widgets/tree/OverlayLayerContainer.js"
);
var agent = navigator.userAgent;
Modified: sandbox/opengeo/geoexplorer/tests/lib/GeoExt/widgets/LegendPanel.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/lib/GeoExt/widgets/LegendPanel.html 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/tests/lib/GeoExt/widgets/LegendPanel.html 2009-05-19 23:40:21 UTC (rev 828)
@@ -3,7 +3,7 @@
<head>
<script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
<script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
- <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all.js"></script>
<script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
<script type="text/javascript">
@@ -34,19 +34,101 @@
return mapPanel;
}
- function test_legendpanel(t) {
- t.plan(6);
+ function test_legendurl(t) {
+ t.plan(1);
var mapPanel = loadMapPanel();
var lp = new GeoExt.LegendPanel({
renderTo: 'legendpanel'});
lp.render();
- t.eq(lp.items.length, 1, "Same number of layers in legend panel and in map");
+ var newUrl = "http://www.geoext.org//trac/geoext/chrome/site/img/GeoExt.png";
+ mapPanel.layers.getAt(0).set("legendURL", newUrl);
+
var item = lp.getComponent(mapPanel.map.layers[0].id);
+ var url = item.items.items[1].items.items[0].getEl().dom.src;
+ t.eq(url, newUrl, "Update the image with the provided legendURL");
+
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_togglevisibility(t) {
+ t.plan(2);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ renderTo: 'legendpanel'});
+ lp.render();
+
+ mapPanel.map.layers[0].setVisibility(false);
+ var id = mapPanel.layers.getAt(0).get('layer').id;
+ t.eq(lp.getComponent(id).hidden, true, "Layer has been hidden in legend");
+
+ mapPanel.map.layers[0].setVisibility(true);
+ t.eq(lp.getComponent(id).hidden, false, "Layer has been made visible again in legend");
+
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_hide(t) {
+ t.plan(1);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ renderTo: 'legendpanel'});
+ lp.render();
+
+ mapPanel.layers.getAt(0).set("hideInLegend", true);
+ var id = mapPanel.layers.getAt(0).get('layer').id;
+ t.eq(lp.getComponent(id).hidden, true, "Layer has been hidden in legend");
+
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_dynamic(t) {
+ t.plan(1);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ dynamic: false,
+ renderTo: 'legendpanel'});
+ lp.render();
+
+ var layer;
+ layer = new OpenLayers.Layer.WMS("test2", '/ows', {layers: 'b', format: 'image/png', transparent: 'TRUE'});
+ mapPanel.map.addLayer(layer);
+
+ t.eq(lp.items.length, 1, "If dynamic is false, do not add or remove layers from legend");
+
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_wms(t) {
+ t.plan(1);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ renderTo: 'legendpanel'});
+ lp.render();
+
+ var item = lp.getComponent(mapPanel.map.layers[0].id);
var url = item.items.items[1].items.items[0].url;
var expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=a";
t.eq(url, expectedUrl, "GetLegendGraphic url is generated correctly");
+ lp.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_addremove(t) {
+ t.plan(4);
+ var mapPanel = loadMapPanel();
+ var lp = new GeoExt.LegendPanel({
+ renderTo: 'legendpanel'});
+ lp.render();
+ t.eq(lp.items.length, 1, "Same number of layers in legend panel and in map");
+
+ var item = lp.getComponent(mapPanel.map.layers[0].id);
+
var layer;
layer = new OpenLayers.Layer.WMS("test2", '/ows', {layers: 'b', format: 'image/png', transparent: 'TRUE'});
mapPanel.map.addLayer(layer);
@@ -56,14 +138,13 @@
layer = new OpenLayers.Layer.WMS("test3", '/ows', {layers: 'c'}, {visibility: false});
mapPanel.map.addLayer(layer);
- t.eq(lp.items.length, 3, "A non visible WMS layer will be added");
+ t.eq(lp.items.length, 3, "A non visible WMS layer will be added but will be invisible");
mapPanel.map.removeLayer(mapPanel.map.layers[0]);
- t.eq(lp.items.length, 3, "Removing the WMS layer only hides the legend from the panel");
+ t.eq(lp.items.length, 2, "Removing the WMS layer really removes the legend from the panel");
- mapPanel.layers.getAt(1).set("hideInLegend", true);
- var id = mapPanel.layers.getAt(1).get('layer').id;
- t.eq(lp.getComponent(id).hidden, true, "Layer has been hidden in legend");
+ lp.destroy();
+ mapPanel.destroy();
}
</script>
Modified: sandbox/opengeo/geoexplorer/tests/list-tests.html
===================================================================
--- sandbox/opengeo/geoexplorer/tests/list-tests.html 2009-05-19 23:30:53 UTC (rev 827)
+++ sandbox/opengeo/geoexplorer/tests/list-tests.html 2009-05-19 23:40:21 UTC (rev 828)
@@ -15,7 +15,7 @@
<li>lib/GeoExt/widgets/form/SearchAction.html</li>
<li>lib/GeoExt/widgets/form/BasicForm.html</li>
<li>lib/GeoExt/widgets/form/FormPanel.html</li>
- <li>lib/GeoExt/widgets/LegendPanel.html</li>
<li>lib/GeoExt/widgets/tree/LayerNode.html</li>
<li>lib/GeoExt/widgets/tree/LayerContainer.html</li>
+ <li>lib/GeoExt/widgets/LegendPanel.html</li>
</ul>
More information about the Commits
mailing list