Permalink
Browse files

Proper getAttributes method

With a59aa9b we can now provide an object with user set attributes.
  • Loading branch information...
1 parent 0f2f269 commit 7ce89f1fbe692bc794c6a420e8812e49abb9895f @tschaub tschaub committed Feb 20, 2013
Showing with 33 additions and 11 deletions.
  1. +9 −11 src/ol/feature.js
  2. +24 −0 test/spec/ol/feature.test.js
View
@@ -28,17 +28,15 @@ goog.inherits(ol.Feature, ol.Object);
* @return {Object} Attributes object.
*/
ol.Feature.prototype.getAttributes = function() {
- // TODO: see https://github.com/openlayers/ol3/pull/217
- // var keys = this.getKeys(),
- // len = keys.length,
- // attributes = {},
- // i, key
- // for (var i = 0; i < len; ++ i) {
- // key = keys[i];
- // attributes[key] = this.get(key);
- // }
- // return attributes;
- return this;
+ var keys = this.getKeys(),
+ len = keys.length,
+ attributes = {},
+ i, key;
+ for (i = 0; i < len; ++ i) {
+ key = keys[i];
+ attributes[key] = this.get(key);
+ }
+ return attributes;
};
@@ -52,6 +52,29 @@ describe('ol.Feature', function() {
});
+ describe('#getAttributes()', function() {
+
+ it('returns an object with all attributes', function() {
+ var point = new ol.geom.Point([15, 30]);
+ var feature = new ol.Feature({
+ foo: 'bar',
+ ten: 10,
+ loc: point
+ });
+
+ var attributes = feature.getAttributes();
+
+ var keys = goog.object.getKeys(attributes);
+ expect(keys.sort()).toEqual(['foo', 'loc', 'ten']);
+
+ expect(attributes.foo).toBe('bar');
+ expect(attributes.loc).toBe(point);
+ expect(attributes.ten).toBe(10);
+ });
+
+ });
+
+
describe('#getGeometry()', function() {
var point = new ol.geom.Point([15, 30]);
@@ -157,5 +180,6 @@ describe('ol.Feature', function() {
});
+goog.require('goog.object');
goog.require('ol.Feature');
goog.require('ol.geom.Point');

0 comments on commit 7ce89f1

Please sign in to comment.