Allow passing undefined to ol.layer.Vector#setStyle
This commit is contained in:
@@ -51,8 +51,7 @@ ol.layer.Vector = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.styleFunction_ = undefined;
|
this.styleFunction_ = undefined;
|
||||||
|
|
||||||
this.setStyle(goog.isDefAndNotNull(options.style) ?
|
this.setStyle(options.style);
|
||||||
options.style : ol.style.defaultStyleFunction);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.Vector, ol.layer.Layer);
|
goog.inherits(ol.layer.Vector, ol.layer.Layer);
|
||||||
@@ -102,13 +101,14 @@ ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) {
|
|||||||
/**
|
/**
|
||||||
* Set the style for features. This can be a single style object, an array
|
* Set the style for features. This can be a single style object, an array
|
||||||
* of styles, or a function that takes a feature and resolution and returns
|
* of styles, or a function that takes a feature and resolution and returns
|
||||||
* an array of styles.
|
* an array of styles. If `undefined` default styles are used.
|
||||||
* @param {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction} style
|
* @param {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
|
||||||
* Layer style.
|
* style Layer style.
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.layer.Vector.prototype.setStyle = function(style) {
|
ol.layer.Vector.prototype.setStyle = function(style) {
|
||||||
this.style_ = style;
|
this.style_ = goog.isDef(style) ? style : ol.style.defaultStyleFunction;
|
||||||
this.styleFunction_ = ol.style.createStyleFunction(style);
|
this.styleFunction_ = goog.isNull(style) ?
|
||||||
|
undefined : ol.style.createStyleFunction(this.style_);
|
||||||
this.dispatchChangeEvent();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,22 +50,21 @@ describe('ol.layer.Vector', function() {
|
|||||||
|
|
||||||
describe('#setStyle()', function() {
|
describe('#setStyle()', function() {
|
||||||
|
|
||||||
var source = new ol.source.Vector();
|
var layer, style;
|
||||||
var style = new ol.style.Style();
|
|
||||||
|
beforeEach(function() {
|
||||||
|
layer = new ol.layer.Vector({
|
||||||
|
source: new ol.source.Vector()
|
||||||
|
});
|
||||||
|
style = new ol.style.Style();
|
||||||
|
});
|
||||||
|
|
||||||
it('allows the style to be set after construction', function() {
|
it('allows the style to be set after construction', function() {
|
||||||
var layer = new ol.layer.Vector({
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
|
|
||||||
layer.setStyle(style);
|
layer.setStyle(style);
|
||||||
expect(layer.getStyle()).to.be(style);
|
expect(layer.getStyle()).to.be(style);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dispatches the change event', function(done) {
|
it('dispatches the change event', function(done) {
|
||||||
var layer = new ol.layer.Vector({
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
layer.on('change', function() {
|
layer.on('change', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -73,15 +72,25 @@ describe('ol.layer.Vector', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates the internal style function', function() {
|
it('updates the internal style function', function() {
|
||||||
var layer = new ol.layer.Vector({
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
|
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
|
||||||
layer.setStyle(style);
|
layer.setStyle(style);
|
||||||
expect(layer.getStyleFunction()).not.to.be(
|
expect(layer.getStyleFunction()).not.to.be(
|
||||||
ol.style.defaultStyleFunction);
|
ol.style.defaultStyleFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows setting an null style', function() {
|
||||||
|
layer.setStyle(null);
|
||||||
|
expect(layer.getStyle()).to.be(null);
|
||||||
|
expect(layer.getStyleFunction()).to.be(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets the default style when passing undefined', function() {
|
||||||
|
layer.setStyle(style);
|
||||||
|
layer.setStyle(undefined);
|
||||||
|
expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction);
|
||||||
|
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getStyle()', function() {
|
describe('#getStyle()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user