Merge pull request #2726 from elemoine/feature-setstyle

Make ol.Feature#setStyle accept null
This commit is contained in:
Éric Lemoine
2014-09-17 19:56:28 +02:00
2 changed files with 21 additions and 8 deletions

View File

@@ -174,9 +174,10 @@ ol.Feature.prototype.getGeometryName = function() {
/**
* @return {ol.style.Style|Array.<ol.style.Style>|
* 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.style.Style>|
* 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>|
* ol.style.Style} obj A feature style function, a single style, or an array
* of styles.
* @param {ol.feature.FeatureStyleFunction|!Array.<ol.style.Style>|
* !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) {

View File

@@ -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() {