Skip to content

Commit

Permalink
Casting property values used as symbolizer labels to strings (allowin…
Browse files Browse the repository at this point in the history
…g us to safely split them in the renderers). r=erilem (see #2193, closes #3249)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11886 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
tschaub committed Apr 7, 2011
1 parent b650d4d commit 13207d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/OpenLayers/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ OpenLayers.Style = OpenLayers.Class({
style.display = "none";
}

if (style.label && typeof style.label !== "string") {
style.label = String(style.label);
}

return style;
},

Expand Down
18 changes: 15 additions & 3 deletions tests/Style.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
Expand All @@ -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");

}

Expand Down

0 comments on commit 13207d4

Please sign in to comment.