Skip to content

Commit

Permalink
Add click to show city
Browse files Browse the repository at this point in the history
  • Loading branch information
tunglinn committed Nov 3, 2023
1 parent 4663b5a commit 8a14c26
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/js/setUpSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ 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;
},
onEachFeature(feature, layer) {
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");
Expand All @@ -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]);
Expand Down

0 comments on commit 8a14c26

Please sign in to comment.