三維地圖 cesium知識


教程視頻網站:https://ke.qq.com/course/468292

教程學習網站:簡書 cesium官方教程

快速上手:推薦使用:marsGIS for Cesium 平台

 

 Cesium功能點介紹

Viewer 地球對象

 

 

scene 場景對象

 

 

影像圖層

 

 地形圖層

坐標轉換:笛卡爾空間直角坐標,地理坐標(弧度制),地理坐標(經緯度)之間可以互轉

 笛卡爾空間直角坐標轉地理坐標經緯度

1 var position2 = new Cesium.Cartesian3(-2180753.065987198,4379023.266141494,4092583.575045952);
2 var cartographic = Cesium.Cartographic.fromCartesian(position2)
3 var lat = Cesium.Math.toDegrees(cartographic.latitude);
4 var lng = Cesium.Math.toDegrees(cartographic.longitude);
5 let position = Cesium.Cartesian3.fromDegrees(lng, lat, cartographic.height); // 116.47329915346744 39.91549386849083 10.773370964241405

 

camera相機:

 

 交互性

 

 實體和底層primitive

 

 三維模型:

 

 

 

 

第一步:添加元素

1 <div id="cesiumContainer"></div>

第二步:添加樣式

1 #cesiumContainer {
2         width: 100%;
3         height: 100%;
4 }

第三步:添加地球

 1 window.$_viewer = this.viewer = new Cesium.Viewer( // 加載底圖
 2                 "cesiumContainer",
 3                 {
 4                     animation: false, //動畫
 5                     navigation: false, //去掉右側導航欄
 6                     homeButton: false, //home鍵
 7                     geocoder: false, //地址搜素
 8                     baseLayerPicker: false, //圖層選擇控件
 9                     timeline: false, //時間軸
10                     fullscreenButton: false, //全屏顯示
11                     //allOverlays: true,  //是否疊加圖層
12                     infoBox: true, // 點擊要素之后浮窗
13                     sceneModePicker: false, //投影方式  三維/二維
14                     navigationInstructionsInitiallyVisible: false, //導航指令
15                     navigationHelpButton: false, //幫助信息
16                     selectionIndicator: false, // 選擇
17                     navigationHelpButton: false,
18                     skyBox: new Cesium.SkyBox({
19                         sources: {
20                             positiveX: require('@/assets/skybox/漫天彩雲_LF.jpg'),
21                             negativeX: require('@/assets/skybox/漫天彩雲_RT.jpg'),
22                             positiveY: require('@/assets/skybox/漫天彩雲_UP.jpg'),
23                             negativeY: require('@/assets/skybox/漫天彩雲_DN.jpg'),
24                             positiveZ: require('@/assets/skybox/漫天彩雲_FR.jpg'),
25                             negativeZ: require('@/assets/skybox/漫天彩雲_BK.jpg'),
26                         },
27                     }),
28                 }
29 )

this.viewer.scene.skyBox.show = false; // 不顯示天空
this.viewer.scene.sun.show = false; // 不顯示太陽
this.viewer.scene.undergroundMode = true; //重要,開啟地下模式,設置基色透明,這樣就看不見黑色地球了
this.viewer.scene.underGlobe.show = true;
this.viewer.scene.underGlobe.baseColor = new Cesium.Color(0, 0, 0, 1);
this.viewer.scene.globe.show = false; // 隱藏地球

第四步:控制顯示

1 this.viewer._cesiumWidget._creditContainer.style.display = "none" // 隱藏cesium icon
2 this.viewer.scene.undergroundMode = true; //重要,開啟地下模式,設置基色透明,這樣就看不見黑色地球了
3 this.viewer.scene.underGlobe.show = true;
4 this.viewer.scene.underGlobe.baseColor = new Cesium.Color(0, 0, 0, 1);
5 this.viewer.scene.globe.show = false; // 隱藏地球
6 this.viewer._cesiumWidget._creditContainer.style.display = "none" // 隱藏cesium icon

第五步:添加底圖

1 this.imageLayer = this.viewer.imageryLayers.addImageryProvider(
2     new Cesium.TileMapServiceImageryProvider({
3            //影像圖
4            url: "http://121.196.59.85:8016/yx_g",
5            fileExtension: "jpg" //url為文件夾地址
6     })
7 )
8 this.imageLayer.show = true //默認顯示影像圖

第六步:添加模型

1 let promise = this.viewer.scene.open(BIMData.serviceUrl, undefined, {
2      autoSetView: false
3  });
4  promise.then((layers) => {
5 }):

第七步:控制模型顯示

1 this.layers.forEach(layer => {
2         layer.setObjsVisible(ids, true);
3 });

第八步:控制模型點擊

1 // 點擊模型出現屬性框
2 this.viewer.pickEvent.addEventListener((feature) => {
3        this.$refs.propertyinfo.serviceloading = true;
4 });

 控制視圖定位在某個區域

 1 this.orientation = {
 2       heading: Cesium.Math.toRadians(348.4202942851978),
 3       pitch: Cesium.Math.toRadians(-89.74026687972041),
 4       roll: Cesium.Math.toRadians(0)
 5 };
 6 this.destination = Cesium.Rectangle.fromDegrees(MaxMinXYData.minx, MaxMinXYData.miny, MaxMinXYData.maxx, MaxMinXYData.maxy)
 7 this.viewer.camera.flyTo({ // 相機飛到矩形對應位置
 8      destination: this.destination, // 位置
 9      orientation: this.orientation,
10      complete: () => {
11             // 定位完成之后的回調函數
12      }
13 });

 控制視圖定位在某個坐標和對應海拔

1 position = Cesium.Cartesian3.fromDegrees(parseFloat(lng), parseFloat(lat), 3000);
2 this.viewer.camera.flyTo({ // 相機飛到矩形對應位置
3         destination: position, // 位置
4 });

 獲取海拔

 1 let height = this.viewer.camera.positionCartographic.height.toFixed(6) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM