在学习Cesium过程中,发现Cesium的Material可以自定义自己所需的材质,看到网上其他资源有实现城市飞线的效果,感觉挺酷炫,于是经过一凡探索,实现了一下效果
调用实现方式:
addFlyintLineByPrimitive(positions) {
// primitive方式添加
const primitive = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: positions,
width: 1.0,
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
})
}),
appearance: new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType(Cesium.Material.PolylineFlowType, {
speed: 10 * Math.random(),
color: Cesium.Color.CYAN,
percent: 0.1,
gradient: 0.01
}),
})
});
this.viewer.scene.primitives.add(primitive);
},
addFlyingLineByEntity(positions) {
//entity方式添加
this.viewer.entities.add({
polyline: {
positions: positions,
width: 2.0,
material: new Cesium.PolylineFlowMaterialProperty({
speed: 6 * Math.random(),
color: Cesium.Color.CYAN,
percent: 0.1,
gradient: 0.01
})
}
})
},
需要该效果详细代码,愿意送出一瓶可乐的请加微信,注明飞线代码哦。