+//= 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) {
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;
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);
var $p = $("<p>")
- .addClass("inner12 search_results_entry clearfix")
.text(featurePrefix(element) + " ")
.appendTo($li);
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) {