Cesium|xt3d动态传输线
- 效果
- 代码
- 预览地址
效果
代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>cesium|xt3d</title>
<!-- 引入Cesium -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/Build/Cesium/Widgets/widgets.css">
<!-- 引入xt3d -->
<script src="http://www.xt3d.cn/xt3dlib/xt3d.min.js"></script>
<style>
html,
body,
#map3d {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="map3d"></div>
<script>
let xt3dInit = {
init(el) {
this.initViewer(el);
this.load3dtiles();
this.addPolylines();
},
//初始化viewer
initViewer(el) {
this.viewer = new Cesium.Viewer(el, {
infoBox: false,
selectionIndicator: false,
navigation: false,
animation: false,
timeline: false,
baseLayerPicker: false,
geocoder: false,
homeButton: false,
sceneModePicker: false,
navigationHelpButton: false,
shouldAnimate: false,
imageryProvider: new Cesium.UrlTemplateImageryProvider({
url: "https://t7.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=tdtTk"
})
});
//是否开启抗锯齿
this.viewer.scene.fxaa = true;
this.viewer.scene.postProcessStages.fxaa.enabled = true;
},
//添加线
addPolylines() {
let positions = [{
x: -1573322.5898919392,
y: 5327819.044424408,
z: 3123159.886483282
}, {
x: -1573593.4933278325,
y: 5327868.7743272325,
z: 3122914.2552465447
}, {
x: -1573838.5503531531,
y: 5327917.311878511,
z: 3122719.1071619135
}, {
x: -1573992.1810728193,
y: 5327947.898810904,
z: 3122595.063992435
}]
this.addPolyline(positions, Cesium.Color.YELLOW, 5000, 6);
positions = [{
x: -1573753.6344409478,
y: 5328022.051847136,
z: 3122597.6760313655
}, {
x: -1573849.1986015164,
y: 5327892.807416029,
z: 3122752.4022583542
}, {
x: -1574011.3916008596,
y: 5327685.2314376,
z: 3123015.1803947105
}]
this.addPolyline(positions, Cesium.Color.YELLOW, 5000, 5);
positions = [{
x: -1573920.830492183,
y: 5328066.683343329,
z: 3122439.390488729
}, {
x: -1574072.6578983108,
y: 5327859.201900331,
z: 3122703.893024206
}]
this.addPolyline(positions, Cesium.Color.YELLOW, 5000, 3);
positions = [{
x: -1573537.5569049332,
y: 5327935.351199462,
z: 3122831.6039051972
}, {
x: -1573727.2305734043,
y: 5327677.711104301,
z: 3123174.6440329007
}]
this.addPolyline(positions, Cesium.Color.YELLOW, 5000, 1);
},
//添加一条线
addPolyline(positions, color, duration, count) {
let line = this.viewer.entities.add({
polyline: {
positions: positions,
width: 8,
material: new xt3d.PolylineObject.PolylineEnergyTransMaterialProperty({
color: color, //颜色
duration: duration, //时间
count: count, //重复数
url: "/data.xt3d.cn/assets/images/polylinematerial/EnergyTransLine.png", //材质图片
}),
clampToGround: true
}
});
},
//加载3dtiles数据
load3dtiles() {
var tileset = this.viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: "http://www.xt3d.cn/data/offset_3dtiles/tileset.json",
})
);
tileset.readyPromise
.then(tileset => {
this.viewer.zoomTo(
tileset,
);
xt3d.TilesetPlugin.setTilesetHeight(tileset, 55);
})
.otherwise(function(error) {
console.log(error);
});
},
destroy() {
this.viewer.entities.removeAll();
this.viewer.imageryLayers.removeAll(true);
this.viewer.destroy();
}
}
xt3dInit.init("map3d");
</script>
</body>
</html>
预览地址
xt3d 在线预览地址