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) {
103 if (name === "notes" || name === "data") {
105 .attr("title", I18n.t("javascripts.site.map_" + name + "_zoom_in_tooltip"))
109 var label = $("<label>")
110 .attr("class", "form-check-label")
113 var checked = map.hasLayer(layer);
115 var input = $("<input>")
116 .attr("type", "checkbox")
117 .attr("class", "form-check-input")
118 .prop("checked", checked)
121 label.append(I18n.t("javascripts.map.layers." + name));
123 input.on("change", function () {
124 checked = input.is(":checked");
128 map.removeLayer(layer);
130 map.fire("overlaylayerchange", { layer: layer });
133 map.on("layeradd layerremove", function () {
134 input.prop("checked", map.hasLayer(layer));
137 map.on("zoomend", function () {
138 var disabled = map.getBounds().getSize() >= maxArea;
139 $(input).prop("disabled", disabled);
141 if (disabled && $(input).is(":checked")) {
142 $(input).prop("checked", false)
145 } else if (!disabled && !$(input).is(":checked") && checked) {
146 $(input).prop("checked", true)
151 .attr("class", disabled ? "disabled" : "")
152 .tooltip(disabled ? "enable" : "disable");
156 addOverlay(map.noteLayer, "notes", OSM.MAX_NOTE_REQUEST_AREA);
157 addOverlay(map.dataLayer, "data", OSM.MAX_REQUEST_AREA);
158 addOverlay(map.gpsLayer, "gps", Number.POSITIVE_INFINITY);