diff --git a/spec/suites/layer/marker/MarkerSpec.js b/spec/suites/layer/marker/MarkerSpec.js index 6a8457f2..e7d64fe6 100644 --- a/spec/suites/layer/marker/MarkerSpec.js +++ b/spec/suites/layer/marker/MarkerSpec.js @@ -47,7 +47,7 @@ describe("Marker", function () { marker.setIcon(new L.Icon({iconUrl: 'icon1.png' })); - expect(marker._icon.afterIcon.src).to.contain('icon2.png'); + expect(marker._icon.src).to.contain('icon1.png'); }); it("changes an image to a DivIcon", function () { @@ -56,7 +56,7 @@ describe("Marker", function () { marker.setIcon(new L.DivIcon({html: 'Inner1Text' })); - expect(marker._icon.afterIcon.innerHTML).to.contain('Inner1Text'); + expect(marker._icon.innerHTML).to.contain('Inner1Text'); }); }); diff --git a/src/layer/marker/DivIcon.js b/src/layer/marker/DivIcon.js index 8c43609a..ffea6a9e 100644 --- a/src/layer/marker/DivIcon.js +++ b/src/layer/marker/DivIcon.js @@ -17,7 +17,7 @@ L.DivIcon = L.Icon.extend({ }, createIcon: function (oldIcon) { - var div = oldIcon || document.createElement('div'), + var div = (oldIcon && oldIcon.tagName == 'DIV') ? oldIcon : document.createElement('div'), options = this.options; if (options.html !== false) { diff --git a/src/layer/marker/Icon.js b/src/layer/marker/Icon.js index 94e2ab68..0cfa9f5f 100644 --- a/src/layer/marker/Icon.js +++ b/src/layer/marker/Icon.js @@ -41,7 +41,7 @@ L.Icon = L.Class.extend({ } var img; - if (!oldIcon) { + if (!oldIcon || oldIcon.tagName != 'IMG') { img = this._createImg(src); } else { img = this._createImg(src, oldIcon); diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index f6934a07..f6575edf 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -109,6 +109,18 @@ L.Marker = L.Class.extend({ this._icon = options.icon.createIcon(); } else { this._icon = this.options.icon.createIcon(this._icon); + + //If the icon isn't being reused + if (reuseIcon !== this._icon) { + //Temporarily reset this._icon to be the one we want to remove so _removeIcon will remove it + var newIcon = this._icon; + this._icon = reuseIcon; + + this._removeIcon(); + + reuseIcon = false; + this._icon = newIcon; + } } if (options.title) {