Mehdiway
Mehdiway

Reputation: 10646

OpenLayers - Style label ignores plus sign

I have a OpenLayers.Style like this :

PoisStyle = new OpenLayers.Style({
    ...
    label: "${poiLabel}"
}, {
    context: {
        ...
        poiLabel: function(feature) {
            return "+212011223344";
        }
    }
});

But the + in +212011223344 gets ignored, all that shows is 212011223344.
Any ideas ?

Upvotes: 0

Views: 61

Answers (2)

user4712985
user4712985

Reputation:

During evaluation the method OpenLayers.Style.createLiteral is called, which contains this line:

value=(isNaN(value)||!value)?value:parseFloat(value);

The content of your string is classified as not being "not a number", therefore feed to parseFloat which returns a number, and this number is converted to a string without a leading "+". Same way you would loose trailing zeros.

As quick fix you may insert a zero width nonbreak space into your literal:

return "+\ufeff212011223344";

This makes the string "not a number" w/o being visible.

Upvotes: 1

Serj
Serj

Reputation: 26

Try the ASCII code instead:

+

Upvotes: 0

Related Questions