-
Notifications
You must be signed in to change notification settings - Fork 28
/
MarkerPrototypeExt.js
107 lines (93 loc) · 3.13 KB
/
MarkerPrototypeExt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {Marker} from 'leaflet';
import BouncingOptions from './BouncingOptions';
import Orchestration from './Orchestration';
const oldSetPos = Marker.prototype._setPos;
const oldOnAdd = Marker.prototype.onAdd;
const oldSetIcon = Marker.prototype.setIcon;
export default {
/** Bouncing options shared by all markers. */
_bouncingOptions: new BouncingOptions(),
_orchestration: new Orchestration(),
/**
* Registers options of bouncing animation for this marker. After registration of options for
* this marker, it will ignore changes of default options. Function automatically recalculates
* animation steps and delays.
*
* @param options {BouncingOptions|object} options object
* @return {Marker} this marker
*/
setBouncingOptions: function(options) {
this._bouncingMotion.updateBouncingOptions(options);
return this;
},
/**
* Returns true if this marker is bouncing. If this marker is not bouncing returns false.
* @return {boolean} true if marker is bouncing, false if not
*/
isBouncing: function() {
return this._bouncingMotion.isBouncing;
},
/**
* Starts bouncing of this marker.
* @param times {number|null} number of times the marker must to bounce
* @return {Marker} this marker
*/
bounce: function(times = null) {
if (times) {
this._bouncingMotion.onMotionEnd = () => {
Marker.prototype._orchestration.removeBouncingMarker(this);
};
}
this._bouncingMotion.bounce(times);
const exclusive = this._bouncingMotion.bouncingOptions.exclusive;
Marker.prototype._orchestration.addBouncingMarker(this, exclusive);
return this;
},
/**
* Stops bouncing of this marker.
* Note: the bouncing not stops immediately after the call of this method.
* Instead, the animation is executed until marker returns to it's original position and takes
* it's full size.
*
* @return {Marker} this marker
*/
stopBouncing: function() {
this._bouncingMotion.stopBouncing();
Marker.prototype._orchestration.removeBouncingMarker(this);
return this;
},
/**
* Starts/stops bouncing of this marker.
* @return {Marker} marker
*/
toggleBouncing: function() {
if (this._bouncingMotion.isBouncing) {
this.stopBouncing();
} else {
this.bounce();
}
return this;
},
isRealMarker: function() {
return this.__proto__ === Marker.prototype;
},
_setPos: function(position) {
oldSetPos.call(this, position);
if (this.isRealMarker()) {
this._bouncingMotion.position = position;
this._bouncingMotion.resetStyles(this);
}
},
onAdd: function(map) {
oldOnAdd.call(this, map);
if (this.isRealMarker()) {
this._bouncingMotion.resetStyles(this);
}
},
setIcon: function(icon) {
oldSetIcon.call(this, icon);
if (this.isRealMarker() && this._icon) {
this._bouncingMotion.resetStyles(this);
}
},
}