summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/lib/api/josm.rb65
-rw-r--r--web/lib/api/key.rb45
-rw-r--r--web/lib/api/tag.rb42
-rw-r--r--web/lib/utils.rb19
-rw-r--r--web/viewsjs/key.js.erb10
-rw-r--r--web/viewsjs/reports/josm_styles.js.erb16
-rw-r--r--web/viewsjs/tag.js.erb10
7 files changed, 189 insertions, 18 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
+
diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb
index 744dde7..bbf142c 100644
--- a/web/viewsjs/key.js.erb
+++ b/web/viewsjs/key.js.erb
@@ -120,21 +120,21 @@ var create_flexigrid_for = {
},
josm: function(key, filter_type) {
create_flexigrid('grid-josm', {
- url: '/api/2/josm/styles/standard/keys?key=' + encodeURIComponent(key),
+ url: '/api/4/key/josm/style/rules?style=standard&key=' + encodeURIComponent(key),
colModel: [
- { display: '<%= osm.value %>', name: 'v', width: 400, sortable: true },
+ { display: '<%= osm.value %>', name: 'value', width: 400, sortable: true },
{ display: '<%= misc.icon %>', name: 'icon', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.line %>', name: 'line', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.area %>', name: 'area', width: 40, sortable: false, align: 'center' }
],
- sortname: 'v',
+ sortname: 'value',
sortorder: 'asc',
emptymsg: '<%= page.josm.no_styles %>',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- row.v ? link_to_value(row.k, row.v) : row.b ? (row.b + ' (Boolean)') : '*',
- row.icon ? '<img src="/api/2/josm/styles/images?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
+ row.value ? link_to_value(row.key, row.value) : row.b ? (row.b + ' (Boolean)') : '*',
+ row.icon ? '<img src="/api/4/josm/style/image?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
'<div>' + (row.line_width > 0 ? '<div title="' + row.line_color + '" style="height: ' + row.line_width + 'px; margin-top: ' + (10 - Math.round(row.line_width/2)) + 'px; padding: 0; background-color: ' + row.line_color + '"></div>' : '') + '</div>',
row.area_color ? '<div title="' + row.area_color + '" style="height: 18px; background-color: ' + row.area_color + '"></div>' : ''
] };
diff --git a/web/viewsjs/reports/josm_styles.js.erb b/web/viewsjs/reports/josm_styles.js.erb
index d051a41..a8ce85e 100644
--- a/web/viewsjs/reports/josm_styles.js.erb
+++ b/web/viewsjs/reports/josm_styles.js.erb
@@ -4,25 +4,25 @@
%>
function create_flexigrid_with_option(stylename) {
create_flexigrid('grid-rules', {
- url: '/api/2/josm/styles/' + stylename,
+ url: '/api/4/josm/style/rules?style=' + stylename,
colModel: [
- { display: '<%= osm.key %>', name: 'k', width: 300, sortable: true },
- { display: '<%= osm.value %>', name: 'v', width: 300, sortable: true },
+ { display: '<%= osm.key %>', name: 'key', width: 300, sortable: true },
+ { display: '<%= osm.value %>', name: 'value', width: 300, sortable: true },
{ display: '<%= misc.icon %>', name: 'icon', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.line %>', name: 'line', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.area %>', name: 'area', width: 40, sortable: false, align: 'center' }
],
searchitems: [
- { display: '<%= osm.key %>/<%= osm.value %>', name: 'k' }
+ { display: '<%= osm.key %>/<%= osm.value %>', name: 'key' }
],
- sortname: 'k',
+ sortname: 'key',
sortorder: 'asc',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- link_to_key(row.k),
- row.v ? link_to_value(row.k, row.v) : row.b ? (row.b + ' (Boolean)') : '*',
- row.icon ? '<img src="/api/2/josm/styles/images?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
+ link_to_key(row.key),
+ row.value ? link_to_value(row.key, row.value) : row.b ? (row.b + ' (Boolean)') : '*',
+ row.icon ? '<img src="/api/4/josm/style/image?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
'<div>' + (row.line_width > 0 ? '<div title="' + row.line_color + '" style="height: ' + row.line_width + 'px; margin-top: ' + (10 - Math.round(row.line_width/2)) + 'px; padding: 0; background-color: ' + row.line_color + '"></div>' : '') + '</div>',
row.area_color ? '<div title="' + row.area_color + '" style="height: 18px; background-color: ' + row.area_color + '"></div>' : ''
] };
diff --git a/web/viewsjs/tag.js.erb b/web/viewsjs/tag.js.erb
index e0fb9f8..173fab0 100644
--- a/web/viewsjs/tag.js.erb
+++ b/web/viewsjs/tag.js.erb
@@ -93,21 +93,21 @@ var create_flexigrid_for = {
},
josm: function(key, value) {
create_flexigrid('grid-josm', {
- url: '/api/2/josm/styles/standard/tags?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value),
+ url: '/api/4/tag/josm/style/rules?style=standard&key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value),
colModel: [
- { display: '<%= osm.value %>', name: 'v', width: 400, sortable: false },
+ { display: '<%= osm.value %>', name: 'value', width: 400, sortable: false },
{ display: '<%= misc.icon %>', name: 'icon', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.line %>', name: 'line', width: 40, sortable: false, align: 'center' },
{ display: '<%= misc.area %>', name: 'area', width: 40, sortable: false, align: 'center' }
],
- sortname: 'v',
+ sortname: 'value',
sortorder: 'asc',
emptymsg: '<%= page.josm.no_styles %>',
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
- row.v ? link_to_value(row.k, row.v) : row.b ? (row.b + ' (Boolean)') : '*',
- row.icon ? '<img src="/api/2/josm/styles/images?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
+ row.value ? link_to_value(row.key, row.value) : row.b ? (row.b + ' (Boolean)') : '*',
+ row.icon ? '<img src="/api/4/josm/style/image?style=standard&image=' + row.icon + '" title="' + row.icon + '" alt=""/>' : '',
'<div>' + (row.line_width > 0 ? '<div title="' + row.line_color + '" style="height: ' + row.line_width + 'px; margin-top: ' + (10 - Math.round(row.line_width/2)) + 'px; padding: 0; background-color: ' + row.line_color + '"></div>' : '') + '</div>',
row.area_color ? '<div title="' + row.area_color + '" style="height: 18px; background-color: ' + row.area_color + '"></div>' : ''
] };