Construct individual points directly from flat coordinates
This commit is contained in:
@@ -90,12 +90,16 @@ ol.geom.MultiPoint.prototype.getCoordinates = function() {
|
|||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.geom.MultiPoint.prototype.getPoints = function() {
|
ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||||
// FIXME we should construct the points from the flat coordinates
|
var flatCoordinates = this.flatCoordinates;
|
||||||
var coordinates = this.getCoordinates();
|
var layout = this.layout;
|
||||||
|
var stride = this.stride;
|
||||||
|
/** @type {Array.<ol.geom.Point>} */
|
||||||
var points = [];
|
var points = [];
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||||
points.push(new ol.geom.Point(coordinates[i]));
|
var point = new ol.geom.Point(null);
|
||||||
|
point.setFlatCoordinates(layout, flatCoordinates.slice(i, i + stride));
|
||||||
|
points.push(point);
|
||||||
}
|
}
|
||||||
return points;
|
return points;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -132,6 +132,17 @@ describe('ol.geom.MultiPoint', function() {
|
|||||||
expect(multiPoint.getStride()).to.be(3);
|
expect(multiPoint.getStride()).to.be(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can return all points', function() {
|
||||||
|
var points = multiPoint.getPoints();
|
||||||
|
expect(points).to.have.length(2);
|
||||||
|
expect(points[0]).to.be.an(ol.geom.Point);
|
||||||
|
expect(points[0].getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||||
|
expect(points[0].getCoordinates()).to.eql([1, 2, 3]);
|
||||||
|
expect(points[1]).to.be.an(ol.geom.Point);
|
||||||
|
expect(points[1].getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||||
|
expect(points[1].getCoordinates()).to.eql([4, 5, 6]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('construct with 4D coordinates', function() {
|
describe('construct with 4D coordinates', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user