Javascript examples for Leaflet:Event
leaflet.js fire event when map zoomed and moved
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"> <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet-src.js"></script> <style id="compiled-css" type="text/css"> #map {/*from w ww .ja va 2s . c o m*/ height: 500px; } </style> <script type="text/javascript"> window.onload=function(){ var map = L.map("map").setView([48.86, 2.35], 12); L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); var currentZoom = document.getElementById("currentZoom"); function showZoom() { currentZoom.innerHTML = map.getZoom(); } map.on("zoomend", showZoom); showZoom(); setInterval(function () { var currentPos = map.getCenter(); map.panTo([ currentPos.lat, currentPos.lng + 0.1 ]) }, 2000); map.on("moveend", function () { console.log(map.getCenter().toString()); }); } </script> </head> <body> <div id="map"></div> <p> Current map zoom: <span id="currentZoom"></span> </p> </body> </html>