Advertisement
mrjayx

Fit bounds to All points leaflet

Aug 12th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. var map = new L.map('map');
  3. L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
  4.             maxZoom: 18,
  5.             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>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
  6.         }).addTo(map);
  7.             var markerLayer = new L.featureGroup();
  8.  
  9.             givePoint(lat, lon){
  10.                 var latlng = new L.LatLng(lat,lon);
  11.                 marker = new L.marker(latlng, {icon: myIcon});
  12.                 marker.addTo(markerLayer);
  13.                 markerLayer.addTo(map);
  14.            
  15.                 var bounds = markerLayer.getBounds();
  16.                 map.fitBounds(bounds);
  17.             }
  18.  
  19. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement