Team Project Resources
Additional instructions for integrating Leaflet maps into your project.
When processing the locations from the places.json file, follow these steps for each place:
-
Create a marker object:
- Instantiate a Leaflet marker object.
- Set its coordinates, custom marker icon, and the information to be displayed in the popup window.
-
Store the marker:
- Save the newly created marker in a global JavaScript array (named
markers) for future reference.
- Popup Behavior: Initially, bind the popup to the marker, but do not open it right away (avoid calling
openPopup()at the start). The popup should only open when the user clicks on the corresponding list item in the left column of the map page.
- Save the newly created marker in a global JavaScript array (named
-
Use the
createNewElementfunction:- Implement the
createNewElementfunction (from the TVMaze lab). This will enable you to attach click event listeners to the<li>elements in the list of places (located in the first column of the map page).
- Implement the
-
Dynamically load place names: While processing the places fetched from the
places.jsonfile:- Add each place name into an ordered HTML list. For each place, create an
<li>element, add to it a custom HTML attribute (data-place-id) to store the place ID, and attach a click event handler. When clicked, the event handler should:- Retrieve the place ID from the clicked item’s custom attribute.
- Search for the corresponding marker in the
markersglobal array. - Call
marker.openPopup()to display the popup for the selected marker.
- Add each place name into an ordered HTML list. For each place, create an