[Commits] r1923 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Thu Mar 4 18:03:56 CET 2010
Author: bartvde
Date: 2010-03-04 18:03:56 +0100 (Thu, 04 Mar 2010)
New Revision: 1923
Modified:
core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
Log:
make sure scale parameter gets updated in the WMS legend component on zoomend, and also make sure LegendURLs coming from GetCapabilities are appended with the scale parameter, r=ahocevar,tschaub (closes #161)
Modified: core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js 2010-03-03 16:43:33 UTC (rev 1922)
+++ core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js 2010-03-04 17:03:56 UTC (rev 1923)
@@ -50,9 +50,14 @@
/** api: config[useScaleParameter]
* ``Boolean``
* Should we use the optional SCALE parameter in the SLD WMS
- * GetLegendGraphic request? Defaults to false.
+ * GetLegendGraphic request? Defaults to true.
*/
- useScaleParameter: false,
+ useScaleParameter: true,
+
+ /** private: property[map]
+ * ``OpenLayers.Map`` The map to register events to.
+ */
+ map: null,
/** private: method[initComponent]
* Initializes the WMS legend. For group layers it will create multiple
@@ -60,6 +65,11 @@
*/
initComponent: function() {
GeoExt.WMSLegend.superclass.initComponent.call(this);
+ var layer = this.layerRecord.get("layer");
+ this.map = layer.map;
+ if (this.useScaleParameter === true) {
+ this.map.events.register("zoomend", this, this.update);
+ }
this.update();
},
@@ -95,20 +105,30 @@
url = styles[0].legend && styles[0].legend.href;
}
}
- return url ||
- layer.getFullRequestString({
- REQUEST: "GetLegendGraphic",
- WIDTH: null,
- HEIGHT: null,
- EXCEPTIONS: "application/vnd.ogc.se_xml",
- LAYER: layerName,
- LAYERS: null,
- STYLE: (styleName !== '') ? styleName: null,
- STYLES: null,
- SRS: null,
- FORMAT: this.imageFormat,
- SCALE: (this.useScaleParameter === true) ? layer.map.getScale(): null
- });
+ if(!url) {
+ url = layer.getFullRequestString({
+ REQUEST: "GetLegendGraphic",
+ WIDTH: null,
+ HEIGHT: null,
+ EXCEPTIONS: "application/vnd.ogc.se_xml",
+ LAYER: layerName,
+ LAYERS: null,
+ STYLE: (styleName !== '') ? styleName: null,
+ STYLES: null,
+ SRS: null,
+ FORMAT: this.imageFormat
+ });
+ }
+ // add scale parameter - also if we have the url from the record's
+ // styles data field and it is actually a GetLegendGraphic request.
+ if(this.useScaleParameter === true &&
+ url.toLowerCase().indexOf("request=getlegendgraphic") != -1) {
+ var scale = layer.map.getScale();
+ //TODO replace with Ext.urlAppend when we drop support for Ext 2.x
+ url = OpenLayers.Util.urlAppend(url, "SCALE=" + scale);
+ }
+
+ return url;
},
/** private: method[update]
@@ -121,6 +141,7 @@
var layerNames, layerName, i, len;
var layer = this.layerRecord.get("layer");
+
layerNames = [layer.params.LAYERS].join(",").split(",");
var destroyList = [];
@@ -156,7 +177,20 @@
}
}
this.doLayout();
+ },
+
+ /** private: method[beforeDestroy]
+ */
+ beforeDestroy: function() {
+ if (this.useScaleParameter === true) {
+ var layer = this.layerRecord.get("layer")
+ this.map && this.map.events &&
+ this.map.events.unregister("zoomend", this, this.update);
+ }
+ delete this.map;
+ GeoExt.WMSLegend.superclass.beforeDestroy.apply(this, arguments);
}
+
});
/** private: method[supports]
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html 2010-03-03 16:43:33 UTC (rev 1922)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html 2010-03-04 17:03:56 UTC (rev 1923)
@@ -42,7 +42,7 @@
t.eq(l.items.length, 5, "We expect 5 items");
url = l.items.get(1).url;
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=a";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=a&SCALE=27683990.15625";
t.eq(url, expectedUrl, "GetLegendGraphic url is generated correctly");
l.destroy();
@@ -54,18 +54,19 @@
t.eq(l.items.length, 3, "We expect 3 items");
url = l.items.get(1).url;
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=x";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=x&SCALE=27683990.15625";
t.eq(url, expectedUrl, "GetLegendGraphic url is generated correctly");
l.destroy();
}
function test_legendurl(t) {
- t.plan(6);
+ t.plan(7);
var l, url, expectedUrl;
var mapPanel = loadMapPanel();
l = new GeoExt.WMSLegend({
renderTo: 'legendwms',
+ useScaleParameter: false,
layerRecord: mapPanel.layers.getAt(0)
});
l.render();
@@ -77,8 +78,7 @@
l = new GeoExt.WMSLegend({
renderTo: 'legendwms',
- layerRecord: mapPanel.layers.getAt(0),
- useScaleParameter: true
+ layerRecord: mapPanel.layers.getAt(0)
});
l.render();
@@ -120,7 +120,7 @@
});
l.render();
url = l.items.get(1).url;
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD=sld&LAYER=a";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD=sld&LAYER=a&SCALE=27683990.15625";
t.eq(url, expectedUrl, "GetLegendGraphic url is generated when layer has SLD set");
l.destroy();
delete mapPanel.map.layers[0].params.SLD;
@@ -133,8 +133,14 @@
});
l.render();
url = l.items.get(1).url;
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD_BODY=sld_body&LAYER=a";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD_BODY=sld_body&LAYER=a&SCALE=27683990.15625";
t.eq(url, expectedUrl, "GetLegendGraphic url is generated when layer has SLD_BODY set");
+
+ mapPanel.map.zoomIn();
+ url = l.items.get(1).url;
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD_BODY=sld_body&LAYER=a&SCALE=13841995.078125";
+ t.eq(url, expectedUrl, "GetLegendGraphic url changes when map scale changes");
+
l.destroy();
delete mapPanel.map.layers[0].params.SLD_BODY;
@@ -176,10 +182,10 @@
l.update();
t.ok(l.getComponent("b"),
"update does not remove components to be updated");
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=b";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=b&SCALE=27683990.15625";
t.eq(l.getComponent("b").url, expectedUrl,
"update updates component URL");
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c&SCALE=27683990.15625";
t.eq(l.getComponent("c").url, expectedUrl,
"update sets correct URL in new component");
@@ -188,7 +194,7 @@
layers: "c",
styles: "style1"
});
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c&STYLE=style1";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c&STYLE=style1&SCALE=27683990.15625";
l.update();
t.eq(l.getComponent("c").url, expectedUrl,
"update sets correct STYLE params in URL");
@@ -212,7 +218,7 @@
sld: "http://url-to-sld.org/"
});
l.update();
- expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&SLD=http%3A%2F%2Furl-to-sld.org%2F&LAYER=c";
+ expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&SLD=http%3A%2F%2Furl-to-sld.org%2F&LAYER=c&SCALE=27683990.15625";
t.eq(l.getComponent("c").url, expectedUrl,
"update does not use the legend href from the " +
"styles field if SLD is set in the layer params");
More information about the Commits
mailing list