流光、预警、城市道路、波纹圆、动态墙等自定义材质。下面是该示例的核心 script 片段,供参考学习;完整可运行代码请进入在线 Demo 或查看仓库源码。
import * as Cesium from 'cesium'
import { initCesium } from '@/utils/cesiumPluginsExtends/index'
export default {
mounted () {
this.initMap()
},
methods: {
async initMap () {
const { viewer,
material,
graphics,
math3d } = new initCesium(
{
cesiumGlobal: Cesium,
containerId: 'cesiumContainer',
viewerConfig: {
infoBox: false,
shouldAnimate: true,
},
extraConfig: {},
MapImageryList: []
})
this.c_viewer = viewer;
this.material = material;
this.graphics = graphics;
this.math3d = math3d;
this.material.setDefSceneConfig()
this.material.setBloomLightScene()
// let tileset = this.c_viewer.scene.primitives.add(
// new Cesium.Cesium3DTileset({
// url: 'static/data/3DTiles/building/tileset.json',
// }),
// )
let tiles = await Cesium.Cesium3DTileset.fromUrl('static/data/3DTiles/building/tileset.json');
let tileset = this.c_viewer.scene.primitives.add(tiles)
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
["${height} >= 300", "rgba(0, 149, 251, 0.3)"],
["${height} >= 200", "rgb(0, 149, 251, 0.3)"],
["${height} >= 100", "rgb(0, 149, 251, 0.3)"],
["${height} >= 50", "rgb(0, 149, 251, 0.3)"],
["${height} >= 25", "rgb(0, 149, 251, 0.3)"],
["${height} >= 10", "rgb(0, 149, 251, 0.3)"],
["${height} >= 5", "rgb(0, 149, 251, 0.3)"],
["true", "rgb(0, 149, 251, 0.3)"]
]
}
})
this.c_viewer.flyTo(tileset)
this.createModel();
},
getCustomMaterialLine (colors) {
return new Cesium.Scene.PolylineFlowMaterialProperty({
color: colors,
duration: 200
})
},
createModel () {
const _self = this;
var colors = [
new Cesium.Color(77 / 255, 201 / 255, 255 / 255, 1),
new Cesium.Color(255 / 255, 201 / 255, 38 / 255, 1),
new Cesium.Color(221 / 255, 221 / 255, 221 / 255, 1)
];
var startPoint = Cesium.Cartesian3.fromDegrees(104.081701757991, 30.627042558105988)
for (var i = 0, len = 8; i < len; i++) {
var endPoint = Cesium.Cartesian3.fromDegrees((Math.random() / 100) + 104.081701757991, (Math.random() / 100) + 30.627042558105988)
var positions = this.math3d.getLinkedPointList(startPoint, endPoint, 100000, 50);
var glowingLine = this.c_viewer.entities.add({
polyline: {
positions: positions,
width: 5,
material: _self.getCustomMaterialLine(colors[i % 3]),
}
});
}
}
},
beforeUnmount () {
this.c_viewer = null;
this.material = null;
this.graphics = null;
}
}
安装:npm install cesium_dev_kit cesium