gpt4 book ai didi

javascript - 铯 - 类型错误 : t is undefined when Focusing Camera on Object

转载 作者:行者123 更新时间:2023-11-28 06:31:26 26 4
gpt4 key购买 nike

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

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

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

TypeError: t is undefined

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

最佳答案

可能有更好的方法来突出显示所选国家/地区。 try catch 所选实体,并更改现有多边形的 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;
});

关于javascript - 铯 - 类型错误 : t is undefined when Focusing Camera on Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34680888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com