Add ol.geom2.LineStringCollection#getIndices

This commit is contained in:
Tom Payne
2013-05-31 12:58:02 +02:00
parent db2f805ed9
commit 3225a07f6f
2 changed files with 51 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
goog.provide('ol.geom2.LineString');
goog.provide('ol.geom2.LineStringCollection');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.geom2');
@@ -134,6 +135,29 @@ ol.geom2.LineStringCollection.prototype.getExtent = function() {
};
/**
* @return {Array} Indices.
*/
ol.geom2.LineStringCollection.prototype.getIndices = function() {
// FIXME cache and track dirty / track output length
// FIXME return UInt16Array?
var dim = this.dim;
var offsets = goog.array.map(goog.object.getKeys(this.ranges), Number);
goog.array.sort(offsets);
var n = offsets.length;
var indices = [];
var i, j, range, stop;
for (i = 0; i < n; ++i) {
range = this.ranges[offsets[i]];
stop = range[1] / dim - 1;
for (j = range[0] / dim; j < stop; ++j) {
indices.push(j, j + 1);
}
}
return indices;
};
/**
* @param {number} offset Offset.
*/