From a7cdb0298d1e4ac2c0685617786c2d20047691a1 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 10 Sep 2018 20:37:36 +0100 Subject: [PATCH] Limit map to the maximum zoom of the current base layer Fix maximum zoom levels for various layers and ensure that the map can't be zoomed beyond the limit of the current base layer. Fixes #1978 --- app/assets/javascripts/leaflet.map.js | 6 ++++++ vendor/assets/leaflet/leaflet.osm.js | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index ba88e5904..e712a8d1f 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -61,6 +61,12 @@ L.OSM.Map = L.Map.extend({ code: "G", name: I18n.t("javascripts.map.base.gps") }); + + this.on("layeradd", function (event) { + if (this.baseLayers.indexOf(event.layer) >= 0) { + this.setMaxZoom(event.layer.options.maxZoom); + } + }); }, updateLayers: function(layerParam) { diff --git a/vendor/assets/leaflet/leaflet.osm.js b/vendor/assets/leaflet/leaflet.osm.js index 813438a1b..37c8bcf7d 100644 --- a/vendor/assets/leaflet/leaflet.osm.js +++ b/vendor/assets/leaflet/leaflet.osm.js @@ -22,6 +22,7 @@ L.OSM.Mapnik = L.OSM.TileLayer.extend({ L.OSM.CycleMap = L.OSM.TileLayer.extend({ options: { url: 'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}{r}.png?apikey={apikey}', + maxZoom: 21, attribution: '© OpenStreetMap contributors. Tiles courtesy of Andy Allan' } }); @@ -29,6 +30,7 @@ L.OSM.CycleMap = L.OSM.TileLayer.extend({ L.OSM.TransportMap = L.OSM.TileLayer.extend({ options: { url: 'https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}{r}.png?apikey={apikey}', + maxZoom: 21, attribution: '© OpenStreetMap contributors. Tiles courtesy of Andy Allan' } }); @@ -45,7 +47,8 @@ L.OSM.HOT = L.OSM.TileLayer.extend({ L.OSM.GPS = L.OSM.TileLayer.extend({ options: { url: 'https://gps-{s}.tile.openstreetmap.org/lines/{z}/{x}/{y}.png', - maxZoom: 20, + maxZoom: 21, + maxNativeZoom: 20, subdomains: 'abc' } }); -- 2.43.2