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 mb-0'>")
12 .appendTo(baseSection);
14 layers.forEach(function (layer) {
16 .attr("class", "rounded-3")
17 .appendTo(baseLayers);
19 if (map.hasLayer(layer)) {
20 item.addClass("active");
26 map.whenReady(function () {
27 var miniMap = L.map(div[0], { attributionControl: false, zoomControl: false, keyboard: false })
28 .addLayer(new layer.constructor({ apikey: layer.options.apikey }));
30 miniMap.dragging.disable();
31 miniMap.touchZoom.disable();
32 miniMap.doubleClickZoom.disable();
33 miniMap.scrollWheelZoom.disable();
40 miniMap.invalidateSize();
41 setView({ animate: false });
42 map.on("moveend", moved);
46 map.off("moveend", moved);
53 function setView(options) {
54 miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0), options);
58 var label = $("<label>")
61 var input = $("<input>")
62 .attr("type", "radio")
63 .prop("checked", map.hasLayer(layer))
66 label.append(layer.options.name);
68 item.on("click", function () {
69 layers.forEach(function (other) {
70 if (other === layer) {
73 map.removeLayer(other);
76 map.fire("baselayerchange", { layer: layer });
79 item.on("dblclick", toggle);
81 map.on("layeradd layerremove", function () {
82 item.toggleClass("active", map.hasLayer(layer));
83 input.prop("checked", map.hasLayer(layer));
87 if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
88 var overlaySection = $("<div>")
89 .attr("class", "section overlay-layers")
93 .text(I18n.t("javascripts.map.layers.overlays"))
94 .attr("class", "text-muted")
95 .appendTo(overlaySection);
97 var overlays = $("<ul class='list-unstyled form-check'>")
98 .appendTo(overlaySection);
100 var addOverlay = function (layer, name, maxArea) {
104 if (name === "notes" || name === "data") {
106 .attr("title", I18n.t("javascripts.site.map_" + name + "_zoom_in_tooltip"))
110 var label = $("<label>")
111 .attr("class", "form-check-label")
114 var checked = map.hasLayer(layer);
116 var input = $("<input>")
117 .attr("type", "checkbox")
118 .attr("class", "form-check-input")
119 .prop("checked", checked)
122 label.append(I18n.t("javascripts.map.layers." + name));
124 input.on("change", function () {
125 checked = input.is(":checked");
129 map.removeLayer(layer);
131 map.fire("overlaylayerchange", { layer: layer });
134 map.on("layeradd layerremove", function () {
135 input.prop("checked", map.hasLayer(layer));
138 map.on("zoomend", function () {
139 var disabled = map.getBounds().getSize() >= maxArea;
140 $(input).prop("disabled", disabled);
142 if (disabled && $(input).is(":checked")) {
143 $(input).prop("checked", false)
146 } else if (!disabled && !$(input).is(":checked") && checked) {
147 $(input).prop("checked", true)
152 .attr("class", disabled ? "disabled" : "")
153 .tooltip(disabled ? "enable" : "disable");
157 addOverlay(map.noteLayer, "notes", OSM.MAX_NOTE_REQUEST_AREA);
158 addOverlay(map.dataLayer, "data", OSM.MAX_REQUEST_AREA);
159 addOverlay(map.gpsLayer, "gps", Number.POSITIVE_INFINITY);