diff --git a/src/ol/geom/geometry.js b/src/ol/geom/geometry.js index d6ea82e51c..2b8d58ae6b 100644 --- a/src/ol/geom/geometry.js +++ b/src/ol/geom/geometry.js @@ -119,7 +119,6 @@ ol.geom.Geometry.prototype.closestPointXY = goog.abstractMethod; * @return {ol.Coordinate} Closest point. */ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) { - // FIXME check extent var closestPoint = goog.isDef(opt_closestPoint) ? opt_closestPoint : [NaN, NaN]; this.closestPointXY(point[0], point[1], closestPoint, Infinity); diff --git a/src/ol/geom/linearring.js b/src/ol/geom/linearring.js index 566e07200b..4531ecf474 100644 --- a/src/ol/geom/linearring.js +++ b/src/ol/geom/linearring.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.LinearRing'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.closest'); goog.require('ol.geom.flat'); @@ -40,6 +41,10 @@ goog.inherits(ol.geom.LinearRing, ol.geom.Geometry); */ ol.geom.LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } if (this.maxDeltaRevision_ != this.revision) { this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index 94b2c9e584..45760bcc73 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.LineString'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.closest'); goog.require('ol.geom.flat'); @@ -40,6 +41,10 @@ goog.inherits(ol.geom.LineString, ol.geom.Geometry); */ ol.geom.LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } if (this.maxDeltaRevision_ != this.revision) { this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); diff --git a/src/ol/geom/multilinestring.js b/src/ol/geom/multilinestring.js index 1c6ecf4331..15e5d578d9 100644 --- a/src/ol/geom/multilinestring.js +++ b/src/ol/geom/multilinestring.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.MultiLineString'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.LineString'); goog.require('ol.geom.closest'); @@ -47,6 +48,10 @@ goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry); */ ol.geom.MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } if (this.maxDeltaRevision_ != this.revision) { this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.flatCoordinates, 0, this.ends_, this.stride, 0)); diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 0330e274d1..ad390a7adf 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.MultiPoint'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.Point'); goog.require('ol.geom.flat'); @@ -24,6 +25,10 @@ goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry); */ ol.geom.MultiPoint.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } var flatCoordinates = this.flatCoordinates; var stride = this.stride; var i, ii; diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index b9aca5c04b..41014f4c0c 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.MultiPolygon'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.Polygon'); goog.require('ol.geom.closest'); @@ -59,6 +60,10 @@ goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry); */ ol.geom.MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } if (this.maxDeltaRevision_ != this.revision) { this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta( this.flatCoordinates, 0, this.endss_, this.stride, 0)); diff --git a/src/ol/geom/polygon.js b/src/ol/geom/polygon.js index dbf17b63e9..fc4b3a891a 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -1,5 +1,6 @@ goog.provide('ol.geom.Polygon'); +goog.require('ol.extent'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.LinearRing'); goog.require('ol.geom.closest'); @@ -59,6 +60,10 @@ goog.inherits(ol.geom.Polygon, ol.geom.Geometry); */ ol.geom.Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) { + if (minSquaredDistance < + ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { + return minSquaredDistance; + } if (this.maxDeltaRevision_ != this.revision) { this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.flatCoordinates, 0, this.ends_, this.stride, 0));