+ });
+
+ if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
+ var overlaySection = $("<div>")
+ .attr("class", "section overlay-layers")
+ .appendTo($ui);
+
+ $("<p>")
+ .text(I18n.t("javascripts.map.layers.overlays"))
+ .attr("class", "text-muted")
+ .appendTo(overlaySection);
+
+ var overlays = $("<ul class='list-unstyled form-check'>")
+ .appendTo(overlaySection);
+
+ var addOverlay = function (layer, name, maxArea) {
+ var item = $("<li>")
+ .tooltip({
+ placement: "top"
+ })
+ .appendTo(overlays);
+
+ var label = $("<label>")
+ .attr("class", "form-check-label")
+ .appendTo(item);
+
+ var checked = map.hasLayer(layer);
+
+ var input = $("<input>")
+ .attr("type", "checkbox")
+ .attr("class", "form-check-input")
+ .prop("checked", checked)
+ .appendTo(label);
+
+ label.append(I18n.t("javascripts.map.layers." + name));
+
+ input.on("change", function () {
+ checked = input.is(":checked");
+ if (checked) {
+ map.addLayer(layer);
+ } else {
+ map.removeLayer(layer);
+ }
+ map.fire("overlaylayerchange", { layer: layer });
+ });
+
+ map.on("layeradd layerremove", function () {
+ input.prop("checked", map.hasLayer(layer));
+ });
+
+ map.on("zoomend", function () {
+ var disabled = map.getBounds().getSize() >= maxArea;
+ $(input).prop("disabled", disabled);
+
+ if (disabled && $(input).is(":checked")) {
+ $(input).prop("checked", false)
+ .trigger("change");
+ checked = true;
+ } else if (!disabled && !$(input).is(":checked") && checked) {
+ $(input).prop("checked", true)
+ .trigger("change");
+ }