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', 'sidebar_close')
26 .bind('click', toggle))
29 .text(I18n.t('javascripts.key.title')));
31 var $section = $('<div>')
32 .attr('class', 'section')
35 options.sidebar.addPane($ui);
41 map.on('baselayerchange', updateButton);
46 map.on('zoomend baselayerchange', update);
47 $section.load('/key', update);
51 map.off('zoomend baselayerchange', update);
57 if (!button.hasClass('disabled')) {
58 options.sidebar.togglePane($ui, button);
62 function updateButton() {
63 var disabled = map.getMapBaseLayerId() !== 'mapnik'
65 .toggleClass('disabled', disabled)
66 .attr('data-original-title', I18n.t(disabled ?
67 'javascripts.key.tooltip_disabled' :
68 'javascripts.key.tooltip'))
72 var layer = map.getMapBaseLayerId(),
75 $('.mapkey-table-entry').each(function () {
76 var data = $(this).data();
77 if (layer == data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {