2016-11-01 4 views
1

私はセシウムで全然ノブなので、どんな愚かさでも私を許してください。私はCesiumに位置データと方向データをストリームするアプリケーションを作成しようとしています。セシウムにはリアルタイムでプロットされ、そこにはどこにあったかを示すパスがあります。エンティティの視覚的な吃音が発生する問題があります。ほとんどの場合、エンティティの位置プロパティが描画呼び出しよりも速く更新されていることが原因です。私は、パスポリラインと同じ問題を抱えて、しかし、私のためにそれを修正したコードスニペットを見つけました:セシウム外部データストリームからのエンティティの動的更新

var pathtrace = new Cesium.PolylineCollection(); 

primitives = viewer.scene.primitives; 

var objpath = pathtrace.add({ 
name : 'Path', 
polyline : { 
     positions : Cesium.Cartesian3.fromDegreesArrayHeights([0, 0, 0, 
                  0, 0, 0]) 
    } 
}); 
primitives.add(pathtrace); 

...Inside loop... 

data = JSON.parse(result.data); 
objpos = data.concat(objpos); 
objpath.positions = Cesium.Cartesian3.fromDegreesArrayHeights(objpos); 

しかし、私は動的なため、エンティティを最適化するためのPolylineCollectionと同じ機能を持つ何かを見つけることができませんでした更新する。現在、私は以下を使用しています:

var vehicle = viewer.entities.add({ 
    name : "Vehicle", 
    position : Cesium.Cartesian3.fromDegrees(0, 0), 
    orientation : orientation, 
    model : { 
     url : url, 
     minimumPixelSize : 50 
    } 
}); 

...Inside loop... 

vehicle.position = Cesium.Cartesian3.fromDegrees(data[0], data[1], data[2]); 

...エンティティが移動する際に前後にジャンプします。これを行うより良い方法はありますか?

答えて

0

最も簡単な解決策はcallbackPropertyです。このような何か:次に

// init somewhere 
var vehiclesPositions = {}; 

// when you parse the data for each vhicle 
... init loop ... 
let vhicle = vhicles[i]; // use let to make sure vhicle is always the same for this loop scope 
vehiclesPositions[vhicle.id] = Cesium.Cartesian3.fromDegrees(vhicle.longitude, vhicle.latitude); 

var vehicle = viewer.entities.add({ 
    name : "Vehicle", 
    position : new Cesium.CallbackProperty(function() { return vehiclesPositions[vhicle.id]; }, // I can't cover all of the issues that might arise with the scope here. See note for the let vhicle line 
    orientation : orientation, 
    model : { 
     url : url, 
     minimumPixelSize : 50 
    } 
}); 

... end init loop ... 

アップデートのループを実行します。更新ループに...

を...

// I assume you get the right ID somehow 
vehiclesPositions[vhicle.id] = Cesium.Cartesian3.fromDegrees(data[0], data[1], data[2]); 

...最終更新ループ...

それから吃音を止めるべきです。

関連する問題