Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5416'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 19, 2024
2 parents 1c2a7b0 + 2ba8547 commit 0434bee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
35 changes: 13 additions & 22 deletions app/assets/javascripts/leaflet.share.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ L.OSM.share = function (options) {
$("<div>")
.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(
$("<ul>").append(
map.baseLayers
.filter(layer => layer.options.canDownloadImage)
.map(layer => $("<li>").text(layer.options.name))))
.appendTo($imageSection);

$form = $("<form>")
Expand Down Expand Up @@ -338,7 +343,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")
Expand Down Expand Up @@ -411,34 +416,20 @@ 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);
$("#mapnik_lat").val(map.getCenter().lat);
$("#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() {
Expand Down
3 changes: 3 additions & 0 deletions config/layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
layerId: "mapnik"
nameId: "standard"
canEmbed: true
canDownloadImage: true
credit:
id: "make_a_donation"
href: "https://supporting.openstreetmap.org"
Expand All @@ -29,6 +30,7 @@
nameId: "cycle_map"
apiKeyId: "THUNDERFOREST_KEY"
canEmbed: true
canDownloadImage: true
credit:
id: "thunderforest_credit"
children:
Expand All @@ -42,6 +44,7 @@
nameId: "transport_map"
apiKeyId: "THUNDERFOREST_KEY"
canEmbed: true
canDownloadImage: true
credit:
id: "thunderforest_credit"
children:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0434bee

Please sign in to comment.