[OpenLayers-Commits] r11886 - in trunk/openlayers: lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Apr 7 14:45:40 EDT 2011


Author: tschaub
Date: 2011-04-07 11:45:31 -0700 (Thu, 07 Apr 2011)
New Revision: 11886

Modified:
   trunk/openlayers/lib/OpenLayers/Style.js
   trunk/openlayers/tests/Style.html
Log:
Casting property values used as symbolizer labels to strings (allowing us to safely split them in the renderers).  r=erilem (see #2193, closes #3249)

Modified: trunk/openlayers/lib/OpenLayers/Style.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Style.js	2011-04-07 18:37:22 UTC (rev 11885)
+++ trunk/openlayers/lib/OpenLayers/Style.js	2011-04-07 18:45:31 UTC (rev 11886)
@@ -191,6 +191,10 @@
             style.display = "none";
         }
         
+        if (style.label && typeof style.label !== "string") {
+            style.label = String(style.label);
+        }
+        
         return style;
     },
     

Modified: trunk/openlayers/tests/Style.html
===================================================================
--- trunk/openlayers/tests/Style.html	2011-04-07 18:37:22 UTC (rev 11885)
+++ trunk/openlayers/tests/Style.html	2011-04-07 18:45:31 UTC (rev 11886)
@@ -127,7 +127,7 @@
     }
     
     function test_Style_createSymbolizer(t) {
-        t.plan(4);
+        t.plan(5);
         var style = new OpenLayers.Style();
 
         // override applySymbolizer to log arguments
@@ -143,11 +143,17 @@
                 type: OpenLayers.Filter.Comparison.EQUAL_TO,
                 property: "foo",
                 value: "bar"
-            })
+            }),
+            symbolizer: {
+                label: "${labelValue}"
+            }
         });
         rule.id = "foo=bar rule";
         var elseRule = new OpenLayers.Rule({
-            elseFilter: true
+            elseFilter: true,
+            symbolizer: {
+                label: "${labelValue}"
+            }
         });
         elseRule.id = "else rule";
         style.addRules([rule, elseRule]);
@@ -167,6 +173,12 @@
         );
         t.eq(log.length, 1, "b) applySymbolizer called once");
         t.eq(log[0] && log[0].id, elseRule.id, "b) applySymbolizer called with correct rule");
+        
+        // c) test that label in returned symbolizer is a string even if property value is a number
+        var symbolizer = style.createSymbolizer(
+            new OpenLayers.Feature.Vector(null, {foo: "bar", labelValue: 10})
+        );
+        t.eq(symbolizer.label, "10", "c) feature property cast to string when used as symbolizer label");
 
     }
     



More information about the Commits mailing list