[OpenLayers-Dev] Destroying popups with abandon

Paul Dziemiela paul at dziemiela.com
Wed Feb 4 16:41:18 EST 2009


Hello,

In some cases I need to "clear the decks" of popups and would like to simply
blast away with the destroy() function anywhere that feature.popup is not
null.  However, when I try this against features that haven't actually
created a popup I get several errors.  Is it reasonable to expect destroy()
to execute in any case without errors?

The following changes would be needed to destroy() in Framed.js

    destroy: function() {
       this.imageSrc = null;
       this.imageSize = null;
       this.isAlphaImage = null;

       this.fixedRelativePosition = false;
       this.positionBlocks = null;

       //remove our blocks
       // Added this test 
       if (this.blocks != null) {
          for(var i = 0; i < this.blocks.length; i++) {
             var block = this.blocks[i];

             if (block.image) {
                block.div.removeChild(block.image);
             }
             block.image = null;

             if (block.div) {
                this.groupDiv.removeChild(block.div);
             }
             block.div = null;
          }
       }
       this.blocks = null;

       OpenLayers.Popup.Anchored.prototype.destroy.apply(this, arguments);
    },

And the following changes to destroy() in Popup.js

    destroy: function() {

       this.id = null;
       this.lonlat = null;
       this.size = null;
       this.contentHTML = null;

       this.backgroundColor = null;
       this.opacity = null;
       this.border = null;

       if (this.events != null) {
          this.events.destroy();
       }
       this.events = null;

       if (this.closeDiv != null) {
          OpenLayers.Event.stopObservingElement(this.closeDiv);
          this.groupDiv.removeChild(this.closeDiv);
       }
       this.closeDiv = null;

       if (this.div != null) {
          this.div.removeChild(this.groupDiv);
       }
       this.groupDiv = null;

       if (this.map != null) {
          this.map.removePopup(this);
       }
       this.map = null;
       this.div = null;

       this.autoSize = null;
       this.minSize = null;
       this.maxSize = null;
       this.padding = null;
       this.panMapIfOutOfView = null;
    },

Thanks!

Paul





More information about the Dev mailing list