更新Cesium Callback属性会导致实体闪烁 [英] Updating Cesium Callback Property causes the entity to flash

查看:2726
本文介绍了更新Cesium Callback属性会导致实体闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是一些可以粘贴到Cesium Sandcastle中的代码。

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

它向地图添加一个实体,然后每秒更新一次位置属性的CallbackProperty 。每次更新时,实体都会闪烁。

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

有没有办法更新这种类型的属性而不会导致实体闪存?也许使用requestAnimationFrame或什么?

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

我需要使用callbackProperties来绘制形状,但是一旦绘制它们,我希望它们使用常量属性。我也尝试更改isConstant属性,但它只读。

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.

推荐答案

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

盒子正在移动,当我将回调函数绑定到浏览器时,它在我的浏览器中没有闪存实体并保持常数=真。

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

这篇关于更新Cesium Callback属性会导致实体闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆