1 L.OSM.layers = function (options) {
 
   2   const control = L.OSM.sidebarPane(options, "layers", "javascripts.map.layers.title", "javascripts.map.layers.header");
 
   4   control.onAddPane = function (map, button, $ui, toggle) {
 
   5     const layers = options.layers;
 
   7     control.onContentLoaded = function () {
 
   8       $ui.find(".base-layers>div").each(initBaseLayer);
 
  11     control.loadContent();
 
  13     function initBaseLayer() {
 
  14       const [container, input, item] = this.children;
 
  15       const layer = layers.find(l => l.options.layerId === container.dataset.layer);
 
  16       input.checked = map.hasLayer(layer);
 
  18       map.whenReady(function () {
 
  19         const miniMap = L.map(container, { attributionControl: false, zoomControl: false, keyboard: false })
 
  20           .addLayer(new layer.constructor(layer.options));
 
  22         miniMap.dragging.disable();
 
  23         miniMap.touchZoom.disable();
 
  24         miniMap.doubleClickZoom.disable();
 
  25         miniMap.scrollWheelZoom.disable();
 
  32           miniMap.invalidateSize();
 
  33           setView({ animate: false });
 
  34           map.on("moveend", moved);
 
  38           map.off("moveend", moved);
 
  45         function setView(options) {
 
  46           miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0), options);
 
  50       $(input).on("click", function () {
 
  51         for (const other of layers) {
 
  52           if (other !== layer) {
 
  53             map.removeLayer(other);
 
  59       $(item).on("dblclick", toggle);
 
  61       map.on("baselayerchange", function () {
 
  62         input.checked = map.hasLayer(layer);
 
  66     function initOverlays() {
 
  67       $ui.find(".overlay-layers div.form-check").each(function () {
 
  69         const layer = map[this.dataset.layerId];
 
  70         const input = this.firstElementChild.firstElementChild;
 
  71         $(item).tooltip("disable");
 
  73         let checked = map.hasLayer(layer);
 
  75         input.checked = checked;
 
  77         $(input).on("change", function () {
 
  78           checked = input.checked;
 
  79           layer.cancelLoading?.();
 
  84             map.removeLayer(layer);
 
  85             $(`#layers-${name}-loading`).remove();
 
  89         map.on("overlayadd overlayremove", function () {
 
  90           input.checked = map.hasLayer(layer);
 
  93         map.on("zoomend", function () {
 
  94           const disabled = map.getBounds().getSize() >= item.dataset.maxArea;
 
  95           input.disabled = disabled;
 
  97           if (disabled && input.checked) {
 
 100           } else if (!disabled && !input.checked && checked) {
 
 104           item.classList.toggle("disabled", disabled);
 
 105           $(item).tooltip(disabled ? "enable" : "disable");