Skip to content

Commit

Permalink
fix: avoid js error when map is not set when activate/deactivate is c…
Browse files Browse the repository at this point in the history
…alled
  • Loading branch information
oterral committed Aug 22, 2024
1 parent 62a427d commit c808a36
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/control/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class BufferControl extends Control {
* @inheritdoc
*/
activate() {
this.map.addInteraction(this.selectInteraction);
this.map?.addInteraction(this.selectInteraction);
super.activate();

document.getElementById('buffer-width')?.addEventListener('change', (e) => {
Expand All @@ -114,7 +114,7 @@ class BufferControl extends Control {
* @inheritdoc
*/
deactivate() {
this.map.removeInteraction(this.selectInteraction);
this.map?.removeInteraction(this.selectInteraction);
super.deactivate();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/control/cad.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,8 @@ class CadControl extends Control {
super.activate(silent);
this.snapLayer.setMap(this.map);
this.linesLayer.setMap(this.map);
this.map.addInteraction(this.pointerInteraction);
this.map.addInteraction(this.snapInteraction);
this.map?.addInteraction(this.pointerInteraction);
this.map?.addInteraction(this.snapInteraction);

document.getElementById('aux-cb')?.addEventListener('change', (evt) => {
this.setProperties({
Expand Down Expand Up @@ -822,8 +822,8 @@ class CadControl extends Control {
super.deactivate(silent);
this.snapLayer.setMap(null);
this.linesLayer.setMap(null);
this.map.removeInteraction(this.pointerInteraction);
this.map.removeInteraction(this.snapInteraction);
this.map?.removeInteraction(this.pointerInteraction);
this.map?.removeInteraction(this.snapInteraction);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/control/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class DrawControl extends Control {
* @inheritdoc
*/
activate() {
this.map.addInteraction(this.drawInteraction);
this.map?.addInteraction(this.drawInteraction);
super.activate();
}

/**
* @inheritdoc
*/
deactivate(silent) {
this.map.removeInteraction(this.drawInteraction);
this.map?.removeInteraction(this.drawInteraction);
super.deactivate(silent);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/control/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class RotateControl extends Control {
* @inheritdoc
*/
activate() {
this.map.addInteraction(this.pointerInteraction);
this.map?.addInteraction(this.pointerInteraction);
this.rotateLayer.setMap(this.map);
super.activate();
}
Expand All @@ -163,7 +163,7 @@ class RotateControl extends Control {
deactivate(silent) {
this.rotateLayer.getSource().clear();
this.rotateLayer.setMap(null);
this.map.removeInteraction(this.pointerInteraction);
this.map?.removeInteraction(this.pointerInteraction);
super.deactivate(silent);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/control/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TopologyControl extends Control {
* @inheritdoc
*/
activate() {
this.map.addInteraction(this.selectInteraction);
this.map?.addInteraction(this.selectInteraction);
this.addedFeatures = [];
super.activate();
}
Expand All @@ -71,7 +71,7 @@ class TopologyControl extends Control {
*/
deactivate(silent) {
this.addedFeatures = [];
this.map.removeInteraction(this.selectInteraction);
this.map?.removeInteraction(this.selectInteraction);
super.deactivate(silent);
}
}
Expand Down

0 comments on commit c808a36

Please sign in to comment.