From 77e39800d5940f8ece90f490aa228290433b56e1 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 13 Mar 2014 18:54:39 +0000 Subject: [PATCH] Build and show partial geometries for relatons --- app/assets/javascripts/index/query.js | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index b9aa4f4d0..c0f40d1e1 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -140,15 +140,27 @@ 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], 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; @@ -171,23 +183,18 @@ OSM.Query = function(map) { 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, radius)) { var $li = $("
  • ") .addClass("query-result") - .data("geometry", featureGeometry(element, nodes)) + .data("geometry", geometry) .appendTo($ul); var $p = $("

    ") .text(featurePrefix(element) + " ") -- 2.39.5