]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.key.js
Fix export
[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', 'layers-ui')
18       .appendTo(options.uiPane);
19
20     $('<h2>')
21       .text(I18n.t('javascripts.key.title'))
22       .appendTo($ui);
23
24     var $section = $('<section>')
25       .appendTo($ui);
26
27     function toggle(e) {
28       e.stopPropagation();
29       e.preventDefault();
30
31       var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
32
33       if ($ui.is(':visible')) {
34         $(options.uiPane).hide();
35         controlContainer.css({paddingRight: '0'});
36         map.off("zoomend baselayerchange", update);
37       } else {
38         $(options.uiPane).show();
39         controlContainer.css({paddingRight: '200px'});
40         map.on("zoomend baselayerchange", update);
41         $section.load('/key', update);
42       }
43     }
44
45     function update() {
46       var mapLayer = getMapBaseLayerId(map),
47         mapZoom = map.getZoom();
48
49       $(".mapkey-table-entry").each(function () {
50         var data = $(this).data();
51
52         if (mapLayer == data.layer && mapZoom >= data.zoomMin && mapZoom <= data.zoomMax) {
53           $(this).show();
54         } else {
55           $(this).hide();
56         }
57       });
58     }
59
60     return $container[0];
61   };
62
63   return control;
64 };