添加测试

This commit is contained in:
qiushijie 2024-06-27 15:10:27 +08:00
parent da05acbf28
commit d3e47ad7ea
2 changed files with 160 additions and 21 deletions

View File

@ -0,0 +1,141 @@
<script setup>
import { ref ,onMounted} from 'vue'
import * as Cesium from 'cesium';
import _ from "lodash";
import * as turf from 'turf';
let viewer = null,
tempEntities = [],
isAddPoint = false;
onMounted(()=>{
initViewer();
})
function initViewer(){
//
const TDT_tk = "ea3530e6803b44025cfa81500eaae01f";
let TDT_IMG_C = "http://{s}.tianditu.gov.cn/img_c/wmts?service=wmts&request=GetTile&version=1.0.0" +
"&LAYER=img&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}" +
"&style=default&format=tiles&tk=" + TDT_tk;
const cesiumKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyNjI2ZjVjMS0zZTFjLTQ3MDAtYTZlZC02YWFjOWQwNzBjNjIiLCJpZCI6ODM1NTQsImlhdCI6MTY0NTY1NzYzM30.IPqS_sM-s_vzNnK0EAiTy6kpYP5RBYkuMgbqJtKQkPw";
Cesium.Ion.defaultAccessToken = cesiumKey;
viewer = new Cesium.Viewer("cesiumContainer",{
geocoder: false, //
homeButton: false, //
sceneModePicker: true, //
baseLayerPicker:false,//
navigationHelpButton: false, //
animation: false, //
creditContainer:document.createElement("div"),//
timeline: false, //线
fullscreenButton: false, //
vrButton: false,
infoBox:false,
selectionIndicator:false,
// scene3DOnly: true, // 3DGPU
// sceneMode: 3, // 1 2D 2 2D 3 3D Cesium.SceneMode
// imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
// url: TDT_IMG_C,
// layer: "tdtImg_c",
// style: "default",
// format: "tiles",
// tileMatrixSetID: "c",
// subdomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
// tilingScheme: new Cesium.GeographicTilingScheme(),
// tileMatrixLabels: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"],
// maximumLevel: 50,
// show: false
// })
// terrain: Cesium.Terrain.fromWorldTerrain({
// requestWaterMask: true,
// requestVertexNormals: true
// })
})
// Cesium ion
const terrain = new Cesium.Terrain(
Cesium.CesiumTerrainProvider.fromIonAssetId(1),
)
viewer.scene.setTerrain(terrain);
viewer.scene.globe.depthTestAgainstTerrain = false; //
viewer.scene.fxaa = false;
//
viewer.scene.screenSpaceCameraController.minimumZoomDistance = 0; //
viewer.scene.screenSpaceCameraController.maximumZoomDistance = 20000000; //
//
viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
);
// Fly the camera to San Francisco at the given longitude, latitude, and height.
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(113.9641713, 23.3191755, 400),
orientation: {
heading: Cesium.Math.toRadians(0.0),
pitch: Cesium.Math.toRadians(-15.0)
}
})
}
</script>
<template>
<div id="cesiumContainer"></div>
<div class="menu-container">
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<el-breadcrumb separator="/">
<el-breadcrumb-item>cesium</el-breadcrumb-item>
<el-breadcrumb-item>绘制功能</el-breadcrumb-item>
<el-breadcrumb-item>线</el-breadcrumb-item>
</el-breadcrumb>
</div>
</el-col>
</el-row>
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<cesiumComponent id="cesium" ref="refCesium" />
</div>
</el-col>
</el-row>
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<el-button type="primary" @click="drawTerrian()">获取视野内的地形</el-button>
<el-button type="primary" @click="filterTerrian()">过滤地形</el-button>
<el-button type="primary" @click="drawTin()">绘制TIN</el-button>
<!-- <el-button type="primary" @click="draw('polyline')">绘制线</el-button>
<el-button type="primary" @click="draw('polygon')">绘制面</el-button>
<el-button type="primary" @click="clearDrawEntities">清空</el-button> -->
</div>
</el-col>
</el-row>
</div>
<div
id="tooltip"
style="
position: absolute;
z-index: 999;
background: rgba(0, 0, 0, 0.3);
color: rgb(255, 255, 255);
font-size: 12px;
padding: 5px;
border-radius: 5px;
"
>
左键点击选点右键确定
</div>
</template>
<style scoped>
#cesiumContainer{
height: 100%;
width: 100%;
}
.menu-container {
position: absolute;
top: 30px;
left: 100px;
z-index: 9999;
}
</style>

View File

@ -76,26 +76,26 @@ onMounted(()=>{
// })
addGeoJson();
//:
var scene = viewer.scene;
var globe = viewer.scene.globe;
//
var tilesToProcess = [];
var quadtree =
viewer.scene.globe._surface._tileProvider._quadtree._tilesToRender;
//
quadtree.forEach(function(tile) {
tilesToProcess.push(tile);
if (tile instanceof Cesium.Cesium3DTileset) return;
});
const MAX_SHORT = 32767;
var terrainProvider=viewer.terrainProvider
// //:
// var scene = viewer.scene;
// var globe = viewer.scene.globe;
// //
// var tilesToProcess = [];
// var quadtree =
// viewer.scene.globe._surface._tileProvider._quadtree._tilesToRender;
// //
// quadtree.forEach(function(tile) {
// tilesToProcess.push(tile);
// if (tile instanceof Cesium.Cesium3DTileset) return;
// });
// const MAX_SHORT = 32767;
// var terrainProvider=viewer.terrainProvider
// Request
const request = new Cesium.Request({
throttle: true,
throttleByServer: true
});
// // Request
// const request = new Cesium.Request({
// throttle: true,
// throttleByServer: true
// });
// terrain.readyEvent.addEventListener(provider => {
// scene.globe.enableLighting = true;
@ -136,12 +136,10 @@ onMounted(()=>{
//
function requestMultipleTiles(tileCoords, level, terrainProvider) {
let promises = [];
for (let tileCoord of tileCoords) {
let promise = requestTileData(tileCoord.x, tileCoord.y, level, terrainProvider);
promises.push(promise);
}
return Promise.all(promises);
}