如何在CZML中指定椭球体的颜色?当我在JavaScript中向查看器添加一个实体时,这个代码片段可以工作:
let redEllipsoid = viewer.entities.add({
"name": "red ellipsoid",
"position": Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),
"ellipsoid": {
"radii": new Cesium.Cartesian3(200000.0, 200000.0, 300000.0),
"material": Cesium.Color.RED.withAlpha(0.5),
"outline": true,
"outlineColor": Cesium.Color.BLACK
}
});
另一个代码片段也可以:
let redEllipsoid = viewer.entities.add({
"name": "red ellipsoid",
"position": {
x: -2083516.9683773473,
y: -4679655.730028949,
z: 4270821.855106338
},
"ellipsoid": {
"radii": {
x: 200000,
y: 200000,
z: 300000
},
"material": Cesium.Color.RED.withAlpha(0.5),
"outline": true,
"outlineColor": {
red: 0,
green: 0,
blue: 0,
alpha: 1
}
}
});
但是这段代码不起作用(生成一个默认为白色的椭球体):
let redEllipsoid = viewer.entities.add({
"name": "red ellipsoid",
"position": {
x: -2083516.9683773473,
y: -4679655.730028949,
z: 4270821.855106338
},
"ellipsoid": {
"radii": {
x: 200000,
y: 200000,
z: 300000
},
"material": {
"solidColor": {
"color": {
"rgba": [1, 0, 0, 0.5]
}
}
},
"outline": true,
"outlineColor": {
red: 0,
green: 0,
blue: 0,
alpha: 1
}
}
});
这个也没有(也产生一个默认白色的椭球体):
let redEllipsoid = viewer.entities.add({
"name": "red ellipsoid",
"position": {
x: -2083516.9683773473,
y: -4679655.730028949,
z: 4270821.855106338
},
"ellipsoid": {
"radii": {
x: 200000,
y: 200000,
z: 300000
},
"material": {
"color": {
red: 1,
green: 0,
blue: 0,
alpha: 0.5
}
},
"outline": true,
"outlineColor": {
red: 0,
green: 0,
blue: 0,
alpha: 1
}
}
});
这个也没有(也产生一个默认白色的椭球体):
let redEllipsoid = viewer.entities.add({
"name": "red ellipsoid",
"position": {
x: -2083516.9683773473,
y: -4679655.730028949,
z: 4270821.855106338
},
"ellipsoid": {
"radii": {
x: 200000,
y: 200000,
z: 300000
},
"material": {
red: 1,
green: 0,
blue: 0,
alpha: 0.5
},
"outline": true,
"outlineColor": {
red: 0,
green: 0,
blue: 0,
alpha: 1
}
}
});
我特别困惑,因为在铯加载返回ne {red: 1, green: 0, blue: 0, alpha: 0.5}
后,将Cesium.Color.RED.withAlpha(0.5)
输入控制台。可以预期,给出静态成员指定的对象是可以工作的……
这是"material"
的类型。因为它是一个没有属性的抽象类,所以我通过CZML指定它是不是不太幸运?如果设置椭球体颜色的唯一方法需要后处理,这将是一个真正的拖累,因为我希望能够离线完成繁重的工作,并且只在浏览器中加载CZML。
请参阅Ellipsoid
页、Material
页、SolidColorMaterial
页、Color
页以及CZML文档的RgbaValue
页。它的格式为GitHub wiki,每个条目都有一个页面,不幸的是,这意味着绝大多数文档项都是隐藏的,直到你点击show 128 more pages
。
这里的问题是EntityCollection.add(…)接受Entity。这些选项与CZML类似,但在某些方面有明显不同。在你的问题中,你的前几个工作片段正确地使用了ConstructorOptions,它们不像CZML那样完全处理颜色或位置。
要将代码转换为原始的CZML,可以对CZML内容使用CzmlDataSource.load(...)
。例如:Sandcastle live demo
const czml = [
{
id: "document",
version: "1.0",
},
{
"id": "red ellipsoid",
"name": "red ellipsoid",
"position": {
"cartesian": [
-2083516.9683773473,
-4679655.730028949,
4270821.855106338
]
},
"ellipsoid": {
"radii": {
"cartesian": [
200000,
200000,
300000
]
},
"material": {
"solidColor": {
"color": {
"rgba": [255, 0, 0, 128]
}
}
},
"outline": true,
"outlineColor": {
red: 0,
green: 0,
blue: 0,
alpha: 1
}
}
},
];
const viewer = new Cesium.Viewer("cesiumContainer");
const dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);
viewer.zoomTo(dataSourcePromise);