Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to remove multiple animations in Location plugin etc #1525

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Cookie: Cookie Notice updated after browser refresh. Fix to PR: [#1509](https://github.com/hajkmap/Hajk/pull/1509)
- FIR plugin - Pagination now remembers page after delete. [#1514](https://github.com/hajkmap/Hajk/pull/1514)
- Fix collapsed InfoClick in Iframe [#1508](https://github.com/hajkmap/Hajk/pull/1508)
- Prevent multiple animations in Location plugin [#1525](https://github.com/hajkmap/Hajk/pull/1525)

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const CustomControlButtonView = React.memo(
// Prepare an output array that contains end-user text
const output = [
...(formattedData.accuracy
? [`Nogranhet: ${formattedData.accuracy} m\n`]
? [`Noggranhet: ${formattedData.accuracy} m\n`]
: []),
...(formattedData.altitude && formattedData.altitudeAccuracy
? [
Expand Down
8 changes: 6 additions & 2 deletions apps/client/src/plugins/Location/LocationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class LocationModel {

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

// Finally, start flashing the position feature
setInterval(() => {
this.flashInterval = setInterval(() => {
this.flash(this.positionFeature);
}, 3000);
}
};

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

enable() {
Expand Down