X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e329bf37c03d11eb32bed0fd0927bcbb76c316fc..5f970fe334c7c1bddd31b8098828df2c4174023c:/app/assets/javascripts/index/query.js?ds=sidebyside diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index 6b64ee8ee..bc4c26771 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -3,13 +3,22 @@ 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; + var featureStyle = { + color: "#FF6200", + weight: 4, + opacity: 1, + fillOpacity: 0.5, + clickable: false + }; + queryButton.on("click", function (e) { e.preventDefault(); e.stopPropagation(); + if (queryButton.hasClass("disabled")) return; + if (queryButton.hasClass("active")) { disableQueryMode(); @@ -17,29 +26,41 @@ OSM.Query = function(map) { } else { enableQueryMode(); } + }).on("disabled", function (e) { + if (queryButton.hasClass("active")) { + map.off("click", clickHandler); + $(map.getContainer()).removeClass("query-active").addClass("query-disabled"); + $(this).tooltip("show"); + } + }).on("enabled", function (e) { + if (queryButton.hasClass("active")) { + map.on("click", clickHandler); + $(map.getContainer()).removeClass("query-disabled").addClass("query-active"); + $(this).tooltip("hide"); + } }); $("#sidebar_content") - .on("mouseover", ".query-results li", function () { + .on("mouseover", ".query-results li.query-result", function () { var geometry = $(this).data("geometry") if (geometry) map.addLayer(geometry); $(this).addClass("selected"); }) - .on("mouseout", ".query-results li", function () { + .on("mouseout", ".query-results li.query-result", function () { var geometry = $(this).data("geometry") if (geometry) map.removeLayer(geometry); $(this).removeClass("selected"); }) - .on("click", ".query-results li", function (e) { + .on("click", ".query-results li.query-result", function (e) { if (!$(e.target).is('a')) { $(this).find("a").simulate("click", e); } }); - 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; } @@ -92,6 +113,8 @@ OSM.Query = function(map) { return tags["name"]; } else if (tags["ref"]) { return tags["ref"]; + } else if (tags["addr:housename"]) { + return tags["addr:housename"]; } else if (tags["addr:housenumber"] && tags["addr:street"]) { return tags["addr:housenumber"] + " " + tags["addr:street"]; } else { @@ -117,21 +140,33 @@ OSM.Query = function(map) { } } - function featureGeometry(feature, nodes) { + function featureGeometry(feature, features) { var geometry; if (feature.type === "node") { - geometry = L.circleMarker([feature.lat, feature.lon]); + geometry = L.circleMarker([feature.lat, feature.lon], featureStyle); } else if (feature.type === "way") { geometry = L.polyline(feature.nodes.map(function (node) { - return nodes[node]; - })); + return features["node" + node].getLatLng(); + }), featureStyle); + } else if (feature.type === "relation") { + geometry = L.featureGroup(); + + feature.members.forEach(function (member) { + if (features[member.type + member.ref]) { + geometry.addLayer(features[member.type + member.ref]); + } + }); + } + + if (geometry) { + features[feature.type + feature.id] = geometry; } return geometry; } - function runQuery(latlng, query, $section) { + function runQuery(latlng, radius, query, $section) { var $ul = $section.find("ul"); $ul.empty(); @@ -142,28 +177,24 @@ OSM.Query = function(map) { }); $.ajax({ - url: "http://overpass-api.de/api/interpreter", - method: "GET", + url: OSM.OVERPASS_URL, + method: "POST", data: { data: "[timeout:5][out:json];" + query, }, success: function(results) { - var nodes = {}; + var features = {}; $section.find(".loader").stopTime("loading").hide(); - results.elements.forEach(function (element) { - if (element.type === "node") { - nodes[element.id] = [element.lat, element.lon]; - } - }); - for (var i = 0; i < results.elements.length; i++) { - var element = results.elements[i]; + var element = results.elements[i], + geometry = featureGeometry(element, features); - if (interestingFeature(element, latlng)) { + if (interestingFeature(element, latlng, radius)) { var $li = $("
") .text(featurePrefix(element) + " ") @@ -175,13 +206,20 @@ OSM.Query = function(map) { .appendTo($p); } } + + if ($ul.find("li").length == 0) { + $("