Disable drag once attained maximum bounds in Leaflet - Javascript Leaflet

Javascript examples for Leaflet:Configuration

Description

Disable drag once attained maximum bounds in Leaflet

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="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script> 
      <style id="compiled-css" type="text/css">

html, body, #map {
   width: 100%;
   height: 100%;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){//from   ww w. j  a  v  a  2s.co  m
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
var bounds = L.latLngBounds([[51.55, -0.2], [51.45, 0]]);
map.setMaxBounds(bounds);
map.on('drag', function() {
   map.panInsideBounds(bounds, { animate: false });
});
    }

      </script> 
   </head> 
   <body> 
      <div id="map"></div>  
   </body>
</html>

Related Tutorials