Cesium - TypeError : t is undefined when Focusing Camera on Object

Cesium - TypeError : t is undefined when Focusing Camera on Object

我已经将一些 JSon 概述地球上每个国家/地区的数据作为 GeoJSonDataSource 加载到我的 Cesium 项目中。每个国家/地区也作为单独的条目复制到数组中。为了突出一个国家,我使用

viewer.entities.add(countryArray[countryID]);

当用户单击它时,它会在所选国家/地区上方放置一个彩色多边形。但是,当我点击 Cesium 默认提供的信息框中的相机图标时,没有任何反应。在控制台中,错误消息显示为:

TypeError: t is undefined

并指向 Cesium.js。如果我不向 viewer.entities 数组添加任何内容,则不会出现此错误。

可能有更好的方法来突出显示所选国家/地区。尝试捕获所选实体,并更改现有多边形的 material 属性,而不是创建一个新多边形。

例如,试一试:加载 Cesium Sandcastle 并将以下代码粘贴到代码编辑器中,然后按 F8:

var viewer = new Cesium.Viewer('cesiumContainer', {
    navigationHelpButton: false, animation: false, timeline: false,
    selectionIndicator: false
});

var deselectColor = Cesium.Color.BLUE.withAlpha(0.3);
var selectedColor = Cesium.Color.LIME.withAlpha(0.5);

var deselectMaterial = new Cesium.ColorMaterialProperty(
        new Cesium.ConstantProperty(deselectColor));
var selectedMaterial = new Cesium.ColorMaterialProperty(
        new Cesium.ConstantProperty(selectedColor));

viewer.dataSources.add(Cesium.GeoJsonDataSource.load(
        '../../SampleData/ne_10m_us_states.topojson', {
    stroke: Cesium.Color.WHITE,
    fill: deselectColor,
    strokeWidth: 2
}));

//Set the camera to a US centered tilted view.
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(-98.0, 40.0),
        new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

var previousEntity;
Cesium.knockout.getObservable(viewer, '_selectedEntity').subscribe(function(newEntity) {
    if (Cesium.defined(previousEntity) && Cesium.defined(previousEntity.polygon)) {
        previousEntity.polygon.material = deselectMaterial;
    }
    if (Cesium.defined(newEntity) && Cesium.defined(newEntity.polygon)) {
        newEntity.polygon.material = selectedMaterial;
    }
    previousEntity = newEntity;
});