Consider resolution when applying rules
This commit is contained in:
@@ -425,12 +425,13 @@ ol.layer.Vector.prototype.getPolygonVertices = function() {
|
||||
|
||||
/**
|
||||
* @param {Object.<string, ol.Feature>} features Features.
|
||||
* @param {number} resolution Map resolution.
|
||||
* @return {Array.<Array>} symbolizers for features. Each array in this array
|
||||
* contains 3 items: an array of features, the symbolizer literal, and
|
||||
* an array with optional additional data for each feature.
|
||||
*/
|
||||
ol.layer.Vector.prototype.groupFeaturesBySymbolizerLiteral =
|
||||
function(features) {
|
||||
function(features, resolution) {
|
||||
var uniqueLiterals = {},
|
||||
featuresBySymbolizer = [],
|
||||
style = this.style_,
|
||||
@@ -447,7 +448,7 @@ ol.layer.Vector.prototype.groupFeaturesBySymbolizerLiteral =
|
||||
if (goog.isNull(style)) {
|
||||
style = ol.style.getDefault();
|
||||
}
|
||||
literals = style.createLiterals(feature);
|
||||
literals = style.createLiterals(feature, resolution);
|
||||
}
|
||||
numLiterals = literals.length;
|
||||
for (j = 0; j < numLiterals; ++j) {
|
||||
|
||||
@@ -509,7 +509,8 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
|
||||
renderByGeometryType:
|
||||
for (type in featuresToRender) {
|
||||
groups = layer.groupFeaturesBySymbolizerLiteral(featuresToRender[type]);
|
||||
groups = layer.groupFeaturesBySymbolizerLiteral(
|
||||
featuresToRender[type], tileResolution);
|
||||
numGroups = groups.length;
|
||||
for (j = 0; j < numGroups; ++j) {
|
||||
group = groups[j];
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user