diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-06 16:58:43 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-06 16:58:43 +0100 |
commit | 395b80de72ce59c42135e9e68579ae1ee039f79a (patch) | |
tree | 25ff58266c69915e887797ce227fee9d0a9f2f20 /web/lib | |
parent | 465a86c863ce81d77079240d33a48d9520182e92 (diff) | |
download | taginfo-395b80de72ce59c42135e9e68579ae1ee039f79a.tar taginfo-395b80de72ce59c42135e9e68579ae1ee039f79a.tar.gz |
Updated josm API calls
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/api/josm.rb | 65 | ||||
-rw-r--r-- | web/lib/api/key.rb | 45 | ||||
-rw-r--r-- | web/lib/api/tag.rb | 42 | ||||
-rw-r--r-- | web/lib/utils.rb | 19 |
4 files changed, 171 insertions, 0 deletions
diff --git a/web/lib/api/josm.rb b/web/lib/api/josm.rb index 7c98b14..22249f7 100644 --- a/web/lib/api/josm.rb +++ b/web/lib/api/josm.rb @@ -2,6 +2,7 @@ class Taginfo < Sinatra::Base api(2, 'josm/styles/images', { + :superseded_by => '4/josm/style/image', :description => 'Access images for map features used in JOSM.', :parameters => { :style => 'JOSM style', :image => 'Image path' }, :result => 'PNG image.', @@ -106,4 +107,68 @@ class Taginfo < Sinatra::Base return get_josm_result(total, res); end + api(4, 'josm/style/rules', { + :description => 'List rules and symbols in JOSM styles.', + :parameters => { + :style => 'JOSM style (required).', + :query => 'Only show results where the key or value matches this query (substring match, optional).' + }, + :paging => :optional, + :result => { + :key => :STRING, + :value => :STRING, + :b => :STRING, + :rule => :STRING, + :area_color => :STRING, + :line_color => :STRING, + :line_width => :INT, + :icon => :STRING + }, + :example => { :style => 'standard', :page => 1, :rp => 10}, + :ui => '/reports/josm_styles' + }) do + style = params[:style] + + total = @db.count('josm_style_rules'). +# condition('style = ?', style). + condition_if("k LIKE '%' || ? || '%' OR v LIKE '%' || ? || '%'", params[:query], params[:query]). + get_first_value().to_i + + res = @db.select('SELECT * FROM josm_style_rules'). +# condition('style = ?', style). + condition_if("k LIKE '%' || ? || '%' OR v LIKE '%' || ? || '%'", params[:query], params[:query]). + order_by(@ap.sortname, @ap.sortorder) { |o| + o.key :k + o.key :v + o.key :b + o.value :v + o.value :b + o.value :k + o.b + }. + paging(@ap). + execute() + + return get_josm_style_rules_result(total, res); + end + + api(4, 'josm/style/image', { + :description => 'Access images for map features used in JOSM.', + :parameters => { + :style => 'JOSM style (required).', + :image => 'Image path (required).' + }, + :result => 'PNG image.', + :example => { :style => 'standard', :image => 'transport/bus.png' }, + :ui => '/keys/landuse#josm' + }) do + style = params[:style] + image = params[:image] + content_type :png + @db.select('SELECT png FROM josm.josm_style_images'). + condition('style = ?', style). + condition('path = ?', image). + get_first_value() + end + end diff --git a/web/lib/api/key.rb b/web/lib/api/key.rb index bee71d8..3fff6b6 100644 --- a/web/lib/api/key.rb +++ b/web/lib/api/key.rb @@ -257,4 +257,49 @@ class Taginfo < Sinatra::Base return get_wiki_result(res) end + api(4, 'key/josm/style/rules', { + :description => 'List rules and symbols for the given key in JOSM styles.', + :parameters => { + :style => 'JOSM style (required).', + :key => 'Tag key (required).', + :query => 'Only show results where the value matches this query (substring match, optional).' + }, + :paging => :optional, + :result => { + :key => :STRING, + :value => :STRING, + :b => :STRING, + :rule => :STRING, + :area_color => :STRING, + :line_color => :STRING, + :line_width => :INT, + :icon => :STRING + }, + :example => { :style => 'standard', :key => 'highway', :page => 1, :rp => 10}, + :ui => '/keys/highway#josm' + }) do + style = params[:style] + key = params[:key] + + total = @db.count('josm_style_rules'). +# condition('style = ?', style). + condition('k = ?', key). + condition_if("v LIKE '%' || ? || '%'", params[:query]). + get_first_value().to_i + + res = @db.select('SELECT * FROM josm_style_rules'). +# condition('style = ?', style). + condition('k = ?', key). + condition_if("v LIKE '%' || ? || '%'", params[:query]). + order_by(@ap.sortname, @ap.sortorder) { |o| + o.value :v + o.value :b + o.b + }. + paging(@ap). + execute() + + return get_josm_style_rules_result(total, res); + end + end diff --git a/web/lib/api/tag.rb b/web/lib/api/tag.rb index a4088c1..3aa577c 100644 --- a/web/lib/api/tag.rb +++ b/web/lib/api/tag.rb @@ -156,4 +156,46 @@ class Taginfo < Sinatra::Base return get_wiki_result(res) end + api(4, 'tag/josm/style/rules', { + :description => 'List rules and symbols for the given tag in JOSM styles.', + :parameters => { + :style => 'JOSM style (required).', + :key => 'Tag key (required).', + :value => 'Tag value (required).' + }, + :paging => :optional, + :result => { + :key => :STRING, + :value => :STRING, + :b => :STRING, + :rule => :STRING, + :area_color => :STRING, + :line_color => :STRING, + :line_width => :INT, + :icon => :STRING + }, + :example => { :style => 'standard', :key => 'highway', :value => 'residential', :page => 1, :rp => 10}, + :ui => '/tags/highway=residential#josm' + }) do + style = params[:style] + key = params[:key] + value = params[:value] + + total = @db.count('josm_style_rules'). +# condition('style = ?', style). + condition('k = ?', key). + condition('v = ?', value). + get_first_value().to_i + + res = @db.select('SELECT * FROM josm_style_rules'). +# condition('style = ?', style). + condition('k = ?', key). + condition('v = ?', value). + order_by([:k, :v], 'ASC'). + paging(@ap). + execute() + + return get_josm_style_rules_result(total, res); + end + end diff --git a/web/lib/utils.rb b/web/lib/utils.rb index c30ff04..384e9c6 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -196,3 +196,22 @@ def get_wiki_result(res) }.to_json end +# Used in josm api calls +def get_josm_style_rules_result(total, res) + return { + :page => @ap.page, + :rp => @ap.results_per_page, + :total => total, + :data => res.map{ |row| { + :key => row['k'], + :value => row['v'], + :b => row['b'], + :rule => h(row['rule']), + :area_color => row['area_color'] ? h(row['area_color'].sub(/^.*#/, '#')) : '', + :line_color => row['line_color'] ? h(row['line_color'].sub(/^.*#/, '#')) : '', + :line_width => row['line_width'] ? row['line_width'].to_i : 0, + :icon => row['icon_source'] && row['icon_source'] != 'misc/deprecated.png' && row['icon_source'] != 'misc/no_icon.png' ? h(row['icon_source']) : '' + } } + }.to_json +end + |