Skip to content

Commit

Permalink
Fix popup behaviour on map
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsiW committed Feb 10, 2025
1 parent 46ef2e5 commit edbd90f
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions html/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,35 @@ <h3 class="name-popup">${properties.name}</h3>
map.on('click', 'place-markers', (e) => {
const clickedFeature = e.features[0];

if (activeFeature && activeFeature.id === clickedFeature.id) {
// Second click on same feature - open URL
// Use some unique property, for example 'name':
if (
activeFeature &&
activeFeature.properties.name === clickedFeature.properties.name
) {
// Second click on the same marker -> open URL
location.href = clickedFeature.properties.url;
activeFeature = null;
popup.remove();
} else {
// First click - show popup
activeFeature = clickedFeature;
createPopup(e);
return;
}

// Otherwise, we just opened a new popup
popup.remove();
activeFeature = clickedFeature;
createPopup(e);

// Add click handler to popup
const popupElement = popup.getElement();
if (popupElement) {
popupElement.addEventListener('click', () => {
if (activeFeature) {
location.href = activeFeature.properties.url;
activeFeature = null;
popup.remove();
}
});
}
// Also handle clicks on the popup to open the link
const popupElement = popup.getElement();
if (popupElement) {
popupElement.addEventListener('click', () => {
location.href = clickedFeature.properties.url;
activeFeature = null;
popup.remove();
});
}
});


// Close popup and reset active feature on any map interaction
map.on('drag', () => {
popup.remove();
Expand Down

0 comments on commit edbd90f

Please sign in to comment.