[Commits] r796 - in sandbox/bartvde/legend2/geoext: examples lib lib/GeoExt/widgets lib/GeoExt/widgets/legend tests tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Mon May 18 07:52:34 CEST 2009


Author: bartvde
Date: 2009-05-18 07:52:34 +0200 (Mon, 18 May 2009)
New Revision: 796

Added:
   sandbox/bartvde/legend2/geoext/examples/legendpanel.html
   sandbox/bartvde/legend2/geoext/examples/legendpanel.js
   sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/LegendPanel.js
   sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/
   sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/Image.js
   sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/WMS.js
   sandbox/bartvde/legend2/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
Modified:
   sandbox/bartvde/legend2/geoext/lib/GeoExt.js
   sandbox/bartvde/legend2/geoext/tests/list-tests.html
Log:
fresh legend panel commit

Added: sandbox/bartvde/legend2/geoext/examples/legendpanel.html
===================================================================
--- sandbox/bartvde/legend2/geoext/examples/legendpanel.html	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/examples/legendpanel.html	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +1,26 @@
+<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>
+        <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>
+        <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</h1>
+        <p>This example shows the how to create a LegendPanel that autopopulates with legends from a map
+        that has already been created.</p>
+        <p>The js is not minified so it is readable. See <a href="legendpanel.js">legendpanel.js</a>.</p>
+        <div id="view"></div>
+    </body>
+</html>

Added: sandbox/bartvde/legend2/geoext/examples/legendpanel.js
===================================================================
--- sandbox/bartvde/legend2/geoext/examples/legendpanel.js	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/examples/legendpanel.js	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +1,82 @@
+
+var mapPanel;
+
+Ext.onReady(function() {
+    var map = new OpenLayers.Map({allOverlays: true});
+    map.addLayers([
+        new OpenLayers.Layer.WMS(
+            "Tasmania",
+            "http://publicus.opengeo.org/geoserver/wms?",
+            {layers: 'topp:tasmania_state_boundaries', format: 'image/png', transparent: true},
+            {singleTile: true}),
+        new OpenLayers.Layer.WMS(
+            "Cities and Roads",
+            "http://publicus.opengeo.org/geoserver/wms?",
+            {layers: 'topp:tasmania_cities,topp:tasmania_roads', format: 'image/png', transparent: true},
+            {singleTile: true}),
+        new OpenLayers.Layer.Vector('Polygons', {styleMap: new OpenLayers.StyleMap({
+                "default": new OpenLayers.Style({
+                    pointRadius: 8,
+                    fillColor: "#00ffee",
+                    strokeColor: "#000000",
+                    strokeWidth: 2
+                }) }) })
+    ]);
+
+    addLayer = function() {
+        var wmslayer = new OpenLayers.Layer.WMS("Bodies of Water",
+            "http://publicus.opengeo.org/geoserver/wms?",
+            {layers: 'topp:tasmania_water_bodies', format: 'image/png', transparent: true},
+            {singleTile: true});
+        mapPanel.map.addLayer(wmslayer);
+    };
+
+    removeLayer = function() {
+        mapPanel.map.removeLayer(mapPanel.map.layers[1]);
+    };
+
+    moveLayer = function(idx) {
+        mapPanel.map.setLayerIndex(mapPanel.map.layers[0], idx);
+    };
+
+    toggleVisibility = function() {
+        mapPanel.map.layers[1].setVisibility(!mapPanel.map.layers[1].getVisibility());
+    };
+
+    updateHideInLegend = function() {
+        mapPanel.layers.getAt(1).set("hideInLegend", true);
+    };
+
+    mapPanel = new GeoExt.MapPanel({
+        region: 'center',
+        height: 400,
+        width: 600,
+        map: map,
+        center: new OpenLayers.LonLat(146.4, -41.6),
+        zoom: 7});
+
+    legendPanel = new GeoExt.LegendPanel({
+        labelCls: 'mylabel',
+        ascending: false,
+        bodyStyle: 'padding:5px',
+        width: 300,
+        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})
+            ]}),
+        autoScroll: true,
+        region: 'west'});
+
+     new Ext.Panel({
+        title: "GeoExt LegendPanel Demo",
+        layout: 'border',
+        renderTo: 'view',
+        height: 400,
+        width: 800,
+        items: [legendPanel, mapPanel] });
+});
+

Added: sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/LegendPanel.js	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/LegendPanel.js	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +1,275 @@
+/* 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, {
+
+    /** api: config[ascending]
+     *  ``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.
+     */
+    ascending: true,
+
+    /** api: config[dynamic]
+     *  ``Boolean``
+     *  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. 
+     */
+    dynamic: true,
+    
+    /** 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,
+
+    /** private: method[initComponent]
+     *  Initializes the legend panel.
+     */
+    initComponent: function() {
+        GeoExt.LegendPanel.superclass.initComponent.call(this);
+    },
+    
+    /** private: method[onRender]
+     *  Private method called when the legend panel is being rendered.
+     */
+    onRender: function() {
+        GeoExt.LegendPanel.superclass.onRender.apply(this, arguments);
+        if(!this.layerStore) {
+            this.layerStore = GeoExt.MapPanel.guess().layers;
+        }
+        this.layerStore.each(this.addLegend, this);
+        if (this.dynamic) {
+            this.layerStore.on({
+                "add": this.onStoreAdd,
+                "move": this.onStoreMove,
+                "remove": this.onStoreRemove,
+                "update": this.onStoreUpdate,
+                scope: this
+            });
+        }
+        this.doLayout();
+    },
+
+    /** 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
+     *  has changed.
+     *
+     *  :param store: ``Ext.data.Store`` The store in which the record was
+     *      changed.
+     *  :param record: ``Ext.data.Record`` The record object corresponding
+     *      to the updated layer.
+     *  :param operation: ``String`` The type of operation.
+     */
+    onStoreUpdate: function(store, record, operation) {
+        var layer = record.get('layer');
+        var legend = this.getComponent(layer.id);
+        if (legend) {
+            legend.setVisible(layer.getVisibility() && !record.get('hideInLegend'));
+        }
+    },
+
+    /** 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.
+     *
+     *  :param store: ``Ext.data.Store`` The store to which the record(s) was 
+     *      added.
+     *  :param record: ``Ext.data.Record`` The record object(s) corresponding
+     *      to the added layers.
+     *  :param index: ``Integer`` The index of the inserted record.
+     */
+    onStoreAdd: function(store, records, index) {
+        for (var i=0, len=records.length; i<len; i++) {
+            this.addLegend(records[i]);
+        }
+        this.doLayout();
+    },
+
+    /** private: method[onStoreRemove]
+     *  Private method called when a layer is removed from the store.
+     *
+     *  :param store: ``Ext.data.Store`` The store from which the record(s) was
+     *      removed.
+     *  :param record: ``Ext.data.Record`` The record object(s) corresponding
+     *      to the removed layers.
+     *  :param index: ``Integer`` The index of the removed record.
+     */
+    onStoreRemove: function(store, record, index) {
+        this.removeLegend(record);
+    },
+
+    /** private: method[removeLegend]
+     *  Remove the legend of a layer.
+     *  :param record: ``Ext.data.Record`` The record object from the layer 
+     *      store to remove.
+     */
+    removeLegend: function(record) {
+        var legend = this.getComponent(record.get('layer').id);
+        if (legend) {
+            legend.hide();
+            this.doLayout();
+        }
+    },
+
+    /** private: method[createLegendSubpanel]
+     *  Create a legend sub panel for the layer.
+     *
+     *  :param record: ``Ext.data.Record`` The record object from the layer
+     *      store.
+     */
+    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});
+                mainPanel.add(legend);
+            }
+        }
+        return mainPanel;
+    },
+
+    /** 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');
+        // 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);
+        }
+    },
+
+    /** 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,
+            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);
+        return panel;
+    },
+
+    /** private: method[onDestroy]
+     *  Private method called during the destroy sequence.
+     */
+    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);
+    }
+    
+});
+
+Ext.reg('gx_legend', GeoExt.LegendPanel);

Added: sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/Image.js
===================================================================
--- sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/Image.js	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/Image.js	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +1,66 @@
+/* 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;
+    }
+
+});

Added: sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/WMS.js
===================================================================
--- sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/WMS.js	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/lib/GeoExt/widgets/legend/WMS.js	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +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);
+        }
+    }
+
+});

Modified: sandbox/bartvde/legend2/geoext/lib/GeoExt.js
===================================================================
--- sandbox/bartvde/legend2/geoext/lib/GeoExt.js	2009-05-18 04:33:56 UTC (rev 795)
+++ sandbox/bartvde/legend2/geoext/lib/GeoExt.js	2009-05-18 05:52:34 UTC (rev 796)
@@ -72,7 +72,10 @@
             "GeoExt/widgets/Popup.js",
             "GeoExt/widgets/form/SearchAction.js",
             "GeoExt/widgets/form/BasicForm.js",
-            "GeoExt/widgets/form/FormPanel.js"
+            "GeoExt/widgets/form/FormPanel.js",
+            "GeoExt/widgets/legend/Image.js",
+            "GeoExt/widgets/legend/WMS.js",
+            "GeoExt/widgets/LegendPanel.js"
         );
 
         var agent = navigator.userAgent;

Added: sandbox/bartvde/legend2/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
===================================================================
--- sandbox/bartvde/legend2/geoext/tests/lib/GeoExt/widgets/LegendPanel.html	                        (rev 0)
+++ sandbox/bartvde/legend2/geoext/tests/lib/GeoExt/widgets/LegendPanel.html	2009-05-18 05:52:34 UTC (rev 796)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html debug="true">
+  <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="../../../../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+
+        function createMap() {
+            var map = new OpenLayers.Map({allOverlays: true});
+            var layer = new OpenLayers.Layer.WMS("test", '/ows', {layers: 'a'});
+            map.addLayer(layer);
+            return map;
+        }
+
+        function loadMapPanel() {
+            var map = createMap();
+
+            mapPanel = new GeoExt.MapPanel({
+                // panel options
+                id: "map-panel",
+                title: "GeoExt MapPanel",
+                renderTo: "mappanel",
+                height: 400,
+                width: 600,
+                // map panel-specific options
+                map: map,
+                center: new OpenLayers.LonLat(5, 45),
+                zoom: 4
+            });
+
+            return mapPanel;
+        }
+
+        function test_legendpanel(t) {
+            t.plan(6);
+            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 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");
+
+            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, 2, "New WMS layer has been added");
+
+            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");
+
+            mapPanel.map.removeLayer(mapPanel.map.layers[0]);
+            t.eq(lp.items.length, 3, "Removing the WMS layer only hides 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");
+        }
+
+    </script>
+  <body>
+    <div id="legendpanel"></div>
+    <div id="mappanel"></div>
+  </body>
+</html>

Modified: sandbox/bartvde/legend2/geoext/tests/list-tests.html
===================================================================
--- sandbox/bartvde/legend2/geoext/tests/list-tests.html	2009-05-18 04:33:56 UTC (rev 795)
+++ sandbox/bartvde/legend2/geoext/tests/list-tests.html	2009-05-18 05:52:34 UTC (rev 796)
@@ -13,4 +13,5 @@
   <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>
 </ul>



More information about the Commits mailing list