@@ -69,13 +69,25 @@ class Editor {
69
69
control . setMap ( this . map ) ;
70
70
control . setEditor ( this ) ;
71
71
72
- control . addEventListener ( 'change:active' , ( e ) => {
73
- this . activeStateChange ( e . detail . control ) ;
74
- } ) ;
72
+ control . addEventListener ( 'change:active' , this . activeStateChange ) ;
75
73
76
74
this . controls . push ( control ) ;
77
75
}
78
76
77
+ /**
78
+ * Remove a control from the editor
79
+ * @param {ole.Control } control The control.
80
+ */
81
+ removeControl ( control ) {
82
+ control . deactivate ( true ) ;
83
+ control . setMap ( null ) ;
84
+ control . setEditor ( null ) ;
85
+ control . removeEventListener ( 'change:active' , this . activeStateChange ) ;
86
+
87
+ this . controls . remove ( control ) ;
88
+ this . activeControls . remove ( control ) ;
89
+ }
90
+
79
91
/**
80
92
* Adds a service to the editor.
81
93
*/
@@ -170,7 +182,8 @@ class Editor {
170
182
* @param {ol.control.Control } control Control.
171
183
* @private
172
184
*/
173
- activeStateChange ( ctrl ) {
185
+ activeStateChange = ( e ) => {
186
+ const ctrl = e . detail . control ;
174
187
// Deactivate other controls that are not standalone
175
188
if ( ctrl . getActive ( ) && ctrl . standalone ) {
176
189
for ( let i = 0 ; i < this . controls . getLength ( ) ; i += 1 ) {
@@ -191,7 +204,7 @@ class Editor {
191
204
} else {
192
205
this . activeControls . remove ( ctrl ) ;
193
206
}
194
- }
207
+ } ;
195
208
}
196
209
197
210
export default Editor ;
0 commit comments