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

@@ -134,7 +134,7 @@ describe('ol.layer.Vector', function() {
})
];
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
var groups = layer.groupFeaturesBySymbolizerLiteral(features, 1);
expect(groups.length).to.be(2);
expect(groups[0][0].length).to.be(1);
expect(groups[0][1].color).to.be('#BADA55');
@@ -164,7 +164,7 @@ describe('ol.layer.Vector', function() {
anotherFeatureWithSymbolizers.setSymbolizers([anotherSymbolizer]);
features.push(featureWithSymbolizers, anotherFeatureWithSymbolizers);
var groups = layer.groupFeaturesBySymbolizerLiteral(features);
var groups = layer.groupFeaturesBySymbolizerLiteral(features, 1);
expect(groups).to.have.length(3);
expect(groups[2][0].length).to.be(2);
expect(groups[2][1].width).to.be(3);

View File

@@ -33,22 +33,121 @@ describe('ol.style.Rule', function() {
it('returns true for a rule without filter', function() {
rule = new ol.style.Rule({});
expect(rule.applies(feature)).to.be(true);
expect(rule.applies(feature, 1)).to.be(true);
});
it('returns false when the rule does not apply', function() {
it('returns false when the filter evaluates to false', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(false)
});
expect(rule.applies(feature)).to.be(false);
expect(rule.applies(feature, 1)).to.be(false);
});
it('returns true when the rule applies', function() {
it('returns true when the filter evaluates to true', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(true)
});
expect(rule.applies(feature)).to.be(true);
expect(rule.applies(feature, 1)).to.be(true);
});
it('returns false when the resolution is less than min', function() {
rule = new ol.style.Rule({
minResolution: 10
});
expect(rule.applies(feature, 9)).to.be(false);
});
it('returns true when the resolution is greater than min', function() {
rule = new ol.style.Rule({
minResolution: 10
});
expect(rule.applies(feature, 11)).to.be(true);
});
it('returns true when the resolution is equal to min', function() {
rule = new ol.style.Rule({
minResolution: 10
});
expect(rule.applies(feature, 10)).to.be(true);
});
it('returns false if filter evaluates to false (with min res)', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(false),
minResolution: 10
});
expect(rule.applies(feature, 11)).to.be(false);
});
it('returns true if filter evaluates to true (with min res)', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(true),
minResolution: 10
});
expect(rule.applies(feature, 11)).to.be(true);
});
it('returns false when the resolution is greater than max', function() {
rule = new ol.style.Rule({
maxResolution: 100
});
expect(rule.applies(feature, 101)).to.be(false);
});
it('returns true when the resolution is less than max', function() {
rule = new ol.style.Rule({
maxResolution: 100
});
expect(rule.applies(feature, 99)).to.be(true);
});
it('returns false when the resolution is equal to max', function() {
rule = new ol.style.Rule({
maxResolution: 100
});
expect(rule.applies(feature, 100)).to.be(false);
});
it('returns false if filter evaluates to false (with max res)', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(false),
maxResolution: 100
});
expect(rule.applies(feature, 99)).to.be(false);
});
it('returns true if filter evaluates to true (with max res)', function() {
rule = new ol.style.Rule({
filter: new ol.expr.Literal(true),
maxResolution: 100
});
expect(rule.applies(feature, 99)).to.be(true);
});
it('returns true if resolution is between min and max', function() {
rule = new ol.style.Rule({
minResolution: 10,
maxResolution: 100
});
expect(rule.applies(feature, 55)).to.be(true);
});
it('returns false if resolution is greater than min and max', function() {
rule = new ol.style.Rule({
minResolution: 10,
maxResolution: 100
});
expect(rule.applies(feature, 1000)).to.be(false);
});
it('returns false if resolution is less than min and max', function() {
rule = new ol.style.Rule({
minResolution: 10,
maxResolution: 100
});
expect(rule.applies(feature, 5)).to.be(false);
});
});
});

View File

@@ -57,12 +57,12 @@ describe('ol.style.Style', function() {
});
feature.set('foo', 'bar');
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
expect(literals[0].fillColor).to.be('#BADA55');
feature.set('foo', 'baz');
expect(style.createLiterals(feature)).to.have.length(0);
expect(style.createLiterals(feature, 1)).to.have.length(0);
});
it('uses the "else" symbolizers when no rules are provided', function() {
@@ -78,7 +78,7 @@ describe('ol.style.Style', function() {
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
});
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
expect(literals[0].color).to.be('#ff0000');
});
@@ -107,7 +107,7 @@ describe('ol.style.Style', function() {
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
});
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
expect(literals[0].color).to.be('#00ff00');
@@ -115,7 +115,7 @@ describe('ol.style.Style', function() {
name: 'match',
geometry: new ol.geom.LineString([[1, 2], [3, 4]])
});
literals = style.createLiterals(feature);
literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
expect(literals[0].color).to.be('#ff00ff');
});
@@ -133,7 +133,7 @@ describe('ol.style.Style', function() {
it('returns an empty array for features without geometry', function() {
var feature = new ol.Feature();
expect(style.createLiterals(feature))
expect(style.createLiterals(feature, 1))
.to.have.length(0);
});
@@ -141,7 +141,7 @@ describe('ol.style.Style', function() {
var feature = new ol.Feature();
feature.setGeometry(new ol.geom.Point([0, 0]));
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
var literal = literals[0];
@@ -158,7 +158,7 @@ describe('ol.style.Style', function() {
var feature = new ol.Feature();
feature.setGeometry(new ol.geom.LineString([[0, 0], [1, 1]]));
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
var literal = literals[0];
@@ -172,7 +172,7 @@ describe('ol.style.Style', function() {
var feature = new ol.Feature();
feature.setGeometry(new ol.geom.Polygon([[[0, 0], [1, 1], [0, 0]]]));
var literals = style.createLiterals(feature);
var literals = style.createLiterals(feature, 1);
expect(literals).to.have.length(1);
var literal = literals[0];