2017-08-16 6 views
15

J'essaie de "déplacer" des objets de rendu autour du globe WorldWind sur un intervalle. Pour illustrer le problème que j'ai, j'ai fait un petit exemple.WebWorldWind Renderable Position Update

Cela fonctionne (mais est inefficace):

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(); 
    } 

C'est ce que je voudrais faire, mais la forme ne se déplace pas:

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(); 
    } 

Y at-il un drapeau que j'ai besoin définir sur le rendu pour le faire actualiser?

Voici le dossier complet de SurfaceShapes.js Je joue avec (basé sur ce http://worldwindserver.net/webworldwind/examples/SurfaceShapes.html):

/* 
* 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(); 
     } 
    } 
); 
+0

Est-ce que vous testez 'Renderable.setPosition (Position position)'? Je pense que cela fonctionne pour votre cas. Si votre 'shape' est un' Renderable', vous pouvez utiliser 'shape.setPosition (...)'. –

Répondre

1

Si quelqu'un d'autre regarde, je trouvé une meilleure solution pour le forcer à recalculer la position du centre en plaçant isPrepared à false et _boundaries à undefined.

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(); 
    } 
+0

Heureux que vous ayez une ligne de réponse, shape._boundaries = undefined, pourquoi est-ce nécessaire? –

4

document dit renderables variable est en lecture seule, mais je pense qu'il peut être possible.
code de changement

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

Pour

index = ShapesLayer.renderables.indexOf(shape); 
ShapesLayer.renderables[index].center = new WorldWind.Location(shape.center.latitude+1, shape.center.longitude); 

Je pense que ShapesLayer.addRenderable créer anthères forme.

Si vous pensez que ce n'est pas bonne façon de le faire, vous pouvez utiliser cette façon

RenderableLayer.prototype.changeRenderable= function (prevRenderable, nextRenderable) { 

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

code principal

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

Document: https://nasaworldwind.github.io/WebWorldWind/layer_RenderableLayer.js.html

+0

Je ne vois pas ShapesLayer dans l'API pour WebWorldWind (https://nasaworldwind.github.io/WebWorldWind/). Je crois que vous pouvez regarder WorldWind Java, pas WebWorldWind comme je suis dans la question. – systemoutprintln