diff options
author | Dave Arter <davea@mysociety.org> | 2019-03-04 16:23:32 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2019-03-25 14:41:12 +0000 |
commit | fd4b300838908c7d040c73f05a7576de656613e5 (patch) | |
tree | dc2b49c7b57110802e8cede72516c551eee04e75 /web | |
parent | c031fc02119b5d1fe9bebe78bcadfdf6ff5270d5 (diff) |
Add Layer.Vector.getFeaturesWithinDistance method
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 732bcb1ef..bb0a1e9ad 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -796,6 +796,34 @@ OpenLayers.Layer.Vector.prototype.getNearestFeature = function(point, threshold) /* + * Returns all features from this layer within a given distance (<threshold> + * metres) of the given OpenLayers.Geometry.Point. + * Returns an empty list if no features meeting these criteria is found. + */ +OpenLayers.Layer.Vector.prototype.getFeaturesWithinDistance = function(point, threshold) { + var features = []; + for (var i = 0; i < this.features.length; i++) { + var candidate = this.features[i]; + if (!candidate.geometry || !candidate.geometry.distanceTo) { + continue; + } + var details = candidate.geometry.distanceTo(point, {details: true}); + // The units used for details.distance aren't metres, they're + // whatever the map projection uses. Convert to metres in order to + // draw a meaningful comparison to the threshold value. + var p1 = new OpenLayers.Geometry.Point(details.x0, details.y0); + var p2 = new OpenLayers.Geometry.Point(details.x1, details.y1); + var line = new OpenLayers.Geometry.LineString([p1, p2]); + var distance_m = line.getGeodesicLength(this.map.getProjectionObject()); + if (distance_m <= threshold) { + features.push(candidate); + } + } + return features; +}; + + +/* * MapServer 6 (the version available on Debian Wheezy) outputs incorrect * GML for MultiCurve geometries - see https://github.com/mapserver/mapserver/issues/4924 * The end result is that features with 'curveMembers' elements in their |