diff --git a/src/js/setUpSite.js b/src/js/setUpSite.js index c5d5567..8eb38bc 100644 --- a/src/js/setUpSite.js +++ b/src/js/setUpSite.js @@ -186,7 +186,7 @@ const setMapToCity = (map, cityId, cityProperties) => { const setUpCitiesLayer = async (map) => { const cities = {}; const cityBoundariesData = await import("../../data/city-boundaries.geojson"); - geoJSON(cityBoundariesData, { + const test = geoJSON(cityBoundariesData, { style() { return STYLES.cities; }, @@ -194,7 +194,9 @@ const setUpCitiesLayer = async (map) => { const cityId = feature.properties.id; cities[cityId] = { layer, ...scoreCardsData[cityId] }; }, - }).addTo(map); + }); + + test.addTo(map); // Set up map to update when city selection changes. const cityToggleElement = document.getElementById("city-choice"); @@ -203,6 +205,13 @@ const setUpCitiesLayer = async (map) => { setMapToCity(map, cityId, cities[cityId]); }); + // Set up map to update when user clicks within a city's boundary + test.addEventListener("click", (e) => { + const cityId = e.sourceTarget.feature.properties.id; + cityToggleElement.value = cityId; + setMapToCity(map, cityId, cities[cityId]); + }); + // Load initial city. const cityId = cityToggleElement.value; setMapToCity(map, cityId, cities[cityId]);