Cesium material 在多边形上被忽略
Cesium material being ignored on polygon
我正在尝试使用 material 属性 设置多边形的颜色,如下所示:
drawOnMap() {
let material = Cesium.Material.fromType('Color');
material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);
const entityObject = {
polygon: {
hierarchy: this.positions !== undefined ? this.positions : undefined,
height: 0,
material: material,
}
};
return this.cesiumEntity = this.cesiumViewerService.getViewer().entities.add( entityObject );
}
我尝试了各种组合来创建 material,但它们都被忽略了,多边形被渲染为白色。我错过了什么?
请注意,如果我使用 Cesium.Color.RED
,多边形会按预期呈现为红色。
不胜感激!
您在这里使用了两个不同的 API。创建实体后,您可以通过设置颜色制服等来编辑现有的 Material。但是,在实体存在之前,您使用的字段用于实体创建选项,而不是用于预先存在的实体。
因此查看 Entity doc, we can see an option polygon
that takes a PolygonGraphics, which has a field material
that takes a MaterialProperty (not a constructed material!), which is an abstract class with a few implementations, one of which is ColorMaterialProperty。
所以,试试这个:
drawOnMap() {
let materialProperty = new Cesium.ColorMaterialProperty(
new Cesium.Color(1.0, 1.0, 0.0, 1.0)
);
const entityObject = {
polygon: {
hierarchy: this.positions !== undefined ? this.positions : undefined,
height: 0,
material: materialProperty
}
};
return this.cesiumEntity = this.cesiumViewerService.getViewer().entities.add( entityObject );
}
我正在尝试使用 material 属性 设置多边形的颜色,如下所示:
drawOnMap() {
let material = Cesium.Material.fromType('Color');
material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);
const entityObject = {
polygon: {
hierarchy: this.positions !== undefined ? this.positions : undefined,
height: 0,
material: material,
}
};
return this.cesiumEntity = this.cesiumViewerService.getViewer().entities.add( entityObject );
}
我尝试了各种组合来创建 material,但它们都被忽略了,多边形被渲染为白色。我错过了什么?
请注意,如果我使用 Cesium.Color.RED
,多边形会按预期呈现为红色。
不胜感激!
您在这里使用了两个不同的 API。创建实体后,您可以通过设置颜色制服等来编辑现有的 Material。但是,在实体存在之前,您使用的字段用于实体创建选项,而不是用于预先存在的实体。
因此查看 Entity doc, we can see an option polygon
that takes a PolygonGraphics, which has a field material
that takes a MaterialProperty (not a constructed material!), which is an abstract class with a few implementations, one of which is ColorMaterialProperty。
所以,试试这个:
drawOnMap() {
let materialProperty = new Cesium.ColorMaterialProperty(
new Cesium.Color(1.0, 1.0, 0.0, 1.0)
);
const entityObject = {
polygon: {
hierarchy: this.positions !== undefined ? this.positions : undefined,
height: 0,
material: materialProperty
}
};
return this.cesiumEntity = this.cesiumViewerService.getViewer().entities.add( entityObject );
}