[OpenLayers-Dev] createLiteral enhancement proposal

Paul Spencer pspencer at dmsolutions.ca
Fri Jun 19 11:14:23 EDT 2009


In the context of calling functions to compute styles for features  
using the ${functionName} syntax, it would be very useful for me if  
the property being computed was passed to functionName() in addition  
to the feature itself.  I've tested this locally by modifying  
createLiterals to pass an array with [feature,i] (where i is the  
property name) and createLiteral to replace feature with args, which  
is passed to String.format as the third value.  This works perfectly  
for me.  The only other use of createLiteral is in Rule, which does  
not use the third argument at all.

I would like to propose this change as a patch but I am undecided if  
the appropriate change is to pass an array as the third argument to  
createLiteral or to test in createLiteral if the third argument is an  
array or not and modify it appropriately for passing on to  
String.format ...

Currently, I am using this:

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

What I could do is:

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

Comments?

__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://research.dmsolutions.ca/




More information about the Dev mailing list