From 58b474225c276b5479036f2efe740356fec683d9 Mon Sep 17 00:00:00 2001 From: timkeane Date: Thu, 25 Oct 2018 18:28:51 -0400 Subject: [PATCH] ol/geom/MultiPoint#containsXY --- src/ol/geom/MultiPoint.js | 11 +++++++++++ test/spec/ol/geom/multipoint.test.js | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index e433e51bf3..65a88f4283 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -57,6 +57,17 @@ class MultiPoint extends SimpleGeometry { return multiPoint; } + /** + * @inheritDoc + * @override + * @api + */ + containsXY(x, y) { + return this.getCoordinates().some(function(coord) { + return coord[0] === x && coord[1] === y; + }); + } + /** * @inheritDoc */ diff --git a/test/spec/ol/geom/multipoint.test.js b/test/spec/ol/geom/multipoint.test.js index bdbb32533c..206eb8dd5f 100644 --- a/test/spec/ol/geom/multipoint.test.js +++ b/test/spec/ol/geom/multipoint.test.js @@ -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); + }); + + }); + });