Accept ol.StyleFunction in ol.Feature#setStyle()
This commit is contained in:
@@ -172,7 +172,7 @@ ol.Feature.prototype.getGeometryName = function() {
|
|||||||
* Get the feature's style. Will return what was provided to the
|
* Get the feature's style. Will return what was provided to the
|
||||||
* {@link ol.Feature#setStyle} method.
|
* {@link ol.Feature#setStyle} method.
|
||||||
* @return {ol.style.Style|Array.<ol.style.Style>|
|
* @return {ol.style.Style|Array.<ol.style.Style>|
|
||||||
* ol.FeatureStyleFunction} The feature style.
|
* ol.FeatureStyleFunction|ol.StyleFunction} The feature style.
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.Feature.prototype.getStyle = function() {
|
ol.Feature.prototype.getStyle = function() {
|
||||||
@@ -233,7 +233,7 @@ ol.Feature.prototype.setGeometry = function(geometry) {
|
|||||||
* of styles, or a function that takes a resolution and returns an array of
|
* 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).
|
* styles. If it is `null` the feature has no style (a `null` style).
|
||||||
* @param {ol.style.Style|Array.<ol.style.Style>|
|
* @param {ol.style.Style|Array.<ol.style.Style>|
|
||||||
* ol.FeatureStyleFunction} style Style for this feature.
|
* ol.FeatureStyleFunction|ol.StyleFunction} style Style for this feature.
|
||||||
* @api stable
|
* @api stable
|
||||||
* @fires ol.events.Event#event:change
|
* @fires ol.events.Event#event:change
|
||||||
*/
|
*/
|
||||||
@@ -291,7 +291,13 @@ ol.Feature.createStyleFunction = function(obj) {
|
|||||||
var styleFunction;
|
var styleFunction;
|
||||||
|
|
||||||
if (typeof obj === 'function') {
|
if (typeof obj === 'function') {
|
||||||
styleFunction = obj;
|
if (obj.length == 2) {
|
||||||
|
styleFunction = function(resolution) {
|
||||||
|
return /** @type {ol.StyleFunction} */ (obj)(this, resolution);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
styleFunction = obj;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* @type {Array.<ol.style.Style>}
|
* @type {Array.<ol.style.Style>}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ describe('ol.Feature', function() {
|
|||||||
var style = new ol.style.Style();
|
var style = new ol.style.Style();
|
||||||
|
|
||||||
var styleFunction = function(feature, resolution) {
|
var styleFunction = function(feature, resolution) {
|
||||||
return null;
|
return resolution;
|
||||||
};
|
};
|
||||||
|
|
||||||
it('accepts a single style', function() {
|
it('accepts a single style', function() {
|
||||||
@@ -321,9 +321,20 @@ describe('ol.Feature', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('accepts a style function', function() {
|
it('accepts a style function', function() {
|
||||||
|
var feature = new ol.Feature();
|
||||||
|
function featureStyleFunction(resolution) {
|
||||||
|
return styleFunction(this, resolution);
|
||||||
|
}
|
||||||
|
feature.setStyle(featureStyleFunction);
|
||||||
|
expect(feature.getStyleFunction()).to.be(featureStyleFunction);
|
||||||
|
expect(feature.getStyleFunction()(42)).to.be(42);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts a layer style function', function() {
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
feature.setStyle(styleFunction);
|
feature.setStyle(styleFunction);
|
||||||
expect(feature.getStyleFunction()).to.be(styleFunction);
|
expect(feature.getStyleFunction()).to.not.be(styleFunction);
|
||||||
|
expect(feature.getStyleFunction()(42)).to.be(42);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts null', function() {
|
it('accepts null', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user