]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.key.js
Fix undefined=undefined in query strings
[rails.git] / app / assets / javascripts / leaflet.key.js
1 L.OSM.key = function (options) {
2   var control = L.control(options);
3
4   control.onAdd = function (map) {
5     var $container = $('<div>')
6       .attr('class', 'control-key');
7
8     $('<a>')
9       .attr('class', 'control-button')
10       .attr('href', '#')
11       .attr('title', I18n.t('javascripts.key.tooltip'))
12       .html('<span class="icon key"></span>')
13       .on('click', toggle)
14       .appendTo($container);
15
16     var $ui = $('<div>')
17       .attr('class', 'key-ui');
18
19     $('<header>')
20       .attr('class', 'sidebar_heading')
21       .appendTo($ui)
22       .append(
23         $('<a>')
24           .text(I18n.t('javascripts.close'))
25           .attr('class', 'sidebar_close')
26           .attr('href', '#')
27           .bind('click', toggle))
28       .append(
29         $('<h4>')
30           .text(I18n.t('javascripts.key.title')));
31
32     var $section = $('<section>')
33       .appendTo($ui);
34
35     options.sidebar.addPane($ui);
36
37     $ui
38       .on('show', shown)
39       .on('hide', hidden);
40
41     function shown() {
42       map.on('zoomend baselayerchange', update);
43       $section.load('/key', update);
44     }
45
46     function hidden() {
47       map.off('zoomend baselayerchange', update);
48     }
49
50     function toggle(e) {
51       e.stopPropagation();
52       e.preventDefault();
53       options.sidebar.togglePane($ui);
54     }
55
56     function update() {
57       var layer = map.getMapBaseLayerId(),
58         zoom = map.getZoom();
59
60       $('.mapkey-table-entry').each(function () {
61         var data = $(this).data();
62         if (layer == data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {
63           $(this).show();
64         } else {
65           $(this).hide();
66         }
67       });
68     }
69
70     return $container[0];
71   };
72
73   return control;
74 };