[OpenLayers-Trac] [OpenLayers] #1548: add support for a context in StyleMap.addUniqueValueRules
OpenLayers
trac at openlayers.org
Thu May 15 11:11:42 EDT 2008
#1548: add support for a context in StyleMap.addUniqueValueRules
----------------------+-----------------------------------------------------
Reporter: pgiraud | Owner:
Type: feature | Status: new
Priority: minor | Milestone:
Component: general | Version: 2.6
Resolution: | Keywords:
State: |
----------------------+-----------------------------------------------------
Comment (by ahocevar):
Actually, this is not a problem of the StyleMap.addUniqueValueRules
method, but of the Rule class in general, because it's context property is
static.
An efficient solution would be a modified getContext method in Rule.js:
{{{
getContext: function(feature) {
var context = this.context;
if (!context) {
context = feature.attributes || feature.data;
}
if (typeof this.context == "function") {
context = this.context(feature);
}
return context;
},
}}}
With that, the use case could be fulfilled with a slightly modified
addUniqueValueRules method in StyleMap.js:
{{{
addUniqueValueRules: function(renderIntent, property, symbolizers,
context) {
var rules = [];
for (var value in symbolizers) {
rules.push(new OpenLayers.Rule({
symbolizer: symbolizers[value],
context: context,
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: property,
value: value
})
}));
}
this.styles[renderIntent].addRules(rules);
},
}}}
To achieve what Pierre wants, his application code would just have to look
like the following:
{{{
var context = function(feature) {
return feature;
}
var lookup = {
"Insert": {fillColor: "green"},
"Delete": {fillColor: "red"}
}
styleMap.addUniqueValueRules("default", "state", lookup, context);
}}}
Although the usage of this Rule context is different than the one of the
Style context, this way of doing it feels more intuitive to me.
--
Ticket URL: <http://trac.openlayers.org/ticket/1548#comment:1>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer
More information about the Trac
mailing list