[OpenLayers-Users] layer.div is null?

Jeff Dege jdege at korterra.com
Mon Oct 29 17:56:47 EDT 2007


I'm getting occassional, unreproducable errors, in Map.destroy().

This is in 2.3-rc3

Among other things, Map.destroy() loops through all the controls that
have been added to the map, and calls destroy() on each.

Control.destroy() looks through all the handlers that have been set for
the control, and calls destroy() on them.

Handler.destroy() calls this.deactivate(), which calls
this.map.removeLayer(this.layer, false);

And Map.removeLayer() then calls
this.layerContainerDiv.removeChild(layer.div).

The problem is that by the time we get there, layer.div is sometimes
null, which throws an exception.

Any ideas as to why this might be happening?

Would there be any consequences to adding a guard test?  

Changing this:

   if (layer.isFixed) {
      this.viewPortDiv.removeChild(layer.div);
   } else {
      this.layerContainerDiv.removeChild(layer.div);
   }

to:

   if (layer.div != null) {
      if (layer.isFixed) {
         this.viewPortDiv.removeChild(layer.div);
      } else {
         this.layerContainerDiv.removeChild(layer.div);
      }
   }




More information about the Users mailing list