ol/geom/MultiPoint#containsXY

This commit is contained in:
timkeane
2018-10-25 18:28:51 -04:00
committed by Frederic Junod
parent daffbde80b
commit 58b474225c
2 changed files with 34 additions and 0 deletions

View File

@@ -57,6 +57,17 @@ class MultiPoint extends SimpleGeometry {
return multiPoint; return multiPoint;
} }
/**
* @inheritDoc
* @override
* @api
*/
containsXY(x, y) {
return this.getCoordinates().some(function(coord) {
return coord[0] === x && coord[1] === y;
});
}
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@@ -287,4 +287,27 @@ describe('ol.geom.MultiPoint', function() {
}); });
describe('#containsXY()', function() {
it('does contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
expect(multi.containsXY(1, 2)).to.be(true);
expect(multi.containsXY(10, 20)).to.be(true);
});
it('does not contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
expect(multi.containsXY(1, 3)).to.be(false);
expect(multi.containsXY(2, 2)).to.be(false);
expect(multi.containsXY(2, 3)).to.be(false);
expect(multi.containsXY(10, 30)).to.be(false);
expect(multi.containsXY(20, 20)).to.be(false);
expect(multi.containsXY(20, 30)).to.be(false);
});
});
}); });