OSM.Query = function(map) {
var queryButton = $(".control-query .control-button"),
uninterestingTags = ['source', 'source_ref', 'source:ref', 'history', 'attribution', 'created_by', 'tiger:county', 'tiger:tlid', 'tiger:upload_uuid'],
+ searchRadius = 10,
marker;
queryButton.on("click", function (e) {
$(this).removeClass("selected");
});
- function interestingFeature(feature) {
+ function interestingFeature(feature, origin) {
if (feature.tags) {
+ if (feature.type === "node" &&
+ OSM.distance(origin, L.latLng(feature.lat, feature.lon)) > searchRadius) {
+ return false;
+ }
+
for (var key in feature.tags) {
if (uninterestingTags.indexOf(key) < 0) {
return true;
return geometry;
}
- function runQuery(query, $section) {
+ function runQuery(latlng, query, $section) {
var $ul = $section.find("ul");
$ul.empty();
for (var i = 0; i < results.elements.length; i++) {
var element = results.elements[i];
- if (interestingFeature(element)) {
+ if (interestingFeature(element, latlng)) {
var $li = $("<li>")
.data("geometry", featureGeometry(element, nodes))
.appendTo($ul);
function queryOverpass(lat, lng) {
var latlng = L.latLng(lat, lng),
- around = "around:10.0," + lat + "," + lng,
+ around = "around:" + searchRadius + "," + lat + "," + lng,
features = "(node(" + around + ");way(" + around + ");relation(" + around + "))",
nearby = "((" + features + ";way(bn));node(w));out;",
isin = "(is_in(" + lat + "," + lng + ");>);out;";
if (marker) {
marker.setLatLng(latlng).addTo(map);
} else {
- marker = L.circle(latlng, 10, { clickable: false }).addTo(map);
+ marker = L.circle(latlng, searchRadius, { clickable: false }).addTo(map);
}
$(document).everyTime(75, "fadeQueryMarker", function (i) {
}
}, 10);
- runQuery(nearby, $("#query-nearby"));
- runQuery(isin, $("#query-isin"));
+ runQuery(latlng, nearby, $("#query-nearby"));
+ runQuery(latlng, isin, $("#query-isin"));
}
function clickHandler(e) {
zoom = map.getZoom(),
precision = OSM.zoomPrecision(zoom);
return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
+ },
+
+ distance: function(latlng1, latlng2) {
+ var lat1 = latlng1.lat * Math.PI / 180,
+ lng1 = latlng1.lng * Math.PI / 180,
+ lat2 = latlng2.lat * Math.PI / 180,
+ lng2 = latlng2.lng * Math.PI / 180,
+ latdiff = lat2 - lat1,
+ lngdiff = lng2 - lng1;
+
+ return 6372795 * 2 * Math.asin(
+ Math.sqrt(
+ Math.pow(Math.sin(latdiff / 2), 2) +
+ Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)
+ ));
}
};
expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|5|M");
});
});
+
+ describe(".distance", function () {
+ it("computes distance between points", function () {
+ var latlng1 = L.latLng(51.76712,-0.00484),
+ latlng2 = L.latLng(51.7675159, -0.0078329);
+
+ expect(OSM.distance(latlng1, latlng2)).to.be.closeTo(210.664, 0.005);
+ expect(OSM.distance(latlng2, latlng1)).to.be.closeTo(210.664, 0.005);
+ });
+ });
});