首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebWorldWind可重定向位置更新

WebWorldWind可重定向位置更新
EN

Stack Overflow用户
提问于 2017-08-16 16:09:16
回答 2查看 676关注 0票数 14

我试图“移动”可渲染的网页世界风地球仪在一个间隔。为了说明我所面临的问题,我举了一个小例子。

这起作用(但效率低下):

代码语言:javascript
复制
    var myVar = setInterval(myTimer, 5000);

    function myTimer() {


        shapesLayer.removeRenderable(shape);
        shape = new WorldWind.SurfaceCircle(new WorldWind.Location(shape.center.latitude+1, shape.center.longitude), 200e3, attributes);
        shapesLayer.addRenderable(shape);

        console.log(" new pos "+shape.center.latitude + " "+shape.center.longitude);

        wwd.redraw();
    }

这是我想做的,但形状不动:

代码语言:javascript
复制
    var myVar = setInterval(myTimer, 5000);

    function myTimer() {

        shape.center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude);

        console.log(" new pos "+shape.center.latitude + " "+shape.center.longitude);

        wwd.redraw();
    }

是否需要在可呈现性上设置一个标志以使其刷新?

下面是我一直在使用的完整SurfaceShapes.js文件(基于这个http://worldwindserver.net/webworldwind/examples/SurfaceShapes.html):

代码语言:javascript
复制
/*
 * Copyright (C) 2014 United States Government as represented by the Administrator of the
 * National Aeronautics and Space Administration. All Rights Reserved.
 */
/**
 * Illustrates how to display SurfaceShapes.
 *
 * @version $Id: SurfaceShapes.js 3320 2015-07-15 20:53:05Z dcollins $
 */

requirejs(['../src/WorldWind',
        './LayerManager'],
    function (ww,
              LayerManager) {
        "use strict";

        // Tell World Wind to log only warnings.
        WorldWind.Logger.setLoggingLevel(WorldWind.Logger.LEVEL_WARNING);

        // Create the World Window.
        var wwd = new WorldWind.WorldWindow("canvasOne");

        /**
         * Added imagery layers.
         */
        var layers = [
            {layer: new WorldWind.BMNGLayer(), enabled: true},
            {layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
            {layer: new WorldWind.CompassLayer(), enabled: true},
            {layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true},
            {layer: new WorldWind.ViewControlsLayer(wwd), enabled: true}
        ];

        for (var l = 0; l < layers.length; l++) {
            layers[l].layer.enabled = layers[l].enabled;
            wwd.addLayer(layers[l].layer);
        }

        // Create a layer to hold the surface shapes.
        var shapesLayer = new WorldWind.RenderableLayer("Surface Shapes");
        wwd.addLayer(shapesLayer);

        // Create and set attributes for it. The shapes below except the surface polyline use this same attributes
        // object. Real apps typically create new attributes objects for each shape unless they know the attributes
        // can be shared among shapes.
        var attributes = new WorldWind.ShapeAttributes(null);
        attributes.outlineColor = WorldWind.Color.BLUE;
        attributes.drawInterior = false;
        attributes.outlineWidth  = 4;
        attributes.outlineStippleFactor = 1;
        attributes.outlineStipplePattern  = 0xF0F0;    

        var highlightAttributes = new WorldWind.ShapeAttributes(attributes);
        highlightAttributes.interiorColor = new WorldWind.Color(1, 1, 1, 1);


        // Create a surface circle with a radius of 200 km.
        var shape = new WorldWind.SurfaceCircle(new WorldWind.Location(35, -120), 200e3, attributes);
        shape.highlightAttributes = highlightAttributes;
        shapesLayer.addRenderable(shape);

        // Create a layer manager for controlling layer visibility.
        var layerManger = new LayerManager(wwd);

        // Now set up to handle highlighting.
        var highlightController = new WorldWind.HighlightController(wwd);

        var myVar = setInterval(myTimer, 5000);

        function myTimer() {

            //Shape doesn't move

            shape.center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude);

            //Shape "moves" but is inefficient

            //shapesLayer.removeRenderable(shape);
            //shape = new WorldWind.SurfaceCircle(new WorldWind.Location(shape.center.latitude+1, shape.center.longitude), 200e3, attributes);
            //shapesLayer.addRenderable(shape);

            console.log(" new pos "+shape.center.latitude + " "+shape.center.longitude);

            wwd.redraw();
        }
    }
);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-29 22:24:54

如果其他人正在研究这个问题,我找到了一个更好的解决方案,通过将isPrepared设置为false,将_boundaries设置为undefined,从而强制它重新计算中心位置。

代码语言:javascript
复制
   var myVar = setInterval(myTimer, 5000);

    function myTimer() {

        shape.isPrepared = false;
        shape._boundaries = undefined;

        shape.center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude);

        console.log(" new pos "+shape.center.latitude + " "+shape.center.longitude);

        wwd.redraw();
    }
票数 1
EN

Stack Overflow用户

发布于 2017-08-22 10:57:00

文档说renderables变量是只读的,但我认为它是可能的。

代码语言:javascript
复制
 change code 
代码语言:javascript
复制
shape.center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude);

代码语言:javascript
复制
index = ShapesLayer.renderables.indexOf(shape);
ShapesLayer.renderables[index].center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude);

我认为ShapesLayer.addRenderable创造了另一个形状。

如果你认为这样做不好,你可以用这种方法

代码语言:javascript
复制
    RenderableLayer.prototype.changeRenderable= function (prevRenderable, nextRenderable) {

      index = ShapesLayer.renderables.indexOf(prevRenderable);
      ShapesLayer.renderables[index].center = nextRenderable;
    };

主码

代码语言:javascript
复制
 ShapesLayer.changeRenderable(shape, new WorldWind.Location(shape.center.latitude+1, shape.center.longitude));

文件:RenderableLayer.js.html

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45718404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档