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

hosuaby / Leaflet.SmoothMarkerBouncing / #50

28 Jul 2024 01:07PM UTC coverage: 72.204% (+0.2%) from 72.026%
#50

push

hosuaby
FEATURE: esm

55 of 102 branches covered (53.92%)

Branch coverage included in aggregate %.

33 of 44 new or added lines in 2 files covered. (75.0%)

171 of 211 relevant lines covered (81.04%)

50.61 hits per line

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

58.7
/src/MarkerPrototypeExt.js
1
import BouncingOptions from './BouncingOptions';
2
import Orchestration from './Orchestration';
3

4
export default function MarkerPrototypeExt(Leaflet) {
5
    const oldSetPos = Leaflet.Marker.prototype._setPos;
3✔
6
    const oldOnAdd = Leaflet.Marker.prototype.onAdd;
3✔
7
    const oldSetIcon = Leaflet.Marker.prototype.setIcon;
3✔
8

9
    return {
3✔
10

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

14
        _orchestration: new Orchestration(),
15

16
        _realMarker: true,
17

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

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

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

51
            this._bouncingMotion.bounce(times);
6✔
52
            const exclusive = this._bouncingMotion.bouncingOptions.exclusive;
6✔
53
            Leaflet.Marker.prototype._orchestration.addBouncingMarker(this, exclusive);
6✔
54
            return this;
6✔
55
        },
56

57
        /**
58
         * Stops bouncing of this marker.
59
         * Note: unless 'immediate' flag is set to true, by the call to this method or in marker options,
60
         * the bouncing will not stop immediately after the call of this method. Instead, the animation
61
         * is executed until marker returns to its original position and takes its full size.
62
         *
63
         * @param immediate {boolean}  if true, marker stop to bounce immediately, without waiting
64
         *      animation to end
65
         * @return {Marker} this marker
66
         */
67
        stopBouncing: function(immediate = false) {
3✔
68
            this._bouncingMotion.stopBouncing(immediate);
5✔
69
            Leaflet.Marker.prototype._orchestration.removeBouncingMarker(this);
5✔
70
            return this;
5✔
71
        },
72

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

86
        isRealMarker: function() {
87
            return Object.hasOwn(this.__proto__, '_realMarker');
30✔
88
        },
89

90
        _setPos: function(position) {
91
            oldSetPos.call(this, position);
9✔
92
            if (this.isRealMarker()) {
9!
93
                this._bouncingMotion.position = position;
9✔
94
                this._bouncingMotion.resetStyles(this);
9✔
95
            }
96
        },
97

98
        onAdd: function(map) {
99
            oldOnAdd.call(this, map);
9✔
100
            if (this.isRealMarker()) {
9!
101
                this._bouncingMotion.resetStyles(this);
9✔
102
            }
103
        },
104

105
        setIcon: function(icon) {
NEW
106
            oldSetIcon.call(this, icon);
×
NEW
107
            if (this.isRealMarker() && this._icon) {
×
NEW
108
                this._bouncingMotion.resetStyles(this);
×
109
            }
110
        },
111
    };
112
}
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

© 2025 Coveralls, Inc