Skip to content

Commit

Permalink
[front-end] Toggle popup when marker clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
rogup committed Nov 22, 2024
1 parent 3a36976 commit 6a8a206
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/front-end/src/components/map/mapLibre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const openPopup = async (
popupClosedCallback: () => void,
offset?: [number, number],
) => {
if (popup?.isOpen() && popupIx === itemIx) {
console.log(`Popup for item @${itemIx} already open`);
return;
}

console.log(`Open popup for item @${itemIx} ${coordinates}`);

// Shift the popup up a bit so it doesn't cover the marker
Expand Down Expand Up @@ -250,6 +255,16 @@ export const createMap = (
const coordinates = feature.geometry.coordinates.slice();
const itemIx = feature.properties?.ix;

if (popup?.isOpen() && popupIx === itemIx) {
console.log(
`Popup for item @${itemIx} already open so toggle closed`,
);
popup?.remove();
popupIx = undefined;
popup = undefined;
return;
}

// ease to a position so that the popup is fully visible
map
.easeTo({
Expand Down Expand Up @@ -339,6 +354,8 @@ export const createMap = (
// Remove previous popup - remove listener to prevent looping back and confusing React code
popup?.off("close", popupClosedCallback);
popup?.remove();
popupIx = undefined;
popup = undefined;
flyToThenOpenPopupRecursive();
});

Expand Down

0 comments on commit 6a8a206

Please sign in to comment.