Skip to content

Commit 577def7

Browse files
authored
Merge pull request #890 from obdulia-losantos/fix-scale
fix: events that trigger scale recalculation
2 parents e40abb3 + fa5a476 commit 577def7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/scale-control.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Map } from 'mapbox-gl';
33
import { AnchorLimits } from './util/types';
44
import { withMap } from './context';
55

6+
const triggerEvents = ['moveend', 'touchend', 'zoomend'];
7+
68
const scales = [
79
0.01,
810
0.02,
@@ -94,12 +96,16 @@ export class ScaleControl extends React.Component<Props, State> {
9496
public UNSAFE_componentWillMount() {
9597
this.setScale();
9698

97-
this.props.map.on('zoomend', this.setScale);
99+
triggerEvents.forEach(event => {
100+
this.props.map.on(event, this.setScale);
101+
});
98102
}
99103

100104
public componentWillUnmount() {
101105
if (this.props.map) {
102-
this.props.map.off('zoomend', this.setScale);
106+
triggerEvents.forEach(event => {
107+
this.props.map.off(event, this.setScale);
108+
});
103109
}
104110
}
105111

0 commit comments

Comments
 (0)