]> git.openstreetmap.org Git - rails.git/commitdiff
Limit map to the maximum zoom of the current base layer
authorTom Hughes <tom@compton.nu>
Mon, 10 Sep 2018 19:37:36 +0000 (20:37 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 10 Sep 2018 19:37:36 +0000 (20:37 +0100)
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
vendor/assets/leaflet/leaflet.osm.js

index ba88e5904dca22cb3c30577ebcf16d25ba95688f..e712a8d1f415719e14746ad6ef279694c5eedc23 100644 (file)
@@ -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) {
index 813438a1b04a164b75b9e44492c11dbaca0771a2..37c8bcf7d8115ad20fd8488ed769e5bf75858eea 100644 (file)
@@ -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: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
   }
 });
@@ -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: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors. Tiles courtesy of <a href="http://www.thunderforest.com/" target="_blank">Andy Allan</a>'
   }
 });
@@ -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'
   }
 });