X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/33aa0a6e454fb2d43b8ccc07395abf0864d47b66..dbc3ab53e76f74306b2fe9722e5e77b52a45cf06:/app/assets/javascripts/leaflet.layers.js
diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js
index 6c83f0c2f..82efab506 100644
--- a/app/assets/javascripts/leaflet.layers.js
+++ b/app/assets/javascripts/leaflet.layers.js
@@ -1,47 +1,157 @@
-//= require templates/map/layers
-
-L.OSM.Layers = L.Control.extend({
- onAdd: function (map) {
- this._initLayout(map);
- return this._container;
- },
-
- _initLayout: function (map) {
- var className = 'leaflet-control-map-ui',
- container = this._container = L.DomUtil.create('div', className);
-
- var link = this._layersLink = L.DomUtil.create('a', 'leaflet-map-ui-layers', container);
- link.href = '#';
- link.title = 'Layers';
-
- this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
-
- L.DomEvent
- .on(this._uiPane, 'click', L.DomEvent.stopPropagation)
- .on(this._uiPane, 'click', L.DomEvent.preventDefault)
- .on(this._uiPane, 'dblclick', L.DomEvent.preventDefault);
-
- $(link).on('click', $.proxy(this.toggleLayers, this));
- },
-
- toggleLayers: function (e) {
- e.stopPropagation();
- e.preventDefault();
-
- var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
-
- if ($(this._uiPane).is(':visible')) {
- $(this._uiPane).hide();
- controlContainer.css({paddingRight: '0'});
- } else {
- $(this._uiPane)
- .show()
- .html(JST["templates/map/layers"]({layers: this.options.layers}));
- controlContainer.css({paddingRight: '200px'});
+L.OSM.layers = function (options) {
+ var control = L.OSM.sidebarPane(options, "layers", "javascripts.map.layers.title", "javascripts.map.layers.header");
+
+ control.onAddPane = function (map, button, $ui, toggle) {
+ var layers = options.layers;
+
+ var baseSection = $("
")
+ .attr("class", "base-layers d-grid gap-3 p-3 border-bottom border-secondary-subtle")
+ .appendTo($ui);
+
+ layers.forEach(function (layer, i) {
+ var id = "map-ui-layer-" + i;
+
+ var buttonContainer = $("
")
+ .appendTo(baseSection);
+
+ var mapContainer = $("
")
+ .appendTo(buttonContainer);
+
+ var input = $("
")
+ .prop("id", id)
+ .prop("checked", map.hasLayer(layer))
+ .appendTo(buttonContainer);
+
+ var item = $("