diff --git a/src/ol/feature.js b/src/ol/feature.js index 5d392bbe84..5ec930866a 100644 --- a/src/ol/feature.js +++ b/src/ol/feature.js @@ -174,9 +174,10 @@ ol.Feature.prototype.getGeometryName = function() { /** * @return {ol.style.Style|Array.| - * ol.feature.FeatureStyleFunction} Return the style as set by setStyle in - * the same format that it was provided in. If setStyle has not been run, - * return `undefined`. + * ol.feature.FeatureStyleFunction} Return the style as set by `setStyle` + * in the same format that it was provided in. If `setStyle` has not been + * called, or if it was called with `null`, then `getStyle()` will return + * `null`. * @api stable */ ol.Feature.prototype.getStyle = function() { @@ -237,13 +238,17 @@ goog.exportProperty( /** + * Set the style for the feature. This can be a single style object, an array + * of styles, or a function that takes a resolution and returns an array of + * styles. If it is `null` the feature has no style (a `null` style). * @param {ol.style.Style|Array.| - * ol.feature.FeatureStyleFunction} style Set the style for this feature. + * ol.feature.FeatureStyleFunction} style Style for this feature. * @api stable */ ol.Feature.prototype.setStyle = function(style) { this.style_ = style; - this.styleFunction_ = ol.feature.createFeatureStyleFunction(style); + this.styleFunction_ = goog.isNull(style) ? + undefined : ol.feature.createFeatureStyleFunction(style); this.changed(); }; @@ -293,9 +298,9 @@ ol.feature.FeatureStyleFunction; * Convert the provided object into a feature style function. Functions passed * through unchanged. Arrays of ol.style.Style or single style objects wrapped * in a new feature style function. - * @param {ol.feature.FeatureStyleFunction|Array.| - * ol.style.Style} obj A feature style function, a single style, or an array - * of styles. + * @param {ol.feature.FeatureStyleFunction|!Array.| + * !ol.style.Style} obj A feature style function, a single style, or an + * array of styles. * @return {ol.feature.FeatureStyleFunction} A style function. */ ol.feature.createFeatureStyleFunction = function(obj) { diff --git a/test/spec/ol/feature.test.js b/test/spec/ol/feature.test.js index fefcec6c08..ef61378656 100644 --- a/test/spec/ol/feature.test.js +++ b/test/spec/ol/feature.test.js @@ -320,6 +320,14 @@ describe('ol.Feature', function() { expect(feature.getStyleFunction()).to.be(styleFunction); }); + it('accepts null', function() { + var feature = new ol.Feature(); + feature.setStyle(style); + feature.setStyle(null); + expect(feature.getStyle()).to.be(null); + expect(feature.getStyleFunction()).to.be(undefined); + }); + it('dispatches a change event', function(done) { var feature = new ol.Feature(); feature.on('change', function() {