Get hit candidates from RTree, then refine result

Now we get exact hits also for lines and polygons.
This commit is contained in:
ahocevar
2013-04-30 13:34:12 +02:00
parent cc1b70c74b
commit 58c8b07ab5
9 changed files with 208 additions and 21 deletions

View File

@@ -146,3 +146,20 @@ ol.geom.LineString.prototype.getType = function() {
ol.geom.LineString.prototype.getSharedId = function() {
return this.sharedId_;
};
/**
* Calculate the distance from a coordinate to this linestring.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @return {number} Distance from the coordinate to this linestring.
*/
ol.geom.LineString.prototype.distanceFromCoordinate = function(coordinate) {
var coordinates = this.getCoordinates();
var dist2 = Infinity;
for (var i = 0, j = 1, len = coordinates.length; j < len; i = j++) {
dist2 = Math.min(dist2, ol.geom.squaredDistanceToSegment(coordinate,
[coordinates[i], coordinates[j]]));
}
return Math.sqrt(dist2);
};