X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ef73cc1f574124b10cda75188aa542d9f4d802bb..1e15b89f763d103cc33acbf5be21db912c080528:/app/assets/javascripts/leaflet.layers.js diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 15f114a5c..55d492b29 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 = $("