Multiple Markers - How to change zIndex?

1,291 views
Skip to first unread message

koichirose

unread,
Mar 14, 2010, 11:44:59 AM3/14/10
to Google Maps JavaScript API v3
Hello.
I have multiple markers on my map and some of them overlap.
So I'm trying to set a higher zIndex on the marker I'm currently
hovering on, so that it'll go on top of the others.
When I hover out I have to set the old zIndex back, otherwise it'll
remain on top.

Here's what I tried:
google.maps.event.addListener(marker, "mouseover", function() {
this.old_ZIndex = this.getZIndex();
console.log(this.old_ZIndex); //<<<<<<---this is undefined, why?
this.setZIndex(1000);
});
google.maps.event.addListener(marker, "mouseout", function() {
if (this.old_ZIndex)
this.setZIndex(this.old_ZIndex);
});

I reported it as an issue (http://code.google.com/p/gmaps-api-issues/
issues/detail?id=2150), but they told me this is the desired
behaviour.
Setting a default ZIndex is not an option, since I don't want to lose
the default behaviour (By default, Markers are displayed according to
their latitude, with Markers of lower latitudes appearing in front of
Markers at higher latitudes.)

How can I solve this?

Chad Killingsworth

unread,
Mar 14, 2010, 11:40:26 PM3/14/10
to Google Maps JavaScript API v3
I made a test case real quick. This worked for me:

marker.setZIndex(999); //hover
marker.setZIndex(undefined); //undo

Chad Killingsworth

koichirose

unread,
Mar 15, 2010, 5:47:25 AM3/15/10
to Google Maps JavaScript API v3
Thank you very much, this solved it for me; I didn't know I could set
a ZIndex as undefined.

On Mar 15, 4:40 am, Chad Killingsworth

Chad Killingsworth

unread,
Mar 15, 2010, 9:33:47 AM3/15/10
to Google Maps JavaScript API v3
Neither did I until I tried it. It was an educated guess.

Chad Killingsworth

Reply all
Reply to author
Forward
0 new messages