Leaflet: set min/maxZoom dynamically - Javascript Leaflet

Javascript examples for Leaflet:Zoom

Description

Leaflet: set min/maxZoom dynamically

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" type="text/css" href="http://leafletjs.com/dist/leaflet.css"> 
      <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css"> 
      <script type="text/javascript" src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  w  ww .  ja  va  2  s .  co m
var map = L.map('map').setView([51.505, -0.09], 13);
map.options.minZoom = 12;
map.options.maxZoom = 14;
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
    '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();
    }

      </script> 
   </head> 
   <body> 
      <div id="map" style="width: 600px; height: 400px"></div>  
   </body>
</html>

Related Tutorials