Make Icon/DivIcon reuse not try reuse the wrong dom element type.

This commit is contained in:
danzel 2013-06-12 16:05:42 +12:00
parent 7f2eff363b
commit fa45913505
4 changed files with 16 additions and 4 deletions

View File

@ -47,7 +47,7 @@ describe("Marker", function () {
marker.setIcon(new L.Icon({iconUrl: 'icon1.png' })); 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 () { it("changes an image to a DivIcon", function () {
@ -56,7 +56,7 @@ describe("Marker", function () {
marker.setIcon(new L.DivIcon({html: 'Inner1Text' })); marker.setIcon(new L.DivIcon({html: 'Inner1Text' }));
expect(marker._icon.afterIcon.innerHTML).to.contain('Inner1Text'); expect(marker._icon.innerHTML).to.contain('Inner1Text');
}); });
}); });

View File

@ -17,7 +17,7 @@ L.DivIcon = L.Icon.extend({
}, },
createIcon: function (oldIcon) { createIcon: function (oldIcon) {
var div = oldIcon || document.createElement('div'), var div = (oldIcon && oldIcon.tagName == 'DIV') ? oldIcon : document.createElement('div'),
options = this.options; options = this.options;
if (options.html !== false) { if (options.html !== false) {

View File

@ -41,7 +41,7 @@ L.Icon = L.Class.extend({
} }
var img; var img;
if (!oldIcon) { if (!oldIcon || oldIcon.tagName != 'IMG') {
img = this._createImg(src); img = this._createImg(src);
} else { } else {
img = this._createImg(src, oldIcon); img = this._createImg(src, oldIcon);

View File

@ -109,6 +109,18 @@ L.Marker = L.Class.extend({
this._icon = options.icon.createIcon(); this._icon = options.icon.createIcon();
} else { } else {
this._icon = this.options.icon.createIcon(this._icon); 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) { if (options.title) {