diff --git a/lib/OpenLayers/Feature.js b/lib/OpenLayers/Feature.js index 2004a45591..c068676dae 100644 --- a/lib/OpenLayers/Feature.js +++ b/lib/OpenLayers/Feature.js @@ -179,13 +179,14 @@ OpenLayers.Feature = OpenLayers.Class({ var id = this.id + "_popup"; var anchor = (this.marker) ? this.marker.icon : null; - this.popup = new this.popupClass(id, - this.lonlat, - this.data.popupSize, - this.data.popupContentHTML, - anchor, - closeBox); - + if (!this.popup) { + this.popup = new this.popupClass(id, + this.lonlat, + this.data.popupSize, + this.data.popupContentHTML, + anchor, + closeBox); + } if (this.data.overflow != null) { this.popup.contentDiv.style.overflow = this.data.overflow; } @@ -204,8 +205,11 @@ OpenLayers.Feature = OpenLayers.Class({ * should also be able to override the destruction */ destroyPopup: function() { - this.popup.feature = null; - this.popup.destroy() + if (this.popup) { + this.popup.feature = null; + this.popup.destroy(); + this.popup = null; + } }, CLASS_NAME: "OpenLayers.Feature" diff --git a/tests/test_Feature.html b/tests/test_Feature.html index 6023cfb29f..1a33f5f074 100644 --- a/tests/test_Feature.html +++ b/tests/test_Feature.html @@ -121,7 +121,7 @@ } function test_04_Feature_createPopup(t) { - t.plan(17); + t.plan(11); //no lonlat var f = { @@ -187,7 +187,7 @@ }; OpenLayers.Feature.prototype.destroyPopup.apply(f, []); - t.ok(f.popup.feature == null, "popup's 'feature' property nullified on destroy"); + t.ok(f.popup == null, "popup property nullified on destroy"); }