[OpenLayers-Trac] Re: [OpenLayers] #2210: Deactivate controls when destroying

OpenLayers trac-20090302 at openlayers.org
Thu Oct 14 12:51:58 EDT 2010


#2210: Deactivate controls when destroying
----------------------+-----------------------------------------------------
 Reporter:  ahocevar  |       Owner:                 
     Type:  bug       |      Status:  new            
 Priority:  minor     |   Milestone:  2.11 Release   
Component:  Control   |     Version:  2.8            
 Keywords:            |       State:  Needs More Work
----------------------+-----------------------------------------------------

Comment(by jorix):

 Replying to [comment:3 ahocevar]:
 > Calling deactivate in destroy causes map destruction to fail badly
 indeed. This can recently be seen with r10732, which we had to partially
 revert.
 >
 > So until we have a better way to fix this (e.g. by adding a
 beforedestroy event to the map - see #2136 - and listening to it), we have
 a don't-call-deactivate-in-destroy policy.
 As refers to the Panel, if all controls are deactivated by the
 destruction, no error will occur. I tried to put this.active = null in
 control.js destroy. And map destruction with a panel with active controls
 not fail.

 I also tested r10732 + #2210 and the tests:
 {{{
         ...
         panel.activate();
         var div = panel.div;
         panel.destroy();
         t.eq(div.innerHTML , "",
             "Panel is not displayed after destroy without any active
 control");
         map.destroy();
     }
     function test_destroy_map_with_panels(t) {
         t.plan(0);
         var map = new OpenLayers.Map("map");
         var control = new OpenLayers.Control();
         var panel = new OpenLayers.Control.Panel({defaultControl:
 control});
         panel.addControls([control]);
         map.addControl(panel);
         map.destroy(); //panel.destroy() also triggers the bug
     }
 }}}

 are working correctly.

 Now in the case of panel, controls are added to the map after the panel.
 And map.destroy() destroys the controls in reverse order, when it's up to
 panel all controls are destroyed and if a control has control.active =
 true try to deactivate and then fails.

 It may be interesting to study the possibility of doing a silent
 deactivation, and do not trigger events to destroy a control.

-- 
Ticket URL: <http://trac.openlayers.org/ticket/2210#comment:5>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list