From 2c84465cc2c131044cb290d596513723d4ce445a Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 10 Dec 2024 00:31:59 +0300 Subject: [PATCH] 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 02ed318ac..6537b0b23 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) { -- 2.39.5