1 L.OSM.layers = function (options) {
2 var control = L.OSM.sidebarPane(options, "layers", "javascripts.map.layers.title", "javascripts.map.layers.header");
4 control.onAddPane = function (map, button, $ui, toggle) {
5 var layers = options.layers;
7 var baseSection = $("<div>")
8 .attr("class", "section base-layers")
11 var baseLayers = $("<ul class='list-unstyled'>")
12 .appendTo(baseSection);
14 layers.forEach(function (layer) {
16 .appendTo(baseLayers);
18 if (map.hasLayer(layer)) {
19 item.addClass("active");
25 map.whenReady(function () {
26 var miniMap = L.map(div[0], { attributionControl: false, zoomControl: false, keyboard: false })
27 .addLayer(new layer.constructor({ apikey: layer.options.apikey }));
29 miniMap.dragging.disable();
30 miniMap.touchZoom.disable();
31 miniMap.doubleClickZoom.disable();
32 miniMap.scrollWheelZoom.disable();
39 miniMap.invalidateSize();
40 setView({ animate: false });
41 map.on("moveend", moved);
45 map.off("moveend", moved);
52 function setView(options) {
53 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0), options);
57 var label = $("<label>")
60 var input = $("<input>")
61 .attr("type", "radio")
62 .prop("checked", map.hasLayer(layer))
65 label.append(layer.options.name);
67 item.on("click", function () {
68 layers.forEach(function (other) {
69 if (other === layer) {
72 map.removeLayer(other);
75 map.fire("baselayerchange", { layer: layer });
78 item.on("dblclick", toggle);
80 map.on("layeradd layerremove", function () {
81 item.toggleClass("active", map.hasLayer(layer));
82 input.prop("checked", map.hasLayer(layer));
86 if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
87 var overlaySection = $("<div>")
88 .attr("class", "section overlay-layers")
92 .text(I18n.t("javascripts.map.layers.overlays"))
93 .attr("class", "text-muted")
94 .appendTo(overlaySection);
96 var overlays = $("<ul class='list-unstyled form-check'>")
97 .appendTo(overlaySection);
99 var addOverlay = function (layer, name, maxArea) {
106 var label = $("<label>")
107 .attr("class", "form-check-label")
110 var checked = map.hasLayer(layer);
112 var input = $("<input>")
113 .attr("type", "checkbox")
114 .attr("class", "form-check-input")
115 .prop("checked", checked)
118 label.append(I18n.t("javascripts.map.layers." + name));
120 input.on("change", function () {
121 checked = input.is(":checked");
125 map.removeLayer(layer);
127 map.fire("overlaylayerchange", { layer: layer });
130 map.on("layeradd layerremove", function () {
131 input.prop("checked", map.hasLayer(layer));
134 map.on("zoomend", function () {
135 var disabled = map.getBounds().getSize() >= maxArea;
136 $(input).prop("disabled", disabled);
138 if (disabled && $(input).is(":checked")) {
139 $(input).prop("checked", false)
142 } else if (!disabled && !$(input).is(":checked") && checked) {
143 $(input).prop("checked", true)
147 $(item).attr("class", disabled ? "disabled" : "");
148 item.attr("data-bs-original-title", disabled ?
149 I18n.t("javascripts.site.map_" + name + "_zoom_in_tooltip") : "");
153 addOverlay(map.noteLayer, "notes", OSM.MAX_NOTE_REQUEST_AREA);
154 addOverlay(map.dataLayer, "data", OSM.MAX_REQUEST_AREA);
155 addOverlay(map.gpsLayer, "gps", Number.POSITIVE_INFINITY);