• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hosuaby / Leaflet.SmoothMarkerBouncing / #42

pending completion
#42

push

hosuaby
FIX #51: bouncing N times when exclisive=true

67 of 120 branches covered (55.83%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 2 files covered. (100.0%)

172 of 213 relevant lines covered (80.75%)

35.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.62
/src/MarkerPrototypeExt.js
1
import {Marker} from 'leaflet';
2✔
2
import BouncingOptions from './BouncingOptions';
2✔
3
import Orchestration from './Orchestration';
2✔
4

5
const oldSetPos = Marker.prototype._setPos;
2✔
6
const oldOnAdd = Marker.prototype.onAdd;
2✔
7
const oldSetIcon = Marker.prototype.setIcon;
2✔
8

9
export default {
2✔
10

11
    /** Bouncing options shared by all markers. */
12
    _bouncingOptions: new BouncingOptions(),
13

14
    _orchestration: new Orchestration(),
15

16
    /**
17
     * Registers options of bouncing animation for this marker. After registration of options for
18
     * this marker, it will ignore changes of default options. Function automatically recalculates
19
     * animation steps and delays.
20
     *
21
     * @param options {BouncingOptions|object}  options object
22
     * @return {Marker} this marker
23
     */
24
    setBouncingOptions: function(options) {
25
        this._bouncingMotion.updateBouncingOptions(options);
2✔
26
        return this;
2✔
27
    },
28

29
    /**
30
     * Returns true if this marker is bouncing. If this marker is not bouncing returns false.
31
     * @return {boolean} true if marker is bouncing, false if not
32
     */
33
    isBouncing: function() {
34
        return this._bouncingMotion.isBouncing;
×
35
    },
36

37
    /**
38
     * Starts bouncing of this marker.
39
     * @param times {number|null} number of times the marker must to bounce
40
     * @return {Marker} this marker
41
     */
42
    bounce: function(times = null) {
5!
43
        if (times) {
5!
44
            this._bouncingMotion.onMotionEnd = () => {
×
45
                Marker.prototype._orchestration.removeBouncingMarker(this);
×
46
            };
47
        }
48

49
        this._bouncingMotion.bounce(times);
5✔
50
        const exclusive = this._bouncingMotion.bouncingOptions.exclusive;
5✔
51
        Marker.prototype._orchestration.addBouncingMarker(this, exclusive);
5✔
52
        return this;
5✔
53
    },
54

55
    /**
56
     * Stops bouncing of this marker.
57
     * Note: the bouncing not stops immediately after the call of this method.
58
     * Instead, the animation is executed until marker returns to it's original position and takes
59
     * it's full size.
60
     *
61
     * @return {Marker} this marker
62
     */
63
    stopBouncing: function() {
64
        this._bouncingMotion.stopBouncing();
4✔
65
        Marker.prototype._orchestration.removeBouncingMarker(this);
4✔
66
        return this;
4✔
67
    },
68

69
    /**
70
     * Starts/stops bouncing of this marker.
71
     * @return {Marker} marker
72
     */
73
    toggleBouncing: function() {
74
        if (this._bouncingMotion.isBouncing) {
×
75
            this.stopBouncing();
×
76
        } else {
77
            this.bounce();
×
78
        }
79
        return this;
×
80
    },
81

82
    isRealMarker: function() {
83
        return this.__proto__ === Marker.prototype;
21✔
84
    },
85

86
    _setPos: function(position) {
87
        oldSetPos.call(this, position);
7✔
88
        if (this.isRealMarker()) {
7!
89
            this._bouncingMotion.position = position;
7✔
90
            this._bouncingMotion.resetStyles(this);
7✔
91
        }
92
    },
93

94
    onAdd: function(map) {
95
        oldOnAdd.call(this, map);
7✔
96
        if (this.isRealMarker()) {
7!
97
            this._bouncingMotion.resetStyles(this);
7✔
98
        }
99
    },
100

101
    setIcon: function(icon) {
102
        oldSetIcon.call(this, icon);
×
103
        if (this.isRealMarker() && this._icon) {
×
104
            this._bouncingMotion.resetStyles(this);
×
105
        }
106
    },
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc