Add styleFunction property to ol.Feature

This commit is contained in:
Tom Payne
2013-12-12 10:59:14 +01:00
parent ece21e18fe
commit a7d6730259

View File

@@ -5,16 +5,24 @@ goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Object');
goog.require('ol.geom.Geometry');
goog.require('ol.style.Style');
/**
* @enum {string}
*/
ol.FeatureProperty = {
GEOMETRY: 'geometry'
GEOMETRY: 'geometry',
STYLE_FUNCTION: 'styleFunction'
};
/**
* @typedef {function(this: ol.Feature, number): Array.<ol.style.Style>}
*/
ol.FeatureStyleFunction;
/**
* @constructor
@@ -47,6 +55,9 @@ ol.Feature = function(opt_geometryOrValues) {
goog.events.listen(
this, ol.Object.getChangeEventType(ol.FeatureProperty.GEOMETRY),
this.handleGeometryChanged_, false, this);
goog.events.listen(
this, ol.Object.getChangeEventType(ol.FeatureProperty.STYLE_FUNCTION),
this.handleStyleFunctionChange_, false, this);
if (goog.isDefAndNotNull(opt_geometryOrValues)) {
if (opt_geometryOrValues instanceof ol.geom.Geometry) {
@@ -102,6 +113,19 @@ ol.Feature.prototype.getRevision = function() {
};
/**
* @return {ol.FeatureStyleFunction|undefined} Style function.
*/
ol.Feature.prototype.getStyleFunction = function() {
return /** @type {ol.FeatureStyleFunction|undefined} */ (
this.get(ol.FeatureProperty.STYLE_FUNCTION));
};
goog.exportProperty(
ol.Feature.prototype,
'getStyleFunction',
ol.Feature.prototype.getStyleFunction);
/**
* @private
*/
@@ -127,6 +151,14 @@ ol.Feature.prototype.handleGeometryChanged_ = function() {
};
/**
* @private
*/
ol.Feature.prototype.handleStyleFunctionChange_ = function() {
this.dispatchChangeEvent();
};
/**
* @param {ol.geom.Geometry|undefined} geometry Geometry.
*/
@@ -139,6 +171,18 @@ goog.exportProperty(
ol.Feature.prototype.setGeometry);
/**
* @param {ol.FeatureStyleFunction|undefined} styleFunction Style function.
*/
ol.Feature.prototype.setStyleFunction = function(styleFunction) {
this.set(ol.FeatureProperty.STYLE_FUNCTION, styleFunction);
};
goog.exportProperty(
ol.Feature.prototype,
'setStyleFunction',
ol.Feature.prototype.setStyleFunction);
/**
* @param {number|string|undefined} id Id.
*/