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 .attr('class', 'sidebar_heading')
26 .text(I18n.t('javascripts.close'))
27 .attr('class', 'sidebar_close')
29 .bind('click', toggle))
32 .text(I18n.t('javascripts.map.layers.header')));
34 var baseSection = $('<div>')
35 .attr('class', 'section base-layers')
39 .appendTo(baseSection);
41 layers.forEach(function(layer) {
45 if (map.hasLayer(layer)) {
46 item.addClass('active');
52 map.whenReady(function() {
53 var miniMap = L.map(div[0], {attributionControl: false, zoomControl: false})
54 .addLayer(new layer.constructor());
56 miniMap.dragging.disable();
57 miniMap.touchZoom.disable();
58 miniMap.doubleClickZoom.disable();
59 miniMap.scrollWheelZoom.disable();
66 miniMap.invalidateSize();
68 map.on('moveend', setView);
72 map.off('moveend', setView);
76 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0));
80 var label = $('<label>')
83 var input = $('<input>')
84 .attr('type', 'radio')
85 .prop('checked', map.hasLayer(layer))
88 label.append(layer.options.name);
90 item.on('click', function() {
91 layers.forEach(function(other) {
92 if (other === layer) {
95 map.removeLayer(other);
98 map.fire('baselayerchange', {layer: layer});
101 map.on('layeradd layerremove', function() {
102 item.toggleClass('active', map.hasLayer(layer));
103 input.prop('checked', map.hasLayer(layer));
107 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
108 var overlaySection = $('<div>')
109 .attr('class', 'section overlay-layers')
113 .text(I18n.t('javascripts.map.layers.overlays'))
114 .appendTo(overlaySection);
117 .appendTo(overlaySection);
119 function addOverlay(layer, name) {
123 var label = $('<label>')
126 var input = $('<input>')
127 .attr('type', 'checkbox')
128 .prop('checked', map.hasLayer(layer))
133 input.on('change', function() {
134 if (input.is(':checked')) {
137 map.removeLayer(layer);
141 map.on('layeradd layerremove', function() {
142 input.prop('checked', map.hasLayer(layer));
146 addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes'));
147 addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data'));
150 options.sidebar.addPane($ui);
155 options.sidebar.togglePane($ui);
158 return $container[0];