Skip to content

Commit 9044435

Browse files
authored
Merge pull request #1525 from hajkmap/fix/1524-Location-multiple-animations
Fix to remove multiple animations in Location plugin etc
2 parents 7c8af05 + 1dbadd5 commit 9044435

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4444
- Cookie: Cookie Notice updated after browser refresh. Fix to PR: [#1509](https://github.com/hajkmap/Hajk/pull/1509)
4545
- FIR plugin - Pagination now remembers page after delete. [#1514](https://github.com/hajkmap/Hajk/pull/1514)
4646
- Fix collapsed InfoClick in Iframe [#1508](https://github.com/hajkmap/Hajk/pull/1508)
47+
- Prevent multiple animations in Location plugin [#1525](https://github.com/hajkmap/Hajk/pull/1525)
4748

4849
### Security
4950

apps/client/src/plugins/Location/CustomControlButtonView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const CustomControlButtonView = React.memo(
5858
// Prepare an output array that contains end-user text
5959
const output = [
6060
...(formattedData.accuracy
61-
? [`Nogranhet: ${formattedData.accuracy} m\n`]
61+
? [`Noggranhet: ${formattedData.accuracy} m\n`]
6262
: []),
6363
...(formattedData.altitude && formattedData.altitudeAccuracy
6464
? [

apps/client/src/plugins/Location/LocationModel.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class LocationModel {
112112

113113
// If deactivating, cleanup
114114
if (active === false) {
115+
// Lets cleanup the flash animating, so we don't get multiple animations.
116+
clearInterval(this.flashInterval);
115117
// Remove features from map if tracking has been switched off
116118
this.layer.getSource().clear();
117119
// Make sure that we zoom to location next time tracking is activated
@@ -124,13 +126,13 @@ class LocationModel {
124126
this.layer.getSource().addFeature(this.positionFeature);
125127

126128
// Finally, start flashing the position feature
127-
setInterval(() => {
129+
this.flashInterval = setInterval(() => {
128130
this.flash(this.positionFeature);
129131
}, 3000);
130132
}
131133
};
132134

133-
// Flash handler: sets up the animation and creats a handler for the postrender
135+
// Flash handler: sets up the animation and creates a handler for the postrender
134136
flash = (feature) => {
135137
// Helper: takes care of the actual animation.
136138
const animate = (event) => {
@@ -176,6 +178,8 @@ class LocationModel {
176178
const flashGeom = feature.getGeometry().clone();
177179
// Save the listener key so we can unsubscribe when animation is done
178180
const listenerKey = this.layer.on("postrender", animate);
181+
// We need to force render, otherwise postrender won't run the first time.
182+
this.map.render();
179183
};
180184

181185
enable() {

0 commit comments

Comments
 (0)