Merge pull request #1257 from bartvde/getattr

feature.getAttributes() should ignore geometry (r=@tschaub)
This commit is contained in:
Bart van den Eijnden
2013-11-19 10:31:55 -08:00
4 changed files with 29 additions and 11 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(),
includeGeometry = !opt_nonGeometry,
len = keys.length,
attributes = {},
i, key;
i, value, key;
for (i = 0; i < len; ++ i) {
key = keys[i];
attributes[key] = this.get(key);
value = this.get(key);
if (includeGeometry || !(value instanceof ol.geom.Geometry)) {
attributes[key] = value;
}
}
return attributes;
};

View File

@@ -351,11 +351,7 @@ ol.parser.GeoJSON.prototype.encodeFeatureCollection_ = function(collection) {
*/
ol.parser.GeoJSON.prototype.encodeFeature_ = function(feature) {
var geometry = feature.getGeometry(),
attributes = feature.getAttributes();
var properties = goog.object.filter(attributes,
function(element, index, array) {
return !(element instanceof ol.geom.Geometry);
});
properties = feature.getAttributes(true);
return /** @type {GeoJSONFeature} */({
type: 'Feature',
properties: properties,

View File

@@ -422,11 +422,10 @@ ol.parser.ogc.GML = function(opt_options) {
this.writeNode('_geometry', feature.getGeometry(), this.featureNS,
node);
}
var attributes = feature.getAttributes();
var attributes = feature.getAttributes(true);
for (var name in attributes) {
var value = attributes[name];
if (goog.isDefAndNotNull(value) && !(value instanceof
ol.geom.Geometry)) {
if (goog.isDefAndNotNull(value)) {
this.writeNode('_attribute', {name: name, value: value},
this.featureNS, node);
}