Skip to content

Commit

Permalink
restoring order, if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hirsch committed Oct 26, 2013
1 parent 9ba379f commit fd014c7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/feature.js
Expand Up @@ -113,13 +113,15 @@ var SOSI = window.SOSI || {};

initialize: function (elements, head) {
this.head = head;
this.index = [];
this.features = _.object(_.map(elements, function (value, key) {
key = key.replace(":", "").split(/\s+/);
var data = {
id: parseInt(key[1], 10),
geometryType: key[0],
lines: _.rest(value)
};
this.index.push(data.id);
return [data.id, new ns.Feature(data, head.origo, head.enhet)];
}, this));
},
Expand All @@ -135,12 +137,20 @@ var SOSI = window.SOSI || {};
return _.size(this.features);
},

at: function(i) {
return this.ensureGeom(this.features[this.index[i]]);
},

getById: function (id) {
return this.ensureGeom(this.features[id]);
},

all: function () {
return _.map(this.features, this.ensureGeom, this);
all: function (ordered) {
if (ordered) {
return _.map(this.index, this.getById, this); /* order comes at a 25% performance loss */
} else {
return _.map(this.features, this.ensureGeom, this);
}
}
});

Expand Down

0 comments on commit fd014c7

Please sign in to comment.