-L.OSM.Layers = L.Control.extend({
- onAdd: function (map) {
- this._map = map;
- this._initLayout();
- return this.$container[0];
- },
-
- _initLayout: function () {
- var map = this._map,
- layers = this.options.layers;
-
- this.$container = $('<div>')
- .attr('class', 'control-layers');
-
- var link = $('<a>')
- .attr('class', 'control-button')
- .attr('href', '#')
- .attr('title', 'Layers')
- .html('<span class="icon layers"></span>')
- .appendTo(this.$container);
-
- if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
- this.$ui = $('<div>')
- .attr('class', 'layers-ui')
- .appendTo(this.options.uiPane);
-
- $('<h2>')
- .text(I18n.t('javascripts.map.layers.header'))
- .appendTo(this.$ui);
-
- var overlaySection = $('<section>')
- .addClass('overlay-layers')
- .appendTo(this.$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);
- }
- });
-
- map.on('layeradd layerremove', function() {
- input.prop('checked', map.hasLayer(layer));
- });
- }
-
- addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes'));
- addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data'));
- }
-
- var baseSection = $('<section>')
- .addClass('base-layers')
- .appendTo(this.$ui);
-
- $('<p>')
- .text(I18n.t('javascripts.map.layers.base'))
- .appendTo(baseSection);
-
- list = $('<ul>')
+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 button = $("<a>")
+ .attr("class", "control-button")
+ .attr("href", "#")
+ .attr("title", I18n.t("javascripts.map.layers.title"))
+ .html("<span class=\"icon layers\"></span>")
+ .on("click", toggle)
+ .appendTo($container);
+
+ var $ui = $("<div>")
+ .attr("class", "layers-ui");
+
+ $("<div>")
+ .attr("class", "sidebar_heading")
+ .appendTo($ui)
+ .append(
+ $("<span>")
+ .text(I18n.t("javascripts.close"))
+ .attr("class", "icon close")
+ .bind("click", toggle))
+ .append(
+ $("<h4>")
+ .text(I18n.t("javascripts.map.layers.header")));
+
+ var baseSection = $("<div>")
+ .attr("class", "section base-layers")
+ .appendTo($ui);
+
+ var baseLayers = $("<ul class='list-unstyled'>")