From 499ba4ac8f23e49b00596c02b4fd813872f2400f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 7 Feb 2014 09:17:21 -0700 Subject: [PATCH] Add a style option for vector layers This can be a single ol.style.Style, and array of styles, or a style function. --- src/objectliterals.jsdoc | 2 +- src/ol/layer/vectorlayer.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index e26100a3b2..27d384f189 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -532,7 +532,7 @@ * @property {number|undefined} opacity Opacity. 0-1. Default is `1`. * @property {number|undefined} saturation Saturation. * @property {ol.source.Vector} source Source. - * @property {ol.feature.StyleFunction|undefined} styleFunction Style function. + * @property {ol.style.Style|Array.|ol.feature.StyleFunction|undefined} style Layer style. * @property {boolean|undefined} visible Visibility. Default is `true` (visible). * @todo stability experimental */ diff --git a/src/ol/layer/vectorlayer.js b/src/ol/layer/vectorlayer.js index e9bd4110d3..39f5b0eb1e 100644 --- a/src/ol/layer/vectorlayer.js +++ b/src/ol/layer/vectorlayer.js @@ -1,7 +1,9 @@ goog.provide('ol.layer.Vector'); +goog.require('goog.asserts'); goog.require('ol.feature'); goog.require('ol.layer.Layer'); +goog.require('ol.style.Style'); /** @@ -27,9 +29,32 @@ ol.layer.Vector = function(opt_options) { goog.base(this, /** @type {olx.layer.LayerOptions} */ (options)); - // FIXME veryify this - if (goog.isDef(options.styleFunction)) { - this.setStyleFunction(options.styleFunction); + if (goog.isDef(options.style)) { + + /** + * @type {ol.feature.StyleFunction} + */ + var styleFunction; + + if (goog.isFunction(options.style)) { + styleFunction = /** @type {ol.feature.StyleFunction} */ (options.style); + } else { + /** + * @type {Array.} + */ + var styles; + if (goog.isArray(options.style)) { + styles = options.style; + } else { + goog.asserts.assertInstanceof(options.style, ol.style.Style); + styles = [options.style]; + } + styleFunction = function(feature, resolution) { + return styles; + }; + } + + this.setStyleFunction(styleFunction); } };