gpt4 book ai didi

polyline - 在Cesium中显示折线(具有一定高度)

转载 作者:行者123 更新时间:2023-12-02 08:03:11 32 4
gpt4 key购买 nike

有人可以告诉我这段代码有什么问题吗?

    Cesium.Math.setRandomNumberSeed(1234);

var viewer = new Cesium.Viewer('cesiumContainer');
var entities = viewer.entities;
var boxes = entities.add(new Cesium.Entity());
var polylines = new Cesium.PolylineCollection();

//Create the entities and assign each entity's parent to the group to which it belongs.
for (var i = 0; i < 5; ++i) {
var height = 100000.0 + (200000.0 * i);
entities.add({
parent : boxes,
position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
box : {
dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
material : Cesium.Color.fromRandom({alpha : 1.0})
}
});
entities.add({
parent : polylines,
position : Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height),
polyline : {
width : new Cesium.ConstantProperty(2),
material : Cesium.Color.fromRandom({alpha : 1.0}),
followSurface : new Cesium.ConstantProperty(false)
}
});
}
viewer.zoomTo(viewer.entities);

它在给定的坐标处显示框,但是当我尝试绘制多段线时,它给出了以下错误:未捕获的类型错误:无法读取未定义的属性“push”(在 https://cesiumjs.org/Cesium/Source/DataSources/Entity.js 的第 300 行)

我想要这样的东西 https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases

提前致谢。

最佳答案

您将实体 API(具有名称和描述的可跟踪实体的高级 API)与基元图形 API(下面的层,仅显示图形基元)混合。

编辑:看起来斯科特·雷诺兹也在 mailing list 上为您回答了这个问题。 ,并且您发布了后续问题。在这里,我借用了 Scott 的“垂直线”代码,删除了“父”关系,因为它们似乎没有在这里使用,并向所有实体添加了可点击的信息框描述。

Cesium.Math.setRandomNumberSeed(1234);

var viewer = new Cesium.Viewer('cesiumContainer');
var entities = viewer.entities;

var prevHeight = 0.0;
for (var i = 0; i < 5; ++i) {
var height = 100000.0 + (200000.0 * i);
entities.add({
name : 'Box ' + i,
description : 'This box is at height: ' + height.toLocaleString() + ' m',
position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
box : {
dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
material : Cesium.Color.fromRandom({alpha : 1.0})
}
});
entities.add({
name : 'Line ' + i,
description : 'This line is from height ' + prevHeight.toLocaleString() +
' m to height ' + height.toLocaleString() + ' m',
position : Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height),
polyline : {
positions: [
Cesium.Cartesian3.fromDegrees(-86.0, 55.0, prevHeight),
Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height)
],
width : new Cesium.ConstantProperty(2),
material : Cesium.Color.fromRandom({alpha : 1.0}),
followSurface : new Cesium.ConstantProperty(false)
}
});

prevHeight = height;
}
viewer.zoomTo(viewer.entities);

关于polyline - 在Cesium中显示折线(具有一定高度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30296606/

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