From 74f0d5fe95bdba2f061747a8fcf84745bc4eb937 Mon Sep 17 00:00:00 2001 From: jacobtoye Date: Fri, 17 Aug 2012 16:24:24 +1200 Subject: [PATCH] Set the icons z-index to show in front after zoom. --- src/layer/marker/Marker.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index bae18f9e..604f8d4a 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -120,6 +120,7 @@ L.Marker = L.Class.extend({ .on(this._icon, 'mouseout', this._sendToBack, this); } } + if (!this._shadow) { this._shadow = options.icon.createShadow(); @@ -167,7 +168,15 @@ L.Marker = L.Class.extend({ L.DomUtil.setPosition(this._shadow, pos); } - this._icon.style.zIndex = pos.y + this.options.zIndexOffset; + this._zIndex = pos.y + this.options.zIndexOffset; + + // Update the icons z-index. If icon has been brought to the front then make sure to bring forward again + this._updateZIndex(); + }, + + _updateZIndex: function() { + var offset = this._broughtToFrontOffset || 0; + this._icon.style.zIndex = this._zIndex + offset; }, _animateZoom: function (opt) { @@ -233,17 +242,15 @@ L.Marker = L.Class.extend({ }, _bringToFront: function () { - this._offsetIconZIndex(this.options.bringToFrontZOffset); + this._broughtToFrontOffset = this.options.bringToFrontZOffset; + + this._updateZIndex(); }, _sendToBack: function () { - this._offsetIconZIndex(this.options.bringToFrontZOffset * -1); - }, + this._broughtToFrontOffset = 0; - _offsetIconZIndex: function (offset) { - var icon = this._icon, - zIndex = parseInt(icon.style.zIndex, 10); - icon.style.zIndex = zIndex + offset; + this._updateZIndex(); } });