Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'canDownloadImage' layer option #5416

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading