2016-11-01 1 views
1

세슘에서 나는 멍청한 녀석이에요. 어리 석음 때문에 용서해주세요. 위치 및 방향 데이터를 세슘에 스트리밍하는 응용 프로그램을 작성하려고합니다.이 위치는 실시간으로 경로가 표시되어 위치를 표시합니다. Entity.position 속성이 draw 호출이 실행할 수있는 것보다 빨리 업데이트된다는 사실 때문에 거의 틀림없이 엔티티의 시각적 말더듬이 발생하는 문제가 있습니다. 나는 경로 폴리 라인과 같은 문제가 발생했지만, 나를 위해 그것을 고정 된 코드를 발견세슘 외부 데이터 스트림에서 엔티티의 동적 업데이트

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]); 

... 최종 업데이트 루프 ...

그러면 더듬 거리는 것을 멈춰야합니다.

관련 문제