Skip to content

Commit

Permalink
Merge pull request #5388 from AntonKhorev/map-layer-can-embed
Browse files Browse the repository at this point in the history
Add 'canEmbed' layer option
  • Loading branch information
gravitystorm authored Dec 18, 2024
2 parents b32021b + 8a8c251 commit 4d4b798
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/leaflet.key.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ L.OSM.key = function (options) {
}

function update() {
var layer = map.getMapBaseLayerId(),
var layerId = map.getMapBaseLayerId(),
zoom = map.getZoom();

$(".mapkey-table-entry").each(function () {
var data = $(this).data();
$(this).toggle(
layer === data.layer &&
layerId === data.layer &&
(!data.zoomMin || zoom >= data.zoomMin) &&
(!data.zoomMax || zoom <= data.zoomMax)
);
Expand Down
13 changes: 8 additions & 5 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ L.OSM.Map = L.Map.extend({
},

getMapBaseLayerId: function () {
var baseLayerId;
this.eachLayer(function (layer) {
if (layer.options && layer.options.layerId) baseLayerId = layer.options.layerId;
});
return baseLayerId;
const layer = this.getMapBaseLayer();
if (layer) return layer.options.layerId;
},

getMapBaseLayer: function () {
for (const layer of this.baseLayers) {
if (this.hasLayer(layer)) return layer;
}
},

getUrl: function (marker) {
Expand Down
9 changes: 5 additions & 4 deletions app/assets/javascripts/leaflet.share.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ L.OSM.share = function (options) {
}

function update() {
var canEmbed = map.getMapBaseLayerId() !== "tracestracktopo";
const layer = map.getMapBaseLayer();
var canEmbed = layer && layer.options.canEmbed;
var bounds = map.getBounds();

$("#link_marker")
Expand Down Expand Up @@ -410,15 +411,15 @@ L.OSM.share = function (options) {
$("#mapnik_image_width").text(mapWidth);
$("#mapnik_image_height").text(mapHeight);

const layer = map.getMapBaseLayerId();
const layerId = map.getMapBaseLayerId();
const layerKeys = new Map([
["mapnik", "standard"],
["cyclemap", "cycle_map"],
["transportmap", "transport_map"]
]);

$("#mapnik_image_layer").text(layerKeys.has(layer) ? I18n.t(`javascripts.map.base.${layerKeys.get(layer)}`) : "");
$("#map_format").val(layer);
$("#mapnik_image_layer").text(layerKeys.has(layerId) ? I18n.t(`javascripts.map.base.${layerKeys.get(layerId)}`) : "");
$("#map_format").val(layerId);

$("#map_zoom").val(map.getZoom());
$("#mapnik_lon").val(map.getCenter().lng);
Expand Down
5 changes: 5 additions & 0 deletions config/layers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
code: "M"
layerId: "mapnik"
nameId: "standard"
canEmbed: true
credit:
id: "make_a_donation"
href: "https://supporting.openstreetmap.org"
Expand All @@ -11,6 +12,7 @@
code: "Y"
layerId: "cyclosm"
nameId: "cyclosm"
canEmbed: true
credit:
id: "cyclosm_credit"
children:
Expand All @@ -26,6 +28,7 @@
layerId: "cyclemap"
nameId: "cycle_map"
apiKeyId: "THUNDERFOREST_KEY"
canEmbed: true
credit:
id: "thunderforest_credit"
children:
Expand All @@ -38,6 +41,7 @@
layerId: "transportmap"
nameId: "transport_map"
apiKeyId: "THUNDERFOREST_KEY"
canEmbed: true
credit:
id: "thunderforest_credit"
children:
Expand All @@ -61,6 +65,7 @@
code: "H"
layerId: "hot"
nameId: "hot"
canEmbed: true
credit:
id: "hotosm_credit"
children:
Expand Down

0 comments on commit 4d4b798

Please sign in to comment.