I am creating a map in leaflet which has markers on the map of various businesses. I created the markers by looping through a list of objects without a problem.
However, I want to be able to pan to each of these markers using a sidebar on my website (outside of the leaflet map). I can do this by creating each individual marker as a variable, but my list is huge and too big to do this manually.
My list of businesses are objects like below:
businesses = [{
'name': 'Business name 1',
'location': 'address',
'id': 'businessid',
'website': 'http://website',
'coords':[0,0]
},]
I created the markers by doing this:
businesses.forEach(element =>
L.marker([element.coords[0],element.coords[1]]).addTo(mymap)
.bindPopup("<strong>"+element.name+"</strong>"));
But I think I can only link to the above markers in my html sidebar if they are declared as a variable. How can I recreate the code above ^ but set each loop instance as a variable? Is this possible?