如何从FileReader.onload获取变量

时间:2018-01-02 12:54:35

标签: javascript reactjs openlayers

var startAnimate;
var reader = new FileReader();
reader.onload = (evt) => {
moveFeature = function (event) {
                    var vectorContext = event.vectorContext;
                    var frameState = event.frameState;

                    if (animating) {

                        var elapsedTime = frameState.time - now;
                        // here the trick to increase speed is to jump some indexes
                        // on lineString coordinates
                        var index = Math.round(speed * elapsedTime / 1000);

                        if (index >= route.length) {
                            stopAnimation(true);
                            return;
                        }
                        var currentPoint = new ol.geom.Point(route[index]);
                        var feature = new ol.Feature(currentPoint);

                        vectorContext.drawFeature(feature, geoMarker.getStyle());
                    }
                    // tell OpenLayers to continue the postcompose animation

                }

            startAnimate = function startAnimation() {
                if (animating) {
                    stopAnimation(false);
                } else {
                    animating = true;
                    now = new Date().getTime();
                    speed = 5;
                    startButton.textContent = 'Cancel Animation';
                    // hide geoMarker
                    geoMarker.setStyle(null);
                    // just in case you pan somewhere else

                }
            }

            function stopAnimation(ended) {
                animating = false;
                startButton.textContent = 'Start Animation';

                // if animation cancelled set the marker at the beginning
                var coord = ended ? route[route.length - 1] : route[0];
                /** @type {ol.geom.Point} */ (geoMarker.getGeometry())
                    .setCoordinates(coord);
                //remove listener
            }
 }
 var test = '<label for="speed">speed:&nbsp;<input id="' + inputID + '" type="range" min="1" max="100" step="1" value="10"></label><button id="' + buttonID + '" onclick={startAnimate}>Start Animation</button>'

所有变量都在reader.onLoad()中找到,并且无法将测试变量以及reader.onLoad()函数中的其他变量放入其中。 我正在使用测试变量为上传的文件创建标记动画按钮

我是这种语言的新手,所以欢迎解释

0 个答案:

没有答案