X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/078059b76b8304368fd7ddac2dd563470e83472e..e329bf37c03d11eb32bed0fd0927bcbb76c316fc:/app/assets/javascripts/index/query.js diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 8d04efd5f..6b64ee8ee 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -1,6 +1,9 @@ +//= require jquery.simulate + 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) { @@ -26,10 +29,20 @@ OSM.Query = function(map) { var geometry = $(this).data("geometry") if (geometry) map.removeLayer(geometry); $(this).removeClass("selected"); + }) + .on("click", ".query-results li", function (e) { + if (!$(e.target).is('a')) { + $(this).find("a").simulate("click", e); + } }); - 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; @@ -118,7 +131,7 @@ OSM.Query = function(map) { return geometry; } - function runQuery(query, $section) { + function runQuery(latlng, query, $section) { var $ul = $section.find("ul"); $ul.empty(); @@ -148,12 +161,11 @@ OSM.Query = function(map) { for (var i = 0; i < results.elements.length; i++) { var element = results.elements[i]; - if (interestingFeature(element)) { + if (interestingFeature(element, latlng)) { var $li = $("
  • ") .data("geometry", featureGeometry(element, nodes)) .appendTo($ul); var $p = $("

    ") - .addClass("inner12 search_results_entry clearfix") .text(featurePrefix(element) + " ") .appendTo($li); @@ -169,7 +181,7 @@ OSM.Query = function(map) { 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;"; @@ -180,7 +192,7 @@ OSM.Query = function(map) { 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) { @@ -194,8 +206,8 @@ OSM.Query = function(map) { } }, 10); - runQuery(nearby, $("#query-nearby")); - runQuery(isin, $("#query-isin")); + runQuery(latlng, nearby, $("#query-nearby")); + runQuery(latlng, isin, $("#query-isin")); } function clickHandler(e) {