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');
22 .text(I18n.t('javascripts.map.layers.header'))
25 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
26 var overlaySection = $('<section>')
27 .addClass('overlay-layers')
31 .text(I18n.t('javascripts.map.layers.overlays'))
32 .appendTo(overlaySection);
35 .appendTo(overlaySection);
37 function addOverlay(layer, name) {
41 var label = $('<label>')
44 var input = $('<input>')
45 .attr('type', 'checkbox')
46 .prop('checked', map.hasLayer(layer))
51 input.on('change', function() {
52 if (input.is(':checked')) {
55 map.removeLayer(layer);
59 map.on('layeradd layerremove', function() {
60 input.prop('checked', map.hasLayer(layer));
64 addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes'));
65 addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data'));
68 var baseSection = $('<section>')
69 .addClass('base-layers')
73 .text(I18n.t('javascripts.map.layers.base'))
74 .appendTo(baseSection);
77 .appendTo(baseSection);
79 layers.forEach(function(layer) {
83 if (map.hasLayer(layer)) {
84 item.addClass('active');
90 map.whenReady(function() {
91 var miniMap = L.map(div[0], {attributionControl: false, zoomControl: false})
92 .setView(map.getCenter(), Math.max(map.getZoom() - 2, 0))
93 .addLayer(new layer.constructor);
95 miniMap.dragging.disable();
96 miniMap.touchZoom.disable();
97 miniMap.doubleClickZoom.disable();
98 miniMap.scrollWheelZoom.disable();
100 map.on('moveend', function() {
101 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0));
104 div.data('map', miniMap);
107 var label = $('<label>')
108 .text(layer.options.name)
111 item.on('click', function() {
112 layers.forEach(function(other) {
113 if (other === layer) {
116 map.removeLayer(other);
121 map.on('layeradd layerremove', function() {
122 item.toggleClass('active', map.hasLayer(layer));
126 options.sidebar.addPane($ui);
132 $ui.find('.base-layers .leaflet-container').each(function() {
133 $(this).data('map').invalidateSize();
140 options.sidebar.togglePane($ui);
143 return $container[0];