Javascript examples for Leaflet:Pop up
Open several popups at the same time
<html> <head> <title>Pop up group</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>"></script> <link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css"> <script type="text/javascript" src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <style id="compiled-css" type="text/css"> .map-container {// ww w. j a v a 2s . c o m width: 800px; margin: 0 auto; } </style> <script type="text/javascript"> window.onload=function(){ var map = new L.Map('map-canvas', { center: new L.LatLng(37.7829,-122.1312), zoom: 10 }); var baseLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, attribution: '[[Attribution]]', id: 'mapbox.streets' } ).addTo(map); var testData = [{lat:37.7829,lon:-122.1312,text:"bonjour"},{lat:37.6921,lon:-122.0312,text:"bonsoir"},{lat:37.893,lon:-122.6312,text:"salut"}]; var popup_layer = new L.layerGroup(); $.each(testData, function(index, p) { var marker = L.marker(L.latLng(p.lat, p.lon)); marker.addTo(map); popup = new L.popup({offset: new L.Point(0, -30)}); popup.setLatLng(L.latLng(p.lat, p.lon)); popup.setContent(p.text); popup.openPopup(); popup_layer.addLayer(popup); }); popup_layer.addTo(map); map.on('click', function() { map.removeLayer(popup_layer); }); } </script> </head> <body> <div class="row"> <div class="col-md-12"> <div class="map-container"> <div id="map-canvas" style="width: 100%; height: 500px"></div> </div> </div> </div> </body> </html>