I am trying to make regions and markers behave similarly with the option to have only one region/marker selected. So when a user selects a region, any previously selected regions or markers become unselected, and vice versa.
I thought I might be able to achieve this by calling map.clearSelectedMarkers(); and map.clearSelectedRegions(); from inside onRegionSelected() and onMarkerSelected() respectively. However, it seems that calling this function triggers a chain of function calls that eventually calls the opposing on*Selected() function, which in turn clears the selected marker or region itself.
Is there a way to avoid this? So I can clear all selected markers and regions without triggering this?
Thinking out loud here, maybe I just need to check if the selected regions/markers is empty before I attempt to clear it. I might have just answered my own question, but I typed this out.
Yes indeed, that's all I needed:
if (selectedRegions.length !== 0) {
map.clearSelectedMarkers();
}
I am trying to make regions and markers behave similarly with the option to have only one region/marker selected. So when a user selects a region, any previously selected regions or markers become unselected, and vice versa.
I thought I might be able to achieve this by calling
map.clearSelectedMarkers();
andmap.clearSelectedRegions();
from insideonRegionSelected()
andonMarkerSelected()
respectively. However, it seems that calling this function triggers a chain of function calls that eventually calls the opposingon*Selected()
function, which in turn clears the selected marker or region itself.Is there a way to avoid this? So I can clear all selected markers and regions without triggering this?
Thinking out loud here, maybe I just need to check if the selected regions/markers is empty before I attempt to clear it. I might have just answered my own question, but I typed this out.
Yes indeed, that's all I needed: