From de0bf2549978f0b517c06c3eadaa477b37433ea6 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 18 Dec 2024 18:28:18 +0300 Subject: [PATCH 1/3] Rename return values of getMapBaseLayerId() to layerId --- app/assets/javascripts/leaflet.key.js | 4 ++-- app/assets/javascripts/leaflet.share.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/leaflet.key.js b/app/assets/javascripts/leaflet.key.js index f89ae0c3d9..090583ced1 100644 --- a/app/assets/javascripts/leaflet.key.js +++ b/app/assets/javascripts/leaflet.key.js @@ -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) ); diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 40ba020e6c..f0d2781098 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -410,15 +410,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); From 2c84465cc2c131044cb290d596513723d4ce445a Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 10 Dec 2024 00:31:59 +0300 Subject: [PATCH 2/3] Add map.getMapBaseLayer() --- app/assets/javascripts/leaflet.map.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index 02ed318acf..6537b0b233 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -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) { From 8a8c2517f2e594bcecba1fda751ffd34b39dbe9a Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 18 Dec 2024 18:36:44 +0300 Subject: [PATCH 3/3] Add 'canEmbed' layer option --- app/assets/javascripts/leaflet.share.js | 3 ++- config/layers.yml | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index f0d2781098..7b0b5ef028 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -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") diff --git a/config/layers.yml b/config/layers.yml index 4f883cc940..6a470687a2 100644 --- a/config/layers.yml +++ b/config/layers.yml @@ -2,6 +2,7 @@ code: "M" layerId: "mapnik" nameId: "standard" + canEmbed: true credit: id: "make_a_donation" href: "https://supporting.openstreetmap.org" @@ -11,6 +12,7 @@ code: "Y" layerId: "cyclosm" nameId: "cyclosm" + canEmbed: true credit: id: "cyclosm_credit" children: @@ -26,6 +28,7 @@ layerId: "cyclemap" nameId: "cycle_map" apiKeyId: "THUNDERFOREST_KEY" + canEmbed: true credit: id: "thunderforest_credit" children: @@ -38,6 +41,7 @@ layerId: "transportmap" nameId: "transport_map" apiKeyId: "THUNDERFOREST_KEY" + canEmbed: true credit: id: "thunderforest_credit" children: @@ -61,6 +65,7 @@ code: "H" layerId: "hot" nameId: "hot" + canEmbed: true credit: id: "hotosm_credit" children: