goog.provide('ol.style.Style'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.GeometryType'); goog.require('ol.style.Circle'); goog.require('ol.style.Fill'); goog.require('ol.style.Image'); goog.require('ol.style.Stroke'); /** * @classdesc * Container for vector feature rendering styles. Any changes made to the style * or its children through `set*()` methods will not take effect until the * feature or layer that uses the style is re-rendered. * * @constructor * @struct * @param {olx.style.StyleOptions=} opt_options Style options. * @api */ ol.style.Style = function(opt_options) { var options = opt_options || {}; /** * @private * @type {string|ol.geom.Geometry|ol.StyleGeometryFunction} */ this.geometry_ = null; /** * @private * @type {!ol.StyleGeometryFunction} */ this.geometryFunction_ = ol.style.defaultGeometryFunction; if (options.geometry !== undefined) { this.setGeometry(options.geometry); } /** * @private * @type {ol.style.Fill} */ this.fill_ = options.fill !== undefined ? options.fill : null; /** * @private * @type {ol.style.Image} */ this.image_ = options.image !== undefined ? options.image : null; /** * @private * @type {ol.style.Stroke} */ this.stroke_ = options.stroke !== undefined ? options.stroke : null; /** * @private * @type {ol.style.Text} */ this.text_ = options.text !== undefined ? options.text : null; /** * @private * @type {number|undefined} */ this.zIndex_ = options.zIndex; }; /** * Get the geometry to be rendered. * @return {string|ol.geom.Geometry|ol.StyleGeometryFunction} * Feature property or geometry or function that returns the geometry that will * be rendered with this style. * @api */ ol.style.Style.prototype.getGeometry = function() { return this.geometry_; }; /** * Get the function used to generate a geometry for rendering. * @return {!ol.StyleGeometryFunction} Function that is called with a feature * and returns the geometry to render instead of the feature's geometry. * @api */ ol.style.Style.prototype.getGeometryFunction = function() { return this.geometryFunction_; }; /** * Get the fill style. * @return {ol.style.Fill} Fill style. * @api */ ol.style.Style.prototype.getFill = function() { return this.fill_; }; /** * Get the image style. * @return {ol.style.Image} Image style. * @api */ ol.style.Style.prototype.getImage = function() { return this.image_; }; /** * Get the stroke style. * @return {ol.style.Stroke} Stroke style. * @api */ ol.style.Style.prototype.getStroke = function() { return this.stroke_; }; /** * Get the text style. * @return {ol.style.Text} Text style. * @api */ ol.style.Style.prototype.getText = function() { return this.text_; }; /** * Get the z-index for the style. * @return {number|undefined} ZIndex. * @api */ ol.style.Style.prototype.getZIndex = function() { return this.zIndex_; }; /** * Set a geometry that is rendered instead of the feature's geometry. * * @param {string|ol.geom.Geometry|ol.StyleGeometryFunction} geometry * Feature property or geometry or function returning a geometry to render * for this style. * @api */ ol.style.Style.prototype.setGeometry = function(geometry) { if (typeof geometry === 'function') { this.geometryFunction_ = geometry; } else if (typeof geometry === 'string') { this.geometryFunction_ = function(feature) { return /** @type {ol.geom.Geometry} */ (feature.get(geometry)); }; } else if (!geometry) { this.geometryFunction_ = ol.style.defaultGeometryFunction; } else if (geometry !== undefined) { this.geometryFunction_ = function() { return /** @type {ol.geom.Geometry} */ (geometry); }; } this.geometry_ = geometry; }; /** * Set the z-index. * * @param {number|undefined} zIndex ZIndex. * @api */ ol.style.Style.prototype.setZIndex = function(zIndex) { this.zIndex_ = zIndex; }; /** * 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.StyleFunction|Array.