Z-Index of KmlLayers

1,713 views
Skip to first unread message

dwieeb

unread,
Jun 16, 2010, 12:34:02 PM6/16/10
to Google Maps JavaScript API v3
Hello,

I've been trying to find some documentation on the z-index of
KmlLayers. I'm not finding anything in the API or by a few google
searches.

I have 4 layers that need to have a specific order from back to front.
Users can show/hide layers by checking or unchecking a checkbox.

Is there a way I can order these layers via some z-index property of
the KmlLayers object?

Dan

Chad Killingsworth

unread,
Jun 16, 2010, 4:53:01 PM6/16/10
to Google Maps JavaScript API v3
Hmm good question. Since no matter how many KML Layers you create,
they all render as a single image tile this would be an issue.

Chad Killingsworth

Brian

unread,
Jun 16, 2010, 3:32:28 PM6/16/10
to Google Maps JavaScript API v3
I am facing this same thing right now and would also very much like
the ability to affect the z-index of KmlLayers.

As it is they are on top no matter what.

Adjusting the z-index of a google.maps.Polyline way positive or
negative never puts it in front of a KmlLayer, whether it is loaded
before or after the Polyline.

Brian

William

unread,
Jun 17, 2010, 9:53:21 PM6/17/10
to Google Maps JavaScript API v3
On Jun 17, 2:34 am, dwieeb <dwi...@gmail.com> wrote:
>
> Is there a way I can order these layers via some z-index property of
> the KmlLayers object?
>
they are displayed as one tile layer, and to control the display
order, you need to call setMap() in the correct order. Because
setMap() is asynchronous, you need to have code to ensure the next
layer is added after the previous one is ready. I found that the
'defaultviewport_changed' event can be used for this. See the
following example for 4 layers:

http://www.william-map.com/20100617/1/map.htm

...

Chad Killingsworth

unread,
Jun 18, 2010, 1:18:56 AM6/18/10
to Google Maps JavaScript API v3
That solution would effectively mean the user downloaded a new set of
tiles for each KMLLayer rather than a single set for all of them. It
would be nice if there was a better method.

Chad Killingsworth

dwieeb

unread,
Jun 23, 2010, 1:10:42 PM6/23/10
to Google Maps JavaScript API v3
On Jun 17, 8:53 pm, William <william.g...@gmail.com> wrote:
> they are displayed as one tile layer, and to control the display
> order, you need to call setMap() in the correct order.  Because
> setMap() is asynchronous, you need to have code to ensure the next
> layer is added after the previous one is ready.  I found that the
> 'defaultviewport_changed' event can be used for this.

Okay, so it is as simple (and ugly) as making some logic that will
always display the layers in the correct order, even after the user
show/hides them. I wish there was a better way.

I think I can make this work though, thanks guys.

Darrin Patey

unread,
Aug 19, 2010, 8:34:40 PM8/19/10
to Google Maps JavaScript API v3
On Jun 23, 1:10 pm, dwieeb <dwi...@gmail.com> wrote:

> > they are displayed as one tile layer, and to control the display
> > order, you need to call setMap() in the correct order.  Because
> > setMap() is asynchronous, you need to have code to ensure the next
> > layer is added after the previous one is ready.  I found that the
> > 'defaultviewport_changed' event can be used for this.

William - your solution works great for polygons. For some reason
when I'm loading my polyline KML files, the 'addListenerOnce' method
withing the setMapLayer function is not firing. Any ideas what's
going on with this? The KMLs themselves load fine when executed
normally, except for the cursed lack of zIndex control for them of
course.

William

unread,
Aug 19, 2010, 11:50:33 PM8/19/10
to Google Maps JavaScript API v3
On Aug 20, 10:34 am, Darrin Patey <darrin.pa...@gmail.com> wrote:
> For some reason
> when I'm loading my polyline KML files,
> the 'addListenerOnce' method
> within the setMapLayer function is not firing.
>

I'm not sure but other people have been using "metadata_changed"
instead of "defaultviewport_changed" as the signal for when the KML
layer has loaded. I'll try a map with polylines and see what works.
...

William

unread,
Aug 20, 2010, 12:49:23 AM8/20/10
to Google Maps JavaScript API v3
Darrin, can you post a link with the KML files that aren't working?

I tried the doco example Chicago CTA with 3 lines on top of each
other, using metadata_changed and it seems to work.
(defaultviewport_changed also worked for me)

http://www.william-map.com/20100820/1/cta.htm

...

Jerrac

unread,
Aug 24, 2010, 3:56:50 PM8/24/10
to Google Maps JavaScript API v3
Hey William, so I've been trying to get something similar working. I
want my groundoverlay with a text image to show up on top of my
placemark polygon.

I copied the code from your first example, and modified it slightly to
work with my kml files. It didn't work, so I tried changing
defaultviewport_changed to metadata_changed, and that didn't work.

Any suggestions? Here are some links to my files:
http://develzone.aetwirk.com/test/lccmaps/index.html
http://develzone.aetwirk.com/test/lccmaps/buildings/buildingLabels.kml
http://develzone.aetwirk.com/test/lccmaps/buildings/center.kml

Thanks!
Reply all
Reply to author
Forward
0 new messages