]> git.openstreetmap.org Git - rails.git/commitdiff
Increase search radius at lower zooms
authorTom Hughes <tom@compton.nu>
Sun, 9 Mar 2014 13:47:18 +0000 (13:47 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 16 Mar 2014 16:18:13 +0000 (16:18 +0000)
app/assets/javascripts/index/query.js

index e264dcf31cb71995bab0d697bf58c48289e2a7d2..096f7cca67358ff9e390a15ccd38ae2e145db26e 100644 (file)
@@ -3,7 +3,6 @@
 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) {
@@ -36,10 +35,10 @@ OSM.Query = function(map) {
       }
     });
 
-  function interestingFeature(feature, origin) {
+  function interestingFeature(feature, origin, radius) {
     if (feature.tags) {
       if (feature.type === "node" &&
-          OSM.distance(origin, L.latLng(feature.lat, feature.lon)) > searchRadius) {
+          OSM.distance(origin, L.latLng(feature.lat, feature.lon)) > radius) {
         return false;
       }
 
@@ -131,7 +130,7 @@ OSM.Query = function(map) {
     return geometry;
   }
 
-  function runQuery(latlng, query, $section) {
+  function runQuery(latlng, radius, query, $section) {
     var $ul = $section.find("ul");
 
     $ul.empty();
@@ -161,7 +160,7 @@ OSM.Query = function(map) {
         for (var i = 0; i < results.elements.length; i++) {
           var element = results.elements[i];
 
-          if (interestingFeature(element, latlng)) {
+          if (interestingFeature(element, latlng, radius)) {
             var $li = $("<li>")
               .addClass("query-result")
               .data("geometry", featureGeometry(element, nodes))
@@ -188,7 +187,8 @@ OSM.Query = function(map) {
 
   function queryOverpass(lat, lng) {
     var latlng = L.latLng(lat, lng),
-      around = "around:" + searchRadius + "," + lat + "," + lng,
+      radius = 10 * Math.pow(1.5, 19 - map.getZoom()),
+      around = "around:" + radius + "," + lat + "," + lng,
       features = "(node(" + around + ");way(" + around + ");relation(" + around + "))",
       nearby = "((" + features + ";way(bn));node(w));out;",
       isin = "(is_in(" + lat + "," + lng + ");>);out;";
@@ -196,11 +196,8 @@ OSM.Query = function(map) {
     $("#sidebar_content .query-intro")
       .hide();
 
-    if (marker) {
-      marker.setLatLng(latlng).addTo(map);
-    } else {
-      marker = L.circle(latlng, searchRadius, { clickable: false }).addTo(map);
-    }
+    if (marker) map.removeLayer(marker);
+    marker = L.circle(latlng, radius, { clickable: false }).addTo(map);
 
     $(document).everyTime(75, "fadeQueryMarker", function (i) {
       if (i == 10) {
@@ -213,8 +210,8 @@ OSM.Query = function(map) {
       }
     }, 10);
 
-    runQuery(latlng, nearby, $("#query-nearby"));
-    runQuery(latlng, isin, $("#query-isin"));
+    runQuery(latlng, radius, nearby, $("#query-nearby"));
+    runQuery(latlng, radius, isin, $("#query-isin"));
   }
 
   function clickHandler(e) {