From 1820aef3fb5c926664de1d4d484f64a5c9ba7099 Mon Sep 17 00:00:00 2001 From: YANGDL <114714267@qq.com> Date: 星期二, 05 一月 2021 17:06:08 +0800 Subject: [PATCH] 优化逻辑 --- src/components/plugin/PathDashFlow.js | 54 +++++++++++++++++++++++++++--------------------------- 1 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/components/plugin/PathDashFlow.js b/src/components/plugin/PathDashFlow.js index 52792fc..1432190 100644 --- a/src/components/plugin/PathDashFlow.js +++ b/src/components/plugin/PathDashFlow.js @@ -1,43 +1,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 - }) +const 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 + var _originalBeforeAdd = L.Path.prototype.beforeAdd - L.Path.include({ + L.Path.include({ - beforeAdd: function(map) { - _originalBeforeAdd.bind(this)(map) + beforeAdd: function (map) { + _originalBeforeAdd.bind(this)(map) - if (this.options.dashSpeed) { - this._lastDashFrame = performance.now() - this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this)) - } - }, + if (this.options.dashSpeed) { + this._lastDashFrame = performance.now() + this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this)) + } + }, - _onDashFrame: function() { - if (!this._renderer) { - return - } + _onDashFrame: function () { + if (!this._renderer) { + return + } - var now = performance.now() - var dashOffsetDelta = (now - this._lastDashFrame) * this.options.dashSpeed / 1000 + 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.options.dashOffset = Number(this.options.dashOffset || 0) + dashOffsetDelta + this._renderer._updateStyle(this) - this._lastDashFrame = performance.now() + this._lastDashFrame = performance.now() - this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this)) - } + this._dashFrame = L.Util.requestAnimFrame(this._onDashFrame.bind(this)) + } - }) + }) } export default { DashFlow } -- Gitblit v1.8.0