铯-类型错误:当相机聚焦在物体上时,t是未定义的

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

本文关键字:未定义 错误 类型 聚焦 相机      更新时间:2023-09-26

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

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

当用户点击它时,它会在选定的国家上方放置一个彩色多边形。然而,当我点击Cesium默认提供的信息框中的相机图标时,什么都不会发生。在控制台中,错误消息显示:

TypeError:t是未定义的

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

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

例如,尝试一下:加载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;
});