+L.OSM.layers = function(options) {
+ var control = L.control(options);
+
+ control.onAdd = function (map) {
+ var layers = options.layers;
+
+ var $container = $('<div>')
+ .attr('class', 'control-layers');
+
+ var link = $('<a>')
+ .attr('class', 'control-button')
+ .attr('href', '#')
+ .attr('title', 'Layers')
+ .html('<span class="icon layers"></span>')
+ .on('click', toggle)
+ .appendTo($container);
+
+ var $ui = $('<div>')
+ .attr('class', 'layers-ui');
+
+ $('<section>')
+ .appendTo($ui)
+ .append(
+ $('<a>')
+ .html('»')
+ .attr('class', 'close-button')
+ .attr('href', '#')
+ .bind('click', toggle))
+ .append(
+ $('<h2>')
+ .text(I18n.t('javascripts.map.layers.header')));
+
+ if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
+ var overlaySection = $('<section>')
+ .addClass('overlay-layers')
+ .appendTo($ui);
+
+ $('<p>')
+ .text(I18n.t('javascripts.map.layers.overlays'))
+ .appendTo(overlaySection);
+
+ var list = $('<ul>')
+ .appendTo(overlaySection);
+
+ function addOverlay(layer, name) {
+ var item = $('<li>')
+ .appendTo(list);
+
+ var label = $('<label>')
+ .appendTo(item);
+
+ var input = $('<input>')
+ .attr('type', 'checkbox')
+ .prop('checked', map.hasLayer(layer))
+ .appendTo(label);
+
+ label.append(name);
+
+ input.on('change', function() {
+ if (input.is(':checked')) {
+ map.addLayer(layer);
+ } else {
+ map.removeLayer(layer);
+ }
+ });