Skip to content

Conversation

mattcurrie
Copy link
Contributor

I had a problem where I needed to have three tile layers displayed in a strict order:

  • base map layer (L.TileLayer)
  • street overlay (L.TileLayer.WMS)
  • marker overlay (L.TileLayer.WMS)

The street and marker WMS overlays can be toggled on and off by the user, so having a z-index set on each layer allows this order to be maintained as they are added and removed from the map.

@@ -12,6 +12,7 @@ L.TileLayer = L.Class.extend({
subdomains: 'abc',
errorTileUrl: '',
attribution: '',
zIndex: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it shouldn't be set by default at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, could remove this, as it is effectively zero anyway I think? I thought I should add a default value in the options as it makes it explicit what z-index the tile layers will have by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to leave it not set so that I could add automatic setting of zIndex for layers that don't have it explicitly set in future (maybe in order they're added to the map).

@mourner
Copy link
Member

mourner commented Jul 27, 2012

While I plan to implement a more extensive zIndex support in 0.5, this may be a good temporary solution, although it doesn't work with the current bringToBack and bringToFront methods (need to add a note to docs about this).

@mattcurrie
Copy link
Contributor Author

I could modify the "bring" methods to iterate through the tile layers and find the maximum/minimum z-index and assign a new z-index based on that.

@mourner
Copy link
Member

mourner commented Jul 27, 2012

I'll merge it in a separate branch and try fiddling with it and eventually merge into master, no need to add anything. Thanks!

@mourner mourner merged commit 6142a8b into Leaflet:master Jul 27, 2012
@mourner
Copy link
Member

mourner commented Jul 27, 2012

Check it out cdfaad9

@mattcurrie
Copy link
Contributor Author

Thanks, looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants