|
|
@@ -21,24 +21,34 @@
|
|
|
//去除覆盖物 removeEntity(id)
|
|
|
//初始化数据 onload()
|
|
|
|
|
|
+ 信息框 --------------------->
|
|
|
+ 添加相应的信息框在相应的数组添加数据即可,具体添加可看数组元素注释部分
|
|
|
-->
|
|
|
|
|
|
<template>
|
|
|
<div class="full">
|
|
|
- <div class="full" id="viewer-container"></div>
|
|
|
- <info-layer ref="infoLayer"></info-layer>
|
|
|
+ <div class="full" id="viewer-container">
|
|
|
+ <danger-circle :viewer="viewer" ref="dangerCircle"></danger-circle>
|
|
|
+ </div>
|
|
|
+ <info-layer ref="infoLayer"
|
|
|
+ :box1="box1"
|
|
|
+ :box2="box2"
|
|
|
+ ></info-layer>
|
|
|
+ <tools-bar></tools-bar>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import InfoLayer from "./map-components/InfoLayer";
|
|
|
- let viewer = undefined;
|
|
|
+ import DangerCircle from "./map-components/overlays/dangerCircle";
|
|
|
+ import ToolsBar from "./map-components/tools-bar/tools-bar";
|
|
|
let scratch = new Cesium.Cartesian2();
|
|
|
export default {
|
|
|
name: "Map3D",
|
|
|
- components: {InfoLayer},
|
|
|
+ components: {ToolsBar, DangerCircle, InfoLayer},
|
|
|
data(){
|
|
|
return{
|
|
|
+ viewer: {},
|
|
|
//默认场景参数
|
|
|
mapOption: {
|
|
|
animation: false, // 动画小组件
|
|
|
@@ -55,10 +65,26 @@ export default {
|
|
|
// 如果最初应该看到导航说明,则为true;如果直到用户明确单击该按钮,则该提示不显示,否则为false。
|
|
|
navigationInstructionsInitiallyVisible: false,
|
|
|
imageryLayers: [],
|
|
|
+ // skyBox: new Cesium.SkyBox({
|
|
|
+ // sources: {
|
|
|
+ // positiveX: '/sky/SKY_u.jpg',
|
|
|
+ // negativeX: '/sky/SKY_r.jpg',
|
|
|
+ // positiveY: '/sky/SKY_b.jpg',
|
|
|
+ // negativeY: '/sky/SKY_l.jpg',
|
|
|
+ // positiveZ: '/sky/SKY_f.jpg',
|
|
|
+ // negativeZ: '/sky/SKY_d.jpg',
|
|
|
+ // }
|
|
|
+ // }),
|
|
|
},
|
|
|
+ isRound: true,
|
|
|
layers: [],
|
|
|
handle: {},
|
|
|
- positionListenerList: [],
|
|
|
+ box1: [
|
|
|
+ // {position: [113.682062,34.702187],title: '汤阴小学',data:[{label: '地点' , value: '汤阴县'},{label: '联系方式' , value: '4664-858585'}],x:0,y:0}
|
|
|
+ ],
|
|
|
+ box2: [
|
|
|
+ // {position: [113.682062,34.702187],data:'我是数据',x:0,y:0},
|
|
|
+ ],
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -83,49 +109,59 @@ export default {
|
|
|
},
|
|
|
//初始化地图
|
|
|
initMap(option=this.mapOption){
|
|
|
- viewer = new Cesium.Viewer("viewer-container",option);
|
|
|
- this.$viewer = viewer;
|
|
|
+ this.viewer = new Cesium.Viewer("viewer-container",option);
|
|
|
// 隐藏logo
|
|
|
- viewer._cesiumWidget._creditContainer.style.display = "none";
|
|
|
-
|
|
|
+ this.viewer._cesiumWidget._creditContainer.style.display = "none";
|
|
|
+ // viewer.scene.globe.show = false; // 隐藏地球实体
|
|
|
// viewer.imageryLayers.removeAll();
|
|
|
- // viewer.imageryLayers.addImageryProvider(
|
|
|
- // new Cesium.BaiduImageryProvider({
|
|
|
- // style: 'normal',
|
|
|
- // crs: 'WGS84'
|
|
|
- // })
|
|
|
- // );
|
|
|
- viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString("rgba(20,56,76,0.5)");
|
|
|
- viewer.scene.preRender.addEventListener(this.moveListener);
|
|
|
+ this.viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString("rgba(20,56,76,0.5)");
|
|
|
+ this.viewer.scene.preRender.addEventListener(this.moveListener);
|
|
|
+ // this.addGltf([113.682062,34.702187,0],'/demo/8H.gltf');
|
|
|
},
|
|
|
//添加建筑矢量数据,url为建模json数据
|
|
|
addBuildingData(url){
|
|
|
- this.$viewer.scene.primitives.add(
|
|
|
+ this.viewer.scene.primitives.add(
|
|
|
new Cesium.Cesium3DTileset({url})
|
|
|
);
|
|
|
},
|
|
|
//添加图层
|
|
|
addLayer(layer,layerId){
|
|
|
this.layers.push({layerId, layer});
|
|
|
- this.$viewer.scene.primitives.add(layer);
|
|
|
+ this.viewer.scene.primitives.add(layer);
|
|
|
},
|
|
|
//移除指定图层
|
|
|
removeLayer(layerId){
|
|
|
this.layers.forEach(item => {
|
|
|
if(item.layerId==layerId){
|
|
|
- this.$viewer.scene.primitives.remove(item.layer);
|
|
|
+ this.viewer.scene.primitives.remove(item.layer);
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ //移除所有信息框
|
|
|
+ removeAllBox(){
|
|
|
+ this.box1 = [];
|
|
|
+ this.box2 = [];
|
|
|
+ },
|
|
|
+ //添加gltf模型
|
|
|
+ addGltf(position=[113.682062,34.702187,0],url,option={scale : 100.0}){
|
|
|
+ var scene = this.viewer.scene;
|
|
|
+ var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
|
|
|
+ Cesium.Cartesian3.fromDegrees(position[0],position[1],position[2]));
|
|
|
+ var model = scene.primitives.add(Cesium.Model.fromGltf({
|
|
|
+ url,
|
|
|
+ modelMatrix,
|
|
|
+ ...option,
|
|
|
+ }));
|
|
|
+ },
|
|
|
//移除所有图层
|
|
|
removeAllLayers(){
|
|
|
this.layers.forEach(item => {
|
|
|
- this.$viewer.scene.primitives.remove(item.layer);
|
|
|
+ this.viewer.scene.primitives.remove(item.layer);
|
|
|
})
|
|
|
},
|
|
|
//指定相机位置
|
|
|
flyToPosition(longitude,latitude,height,heading,pitch,roll){
|
|
|
- this.$viewer.camera.flyTo({
|
|
|
+ this.viewer.camera.flyTo({
|
|
|
destination : Cesium.Cartesian3.fromDegrees(longitude,latitude,height),
|
|
|
orientation : {
|
|
|
heading : Cesium.Math.toRadians(heading),
|
|
|
@@ -141,7 +177,7 @@ export default {
|
|
|
},
|
|
|
//添加图标覆盖物(单个)
|
|
|
addBillBoard(longitude,latitude,height,image,option= {},id){
|
|
|
- this.$viewer.entities.add(
|
|
|
+ this.viewer.entities.add(
|
|
|
{
|
|
|
position : Cesium.Cartesian3.fromDegrees(longitude, latitude,height),
|
|
|
billboard : {
|
|
|
@@ -154,8 +190,8 @@ export default {
|
|
|
},
|
|
|
//添加百度地图地图
|
|
|
addBaiduLayer(){
|
|
|
- viewer.imageryLayers.removeAll();
|
|
|
- viewer.imageryLayers.addImageryProvider(
|
|
|
+ this.viewer.imageryLayers.removeAll();
|
|
|
+ this.viewer.imageryLayers.addImageryProvider(
|
|
|
new Cesium.BaiduImageryProvider({
|
|
|
style: 'midnight',
|
|
|
crs: 'WGS84'
|
|
|
@@ -179,35 +215,46 @@ export default {
|
|
|
},
|
|
|
//去除覆盖物
|
|
|
removeEntity(id){
|
|
|
- this.$viewer.entities.removeById(id);
|
|
|
+ this.viewer.entities.removeById(id);
|
|
|
},
|
|
|
//去除所有覆盖物
|
|
|
removeAllEntity(){
|
|
|
- this.$viewer.entities.removeAll();
|
|
|
+ this.viewer.entities.removeAll();
|
|
|
},
|
|
|
//屏幕坐标转化
|
|
|
- convertScreen(position){
|
|
|
- return viewer.scene.cartesianToCanvasCoordinates(
|
|
|
- Cesium.Cartesian3.fromDegrees(position[0], position[1], 0),
|
|
|
- new Cesium.Cartesian2()
|
|
|
- );
|
|
|
- },
|
|
|
- //相机移动事件
|
|
|
- moveListener(){
|
|
|
-
|
|
|
- this.positionListenerList.forEach(item => {
|
|
|
- let location = this.convertScreen(item.position);
|
|
|
+ convertScreen(list){
|
|
|
+ list.forEach(item => {
|
|
|
+ let location = this.viewer.scene.cartesianToCanvasCoordinates(
|
|
|
+ Cesium.Cartesian3.fromDegrees(item.position[0], item.position[1], 0),
|
|
|
+ new Cesium.Cartesian2()
|
|
|
+ );
|
|
|
if(Cesium.defined(location)) {
|
|
|
- item.x = location.x;
|
|
|
- item.y = location.y;
|
|
|
- }
|
|
|
+ item.x = location.x;
|
|
|
+ item.y = location.y;
|
|
|
+ }
|
|
|
})
|
|
|
+
|
|
|
+ },
|
|
|
+ //绕点旋转
|
|
|
+ round(){
|
|
|
+ const center = Cesium.Cartesian3.fromDegrees(113.702062,34.702187);
|
|
|
+ let heading = Cesium.Math.toRadians(50.0);
|
|
|
+ const pitch = Cesium.Math.toRadians(-20.0);
|
|
|
+ const range = 5000.0;
|
|
|
+ let x=50;
|
|
|
+ let _this = this;
|
|
|
+ this.viewer.scene.preUpdate.addEventListener( () => {
|
|
|
+ if(_this.isRound){
|
|
|
+ x+=0.1;
|
|
|
+ heading = Cesium.Math.toRadians(x);
|
|
|
+ _this.viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range))
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
- //添加坐标监控
|
|
|
- addPosition(position){
|
|
|
- let cartesian2 = this.convertScreen(position);
|
|
|
- this.positionListenerList.push({position,x:cartesian2.x,y:cartesian2.y});
|
|
|
- console.log(this.positionListenerList);
|
|
|
+ //相机移动事件
|
|
|
+ moveListener(){
|
|
|
+ this.convertScreen(this.box1);
|
|
|
+ this.convertScreen(this.box2);
|
|
|
},
|
|
|
//初始化数据
|
|
|
onload(){
|
|
|
@@ -215,13 +262,14 @@ export default {
|
|
|
this.initMap();
|
|
|
//初始化弹框图层
|
|
|
this.$refs['infoLayer'].onload();
|
|
|
+ this.$refs['dangerCircle'].onLoad();
|
|
|
+ this.round();
|
|
|
//添加建筑矢量数据
|
|
|
this.addBuildingData('http://139.9.103.171/mapData/zhengzhou/tileset.json')
|
|
|
//定位建筑群位置
|
|
|
- this.flyToPosition(113.682062,34.662187, 2000.0,0,-20.0,0.0);
|
|
|
+ this.flyToPosition(113.702062,34.702187, 2000.0,0,-20.0,0.0);
|
|
|
},
|
|
|
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
</script>
|