OK, so I found a pretty simple solution. I created an array with each menu 
item in it, before I show the desired menu I first run for loop through the 
array and hide each menu. See below where the addMenu is the normal map 
context menu (not part of the array) and the MarkerMenus are the menus for 
the markers.

Placing the menus into an array using the hideOtherMenus function and then 
showing the newly made menu. 
var pos = markerMenus.push(new ContextMenu(map, contextMenuOptions)) - 1;
 
google.maps.event.addListener(marker, 'rightclick', function(mouseEvent){
    hideOtherMenus();
    markerMenus[pos].show(mouseEvent.latLng);
});

And the hideOtherMenus function
function hideOtherMenus(){
    addMenu.hide();
    for(i=0;i<markerMenus.length;i++){
        markerMenus[i].hide();
    }
}

I hope this helps.


On Saturday, 5 September 2015 02:58:45 UTC-4, Stuart Clarke wrote:
>
> Hi,
>
> Thanks for sharing, I love this simple menu.
>
> I have a quick question that you or someone else might be able to help 
> with. I have a menu for the map that works really well, but I've also 
> introduced a menu for each marker, now when I rightclick the markers, the 
> map menu doesn't disappear and when I rightclick another marker the 
> original menu doesn't disappear, they keep accumulating until I leftclick 
> the map again.
>
> Any thought??
>
> Cheers,
>
> Stu.
>
> On Monday, 21 November 2011 04:00:21 UTC-5, Martin™ wrote:
>>
>> Hi all.
>>
>> I've recently had to develop a context menu for a Google Maps API v3
>> map and decided that i'd share it with you all.
>>
>> I searched and found no v3 context menu so hope this will be useful to
>> others.
>>
>> Main project page:
>>
>> http://code.martinpearman.co.uk/googlemapsapi/contextmenu/
>>
>> Advanced example page:
>>
>>
>> http://code.martinpearman.co.uk/googlemapsapi/contextmenu/1.0/examples/advanced_example.htm
>>
>> As always - constructive comments welcomed!
>>
>> Thanks.
>>
>> Martin.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-maps-js-api-v3+unsubscr...@googlegroups.com.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
Visit this group at http://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.

Reply via email to