Skip to content

Commit 3907615

Browse files
authored
fix: cleanup map events unmounting cad control (#264)
1 parent 6f4fbc6 commit 3907615

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/control/cad.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -189,30 +189,34 @@ class CadControl extends Control {
189189
`;
190190
}
191191

192+
handleInteractionAdd = (e) => {
193+
const pos = e.target.getArray().indexOf(this.snapInteraction);
194+
195+
if (
196+
this.snapInteraction.getActive() &&
197+
pos > -1 &&
198+
pos !== e.target.getLength() - 1
199+
) {
200+
this.deactivate(true);
201+
this.activate(true);
202+
}
203+
};
204+
192205
/**
193206
* @inheritdoc
194207
*/
195208
setMap(map) {
209+
if (this.map) {
210+
this.map.getInteractions().un('add', this.handleInteractionAdd);
211+
}
212+
196213
super.setMap(map);
197214

198215
// Ensure that the snap interaction is at the last position
199216
// as it must be the first to handle the pointermove event.
200-
this.map.getInteractions().on(
201-
'add',
202-
((e) => {
203-
const pos = e.target.getArray().indexOf(this.snapInteraction);
204-
205-
if (
206-
this.snapInteraction.getActive() &&
207-
pos > -1 &&
208-
pos !== e.target.getLength() - 1
209-
) {
210-
this.deactivate(true);
211-
this.activate(true);
212-
}
213-
// eslint-disable-next-line no-extra-bind
214-
}).bind(this),
215-
);
217+
if (this.map) {
218+
this.map.getInteractions().on('add', this.handleInteractionAdd);
219+
}
216220
}
217221

218222
/**

0 commit comments

Comments
 (0)