Fixed several destroy() methods to avoid running into undefined objects when the page unloads. r=crschmidt,me (closes #1222)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6172 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -166,6 +166,7 @@ OpenLayers.Control = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
this.events.destroy();
|
this.events.destroy();
|
||||||
|
this.events = null;
|
||||||
// eliminate circular references
|
// eliminate circular references
|
||||||
if (this.handler) {
|
if (this.handler) {
|
||||||
this.handler.destroy();
|
this.handler.destroy();
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
destroy: function() {
|
destroy: function() {
|
||||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||||
for(var i = this.controls.length - 1 ; i >= 0; i--) {
|
for(var i = this.controls.length - 1 ; i >= 0; i--) {
|
||||||
this.controls[i].events.un({
|
if(this.controls[i].events) {
|
||||||
"activate": this.redraw,
|
this.controls[i].events.un({
|
||||||
"deactivate": this.redraw,
|
"activate": this.redraw,
|
||||||
scope: this
|
"deactivate": this.redraw,
|
||||||
});
|
scope: this
|
||||||
|
});
|
||||||
|
}
|
||||||
OpenLayers.Event.stopObservingElement(this.controls[i].panel_div);
|
OpenLayers.Event.stopObservingElement(this.controls[i].panel_div);
|
||||||
this.controls[i].panel_div = null;
|
this.controls[i].panel_div = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -485,6 +485,12 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
this.events.unregister("resize", this, this.updateSize);
|
this.events.unregister("resize", this, this.updateSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.controls != null) {
|
||||||
|
for (var i = this.controls.length - 1; i>=0; --i) {
|
||||||
|
this.controls[i].destroy();
|
||||||
|
}
|
||||||
|
this.controls = null;
|
||||||
|
}
|
||||||
if (this.layers != null) {
|
if (this.layers != null) {
|
||||||
for (var i = this.layers.length - 1; i>=0; --i) {
|
for (var i = this.layers.length - 1; i>=0; --i) {
|
||||||
//pass 'false' to destroy so that map wont try to set a new
|
//pass 'false' to destroy so that map wont try to set a new
|
||||||
@@ -493,12 +499,6 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
this.layers = null;
|
this.layers = null;
|
||||||
}
|
}
|
||||||
if (this.controls != null) {
|
|
||||||
for (var i = this.controls.length - 1; i>=0; --i) {
|
|
||||||
this.controls[i].destroy();
|
|
||||||
}
|
|
||||||
this.controls = null;
|
|
||||||
}
|
|
||||||
if (this.viewPortDiv) {
|
if (this.viewPortDiv) {
|
||||||
this.div.removeChild(this.viewPortDiv);
|
this.div.removeChild(this.viewPortDiv);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user