Leaflet: Control the z-index of polylines

Created on 14 Jul 2011  Β·  5Comments  Β·  Source: Leaflet/Leaflet

A minor feature request.

It'd be good to have a way to control the z-index of the polylines that are added to the map. If I have 2 overlapping polylines, then I'd like to be able to control which one appeared on top.

Apologies if there is already a way of controlling this, I can't see a way to do it.

feature

Most helpful comment

Unfortunately after some research I figured out that SVG doesn't support z-index ordering. The only way to manipulate order of the elements is to reorder corresponding elements in the DOM. So instead of a precise z-index control, I added two methods: path.bringToFront() and path.bringToBack. See commit ed3176f

All 5 comments

No way currently, thanks for the request! Seems this might be useful.

Sorry for writing comment in russian, my english is not good enough.

Данная Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΌΠ½Π΅ Ρ‚ΠΎΠΆΠ΅ Π½ΡƒΠΆΠ½Π°.

ВСкущая Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΠ½Π³ модСль Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ Π·Π°Ρ‚ΠΎΡ‡Π΅Π½Π° Π½Π° ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΠΈΡΡ‚ΠΈΡ‡Π½ΠΎΡΡ‚ΡŒ, ΠΏΠΎΠ½ΡΡ‚Π½ΠΎΡΡ‚ΡŒ ΠΈ быстроту Ρ€Π°Π±ΠΎΡ‚Ρ‹. Но ΠΎΠ½Π° ΠΏΡ€ΠΈ этом Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Π° ΠΎΡΡ‚Π°Π²Π°Ρ‚ΡŒΡΡ ΠΏΡ€ΠΈΠΌΠΈΡ‚ΠΈΠ²Π½ΠΎΠΉ. Π Π΅Π½Π΄Π΅Ρ€ΠΈΠ½Π³ модСль Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ Π΄ΠΎΠ»ΠΆΠ½Π° ΡƒΠΌΠ΅Ρ‚ΡŒ ΠΊΠΎΠ½Ρ‚Ρ€ΠΎΠ»ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ z-index ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ², ΠΌΠ½Π΅ каТСтся это Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΠΎΡΡƒΡ‰Π΅ΡΡ‚Π²Π»ΡΡ‚ΡŒΡΡ Ρ‡Π΅Ρ€Π΅Π· стили: ilayer.setStyle('z-index', 5); А нСкоторая ΡΡƒΡ‰Π½ΠΎΡΡ‚ΡŒ отрисовщик ΡƒΠΆΠ΅ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΠ»Π° Π±Ρ‹ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹ Π² Π½ΡƒΠΆΠ½ΠΎΠΌ порядкС, ΠΈ Π½Π΅ позволяла ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°ΠΌ Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΡ‚ΡŒ сСбя Π² ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠΌ порядкС.

Π’ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ я Π΄Π°ΠΆΠ΅ Π²ΠΎΠ·ΡŒΠΌΡƒΡΡŒ Π·Π° Π΄Π°Π½Π½ΡƒΡŽ Π·Π°Π΄Π°Ρ‡Ρƒ ΠΏΡ€ΠΈ Π½Π°Π»ΠΈΡ‡ΠΈΠΈ свободного Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ.

Π­Ρ‚ΠΎΡ‚ Ρ‚ΠΈΠΊΠ΅Ρ‚ ΠΈ Ρ‚ΠΈΠΊΠ΅Ρ‚ #155 ΠΏΠΎ сути ΠΎΠ± ΠΎΠ΄Π½ΠΎΠΌ ΠΈ Ρ‚ΠΎΠΌ ΠΆΠ΅ Π² ΠΏΠ»Π°Π½Π΅ Ρ€Π΅Π°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ.

Π― всё-Ρ‚Π°ΠΊΠΈ ΠΏΠΎΠΊΠ° Ρ‡Ρ‚ΠΎ с большой опаской ΡΠΌΠΎΡ‚Ρ€ΡŽ Π½Π° Ρ‚Π°ΠΊΠΎΠΉ Ρ€Π΅Ρ„Π°ΠΊΡ‚ΠΎΡ€ΠΈΠ½Π³ β€” Π½Π΅ принимайся Π·Π° Π½Π΅Π³ΠΎ Π±Π΅Π· ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ обговаривания. МнС каТСтся, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎ Π·Π°Π΄Π°Ρ‡Ρƒ с z-index'ΠΎΠΌ ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π΅ΡˆΠΈΡ‚ΡŒ Π½Π°ΠΌΠ½ΠΎΠ³ΠΎ ΠΏΡ€ΠΎΡ‰Π΅.

I'm porting a library of mine from the Google Maps API (https://github.com/jawj/OverlappingMarkerSpiderfier), and I'd +1 this.

Unfortunately after some research I figured out that SVG doesn't support z-index ordering. The only way to manipulate order of the elements is to reorder corresponding elements in the DOM. So instead of a precise z-index control, I added two methods: path.bringToFront() and path.bringToBack. See commit ed3176f

Was this page helpful?
0 / 5 - 0 ratings