diff --git a/src/ol/geom/point.js b/src/ol/geom/point.js index 4e357f7e5a..46c76b5a9a 100644 --- a/src/ol/geom/point.js +++ b/src/ol/geom/point.js @@ -40,8 +40,12 @@ ol.geom.Point.prototype.closestPointXY = var squaredDistance = ol.geom.flat.squaredDistance( x, y, flatCoordinates[0], flatCoordinates[1]); if (squaredDistance < minSquaredDistance) { - closestPoint[0] = flatCoordinates[0]; - closestPoint[1] = flatCoordinates[1]; + var stride = this.stride; + var i; + for (i = 0; i < stride; ++i) { + closestPoint[i] = flatCoordinates[i]; + } + closestPoint.length = stride; return squaredDistance; } else { return minSquaredDistance; diff --git a/test/spec/ol/geom/point.test.js b/test/spec/ol/geom/point.test.js index 72389411ac..84b01276c3 100644 --- a/test/spec/ol/geom/point.test.js +++ b/test/spec/ol/geom/point.test.js @@ -95,6 +95,15 @@ describe('ol.geom.Point', function() { expect(point.getStride()).to.be(4); }); + describe('#getClosestPoint', function() { + + it('preseves extra dimensions', function() { + var closestPoint = point.getClosestPoint([0, 0]); + expect(closestPoint).to.eql([1, 2, 3, 4]); + }); + + }); + }); });