X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ef73cc1f574124b10cda75188aa542d9f4d802bb..507c395f51c20c3c0d5375313ea1ca0ed4156c75:/app/assets/javascripts/leaflet.layers.js diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 15f114a5c..35b958c7a 100644 --- a/app/assets/javascripts/leaflet.layers.js +++ b/app/assets/javascripts/leaflet.layers.js @@ -1,92 +1,157 @@ -//= require templates/map/layers +L.OSM.layers = function (options) { + var control = L.OSM.sidebarPane(options, "layers", "javascripts.map.layers.title", "javascripts.map.layers.header"); -L.OSM.Layers = L.Control.extend({ - onAdd: function (map) { - this._map = map; - this._initLayout(map); - return this._container; - }, + control.onAddPane = function (map, button, $ui, toggle) { + var layers = options.layers; - _initLayout: function () { - var className = 'leaflet-control-map-ui', - container = this._container = L.DomUtil.create('div', className); + var baseSection = $("
") + .attr("class", "base-layers d-grid gap-3 p-3 border-bottom border-secondary-subtle") + .appendTo($ui); - var link = L.DomUtil.create('a', 'control-button', container); - link.innerHTML = ""; - link.href = '#'; - link.title = 'Layers'; + layers.forEach(function (layer, i) { + var id = "map-ui-layer-" + i; - this._ui = $(L.DomUtil.create('div', 'layers-ui', this.options.uiPane)) - .html(JST["templates/map/layers"]()); + var buttonContainer = $("
") + .appendTo(baseSection); - var list = this._ui.find('.base-layers ul'); + var mapContainer = $("
") + .appendTo(buttonContainer); - this.options.layers.forEach(function(layer) { - var item = $('
  • ') - .appendTo(list); + var input = $("") + .prop("id", id) + .prop("checked", map.hasLayer(layer)) + .appendTo(buttonContainer); - if (this._map.hasLayer(layer)) { - item.addClass('active'); - } + var item = $("