From 6cb9e2de145ebfc8a3caad377cd40780823d1ad2 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 15 May 2014 09:04:48 +0200 Subject: Use different overpass turbo call when numbers of objects is small. When there aren't too many objects with a given key or tag, use the new wizard interface of overpass turbo, which runs automatically in global context and automatically zooms to the results. This is much nicer and easier. If there are too many objects, we keep the old behaviour. Unfortunately this is rather confusing. Maybe we can figure out something better... --- taginfo-config-example.json | 5 ++++- web/lib/utils.rb | 40 +++++++++++++++++++++++++++------------- web/views/key.erb | 2 +- web/views/tag.erb | 2 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/taginfo-config-example.json b/taginfo-config-example.json index 74789c2..2ea5db2 100644 --- a/taginfo-config-example.json +++ b/taginfo-config-example.json @@ -36,7 +36,10 @@ "url_prefix": "http://overpass-api.de/api/xapi_meta?" }, "turbo": { - "url_prefix": "http://overpass-turbo.eu/?" + "max_auto": 100, + "url_prefix": "http://overpass-turbo.eu/?", + "wizard_url_prefix": "http://overpass-turbo.eu/master?", + "wizard_area": "global" }, "level0": { "max_results": 50, diff --git a/web/lib/utils.rb b/web/lib/utils.rb index 33aac9b..7d64538 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -85,22 +85,36 @@ def josm_link(element, key, value=nil) '' + external_link('josm_button', 'JOSM', 'http://localhost:8111/import?url=' + Rack::Utils::escape(xapi_url(element, key, value)), true) + '' end -def turbo_link(filter, key, value=nil) - template = 'key'; - parameters = { :key => key } +def quote_double(text) + text.gsub(/["\\]/, "\\\\\\0") +end - unless value.nil? - parameters[:value] = value; - template += '-value' - end +def turbo_link(count, filter, key, value=nil) + if count <= TaginfoConfig.get('turbo.max_auto', 100) + key = quote_double(key) + if value.nil? + value = '*' + else + value = '"' + quote_double(value) + '"' + end + url = TaginfoConfig.get('turbo.wizard_url_prefix', 'http://overpass-turbo.eu/master?') + 'w=' + Rack::Utils::escape('"' + key + '"=' + value + ' ' + TaginfoConfig.get('turbo.wizard_area', 'global')) + '&R' + else + template = 'key'; + parameters = { :key => key } + + unless value.nil? + parameters[:value] = value; + template += '-value' + end + + if filter != 'all' + template += '-type' + parameters[:type] = filter.chop + end + parameters[:template] = template - if filter != 'all' - template += '-type' - parameters[:type] = filter.chop + url = TaginfoConfig.get('turbo.url_prefix', 'http://overpass-turbo.eu/?') + Rack::Utils::build_query(parameters) end - parameters[:template] = template - - url = TaginfoConfig.get('turbo.url_prefix', 'http://overpass-turbo.eu/?') + Rack::Utils::build_query(parameters) return '' + external_link('turbo_button', ' overpass turbo', url, true) + '' end diff --git a/web/views/key.erb b/web/views/key.erb index a4a415a..d168aa4 100644 --- a/web/views/key.erb +++ b/web/views/key.erb @@ -20,7 +20,7 @@ <% else %> Level0 Editor <% end %> - <%= turbo_link(@filter_type, @key) %> + <%= turbo_link(@count_all_values, @filter_type, @key) %>

<%= @desc %>

diff --git a/web/views/tag.erb b/web/views/tag.erb index b3b7782..b1758fa 100644 --- a/web/views/tag.erb +++ b/web/views/tag.erb @@ -20,7 +20,7 @@ <% else %> Level0 Editor <% end %> - <%= turbo_link(@filter_type, @key, @value) %> + <%= turbo_link(@count_all, @filter_type, @key, @value) %>

<%= @desc %>

-- cgit v1.2.3