I have a JSON in which there are places with their coordinates and their textual content to be inserted in the relative marker's popup.
If in the JSON there is 2 times the same place (with the same coordinates), I have to bind 2 popups with their respective contents on the same marker (or at most I have to update the popup with the new content while keeping the old one).
<html>
<head>
<!-- Libraries leaflet/jquery for may project-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
</head>
<body>
<div id="map" style="width:100%; height: 100%"></div>
<script>
// my json data
var data = [
{
"name" : "Location A",
"lat" :"27",
"long" : "29",
"popupContent" : "content 1"
},
{
"name" : "Location B",
"lat" :"51",
"long" : "12",
"popupContent" : "content 2"
},
{
"name" : "Location A",
"lat" :"27",
"long" : "29",
"popupContent" : "content 3"
}
]
//init leaflet map
var map = new L.Map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
maxZoom: 18
}).addTo(map);
var italy = new L.LatLng(42.504154,12.646361);
map.setView(italy, 6);
//iterate my json data and create markers with popups
for(let key in data){
L.marker([data[key].lat,data[key].long]).bindPopup(data[key].popupContent).addTo(map)
}
</script>
</body>
</html>
With this code, the third place overrides the first, and I have a single marker and a single popup with written "content 3".
I would like 2 popups (one with written "content 1" and one with "content 3") or one single popup with all two contents.
