diff options
author | Jochen Topf <jochen@topf.org> | 2014-05-15 09:04:48 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2014-05-15 09:04:48 +0200 |
commit | 6cb9e2de145ebfc8a3caad377cd40780823d1ad2 (patch) | |
tree | 0cf096dfcdcae4c360f3d23a23fe930955bc63ea /web/lib | |
parent | 2b0703de9606fb40aa437b7e962bd09a2e4783b0 (diff) | |
download | taginfo-6cb9e2de145ebfc8a3caad377cd40780823d1ad2.tar taginfo-6cb9e2de145ebfc8a3caad377cd40780823d1ad2.tar.gz |
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...
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/utils.rb | 40 |
1 files changed, 27 insertions, 13 deletions
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) '<span class="button">' + external_link('josm_button', 'JOSM', 'http://localhost:8111/import?url=' + Rack::Utils::escape(xapi_url(element, key, value)), true) + '</span>' 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 '<span class="button">' + external_link('turbo_button', '<img src="/img/turbo.png"/> overpass turbo', url, true) + '</span>' end |