leafletjs-adding points dynamically and draw line string - Javascript Leaflet

Javascript examples for Leaflet:Point

Description

leafletjs-adding points dynamically and draw line string

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://unpkg.com/leaflet@1.0.3/dist/leaflet.css"> 
      <script type="text/javascript" src="https://unpkg.com/leaflet@1.0.3/dist/leaflet-src.js"></script> 
      <style id="compiled-css" type="text/css">

#map {/*from w  ww .  j  a v  a  2s  .c o m*/
   height: 500px;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var map = L.map("map");
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png").addTo(map);
map.setView([48.85, 2.35], 12);
var myPolyline = L.polyline([
   [48.86, 2.34],
  [48.85, 2.35]
]).addTo(map).bindPopup("popup").openPopup();
var count = 1;
document.getElementById("button").addEventListener("click", function (event) {
   event.preventDefault();
  myPolyline.addLatLng([
     48.85 - (count + Math.random()) * 0.01,
    2.35 + (count + Math.random()) * 0.01
  ]);
  count += 1;
});
    }

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

Related Tutorials