add an optional argument to getAttributes so we can get a feature's attributes except for the geometry ones

This commit is contained in:
Bart van den Eijnden
2013-11-19 15:39:22 +01:00
parent 936f86568e
commit 8d03fa1197
4 changed files with 28 additions and 10 deletions

View File

@@ -68,17 +68,23 @@ goog.inherits(ol.Feature, ol.Object);
/**
* Gets a copy of the attributes of this feature.
* @param {boolean=} opt_nonGeometry Don't include any geometry attributes
* (by default geometry attributes are returned).
* @return {Object.<string, *>} Attributes object.
* @todo stability experimental
*/
ol.Feature.prototype.getAttributes = function() {
ol.Feature.prototype.getAttributes = function(opt_nonGeometry) {
var keys = this.getKeys(),
len = keys.length,
attributes = {},
i, key;
for (i = 0; i < len; ++ i) {
key = keys[i];
attributes[key] = this.get(key);
var value = this.get(key);
if (!goog.isDef(opt_nonGeometry) || opt_nonGeometry == false ||
(opt_nonGeometry === true && !(value instanceof ol.geom.Geometry))) {
attributes[key] = value;
}
}
return attributes;
};