OpenLayers OpenLayers

Changeset 6553

Show
Ignore:
Timestamp:
03/19/08 15:23:15 (6 months ago)
Author:
tschaub
Message:

Fixing OpenLayers.Style.createLiteral to work with all strings. r=ahocevar (closes #1439)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Style.js

    r6512 r6553  
    332332    if (typeof value == "string" && value.indexOf("${") != -1) { 
    333333        value = OpenLayers.String.format(value, context, [feature]); 
    334         value = isNaN(value) ? value : parseFloat(value); 
     334        value = (isNaN(value) || !value) ? value : parseFloat(value); 
    335335    } 
    336336    return value; 
  • trunk/openlayers/tests/test_Style.html

    r6505 r6553  
    156156        t.eq(typeof propertyStyles.pointRadius, "undefined", "correctly detected pointRadius as non-property style"); 
    157157    } 
     158     
     159    function test_createLiteral(t) { 
     160        t.plan(6); 
     161         
     162        var value, context, feature, result, expected; 
     163        var func = OpenLayers.Style.createLiteral; 
     164 
     165        // without templates 
     166        value = "foo"; 
     167        expected = value; 
     168        result = func(value); 
     169        t.eq(result, expected, "(no template) preserves literal"); 
     170         
     171        // with templates 
     172        value = "${foo}" 
     173        expected = "bar"; 
     174        context = {foo: expected}; 
     175        result = func(value, context); 
     176        t.eq(result, expected, "(template) preserves literal"); 
     177         
     178        expected = ""; 
     179        context = {foo: expected}; 
     180        result = func(value, context); 
     181        t.eq(result, expected, "(template) preserves empty string"); 
     182         
     183        expected = "16/03/2008"; 
     184        context = {foo: expected}; 
     185        result = func(value, context); 
     186        t.eq(result, expected, "(template) preserves string with numbers"); 
     187         
     188        expected = 16; 
     189        context = {foo: expected + ""}; 
     190        result = func(value, context); 
     191        t.eq(result, expected, "(template) casts integer in a string"); 
     192 
     193        expected = 16; 
     194        context = {foo: " " + expected + " "}; 
     195        result = func(value, context); 
     196        t.eq(result, expected, "(template) casts integer in a space padded string"); 
     197 
     198    } 
    158199 
    159200    function test_Style_destroy(t) {