Nasa worldwind - 在地球动画结束后运行自定义函数

问题描述

我正在使用 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)),s = this.wwd.globe.computePointFromLocation(this.targetPosition.latitude,this.targetPosition.longitude,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');”。它工作正常,但它在地球自转的开始运行。我需要它在轮换结束后运行。

知道我怎样才能做到这一点吗?

提前致谢。

解决方法

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

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

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