派生自 wuyushui/SewerAndRainNetwork

wangrui
2020-12-14 0d7669f8bf28300362fc0dacd5c794ff823d0297
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
// @class PolyLine
import * as L from 'leaflet'
 
let DashFlow = () => {
    L.Path.mergeOptions({
        // @option dashSpeed: Number
        // The speed of the dash array, in pixels per second
        dashSpeed: 0
    })
 
    var _originalBeforeAdd = L.Path.prototype.beforeAdd
 
    L.Path.include({
 
        beforeAdd: function(map) {
            _originalBeforeAdd.bind(this)(map)
 
            if (this.options.dashSpeed) {
                this._lastDashFrame = performance.now()
                this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this))
            }
        },
 
        _onDashFrame: function() {
            if (!this._renderer) {
                return
            }
 
            var now = performance.now()
            var dashOffsetDelta = (now - this._lastDashFrame) * this.options.dashSpeed / 1000
 
            this.options.dashOffset = Number(this.options.dashOffset || 0) + dashOffsetDelta
            this._renderer._updateStyle(this)
 
            this._lastDashFrame = performance.now()
 
            this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this))
        }
 
    })
}
 
export default { DashFlow }