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 .addLayer(new layer.constructor);
94 miniMap.dragging.disable();
95 miniMap.touchZoom.disable();
96 miniMap.doubleClickZoom.disable();
97 miniMap.scrollWheelZoom.disable();
104 miniMap.invalidateSize();
106 map.on('moveend', setView);
110 map.off('moveend', setView);
114 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0));
118 var label = $('<label>')
119 .text(layer.options.name)
122 item.on('click', function() {
123 layers.forEach(function(other) {
124 if (other === layer) {
127 map.removeLayer(other);
132 map.on('layeradd layerremove', function() {
133 item.toggleClass('active', map.hasLayer(layer));
137 options.sidebar.addPane($ui);
142 options.sidebar.togglePane($ui);
145 return $container[0];