From 6c1704b24587537cb7ebd3844db2500052523c6c Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 18 Dec 2024 19:41:25 +0300 Subject: [PATCH 1/2] Add 'canDownloadImage' layer option --- app/assets/javascripts/leaflet.share.js | 28 +++++++------------------ config/layers.yml | 3 +++ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 7b0b5ef028..2faa5a2a1f 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -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() { diff --git a/config/layers.yml b/config/layers.yml index 6a470687a2..98ef2e6915 100644 --- a/config/layers.yml +++ b/config/layers.yml @@ -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: From 2ba85472be499331cc0e9d7e65c124c409819baa Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 18 Dec 2024 19:55:45 +0300 Subject: [PATCH 2/2] Change image download warning message to a list --- app/assets/javascripts/leaflet.share.js | 7 ++++++- config/locales/en.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 2faa5a2a1f..7713a6b147 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -130,7 +130,12 @@ L.OSM.share = function (options) { $("
") .attr("id", "export-warning") .attr("class", "text-body-secondary") - .text(I18n.t("javascripts.share.only_standard_layer")) + .text(I18n.t("javascripts.share.only_layers_exported_as_image")) + .append( + $("
    ").append( + map.baseLayers + .filter(layer => layer.options.canDownloadImage) + .map(layer => $("
  • ").text(layer.options.name)))) .appendTo($imageSection); $form = $("
    ") diff --git a/config/locales/en.yml b/config/locales/en.yml index 0e7946c0fa..7faf3bebcf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3105,7 +3105,7 @@ en: center_marker: "Center map on marker" paste_html: "Paste HTML to embed in website" view_larger_map: "View Larger Map" - only_standard_layer: "Only the Standard, Cycle Map and Transport layers can be exported as an image" + only_layers_exported_as_image: "Only the following layers can be exported as an image:" embed: report_problem: "Report a problem" key: