1 L.OSM.key = function (options) {
2 var control = L.control(options);
4 control.onAdd = function (map) {
5 var $container = $('<div>')
6 .attr('class', 'control-key');
9 .attr('class', 'control-button')
11 .html('<span class="icon key"></span>')
13 .appendTo($container);
16 .attr('class', 'key-ui');
19 .attr('class', 'sidebar_heading')
23 .text(I18n.t('javascripts.close'))
24 .attr('class', 'icon close')
25 .bind('click', toggle))
28 .text(I18n.t('javascripts.key.title')));
30 var $section = $('<div>')
31 .attr('class', 'section')
34 options.sidebar.addPane($ui);
40 map.on('baselayerchange', updateButton);
45 map.on('zoomend baselayerchange', update);
46 $section.load('/key', update);
50 map.off('zoomend baselayerchange', update);
56 if (!button.hasClass('disabled')) {
57 options.sidebar.togglePane($ui, button);
61 function updateButton() {
62 var disabled = map.getMapBaseLayerId() !== 'mapnik'
64 .toggleClass('disabled', disabled)
65 .attr('data-original-title', I18n.t(disabled ?
66 'javascripts.key.tooltip_disabled' :
67 'javascripts.key.tooltip'))
71 var layer = map.getMapBaseLayerId(),
74 $('.mapkey-table-entry').each(function () {
75 var data = $(this).data();
76 if (layer == data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {