]> git.openstreetmap.org Git - rails.git/commitdiff
Add 'canDownloadImage' layer option
authorAnton Khorev <tony29@yandex.ru>
Wed, 18 Dec 2024 16:41:25 +0000 (19:41 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 19 Dec 2024 15:58:32 +0000 (18:58 +0300)
app/assets/javascripts/leaflet.share.js
config/layers.yml

index 7b0b5ef028001b14b842e139af76750e68c706a0..2faa5a2a1fa64f28cd6ab930d1525ccd0a327dea 100644 (file)
@@ -338,7 +338,7 @@ L.OSM.share = function (options) {
 
     function update() {
       const layer = map.getMapBaseLayer();
-      var canEmbed = layer && layer.options.canEmbed;
+      var canEmbed = Boolean(layer && layer.options.canEmbed);
       var bounds = map.getBounds();
 
       $("#link_marker")
@@ -411,15 +411,10 @@ L.OSM.share = function (options) {
       $("#mapnik_image_width").text(mapWidth);
       $("#mapnik_image_height").text(mapHeight);
 
-      const layerId = map.getMapBaseLayerId();
-      const layerKeys = new Map([
-        ["mapnik", "standard"],
-        ["cyclemap", "cycle_map"],
-        ["transportmap", "transport_map"]
-      ]);
+      const canDownloadImage = Boolean(layer && layer.options.canDownloadImage);
 
-      $("#mapnik_image_layer").text(layerKeys.has(layerId) ? I18n.t(`javascripts.map.base.${layerKeys.get(layerId)}`) : "");
-      $("#map_format").val(layerId);
+      $("#mapnik_image_layer").text(canDownloadImage ? layer.options.name : "");
+      $("#map_format").val(canDownloadImage ? layer.options.layerId : "");
 
       $("#map_zoom").val(map.getZoom());
       $("#mapnik_lon").val(map.getCenter().lng);
@@ -427,18 +422,9 @@ L.OSM.share = function (options) {
       $("#map_width").val(mapWidth);
       $("#map_height").val(mapHeight);
 
-      if (["cyclemap", "transportmap"].includes(map.getMapBaseLayerId())) {
-        $("#export-image").show();
-        $("#mapnik_scale_row").hide();
-        $("#export-warning").hide();
-      } else if (map.getMapBaseLayerId() === "mapnik") {
-        $("#export-image").show();
-        $("#mapnik_scale_row").show();
-        $("#export-warning").hide();
-      } else {
-        $("#export-image").hide();
-        $("#export-warning").show();
-      }
+      $("#export-image").toggle(canDownloadImage);
+      $("#export-warning").toggle(!canDownloadImage);
+      $("#mapnik_scale_row").toggle(canDownloadImage && layer.options.layerId === "mapnik");
     }
 
     function select() {
index 6a470687a22dfc7ee2478b982e6946e32b6f1b16..98ef2e691557d3264a9eed129345ad092d310c18 100644 (file)
@@ -3,6 +3,7 @@
   layerId: "mapnik"
   nameId: "standard"
   canEmbed: true
+  canDownloadImage: true
   credit:
     id: "make_a_donation"
     href: "https://supporting.openstreetmap.org"
@@ -29,6 +30,7 @@
   nameId: "cycle_map"
   apiKeyId: "THUNDERFOREST_KEY"
   canEmbed: true
+  canDownloadImage: true
   credit:
     id: "thunderforest_credit"
     children:
@@ -42,6 +44,7 @@
   nameId: "transport_map"
   apiKeyId: "THUNDERFOREST_KEY"
   canEmbed: true
+  canDownloadImage: true
   credit:
     id: "thunderforest_credit"
     children: