Merge pull request #2394 from tonio/style_order

Give precedence to feature styles
This commit is contained in:
Bart van den Eijnden
2014-07-25 11:34:24 +02:00
14 changed files with 248 additions and 182 deletions

View File

@@ -411,35 +411,6 @@ describe('ol.Feature', function() {
});
describe('ol.feature.createStyleFunction()', function() {
var style = new ol.style.Style();
it('creates a style function from a single style', function() {
var styleFunction = ol.feature.createStyleFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
var styleFunction = ol.feature.createStyleFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
var original = function() {
return [style];
};
var styleFunction = ol.feature.createStyleFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
ol.feature.createStyleFunction({bogus: 'input'});
}).to.throwException();
});
});
describe('ol.feature.createFeatureStyleFunction()', function() {
var style = new ol.style.Style();

View File

@@ -1,5 +1,7 @@
goog.provide('ol.test.layer.Vector');
goog.require('ol.feature');
describe('ol.layer.Vector', function() {
describe('constructor', function() {
@@ -74,9 +76,10 @@ describe('ol.layer.Vector', function() {
var layer = new ol.layer.Vector({
source: source
});
expect(layer.getStyleFunction()).to.be(undefined);
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
layer.setStyle(style);
expect(layer.getStyleFunction()).to.be.a('function');
expect(layer.getStyleFunction()).not.to.be(
ol.style.defaultStyleFunction);
});
});
@@ -91,7 +94,7 @@ describe('ol.layer.Vector', function() {
source: source
});
expect(layer.getStyle()).to.be(null);
expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction);
layer.setStyle(style);
expect(layer.getStyle()).to.be(style);

View File

@@ -0,0 +1,72 @@
goog.provide('ol.test.renderer.canvas.VectorLayer');
describe('ol.renderer.canvas.VectorLayer', function() {
describe('constructor', function() {
it('creates a new instance', function() {
var map = new ol.Map({
target: document.createElement('div')
});
var layer = new ol.layer.Vector({
source: new ol.source.Vector()
});
var renderer = new ol.renderer.canvas.VectorLayer(map.getRenderer(),
layer);
expect(renderer).to.be.a(ol.renderer.canvas.VectorLayer);
});
it('gives precedence to feature styles over layer styles', function() {
var target = document.createElement('div');
target.style.width = '256px';
target.style.height = '256px';
document.body.appendChild(target);
var map = new ol.Map({
view: new ol.View({
center: [0, 0],
zoom: 0
}),
target: target
});
var layerStyle = [new ol.style.Style({
text: new ol.style.Text({
text: 'layer'
})
})];
var featureStyle = [new ol.style.Style({
text: new ol.style.Text({
text: 'feature'
})
})];
var feature1 = new ol.Feature(new ol.geom.Point([0, 0]));
var feature2 = new ol.Feature(new ol.geom.Point([0, 0]));
feature2.setStyle(featureStyle);
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature1, feature2]
}),
style: layerStyle
});
map.addLayer(layer);
var spy = sinon.spy(map.getRenderer().getLayerRenderer(layer),
'renderFeature');
map.renderSync();
expect(spy.getCall(0).args[3]).to.be(layerStyle);
expect(spy.getCall(1).args[3]).to.be(featureStyle);
document.body.removeChild(target);
});
});
});
goog.require('ol.Feature');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.geom.Point');
goog.require('ol.layer.Vector');
goog.require('ol.renderer.canvas.VectorLayer');
goog.require('ol.source.Vector');
goog.require('ol.style.Style');
goog.require('ol.style.Text');

View File

@@ -0,0 +1,32 @@
goog.provide('ol.test.style.Style');
describe('ol.style.createStyleFunction()', function() {
var style = new ol.style.Style();
it('creates a style function from a single style', function() {
var styleFunction = ol.style.createStyleFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
var styleFunction = ol.style.createStyleFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
var original = function() {
return [style];
};
var styleFunction = ol.style.createStyleFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
ol.style.createStyleFunction({bogus: 'input'});
}).to.throwException();
});
});
goog.require('ol.style.Style');