Setting zIndex of a marker to absolute front

2,335 views
Skip to first unread message

MacGoose

unread,
Jul 23, 2010, 3:23:06 AM7/23/10
to Google Maps JavaScript API v3
Hi!

I have a bunch of markers that each represent a pingable object. They
all have a neutral color. And when I ping them a reply colors them
green and a timeout colors them red.

As it is now neutral markers have an undefined zIndex letting the API
handle that. And I set all green markers' zIndex to 0 and all the red
ones' to 1. This is an effective way to get the red ones infront of
the green ones. But not infront of the neutral ones. As I understand
the default zIndex of a marker is calculated out of the latitude. So
a marker at latitude 60 will have a zIndex of lets say 60. I know
this isn't the correct algortihm because I tried setting green markers
to 181 and red to 182 as this would place the markers infront all -
but it didn't.

Does anybody know what the highest calculaten zIndex for a marker is
so that I can just add 1 to that number and be sure that marker is
infron of all other markers?

TIA!

, MacGoose

Chad Killingsworth

unread,
Jul 23, 2010, 7:46:05 AM7/23/10
to Google Maps JavaScript API v3
In other threads, we've used 999 to be on top of every marker. See
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/10fc4eb7f60fe7f6/f86126411f8bd3c7

Chad Killingsworth

MacGoose

unread,
Jul 23, 2010, 7:55:48 AM7/23/10
to Google Maps JavaScript API v3
Thanx!

But if anyone know how it is calculated I would like to know. Because
as undefined the markers are on top of each other the correct way.
But when setting all the markers to the same zIndex then it doesn't
look as good - some markers are ontop of markers it should be behind.
So what I would like to do is calculate the undefined zIndex and add
999 so they look better.

, MacGoose


On 23 Jul, 13:46, Chad Killingsworth
<chadkillingswo...@missouristate.edu> wrote:
> In other threads, we've used 999 to be on top of every marker. Seehttp://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...

Rossko

unread,
Jul 23, 2010, 10:03:20 AM7/23/10
to Google Maps JavaScript API v3
> So what I would like to do is calculate the undefined zIndex and add
> 999 so they look better.

You could try the documented marker getZIndex method
http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker
although others have said it doesn't seem to work, in the past

Ben Appleton

unread,
Jul 25, 2010, 9:22:12 PM7/25/10
to google-map...@googlegroups.com
Marker .getZIndex will return the value of the zIndex property that
you set, if any.

If a marker is dragging it is assigned a zIndex of 1000000* to ensure
it appears in front of all other markers. Else if a marker has an
explicit zIndex it is rendered at that zIndex. Else a marker is
rendered with a zIndex that is its y-coordinate returned by
MapCanvasProjection .fromLatLngToDivPixel
(http://code.google.com/apis/maps/documentation/javascript/reference.html#MapCanvasProjection).

* Value subject to change.

To bring a marker to front I suggest assigning it a large zIndex such as 10000.

> --
> You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

MacGoose

unread,
Aug 17, 2010, 7:13:17 AM8/17/10
to Google Maps JavaScript API v3
Thanx!

I have lots of markers I want to bring to the front but still have
them keep its relative z index to each other. This is what I'm trying
to do:

var point = new
google.maps.Point( google.maps.fromLatLngToDivPixel( marker.getPosition() ) );

marker.setZIndex( 10000 + point.y );

This however doesn't work. I suspect it's my knowledge in JavaScript
and the Google Maps API.

Any help further into this appreciated.

, MacGoose


On 26 Jul, 03:22, Ben Appleton <apple...@google.com> wrote:
> Marker .getZIndex will return the value of the zIndex property that
> you set, if any.
>
> If a marker is dragging it is assigned a zIndex of 1000000* to ensure
> it appears in front of all other markers.  Else if a marker has an
> explicit zIndex it is rendered at that zIndex.  Else a marker is
> rendered with a zIndex that is its y-coordinate returned by
> MapCanvasProjection .fromLatLngToDivPixel
> (http://code.google.com/apis/maps/documentation/javascript/reference.h...).
>
> * Value subject to change.
>
> To bring a marker to front I suggest assigning it a large zIndex such as 10000.
>
>
>
> On Sat, Jul 24, 2010 at 12:03 AM, Rossko <ros...@culzean.clara.co.uk> wrote:
> >> So what I would like to do is calculate the undefined zIndex and add
> >> 999 so they look better.
>
> > You could try the documented marker getZIndex method
> >  http://code.google.com/apis/maps/documentation/javascript/reference.h...
Reply all
Reply to author
Forward
0 new messages