Skip to content

Commit c808a36

Browse files
committed
fix: avoid js error when map is not set when activate/deactivate is called
1 parent 62a427d commit c808a36

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/control/buffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class BufferControl extends Control {
9393
* @inheritdoc
9494
*/
9595
activate() {
96-
this.map.addInteraction(this.selectInteraction);
96+
this.map?.addInteraction(this.selectInteraction);
9797
super.activate();
9898

9999
document.getElementById('buffer-width')?.addEventListener('change', (e) => {
@@ -114,7 +114,7 @@ class BufferControl extends Control {
114114
* @inheritdoc
115115
*/
116116
deactivate() {
117-
this.map.removeInteraction(this.selectInteraction);
117+
this.map?.removeInteraction(this.selectInteraction);
118118
super.deactivate();
119119
}
120120
}

src/control/cad.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ class CadControl extends Control {
790790
super.activate(silent);
791791
this.snapLayer.setMap(this.map);
792792
this.linesLayer.setMap(this.map);
793-
this.map.addInteraction(this.pointerInteraction);
794-
this.map.addInteraction(this.snapInteraction);
793+
this.map?.addInteraction(this.pointerInteraction);
794+
this.map?.addInteraction(this.snapInteraction);
795795

796796
document.getElementById('aux-cb')?.addEventListener('change', (evt) => {
797797
this.setProperties({
@@ -822,8 +822,8 @@ class CadControl extends Control {
822822
super.deactivate(silent);
823823
this.snapLayer.setMap(null);
824824
this.linesLayer.setMap(null);
825-
this.map.removeInteraction(this.pointerInteraction);
826-
this.map.removeInteraction(this.snapInteraction);
825+
this.map?.removeInteraction(this.pointerInteraction);
826+
this.map?.removeInteraction(this.snapInteraction);
827827
}
828828
}
829829

src/control/draw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class DrawControl extends Control {
6464
* @inheritdoc
6565
*/
6666
activate() {
67-
this.map.addInteraction(this.drawInteraction);
67+
this.map?.addInteraction(this.drawInteraction);
6868
super.activate();
6969
}
7070

7171
/**
7272
* @inheritdoc
7373
*/
7474
deactivate(silent) {
75-
this.map.removeInteraction(this.drawInteraction);
75+
this.map?.removeInteraction(this.drawInteraction);
7676
super.deactivate(silent);
7777
}
7878
}

src/control/rotate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class RotateControl extends Control {
152152
* @inheritdoc
153153
*/
154154
activate() {
155-
this.map.addInteraction(this.pointerInteraction);
155+
this.map?.addInteraction(this.pointerInteraction);
156156
this.rotateLayer.setMap(this.map);
157157
super.activate();
158158
}
@@ -163,7 +163,7 @@ class RotateControl extends Control {
163163
deactivate(silent) {
164164
this.rotateLayer.getSource().clear();
165165
this.rotateLayer.setMap(null);
166-
this.map.removeInteraction(this.pointerInteraction);
166+
this.map?.removeInteraction(this.pointerInteraction);
167167
super.deactivate(silent);
168168
}
169169
}

src/control/topology.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TopologyControl extends Control {
6161
* @inheritdoc
6262
*/
6363
activate() {
64-
this.map.addInteraction(this.selectInteraction);
64+
this.map?.addInteraction(this.selectInteraction);
6565
this.addedFeatures = [];
6666
super.activate();
6767
}
@@ -71,7 +71,7 @@ class TopologyControl extends Control {
7171
*/
7272
deactivate(silent) {
7373
this.addedFeatures = [];
74-
this.map.removeInteraction(this.selectInteraction);
74+
this.map?.removeInteraction(this.selectInteraction);
7575
super.deactivate(silent);
7676
}
7777
}

0 commit comments

Comments
 (0)