(Closes #2146) enhance createLiterals to merge context, attributes and pass attribute name through to context functions
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9676 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -256,10 +256,11 @@ OpenLayers.Style = OpenLayers.Class({
|
||||
* {Object} the modified style
|
||||
*/
|
||||
createLiterals: function(style, feature) {
|
||||
var context = this.context || feature.attributes || feature.data;
|
||||
var context = OpenLayers.Util.extend({}, feature.attributes || feature.data);
|
||||
OpenLayers.Util.extend(context, this.context);
|
||||
|
||||
for (var i in this.propertyStyles) {
|
||||
style[i] = OpenLayers.Style.createLiteral(style[i], context, feature);
|
||||
style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i);
|
||||
}
|
||||
return style;
|
||||
},
|
||||
@@ -383,17 +384,20 @@ OpenLayers.Style = OpenLayers.Class({
|
||||
* will be replaced by the value of the "bar" attribute of the passed
|
||||
* feature.
|
||||
* context - {Object} context to take attribute values from
|
||||
* feature - {OpenLayers.Feature.Vector} The feature that will be passed
|
||||
* to <OpenLayers.String.format> for evaluating functions in the context.
|
||||
* feature - {<OpenLayers.Feature.Vector>} optional feature to pass to
|
||||
* <OpenLayers.String.format> for evaluating functions in the
|
||||
* context.
|
||||
* property - {String} optional, name of the property for which the literal is
|
||||
* being created for evaluating functions in the context.
|
||||
*
|
||||
* Returns:
|
||||
* {String} the parsed value. In the example of the value parameter above, the
|
||||
* result would be "foo valueOfBar", assuming that the passed feature has an
|
||||
* attribute named "bar" with the value "valueOfBar".
|
||||
*/
|
||||
OpenLayers.Style.createLiteral = function(value, context, feature) {
|
||||
OpenLayers.Style.createLiteral = function(value, context, feature, property) {
|
||||
if (typeof value == "string" && value.indexOf("${") != -1) {
|
||||
value = OpenLayers.String.format(value, context, [feature]);
|
||||
value = OpenLayers.String.format(value, context, [feature, property]);
|
||||
value = (isNaN(value) || !value) ? value : parseFloat(value);
|
||||
}
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user