diff --git a/lib/OpenLayers/Style.js b/lib/OpenLayers/Style.js index 90997575cf..40d9ac8c59 100644 --- a/lib/OpenLayers/Style.js +++ b/lib/OpenLayers/Style.js @@ -115,7 +115,8 @@ OpenLayers.Style = OpenLayers.Class({ * {Object} symbolizer hash */ createSymbolizer: function(feature) { - var style = OpenLayers.Util.extend({}, this.defaultStyle); + var style = this.createLiterals( + OpenLayers.Util.extend({}, this.defaultStyle), feature); var rules = this.rules; @@ -173,11 +174,9 @@ OpenLayers.Style = OpenLayers.Class({ var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; - var context = this.context || feature.attributes || feature.data; - // merge the style with the current style return this.createLiterals( - OpenLayers.Util.extend(style, symbolizer), context); + OpenLayers.Util.extend(style, symbolizer), feature); }, /** @@ -188,14 +187,14 @@ OpenLayers.Style = OpenLayers.Class({ * Parameters: * style - {Object} style to create literals for. Will be modified * inline. - * context - {Object} context to take property values from. Defaults to - * feature.attributes (or feature.data, if attributes are not - * available) + * feature - {Object} * * Returns: * {Object} the modified style */ - createLiterals: function(style, context) { + createLiterals: function(style, feature) { + var context = this.context || feature.attributes || feature.data; + for (var i in this.propertyStyles) { style[i] = OpenLayers.Style.createLiteral(style[i], context); } diff --git a/tests/test_Style.html b/tests/test_Style.html index a6541d8a6e..7714d3b2be 100644 --- a/tests/test_Style.html +++ b/tests/test_Style.html @@ -41,7 +41,6 @@ symbolizer: {"Point": {fillColor: "red"}}, minScaleDenominator: 1000000, maxScaleDenominator: 2500000}); - style.addRules([rule1, rule2, rule3]); var feature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(3,5), @@ -58,9 +57,13 @@ map.setCenter(new OpenLayers.LonLat(3,5), 10); - // at this scale, the feature should be green var createdStyle = style.createSymbolizer(feature); - t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly."); + t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style for default symbolizer correctly."); + + style.addRules([rule1, rule2, rule3]); + createdStyle = style.createSymbolizer(feature); + + // at this scale, the feature should be green t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale()); t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly.");