[OpenLayers-Users] OpenLayers.Style.createLiteral fails with string value = e.g. "010"

billChadwick w.chadwick at sky.com
Tue Sep 18 15:04:50 PDT 2012


OpenLayers.Style.createLiteral = function(value, context, feature, property)
{
    if (typeof value == "string" && value.indexOf("${") != -1) {
        value = OpenLayers.String.format(value, context, [feature,
property]);
        value = (isNaN(value) || !value) ? value : parseFloat(value);
    }
    return value;
};

If 'value' is a fixed length numeric string with leading zeros, isNaN
returns false and the string is mistakenly put through parseFloat stripping
off the leading zeros.

I found this whilst trying to use a Point geometry to label a cartesian
graticule with numbers in 100s of km and wanting "000" and "010" which were
being turned into "0" and "10".



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/OpenLayers-Style-createLiteral-fails-with-string-value-e-g-010-tp5002786.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list