Give precedence to feature style

This commit is contained in:
Antoine Abt
2014-07-10 12:11:02 +02:00
parent 0b9936107d
commit 60f1874766
14 changed files with 172 additions and 176 deletions
+46
View File
@@ -1,5 +1,7 @@
goog.provide('ol.style.Style');
goog.require('goog.asserts');
goog.require('goog.functions');
goog.require('ol.style.Fill');
goog.require('ol.style.Image');
@@ -93,3 +95,47 @@ ol.style.Style.prototype.getText = function() {
ol.style.Style.prototype.getZIndex = function() {
return this.zIndex_;
};
/**
* A function that takes an {@link ol.Feature} and a `{number}` representing
* the view's resolution. The function should return an array of
* {@link ol.style.Style}. This way e.g. a vector layer can be styled.
*
* @typedef {function(ol.Feature, number): Array.<ol.style.Style>}
* @api
*/
ol.style.StyleFunction;
/**
* Convert the provided object into a style function. Functions passed through
* unchanged. Arrays of ol.style.Style or single style objects wrapped in a
* new style function.
* @param {ol.style.StyleFunction|Array.<ol.style.Style>|ol.style.Style} obj
* A style function, a single style, or an array of styles.
* @return {ol.style.StyleFunction} A style function.
*/
ol.style.createStyleFunction = function(obj) {
/**
* @type {ol.style.StyleFunction}
*/
var styleFunction;
if (goog.isFunction(obj)) {
styleFunction = /** @type {ol.style.StyleFunction} */ (obj);
} else {
/**
* @type {Array.<ol.style.Style>}
*/
var styles;
if (goog.isArray(obj)) {
styles = obj;
} else {
goog.asserts.assertInstanceof(obj, ol.style.Style);
styles = [obj];
}
styleFunction = goog.functions.constant(styles);
}
return styleFunction;
};