Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed May 5, 2024
1 parent 1de8dba commit e70753f
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions islands/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,21 @@ function MapComponent(
.bindPopup(`Selected '${activeCountry}'`)
.openPopup();
map.setView(latlng, 4);

map.on(
"click",
async (ev) => {
activeMark.remove();
const result = await (async () => {
const map = ev.target;

const activeCountryNew = await countryFromLatLng(ev.latlng);
if (!activeCountry) {
return;
}
const latlon = await getLatLng(activeCountryNew);
const activeMark = leaf.marker(latlon).addTo(map)
.bindPopup(`Selected '${activeCountryNew}'`)
.openPopup();
return [activeMark, activeCountryNew] as const;
})();
if (result) {
activeMark = result[0];
setActiveCountry(result[1]);
const activeCountryNew = await countryFromLatLng(ev.latlng);
if (!activeCountry) {
return;
}
const latlng = await getLatLng(activeCountryNew);
activeMark = leaf.marker(latlng).addTo(ev.target)
.bindPopup(`Selected '${activeCountryNew}'`)
.openPopup();
setActiveCountry(activeCountryNew);
},
);
}, []);
Expand Down

0 comments on commit e70753f

Please sign in to comment.