-
-
Save petersmythe/9b707dfb6658d2d58fa2c90c5ee5b872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
//Map the offices array to an array Leaflet Markers, and add them to the map. Bind a function to the popup event. | |
const officeMarkers = offices.map((element) => { | |
const marker = L.marker(L.latLng([element.latitude, element.longitude])); | |
marker.bindPopup(officeInfo(element)) | |
.addTo(map); | |
return marker; | |
}); | |
//Add the array of Leaflet Markers to a Leaflet Feature group. Fit the bounds of the map the bounds of the Feature group. | |
const group = new L.featureGroup(officeMarkers); | |
map.fitBounds(group.getBounds()); | |
//Function to return the HTML string for display within a Leaflet Popup. | |
function officeInfo(office) { | |
return `<div class='at-leaflet-popup'> | |
<div class='at-leaflet-popup__content'> | |
<dl class='at-leaflet-popup__info'> | |
<dt>${office.name}</dt> | |
</dl> | |
</div> | |
</div>`; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment