/markers.html Secret
Last active
September 5, 2018 11:39
This file contains hidden or 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