Consider resolution when applying rules

This commit is contained in:
Tim Schaub
2013-09-27 11:46:48 +02:00
parent 78c54addb3
commit bbef15e50e
7 changed files with 131 additions and 24 deletions

View File

@@ -58,11 +58,16 @@ ol.style.Rule = function(options) {
/**
* @param {ol.Feature} feature Feature.
* @param {number} resolution Map resolution.
* @return {boolean} Does the rule apply to the feature?
*/
ol.style.Rule.prototype.applies = function(feature) {
return goog.isNull(this.filter_) ?
true : !!ol.expr.evaluateFeature(this.filter_, feature);
ol.style.Rule.prototype.applies = function(feature, resolution) {
var applies = resolution >= this.minResolution_ &&
resolution < this.maxResolution_;
if (applies && !goog.isNull(this.filter_)) {
applies = !!ol.expr.evaluateFeature(this.filter_, feature);
}
return applies;
};

View File

@@ -45,17 +45,18 @@ ol.style.Style = function(options) {
/**
* Create an array of symbolizer literals for a feature.
* @param {ol.Feature} feature Feature.
* @param {number} resolution Map resolution.
* @return {Array.<ol.style.Literal>} Symbolizer literals for the
* feature.
*/
ol.style.Style.prototype.createLiterals = function(feature) {
ol.style.Style.prototype.createLiterals = function(feature, resolution) {
var rules = this.rules_,
symbolizers = [],
applies = false,
rule;
for (var i = 0, ii = rules.length; i < ii; ++i) {
rule = rules[i];
if (rule.applies(feature)) {
if (rule.applies(feature, resolution)) {
applies = true;
symbolizers.push.apply(symbolizers, rule.getSymbolizers());
}