Trigger click on marker on page load
-
Hi, how can i trigger a click envent on a map marker right after the page is loaded?
I have a map with markers on countries which open a popin. I’d like to have one of the countrie’s popin open by default, ideally by passing the country name in the URL.
This is the code I have so far, but the click event doesn’t open the popin.
let mapContainer = document.getElementById('map_15822'); mapContainer.addEventListener('mapready', function(ev) { const urlParams = new URLSearchParams(window.location.search); const country = urlParams.get('country'); if (country) { let groups = document.querySelectorAll('.imapsSprite-group'); for(let i = 0; i < groups.length; i++) { let tspan = groups[i].querySelector('tspan'); if (tspan && tspan.textContent === country) { console.log('clicking on', tspan.textContent); groups[i].dispatchEvent(new MouseEvent('click', { bubbles: true })); break; } } } });
Thanks ??
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.