【问题标题】:Nasa worldwind - run custom function after the earth animation endsNasa worldwind - 地球动画结束后运行自定义函数
【发布时间】:2021-04-13 04:44:10
【问题描述】:

我正在使用 worldwind nasa earth。

我创建了一组位置(每个位置都有不同的坐标),每次地球从一个位置移动到另一个位置时,我都需要运行一个函数。该函数必须在每次旋转结束时运行。

问题是在不同地点之间移动的时间不同(例如从意大利到美国,然后到英国)。

我已取消缩小 worldwind.js 文件并尝试在 t.prototype.goTo 函数中运行我的函数

(t.prototype.goTo = function (t, e) {
                if (!t) throw new ArgumentError(d.logMessage(d.LEVEL_SEVERE, "GoToAnimator", "goTo", "missingPosition"));
                (this.completionCallback = e),
                    (this.cancelled = !1),
                    (this.targetPosition = new f(t.latitude, t.longitude, t.altitude || this.wwd.navigator.range)),
                    (this.startPosition = new f(this.wwd.navigator.lookAtLocation.latitude, this.wwd.navigator.lookAtLocation.longitude, this.wwd.navigator.range)),
                    (this.startTime = Date.now());
                var i,
                    r = this.travelTime,
                    n = c.greatCircleDistance(this.startPosition, this.targetPosition),
                    o = this.wwd.globe.computePointFromLocation(this.startPosition.latitude, this.startPosition.longitude, new p(0, 0, 0)),
                    s = this.wwd.globe.computePointFromLocation(this.targetPosition.latitude, this.targetPosition.longitude, new p(0, 0, 0));
                this.maxAltitude = o.distanceTo(s);
                var a = (this.wwd.navigator.currentState().pixelSizeAtDistance(this.startPosition.altitude) * this.wwd.canvas.clientWidth) / this.wwd.globe.equatorialRadius;
                n <= 2 * a && (this.maxAltitude = this.startPosition.altitude),
                    (this.maxAltitudeReachedTime = this.maxAltitude <= this.wwd.navigator.range ? Date.now() : null),
                    this.maxAltitude > this.startPosition.altitude
                        ? ((i = Math.max(0, this.maxAltitude - this.startPosition.altitude)), (i += Math.abs(this.targetPosition.altitude - this.maxAltitude)))
                        : (i = Math.abs(this.targetPosition.altitude - this.startPosition.altitude));
                var l = Math.max(n, i / this.wwd.globe.equatorialRadius);
                if (0 !== l) {
                    l < 2 * a && (r = Math.min((l / a) * this.travelTime, this.travelTime)), (r = Math.max(1, r)), (this.panVelocity = n / r), (this.rangeVelocity = i / r);
                    var h = this,
                        u = function () {
                            h.cancelled ? h.completionCallback && h.completionCallback(h) : h.update() ? setTimeout(u, h.animationFrequency) : h.completionCallback && h.completionCallback(h);
                        };
                    setTimeout(u, this.animationFrequency);
                }
                
                $('#searchButton').css('color', '#000');
            })

我用于测试的自定义行是“$('#searchButton').css('color', '#000');”。它工作正常,但它在地球自转的开始运行。我需要它在轮换结束后运行。

知道如何实现这一点吗?

提前谢谢你。

【问题讨论】:

  • 可能很难帮助您缩小代码。
  • 我已将文件解压缩...

标签: javascript jquery animation worldwind


【解决方案1】:

最简单的可能是使用超时:

setTimeout(()=>{ $('#searchButton').css('color', '#000');
}, 2000);
            

设置时间值以确保它始终在动画完成后运行。

【讨论】:

  • 嗨,我试过这个,但每个动画之间的时间不同,例如。从意大利移动到瑞典需要 2 秒,从瑞典移动到墨西哥需要 4 秒。
  • 您可以设置最长、最坏情况下的时间。还是根据移动的距离计算延迟时间?
猜你喜欢
  • 2018-11-30
  • 2012-08-31
  • 2011-09-13
  • 2012-09-05
  • 2013-12-15
  • 2011-08-04
  • 1970-01-01
  • 2016-11-19
  • 2020-02-25
相关资源
最近更新 更多