Putting multiple markers in Layer Group - Javascript Leaflet

Javascript examples for Leaflet:Marker

Description

Putting multiple markers in Layer Group

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>layerGroup</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"> 
      <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script> 
      <style id="compiled-css" type="text/css">

#map {/*ww w .j  av a  2 s  .  c o  m*/
   height: 600px;
   width: 600px;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var map = L.map('map').setView([44.6499282, 22.6327532], 14);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var coordinates = [
    [44.649, 22.632],
    [44.650, 22.642],
    [44.652, 22.632]
];
var layerGroup = L.layerGroup().addTo(map);
for (i = 0; i < coordinates.length; i++) {
    marker = L.marker([coordinates[i][0], coordinates[i][1]]);
    layerGroup.addLayer(marker);
}
var overlay = {'markers': layerGroup};
L.control.layers(null, overlay).addTo(map);
    }

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

Related Tutorials