Updating Cesium Callback Property causes the entity to flash

こ雲淡風輕ζ 提交于 2019-12-08 03:09:28

问题


Here is some code that can be pasted into a Cesium Sandcastle.

It adds an entity to the map, then every second, updates the CallbackProperty for the position property. Each time it is updated the entity flashes.

var viewer = new Cesium.Viewer('cesiumContainer');
var position = new Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0);
var constant = false;
var blueBox = viewer.entities.add({
    name : 'Blue box',
    position: new Cesium.CallbackProperty(getPos, constant),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        material : Cesium.Color.BLUE
    }
});

function getPos() {
    return position;
}

function setPosCallback() {
    constant = !constant;
    blueBox.position.setCallback(getPos, constant);
}

setInterval(setPosCallback, 1000);

Is there a way to update this type of property without causing the entity to flash? Maybe using requestAnimationFrame or something?

I need to use the callbackProperties for drawing shapes, but once they are drawn, I want them to use constant properties. I have also tried changing the isConstant property, but its read only.


回答1:


var viewer = new Cesium.Viewer('cesiumContainer');
var position = new Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0);
var constant = true;
var blueBox = viewer.entities.add({
    name : 'Blue box',
    position: new Cesium.CallbackProperty(getPos, constant),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        material : Cesium.Color.BLUE
    }
});

var count = -114.0;
function getPos() {
count+=0.2;
    return new Cesium.Cartesian3.fromDegrees(count, 40.0, 300000.0);
}

function setPosCallback() {
    constant = !constant;
    blueBox.position.setCallback(getPos.bind(blueBox), true);
}

setInterval(setPosCallback, 1000);

hi, the box is moving and it didnt flash in my browser when i bind the callback function to the entity and kept constant = true.

you might want to try again. cheers



来源:https://stackoverflow.com/questions/36747621/updating-cesium-callback-property-causes-the-entity-to-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!