1 L.OSM.layers = function(options) {
2 var control = L.control(options);
4 control.onAdd = function (map) {
5 var layers = options.layers;
7 var $container = $('<div>')
8 .attr('class', 'control-layers');
11 .attr('class', 'control-button')
13 .attr('title', 'Layers')
14 .html('<span class="icon layers"></span>')
16 .appendTo($container);
19 .attr('class', 'layers-ui');
26 .attr('class', 'close-button')
28 .bind('click', toggle))
31 .text(I18n.t('javascripts.map.layers.header')));
33 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
34 var overlaySection = $('<section>')
35 .addClass('overlay-layers')
39 .text(I18n.t('javascripts.map.layers.overlays'))
40 .appendTo(overlaySection);
43 .appendTo(overlaySection);
45 function addOverlay(layer, name) {
49 var label = $('<label>')
52 var input = $('<input>')
53 .attr('type', 'checkbox')
54 .prop('checked', map.hasLayer(layer))
59 input.on('change', function() {
60 if (input.is(':checked')) {
63 map.removeLayer(layer);
67 map.on('layeradd layerremove', function() {
68 input.prop('checked', map.hasLayer(layer));
72 addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes'));
73 addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data'));
76 var baseSection = $('<section>')
77 .addClass('base-layers')
81 .text(I18n.t('javascripts.map.layers.base'))
82 .appendTo(baseSection);
85 .appendTo(baseSection);
87 layers.forEach(function(layer) {
91 if (map.hasLayer(layer)) {
92 item.addClass('active');
98 map.whenReady(function() {
99 var miniMap = L.map(div[0], {attributionControl: false, zoomControl: false})
100 .addLayer(new layer.constructor());
102 miniMap.dragging.disable();
103 miniMap.touchZoom.disable();
104 miniMap.doubleClickZoom.disable();
105 miniMap.scrollWheelZoom.disable();
112 miniMap.invalidateSize();
114 map.on('moveend', setView);
118 map.off('moveend', setView);
122 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0));
126 var label = $('<label>')
127 .text(layer.options.name)
130 item.on('click', function() {
131 layers.forEach(function(other) {
132 if (other === layer) {
135 map.removeLayer(other);
140 map.on('layeradd layerremove', function() {
141 item.toggleClass('active', map.hasLayer(layer));
145 options.sidebar.addPane($ui);
150 options.sidebar.togglePane($ui);
153 return $container[0];