summaryrefslogtreecommitdiff
path: root/web/views/key.erb
blob: 5f5ea457c0acdc50595f724dd8639d94bd77afe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<table id="overview">
</table>

<h1><%= @key_pp %></h1>

<div class="source-wiki" title="Description from the wiki">
    <%= @desc %>
</div>

<div id="tools">
    <% if @count_all_values < 1000 %>
        <%= xapi_link('*', @key) %> <%= josm_link('*', @key) %>
    <% else %>
        <span class="button disabled" title="Button disabled, because there are too many objects with this key"><img src="/img/link-extern-disabled.gif" width="14" height="10" alt=""/>XAPI</span>
        <span class="button disabled" title="Button disabled, because there are too many objects with this key"><img src="/img/link-extern-disabled.gif" width="14" height="10" alt=""/>JOSM</span>
    <% end %>
</div>

<form id="filter-form">
    <label for="filter">Filter:</label>
    <select id="filter" name="filter">
        <option value="all"<%=       @sel['all']       %>>No filter</option>
        <option value="nodes"<%=     @sel['nodes']     %>>Nodes only</option>
        <option value="ways"<%=      @sel['ways']      %>>Ways only</option>
        <option value="relations"<%= @sel['relations'] %>>Relations only</option>
    </select>
</form>

<div id="tabs">
    <ul>
        <li><a href="#values"><%= t.osm.values %></a></li>
        <li><a href="#keys"><%= t.taginfo.key_combinations %></a></li>
        <li><a href="#map"><%= t.taginfo.map %></a></li>
        <li><a href="#wiki"><%= t.sources.wiki.name %></a></li>
        <li><a href="#josm"><%= t.sources.josm.name %></a></li>
    </ul>
    <div id="values">
        <h2>Values used with this key</h2>
        <div class="canvas" id="canvas-values" style="position: absolute;"></div>
        <div style="margin-left: 180px;">
            <table id="grid-values">
            </table>
        </div>
    </div>
    <div id="keys">
        <h2>Other keys used together with this key</h2>
        <table id="grid-keys">
        </table>
    </div>
    <div id="map">
        <h2>Geographical distribution of this key</h2>
        <% if @filter_type == 'all' %>
            <div style="background-image: url(<%= TaginfoConfig.get('geodistribution.background_image') %>); background-repeat: no-repeat;"/>
                <img src="/api/3/db/keys/distribution/nodes?key=<%= @key_uri %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>" style="position: absolute;"/>
                <img src="/api/3/db/keys/distribution/ways?key=<%= @key_uri %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>"/>
            </div>
        <% elsif @filter_type == 'nodes' %>
            <div style="background-image: url(<%= TaginfoConfig.get('geodistribution.background_image') %>); background-repeat: no-repeat;"/>
                <img src="/api/3/db/keys/distribution/nodes?key=<%= @key_uri %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>"/>
            </div>
        <% elsif @filter_type == 'ways' %>
            <div style="background-image: url(<%= TaginfoConfig.get('geodistribution.background_image') %>); background-repeat: no-repeat;"/>
                <img src="/api/3/db/keys/distribution/ways?key=<%= @key_uri %>" alt="" width="<%= @img_width %>" height="<%= @img_height %>"/>
            </div>
        <% elsif @filter_type == 'relations' %>
            <p><i>Relations do not have a geographical location, so no map can be shown.</i></p>
        <% end %>
    </div>
    <div id="wiki">
        <h2>Wiki pages about this key</h2>
        <% if @wiki_count > 0 %>
            <table id="grid-wiki">
            </table>
        <% else %>
            <p><i>No wiki page available for this key.</i></p>
            <p>[<a href="http://wiki.openstreetmap.org/w/index.php?action=edit&title=Key:<%= @key_uri %>">Create wiki page</a>]</p>
        <% end %>
    </div>
    <div id="josm">
        <h2>JOSM style rules with this key</h2>
        <form>
            <label for="josm-style">Choose style:</label>
            <select id="josm-style" name="josm-style">
                <option>Standard</option>
            </select>
        </form>
       <table id="grid-josm">
       </table>
    </div>
<!--    <div id="merkaartor">
        <p>Type: <%= @merkaartor_type %></p>
        <% if @merkaartor_link %>
            <p>Link: XXX</p>
        <% end %>
        <p>
            <%= @merkaartor_images %>
        </p>
        <h3>Values</h3>
        <%= @merkaartor_values.map{ |value| link_to_value(@key, value) }.join(', ') %>
        <h3>Descriptions</h3>
        <table>
            <% @merkaartor_desc.each do |desc| %>
                <tr><td><%= desc['lang'] %></td><td><%= desc['description'] %></td></tr>
            <% end %>
        </table>
    </div>-->
</div>

<iframe id="josmiframe" name="josmiframe"></iframe>

<% javascript do
    JQuery.ready do
        JS.raw(<<"JAVASCRIPT")

jQuery('#josm_button').bind('click', function() {
    jQuery('#josmiframe')[0].src = jQuery('#josm_button')[0].href;
    return false;
});

jQuery('#filter').bind('change', function() {
    var value = this.value;

    var qs = jQuery.getQueryString;
    qs['filter'] = value;

    window.location.search = jQuery.param(qs);
});

jQuery.getJSON('/api/2/db/keys/overview?key=#{ @key_uri }', function(data, textStatus) {
    var table_content = '<tr><th></th><th title="Number of objects with this key">Number of objects</th><th class="values" title="Number of different values">Values</th></tr>';
    table_content += jQuery.map(['all', 'nodes', 'ways', 'relations'], function(obj, i) {
        var d = data[obj];
        return '<tr><td>' + print_image(obj) + '</td><td class="count">' + print_value_with_percent(d.count, d.count_fraction) + '</td><td class="values">' + print_with_ts(d.values) + '</td></tr>';
    }).join('');
    jQuery('#overview').append(table_content);
});

var tabs = jQuery('#tabs').tabs({
    show: function(event, ui) { 
        window.location.hash = ui.tab.hash;
        create_flexigrid_for.key[ui.tab.hash.substring(1)](#{ @key.to_json }, #{ @filter_type.to_json });
    }
});

var data = #{ @prevalent_values.to_json() };

var w=160, h=440;

var vis = new pv.Panel()
    .canvas('canvas-values')
    .width(w)
    .height(h + 20);

var scale = pv.Scale.linear(0, #{ @count_all_values }).range(0, h);

vis.add(pv.Layout.Stack)
    .bottom(10)
    .order('reverse')
    .layers(data)
    .x(10)
    .y(function(d) { return scale(d.count); })
  .layer.add(pv.Bar)
    .width(20)
    .cursor(function() {
        return this.data().value == '(other)' ? 'default' : 'pointer';
    })
    .event('click', function() {
        if (this.data().value != '(other)') {
            window.location = url_to_value(#{ @key_json }, this.data().value);
        }
    })
  .anchor('left')
    .add(pv.Label)
    .left(30)
    .text(function(d) { return d.value; });

vis.render();

JAVASCRIPT
    end
end
%>