[Commits] r2848 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Wed Oct 5 13:00:48 CEST 2011
Author: bartvde
Date: 2011-10-05 13:00:48 +0200 (Wed, 05 Oct 2011)
New Revision: 2848
Modified:
core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
Log:
VectorLegend should use style.title if no rules are present within style, p=rdewit, r=me (closes #358)
Modified: core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2011-10-05 09:24:48 UTC (rev 2847)
+++ core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2011-10-05 11:00:48 UTC (rev 2848)
@@ -299,6 +299,7 @@
if (style.rules.length === 0) {
this.rules = [
new OpenLayers.Rule({
+ title: style.title,
symbolizer: style.createSymbolizer(this.feature)
})
];
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2011-10-05 09:24:48 UTC (rev 2847)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2011-10-05 11:00:48 UTC (rev 2848)
@@ -228,6 +228,80 @@
}
+ function test_setRules(t) {
+ t.plan(2);
+ var legend;
+ var map = new OpenLayers.Map();
+ var store = new GeoExt.data.LayerStore({map: map});
+
+ // First test with a style without a rule but with a title. The
+ // style title should be shown in the legend
+ var options1 = {
+ styleMap: new OpenLayers.StyleMap({
+ "default": new OpenLayers.Style(
+ {"strokeColor": "red"},
+ {title: "Style Title"}
+ )
+ })
+ };
+
+ var layer1 = new OpenLayers.Layer.Vector("test1", options1);
+ map.addLayer(layer1);
+
+ layer1.addFeatures([
+ new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,1))
+ ]);
+
+ var legend1 = new GeoExt.VectorLegend({
+ layerRecord: store.getAt(0)
+ });
+
+ t.eq(
+ legend1.getRuleTitle(legend1.rules[0]),
+ layer1.styleMap.styles["default"].title,
+ "style title is used when no rules are present in style"
+ );
+
+ // Second, a test with a style with a title that also contains
+ // a rule with a title. Rule title should have precedence over
+ // style title
+ var options2 = {
+ styleMap: new OpenLayers.StyleMap({
+ "default": new OpenLayers.Style({}, {
+ title: "Style Title",
+ rules: [new OpenLayers.Rule({
+ title: "Rule Title",
+ symbolizer: {
+ "strokeColor": "red"
+ }
+ })]
+ })
+ })
+ }
+
+ var layer2 = new OpenLayers.Layer.Vector("test2", options2);
+ map.addLayer(layer2);
+
+ layer2.addFeatures([
+ new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(2,2))
+ ]);
+
+ var legend2 = new GeoExt.VectorLegend({
+ layerRecord: store.getAt(1)
+ });
+
+ t.eq(
+ legend2.getRuleTitle(legend2.rules[0]),
+ layer2.styleMap.styles["default"].rules[0].title,
+ "when rules are present in style, any style title should be ignored and the rule title should be used"
+ );
+
+ legend1.destroy();
+ legend2.destroy();
+ map.destroy();
+
+ }
+
</script>
</head><body>
<div id="legendpanel"></div>
More information about the Commits
mailing list