Add ol.geom.MultiPoint#getPoint
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
@exportProperty ol.geom.MultiPoint.prototype.appendPoint
|
||||
@exportProperty ol.geom.MultiPoint.prototype.clone
|
||||
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
|
||||
@exportProperty ol.geom.MultiPoint.prototype.getPoint
|
||||
@exportProperty ol.geom.MultiPoint.prototype.getPoints
|
||||
@exportProperty ol.geom.MultiPoint.prototype.getType
|
||||
@exportProperty ol.geom.MultiPoint.prototype.setCoordinates
|
||||
|
||||
@@ -85,6 +85,24 @@ ol.geom.MultiPoint.prototype.getCoordinates = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} index Index.
|
||||
* @return {ol.geom.Point} Point.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getPoint = function(index) {
|
||||
var n = goog.isNull(this.flatCoordinates) ?
|
||||
0 : this.flatCoordinates.length / this.stride;
|
||||
goog.asserts.assert(0 <= index && index < n);
|
||||
if (index < 0 || n <= index) {
|
||||
return null;
|
||||
}
|
||||
var point = new ol.geom.Point(null);
|
||||
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
|
||||
index * this.stride, (index + 1) * this.stride));
|
||||
return point;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.geom.Point>} Points.
|
||||
* @todo stability experimental
|
||||
|
||||
@@ -132,6 +132,15 @@ describe('ol.geom.MultiPoint', function() {
|
||||
expect(multiPoint.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('can return individual points', function() {
|
||||
var point0 = multiPoint.getPoint(0);
|
||||
expect(point0.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(point0.getCoordinates()).to.eql([1, 2, 3]);
|
||||
var point1 = multiPoint.getPoint(1);
|
||||
expect(point1.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(point1.getCoordinates()).to.eql([4, 5, 6]);
|
||||
});
|
||||
|
||||
it('can return all points', function() {
|
||||
var points = multiPoint.getPoints();
|
||||
expect(points).to.have.length(2);
|
||||
|
||||
Reference in New Issue
Block a user