diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 1cc711b710..142c6f4c92 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -42,14 +42,16 @@ ol.geom.MultiPoint.prototype.closestPointXY = } var flatCoordinates = this.flatCoordinates; var stride = this.stride; - var i, ii; + var i, ii, j; for (i = 0, ii = flatCoordinates.length; i < ii; i += stride) { var squaredDistance = ol.geom.flat.squaredDistance( x, y, flatCoordinates[i], flatCoordinates[i + 1]); if (squaredDistance < minSquaredDistance) { minSquaredDistance = squaredDistance; - closestPoint[0] = flatCoordinates[i]; - closestPoint[1] = flatCoordinates[i + 1]; + for (j = 0; j < stride; ++j) { + closestPoint[j] = flatCoordinates[i + j]; + } + closestPoint.length = stride; } } return minSquaredDistance; diff --git a/test/spec/ol/geom/multipoint.test.js b/test/spec/ol/geom/multipoint.test.js index f2ef5bef66..336b5558c9 100644 --- a/test/spec/ol/geom/multipoint.test.js +++ b/test/spec/ol/geom/multipoint.test.js @@ -154,6 +154,15 @@ describe('ol.geom.MultiPoint', function() { expect(multiPoint.getStride()).to.be(4); }); + describe('#getClosestPoint', function() { + + it('preserves extra dimensions', function() { + var closestPoint = multiPoint.getClosestPoint([6, 6]); + expect(closestPoint).to.eql([5, 6, 7, 8]); + }); + + }); + }); });