效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1815cf581ac7bc5a463b5cc691021b64.png#pic_center)
代码
<!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://unpkg.com/cesium@1.84.0/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://unpkg.com/cesium@1.84.0/Build/Cesium/Widgets/widgets.css">
<!-- 使用vue绑定控件 -->
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.5/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui@2.15.5/lib/index.js"></script>
<!-- 引入xt3d -->
<script src="http://www.xt3d.cn/xt3dlib/xt3d.min.js"></script>
<style>
html,
body,
#map3d {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
.form-container {
position: absolute;
left: 10px;
top: 90px;
padding: 10px 15px;
border-radius: 4px;
border: 1px solid rgba(128, 128, 128, 0.5);
color: #ffffff;
background: rgba(0, 0, 0, 0.4);
box-shadow: 0 3px 14px rgb(128 128 128 / 50%);
max-width: 380px;
}
button {
background: transparent;
border: 1px solid #00d0ffb8;
color: white;
padding: 7px 9px;
border-radius: 2px;
margin: 3px;
cursor: pointer
}
.tip-item {
margin: 2px 0px;
padding: 5px 1px;
}
</style>
</head>
<body>
<div id="map3d"></div>
<div class="form-container" id="formContainer">
<button @click="addViewShed">添加视域</button>
<button @click="removeViewShed">清除视域</button>
<div class="tip-item">点击“添加视域”按钮后在场景中点击两个点添加视域</div>
<div class="tip-item" style="margin-bottom:20px">参数调整</div>
<span>视域方向</span>
<el-slider v-model="form.viewHeading" :step="10" :show-tooltip="true" @input="valueChange" :min="0" :max="360"></el-slider>
<span>水平张角</span>
<el-slider v-model="form.horizontalViewAngle" :step="10" :show-tooltip="true" @input="valueChange" :min="1" :max="120"></el-slider>
<span>视域距离</span>
<el-slider v-model="form.viewDistance" :show-tooltip="true" @input="valueChange" :min="1" :max="1000" :step="10"></el-slider>
</div>
<script>
let xt3dInit = {
init(el) {
this.initViewer(el);
this.load3dtiles();
this.setView();
},
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.ArcGisMapServerImageryProvider({
url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
})
});
this.viewer.scene.fxaa = true;
this.viewer.scene.postProcessStages.fxaa.enabled = true;
},
load3dtiles() {
let tileset = this.viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: "http://earthsdk.com/v/last/Apps/assets/dayanta/tileset.json"
})
);
tileset.readyPromise
.then(tileset => {
xt3d.TilesetPlugin.setTilesetHeight(tileset, 20);
})
.otherwise(function(error) {
console.log(error);
});
},
setView() {
let flyToOpts = {
destination: {
x: -1715409.562837149,
y: 4993440.195172727,
z: 3566464.775408765
},
orientation: {
heading: 0.10239989100003832,
pitch: -0.532365037425917,
roll: 0.00037077146741548717
},
duration: 1
};
this.viewer.scene.camera.setView(flyToOpts);
},
destroy() {
this.viewer.entities.removeAll();
this.viewer.imageryLayers.removeAll(true);
this.viewer.destroy();
}
}
xt3dInit.init("map3d");
let viewShed = new xt3d.SpatialAnalysis.ViewShed3D(xt3dInit.viewer);
let fiewField;
viewShed.DrawEndEvent.addEventListener(e => {
fiewField = e;
vm.form = e.getStyle();
});
let vm = new Vue({
el: "#formContainer",
data() {
return {
form: {
viewHeading: 0,
viewDistance: 0,
horizontalViewAngle: 0,
verticalViewAngle: 0
}
}
},
methods: {
valueChange() {
if (!fiewField) return;
fiewField.updateStyle(this.form);
},
addViewShed() {
this.removeViewShed();
viewShed.activate();
},
removeViewShed() {
if (fiewField) {
fiewField.remove();
fiewField = undefined;
}
}
}
})
</script>
</body>
</html>
预览地址
xt3d 在线预览地址