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

@@ -88,3 +88,26 @@ ol.geom.Polygon.prototype.getCoordinates = function() {
ol.geom.Polygon.prototype.getType = function() {
return ol.geom.GeometryType.POLYGON;
};
/**
* Check whether a given coordinate is inside this polygon.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @return {boolean} Whether the coordinate is inside the polygon.
*/
ol.geom.Polygon.prototype.containsCoordinate = function(coordinate) {
var rings = this.rings;
var containsCoordinate = ol.geom.pointInPolygon(coordinate,
rings[0].getCoordinates());
if (containsCoordinate) {
// if inner ring contains point, polygon does not contain it
for (var i = 1, ii = rings.length; i < ii; ++i) {
if (ol.geom.pointInPolygon(coordinate, rings[i].getCoordinates())) {
containsCoordinate = false;
break;
}
}
}
return containsCoordinate;
};