Javascript examples for Leaflet:Configuration
leaflet fitbounds
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.js"></script> <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"> #map {/*from w ww . j ava2s.c o m*/ height: 500px; width: 500px; } </style> <script type="text/javascript"> $(window).load(function(){ $(document).ready(function () { map = new L.Map('map'); var osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data ? <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' }); map.addLayer(osm); var markersGroup = L.featureGroup(); var startMarker = L.marker([50.5, 30.5]); startMarker.addTo(markersGroup); map.addLayer(markersGroup); var i = 0; setInterval(function () { L.marker([50.5 + i / 100, 30.5 + i / 100]).addTo(markersGroup); i++; map.fitBounds(markersGroup.getBounds().pad(0.05)); }, 1000); }); }); </script> </head> <body> <div id="map"> </div> </body> </html>