[Commits] r1258 - in core/trunk/geoext: lib/GeoExt/widgets tests tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed Jul 15 01:10:40 CEST 2009
Author: ahocevar
Date: 2009-07-15 01:10:40 +0200 (Wed, 15 Jul 2009)
New Revision: 1258
Added:
core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html
Modified:
core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js
core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
core/trunk/geoext/tests/list-tests.html
Log:
Use LegendURL from WMSCapabilities if available. r=sbenthall (closes #116)
Modified: core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-07-14 21:47:21 UTC (rev 1257)
+++ core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-07-14 23:10:40 UTC (rev 1258)
@@ -56,6 +56,12 @@
* container. If not provided it will be taken from the MapPanel.
*/
layerStore: null,
+
+ /** api: config[legendOptions]
+ * ``Object``
+ * Config options for the legend generator, i.e. the panel that provides
+ * the legend image.
+ */
/** private: method[initComponent]
* Initializes the legend panel.
@@ -212,7 +218,10 @@
"Legend" + layer.CLASS_NAME.split(".").pop()
];
if (legendGenerator) {
- legend = new legendGenerator({layer: layer});
+ legend = new legendGenerator(Ext.applyIf({
+ layer: layer,
+ record: record
+ }, this.legendOptions));
mainPanel.add(legend);
}
}
Modified: core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js 2009-07-14 21:47:21 UTC (rev 1257)
+++ core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js 2009-07-14 23:10:40 UTC (rev 1258)
@@ -26,16 +26,35 @@
/** api: config[imageFormat]
* ``String``
- * The image format to request the legend image in.
- * Defaults to image/png.
+ * The image format to request the legend image in if the url cannot be
+ * determined from the styles field of the layer record. Defaults to
+ * image/gif.
*/
imageFormat: "image/gif",
+
+ /** api: config[defaultStyleIsFirst]
+ * ``String``
+ * The WMS spec does not say if the first style advertised for a layer in
+ * a Capabilities document is the default style that the layer is
+ * rendered with. We make this assumption by default. To be strictly WMS
+ * compliant, set this to false, but make sure to configure a STYLES
+ * param with your WMS layers, otherwise LegendURLs advertised in the
+ * GetCapabilities document cannot be used.
+ */
+ defaultStyleIsFirst: true,
/** api: config[layer]
* ``OpenLayers.Layer.WMS``
- * The WMS layer to request the legend for.
+ * The WMS layer to request the legend for. Not required if record is
+ * provided.
*/
- layer: null,
+ layer: null,
+
+ /** api: config[record]
+ * ``Ext.data.Record``
+ * optional record containing the layer
+ */
+ record: null,
/** api: config[bodyBorder]
* ``Boolean``
@@ -48,7 +67,10 @@
* image box components.
*/
initComponent: function() {
- GeoExt.LegendWMS.superclass.initComponent.call(this);
+ GeoExt.LegendWMS.superclass.initComponent.call(this);
+ if(!this.layer) {
+ this.layer = this.record.get("layer");
+ }
this.createLegend();
},
@@ -77,13 +99,28 @@
* Add one BoxComponent per sublayer to this panel.
*/
createLegend: function() {
- var layers = this.layer.params.LAYERS.split(",");
+ var layers = this.layer.params.LAYERS.split(",");
+ var styleNames = this.layer.params.STYLES &&
+ this.layer.params.STYLES.split(",");
+ var styles = this.record && this.record.get("styles");
+ var url, layerName, styleName;
for (var i = 0, len = layers.length; i < len; i++){
- var layerName = layers[i];
+ layerName = layers[i];
+ if(styles) {
+ styleName = styleNames && styleNames[i];
+ if(styleName) {
+ Ext.each(styles, function(s) {
+ url = (s.name == styleName && s.legend) && s.legend.href;
+ return !url;
+ })
+ } else if(this.defaultStyleIsFirst === true){
+ url = styles[0].legend && styles[0].legend.href;
+ }
+ }
var legend = new GeoExt.LegendImage({url:
- this.getLegendUrl(layerName)});
+ url || this.getLegendUrl(layerName)});
this.add(legend);
}
}
-});
\ No newline at end of file
+});
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html 2009-07-14 21:47:21 UTC (rev 1257)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/LegendPanel.html 2009-07-14 23:10:40 UTC (rev 1258)
@@ -8,16 +8,7 @@
<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",
@@ -26,7 +17,9 @@
height: 400,
width: 600,
// map panel-specific options
- map: map,
+ layers: [
+ new OpenLayers.Layer.WMS("test", '/ows', {layers: 'a'})
+ ],
center: new OpenLayers.LonLat(5, 45),
zoom: 4
});
@@ -41,7 +34,7 @@
renderTo: 'legendpanel'});
lp.render();
- var newUrl = "http://www.geoext.org//trac/geoext/chrome/site/img/GeoExt.png";
+ var newUrl = "http://trac.geoext.org/chrome/site/img/GeoExt.png";
mapPanel.layers.getAt(0).set("legendURL", newUrl);
var item = lp.getComponent(mapPanel.map.layers[0].id);
@@ -104,19 +97,24 @@
}
function test_wms(t) {
- t.plan(1);
+ t.plan(3);
var mapPanel = loadMapPanel();
+ var LegendWMS = GeoExt.LegendWMS;
+ GeoExt.LegendWMS = function(config) {
+ t.ok(config.record == mapPanel.layers.getAt(0), "layer record passed correctly");
+ t.ok(config.layer == mapPanel.map.layers[0], "layer passed correctly");
+ t.eq(config.foo, "bar", "legendOptions passed correctly");
+ return new Ext.Panel();
+ }
var lp = new GeoExt.LegendPanel({
- renderTo: 'legendpanel'});
+ renderTo: 'legendpanel',
+ legendOptions: {foo: "bar"}
+ });
lp.render();
- var item = lp.getComponent(mapPanel.map.layers[0].id);
- var url = item.items.get(1).items.get(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();
+ GeoExt.LegendWMS = LegendWMS;
}
function test_addremove(t) {
Added: core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html (rev 0)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html 2009-07-14 23:10:40 UTC (rev 1258)
@@ -0,0 +1,78 @@
+<!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.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <script type="text/javascript">
+
+ function loadMapPanel() {
+ var mapPanel = new GeoExt.MapPanel({
+ // panel options
+ id: "map-panel",
+ title: "GeoExt MapPanel",
+ renderTo: "mappanel",
+ height: 400,
+ width: 600,
+ // map panel-specific options
+ layers: [
+ new OpenLayers.Layer.WMS("test", '/ows', {layers: 'a'})
+ ],
+ center: new OpenLayers.LonLat(5, 45),
+ zoom: 4
+ });
+
+ return mapPanel;
+ }
+
+ function test_legendurl(t) {
+ t.plan(3);
+ var mapPanel = loadMapPanel();
+ var l = new GeoExt.LegendWMS({
+ renderTo: 'legendwms',
+ record: mapPanel.layers.getAt(0)
+ });
+ l.render();
+
+ var url = l.items.get(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");
+ l.destroy()
+
+ mapPanel.map.layers[0].params.STYLES="bar";
+ mapPanel.layers.getAt(0).set("styles", [{
+ name: "bar",
+ legend: {href: "foo"}
+ }]);
+ var l = new GeoExt.LegendWMS({
+ renderTo: 'legendwms',
+ record: mapPanel.layers.getAt(0)
+ });
+ l.render();
+ var url = l.items.get(0).url;
+ t.eq(url, "foo", "legend url from styles field of layer record used correctly.");
+ l.destroy();
+
+ delete mapPanel.map.layers[0].params.STYLES;
+ var l = new GeoExt.LegendWMS({
+ renderTo: 'legendwms',
+ record: mapPanel.layers.getAt(0),
+ defaultStyleIsFirst: true
+ });
+ l.render();
+ var url = l.items.get(0).url;
+ t.eq(url, "foo", "legend url from styles field of layer record used correctly when defaultStyleIsFirst set to true and layer has no STYLES param.");
+
+ l.destroy();
+ mapPanel.destroy();
+ }
+
+
+ </script>
+ <body>
+ <div id="legendwms"></div>
+ <div id="mappanel"></div>
+ </body>
+</html>
Property changes on: core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/geoext/tests/list-tests.html
===================================================================
--- core/trunk/geoext/tests/list-tests.html 2009-07-14 21:47:21 UTC (rev 1257)
+++ core/trunk/geoext/tests/list-tests.html 2009-07-14 23:10:40 UTC (rev 1258)
@@ -21,5 +21,6 @@
<li>lib/GeoExt/widgets/tree/LayerNode.html</li>
<li>lib/GeoExt/widgets/LegendImage.html</li>
<li>lib/GeoExt/widgets/LegendPanel.html</li>
+ <li>lib/GeoExt/widgets/LegendWMS.html</li>
<li>lib/GeoExt/widgets/ZoomSlider.html</li>
</ul>
More information about the Commits
mailing list