Fixing OpenLayers.Style.createLiteral to work with all strings. r=ahocevar (closes #1439)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6553 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -331,7 +331,7 @@ OpenLayers.Style = OpenLayers.Class({
|
|||||||
OpenLayers.Style.createLiteral = function(value, context, feature) {
|
OpenLayers.Style.createLiteral = function(value, context, feature) {
|
||||||
if (typeof value == "string" && value.indexOf("${") != -1) {
|
if (typeof value == "string" && value.indexOf("${") != -1) {
|
||||||
value = OpenLayers.String.format(value, context, [feature]);
|
value = OpenLayers.String.format(value, context, [feature]);
|
||||||
value = isNaN(value) ? value : parseFloat(value);
|
value = (isNaN(value) || !value) ? value : parseFloat(value);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,47 @@
|
|||||||
t.ok(propertyStyles.strokeColor, "detected strokeColor from style correctly");
|
t.ok(propertyStyles.strokeColor, "detected strokeColor from style correctly");
|
||||||
t.eq(typeof propertyStyles.pointRadius, "undefined", "correctly detected pointRadius as non-property style");
|
t.eq(typeof propertyStyles.pointRadius, "undefined", "correctly detected pointRadius as non-property style");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_createLiteral(t) {
|
||||||
|
t.plan(6);
|
||||||
|
|
||||||
|
var value, context, feature, result, expected;
|
||||||
|
var func = OpenLayers.Style.createLiteral;
|
||||||
|
|
||||||
|
// without templates
|
||||||
|
value = "foo";
|
||||||
|
expected = value;
|
||||||
|
result = func(value);
|
||||||
|
t.eq(result, expected, "(no template) preserves literal");
|
||||||
|
|
||||||
|
// with templates
|
||||||
|
value = "${foo}"
|
||||||
|
expected = "bar";
|
||||||
|
context = {foo: expected};
|
||||||
|
result = func(value, context);
|
||||||
|
t.eq(result, expected, "(template) preserves literal");
|
||||||
|
|
||||||
|
expected = "";
|
||||||
|
context = {foo: expected};
|
||||||
|
result = func(value, context);
|
||||||
|
t.eq(result, expected, "(template) preserves empty string");
|
||||||
|
|
||||||
|
expected = "16/03/2008";
|
||||||
|
context = {foo: expected};
|
||||||
|
result = func(value, context);
|
||||||
|
t.eq(result, expected, "(template) preserves string with numbers");
|
||||||
|
|
||||||
|
expected = 16;
|
||||||
|
context = {foo: expected + ""};
|
||||||
|
result = func(value, context);
|
||||||
|
t.eq(result, expected, "(template) casts integer in a string");
|
||||||
|
|
||||||
|
expected = 16;
|
||||||
|
context = {foo: " " + expected + " "};
|
||||||
|
result = func(value, context);
|
||||||
|
t.eq(result, expected, "(template) casts integer in a space padded string");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_Style_destroy(t) {
|
function test_Style_destroy(t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user