From: Tom Hughes Date: Mon, 10 Sep 2018 19:37:36 +0000 (+0100) Subject: Limit map to the maximum zoom of the current base layer X-Git-Tag: live~2878 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/a7cdb0298d1e4ac2c0685617786c2d20047691a1?ds=inline 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 --- 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' } });