[Commits] r2113 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Mon Apr 26 12:43:08 CEST 2010


Author: ahocevar
Date: 2010-04-26 12:43:08 +0200 (Mon, 26 Apr 2010)
New Revision: 2113

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
Log:
Allow VectorLegend to use a different symbol type for rules that don't have a symbolizer matching the configured symbolType. r=bartvde (closes #268)

Modified: core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js	2010-04-26 10:23:01 UTC (rev 2112)
+++ core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js	2010-04-26 10:43:08 UTC (rev 2113)
@@ -54,7 +54,11 @@
      *  The symbol type for legend swatches.  Must be one of ``"Point"``, 
      *  ``"Line"``, or ``"Polygon"``.  If not provided, the ``layer`` or
      *  ``layerRecord`` config property must be specified, and the geometry type
-     *  of the first feature found on the layer will be used.
+     *  of the first feature found on the layer will be used. If a rule does
+     *  not have a symbolizer for ``symbolType``, we look at the symbolizers
+     *  for the rule, and see if it has a ``"Point"``, ``"Line"`` or
+     *  ``"Polygon"`` symbolizer, which we use for rendering a swatch of the
+     *  respective geometry type. 
      */
     symbolType: null,
 
@@ -434,12 +438,19 @@
      */
     createRuleRenderer: function(rule) {
         var symbolizer = rule.symbolizer;
-        if (symbolizer[this.symbolType]) {
-            symbolizer = symbolizer[this.symbolType];
+        var types = [this.symbolType, "Point", "Line", "Polygon"];
+        var type, haveType;
+        for(var i=0, len=types.length; i<len; ++i) {
+            type = types[i];
+            if(symbolizer[type]) {
+                symbolizer = symbolizer[type];
+                haveType = true;
+                break;
+            }
         }
         return {
             xtype: "gx_renderer",
-            symbolType: this.symbolType,
+            symbolType: haveType === true ? type : this.symbolType,
             symbolizers: [symbolizer],
             style: this.clickableSymbol ? {cursor: "pointer"} : undefined,
             listeners: {

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html	2010-04-26 10:23:01 UTC (rev 2112)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html	2010-04-26 10:43:08 UTC (rev 2113)
@@ -7,7 +7,7 @@
     <script>
 
     function test_constructor(t) {
-        t.plan(5);
+        t.plan(7);
         
         var legend;
 
@@ -23,7 +23,12 @@
             renderTo: "legendpanel",
             rules: [
                 new OpenLayers.Rule({title: "first rule"}),
-                new OpenLayers.Rule({title: "second rule"})
+                new OpenLayers.Rule({
+                    title: "second rule",
+                    symbolizer: {
+                        "Polygon": {strokeColor: "blue"}
+                    }
+                })
             ],
             symbolType: "Point"
         });
@@ -39,6 +44,9 @@
         // this should eventually become a container instead of a panel
         t.ok(ruleTitleCmp.getEl().dom.innerHTML.indexOf("first rule") > -1, "correct title for first rule");
 
+        t.eq(ruleCmp.getComponent(0).feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "1st swatch uses a Point feature");
+        t.eq(legend.rulesContainer.getComponent(1).getComponent(0).feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "2nd swatch uses a Polygon feature");
+
         legend.destroy();
     }
     



More information about the Commits mailing list