当前位置: 首页 > wzjs >正文

江干网站建设建设电动车官方网站

江干网站建设,建设电动车官方网站,wordpress和新浪微博同步,湖北宜昌网络科技有限公司基于cesium和vue绘制多边形实现地形开挖效果,适合学习Cesium与前端框架结合开发3D可视化项目。 demo源码运行环境以及配置 运行环境:依赖Node安装环境,demo本地Node版本:推荐v18。 运行工具:vscode或者其他工具。 配置方式&#x…

基于cesium和vue绘制多边形实现地形开挖效果,适合学习Cesium与前端框架结合开发3D可视化项目。

demo源码运行环境以及配置

运行环境:依赖Node安装环境,demo本地Node版本:推荐v18+。

运行工具:vscode或者其他工具。

配置方式:下载demo源码,vscode打开,然后顺序执行以下命令:
(1)下载demo环境依赖包命令:npm install
(2)启动demo命令:npm run dev
(3)打包demo命令: npm run build

技术栈

Vue 3.5.13

Vite 6.2.0

Cesium 1.128.0

示例效果
在这里插入图片描述
核心源码

<template><div id="cesiumContainer" class="cesium-container"><!-- 模型调整控制面板 --><div class="control-panel"><div class="panel-header"><h3>地形开挖</h3></div><div class="panel-body"><div class="control-group"><button @click="startDrawPolygon">绘制多边形</button></div><div class="control-group"><button @click="clearDrawing">清除绘制</button></div><div class="control-group" v-if="drawingInstructions"><span>{{ drawingInstructions }}</span></div></div></div></div>
</template><script setup>
import { onMounted, onUnmounted, ref } from 'vue';
import * as Cesium from 'cesium';Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxZjhjYjhkYS1jMzA1LTQ1MTEtYWE1Mi0zODc5NDljOGVkMDYiLCJpZCI6MTAzNjEsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyJdLCJpYXQiOjE1NzA2MDY5ODV9.X7tj92tunUvx6PkDpj3LFsMVBs_SBYyKbIL_G9xKESA';
// 声明Cesium Viewer实例
let viewer = null;
// 声明变量用于存储事件处理器和绘制状态
let handler = null;
let activeShapePoints = [];
let activeShape = null;
let floatingPoint = null;
let excavateInstance = null;// 绘制状态提示
const drawingInstructions = ref('');// 组件挂载后初始化Cesium
onMounted(async () => {const files = ["./excavateTerrain/excavateTerrain.js"];loadScripts(files, function () {console.log("All scripts loaded");initMap();});
});
const loadScripts = (files, callback) => {// Make Cesium available globally for the scriptswindow.Cesium = Cesium;if (files.length === 0) {callback();return;}const file = files.shift();const script = document.createElement("script");script.onload = function () {loadScripts(files, callback);};script.src = file;document.head.appendChild(script);
};
const initMap = async () => {// 初始化Cesium Viewerviewer = new Cesium.Viewer('cesiumContainer', {// 基础配置animation: false, // 动画小部件baseLayerPicker: false, // 底图选择器fullscreenButton: false, // 全屏按钮vrButton: false, // VR按钮geocoder: false, // 地理编码搜索框homeButton: false, // 主页按钮infoBox: false, // 信息框 - 禁用点击弹窗sceneModePicker: false, // 场景模式选择器selectionIndicator: false, // 选择指示器timeline: false, // 时间轴navigationHelpButton: false, // 导航帮助按钮navigationInstructionsInitiallyVisible: false, // 导航说明初始可见性scene3DOnly: false, // 仅3D场景terrain: Cesium.Terrain.fromWorldTerrain(), // 使用世界地形});// 隐藏logoviewer.cesiumWidget.creditContainer.style.display = "none";viewer.scene.globe.enableLighting = true;// 禁用大气层和太阳viewer.scene.skyAtmosphere.show = false;//前提先把场景上的图层全部移除或者隐藏 // viewer.scene.globe.baseColor = Cesium.Color.BLACK; //修改地图蓝色背景viewer.scene.globe.baseColor = new Cesium.Color(0.0, 0.1, 0.2, 1.0); //修改地图为暗蓝色背景// 设置抗锯齿viewer.scene.postProcessStages.fxaa.enabled = true;// 清除默认底图viewer.imageryLayers.remove(viewer.imageryLayers.get(0));// 加载底图 - 使用更暗的地图服务const imageryProvider = await Cesium.ArcGisMapServerImageryProvider.fromUrl("https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");viewer.imageryLayers.addImageryProvider(imageryProvider);// 设置默认视图位置 - 默认显示全球视图viewer.camera.setView({destination: Cesium.Cartesian3.fromDegrees(104.0, 30.0, 10000000.0), // 中国中部上空orientation: {heading: 0.0,pitch: -Cesium.Math.PI_OVER_TWO,roll: 0.0}});// 启用地形深度测试,确保地形正确渲染viewer.scene.globe.depthTestAgainstTerrain = true;// 清除默认地形// viewer.scene.terrainProvider = new Cesium.EllipsoidTerrainProvider({});// 开启帧率viewer.scene.debugShowFramesPerSecond = true;
}
// 开始绘制多边形
const startDrawPolygon = () => {// 清除之前的绘制clearDrawing();// 设置绘制提示drawingInstructions.value = '左键点击添加顶点,右键完成绘制';// 创建新的事件处理器handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);// 监听左键点击事件 - 添加顶点handler.setInputAction((click) => {// 获取点击位置的笛卡尔坐标const cartesian = viewer.scene.pickPosition(click.position);if (!Cesium.defined(cartesian)) {return;}// 将点添加到活动形状点数组activeShapePoints.push(cartesian);// 如果是第一个点,创建浮动点if (activeShapePoints.length === 1) {floatingPoint = createPoint(cartesian);// 创建动态多边形activeShape = createPolygon(activeShapePoints);}}, Cesium.ScreenSpaceEventType.LEFT_CLICK);// 监听鼠标移动事件 - 更新动态多边形handler.setInputAction((movement) => {if (activeShapePoints.length >= 1) {const cartesian = viewer.scene.pickPosition(movement.endPosition);if (!Cesium.defined(cartesian)) {return;}// 更新浮动点位置if (floatingPoint) {floatingPoint.position.setValue(cartesian);}// 更新动态多边形if (activeShape) {const positions = activeShapePoints.concat([cartesian]);activeShape.polygon.hierarchy = new Cesium.PolygonHierarchy(positions);}}}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);// 监听右键点击事件 - 完成绘制handler.setInputAction(() => {if (activeShapePoints.length < 3) {// 至少需要3个点才能形成多边形drawingInstructions.value = '至少需要3个点才能形成多边形,请继续绘制';return;}// 完成绘制terminateShape();// 执行地形开挖performExcavation(activeShapePoints);// 清除绘制状态drawingInstructions.value = '绘制完成,地形已开挖';// 清除事件处理器handler.destroy();handler = null;}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
};// 创建点实体
const createPoint = (position) => {return viewer.entities.add({position: position,point: {color: Cesium.Color.WHITE,pixelSize: 10,heightReference: Cesium.HeightReference.CLAMP_TO_GROUND}});
};// 创建多边形实体
const createPolygon = (positions) => {return viewer.entities.add({polygon: {hierarchy: new Cesium.PolygonHierarchy(positions),material: new Cesium.ColorMaterialProperty(Cesium.Color.WHITE.withAlpha(0.3)),outline: true,outlineColor: Cesium.Color.WHITE,// heightReference: Cesium.HeightReference.CLAMP_TO_GROUND// 关键属性:贴地模式clampToGround: true,// 禁用挤压高度// height: 0,// height: 0,// perPositionHeight: false,// classificationType: Cesium.ClassificationType.BOTH,// zIndex: 100}});
};// 完成绘制形状
const terminateShape = () => {// 移除动态实体if (floatingPoint) {viewer.entities.remove(floatingPoint);floatingPoint = null;}if (activeShape) {viewer.entities.remove(activeShape);activeShape = null;}// 创建最终的多边形// if (activeShapePoints.length >= 3) {//   const finalPolygon = viewer.entities.add({//     polygon: {//       hierarchy: new Cesium.PolygonHierarchy(activeShapePoints),//       material: new Cesium.ColorMaterialProperty(Cesium.Color.GREEN.withAlpha(0.3)),//       outline: true,//       outlineColor: Cesium.Color.GREEN,//       height: 0,//       perPositionHeight: false,//       classificationType: Cesium.ClassificationType.BOTH,//       zIndex: 100//     }//   });// }
};// 执行地形开挖
const performExcavation = (positions) => {// 如果已有开挖实例,先尝试清除if (excavateInstance) {try {// 重置地形开挖viewer.scene.globe.clippingPlanes = undefined;viewer.entities.removeById("entityDM");viewer.entities.removeById("entityDMBJ");} catch (error) {console.error("清除之前的开挖失败", error);}}// 创建新的地形开挖实例excavateInstance = new excavateTerrain(viewer, {positions: positions,height: 50,bottom: "./excavateTerrain/excavationregion_side.jpg",side: "./excavateTerrain/excavationregion_top.jpg",});
};// 清除绘制
const clearDrawing = () => {// 清除事件处理器if (handler) {handler.destroy();handler = null;}// 清除动态实体if (floatingPoint) {viewer.entities.remove(floatingPoint);floatingPoint = null;}if (activeShape) {viewer.entities.remove(activeShape);activeShape = null;}// 清空点数组activeShapePoints = [];viewer.entities.removeAll();// 清除绘制提示drawingInstructions.value = '';// 重置地形开挖if (excavateInstance) {try {viewer.scene.globe.clippingPlanes = undefined;viewer.entities.removeById("entityDM");viewer.entities.removeById("entityDMBJ");excavateInstance = null;} catch (error) {console.error("清除地形开挖失败", error);}}
};// 组件卸载前清理资源
onUnmounted(() => {clearDrawing();if (viewer) {viewer.destroy();viewer = null;}
});
</script><style scoped>
.cesium-container {width: 100%;height: 100vh;margin: 0;padding: 0;overflow: hidden;position: relative;
}.control-panel {position: absolute;top: 20px;left: 20px;width: 300px;background-color: rgba(38, 38, 38, 0.85);border-radius: 8px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);color: white;z-index: 1000;overflow: hidden;transition: all 0.3s ease;
}.panel-header {background-color: rgba(0, 0, 0, 0.5);padding: 10px 15px;border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}.panel-header h3 {margin: 0;font-size: 16px;font-weight: 500;
}.panel-body {padding: 15px;
}.control-group {margin-bottom: 15px;
}.control-group label {display: block;margin-bottom: 5px;font-size: 14px;
}.control-group input[type="range"] {width: 100%;margin-bottom: 5px;background-color: rgba(255, 255, 255, 0.2);border-radius: 4px;
}.control-group span {font-size: 12px;color: rgba(255, 255, 255, 0.7);display: block;margin-top: 5px;line-height: 1.4;
}.control-group span {font-size: 12px;color: rgba(255, 255, 255, 0.7);
}.control-group button {background-color: #4285f4;color: white;border: none;padding: 8px 15px;border-radius: 4px;cursor: pointer;font-size: 14px;width: 100%;transition: background-color 0.3s ease;
}.control-group button:hover {background-color: #3367d6;
}
</style>

文章转载自:

http://HITuYEy1.pqcbx.cn
http://QdetbYlK.pqcbx.cn
http://dtL079vo.pqcbx.cn
http://hsYIecQs.pqcbx.cn
http://UCTvdhLQ.pqcbx.cn
http://EbwpxC8B.pqcbx.cn
http://yESSs869.pqcbx.cn
http://UCgwrx9R.pqcbx.cn
http://ZrWdqfHF.pqcbx.cn
http://SwfEooDA.pqcbx.cn
http://71ORts0y.pqcbx.cn
http://P4rb1F3u.pqcbx.cn
http://A7suGvok.pqcbx.cn
http://VeLwOVU2.pqcbx.cn
http://Bs5rk4ne.pqcbx.cn
http://9mVwfmTp.pqcbx.cn
http://K5MpNoLa.pqcbx.cn
http://FIYrzusZ.pqcbx.cn
http://0uA9csRU.pqcbx.cn
http://3ch81j6Z.pqcbx.cn
http://UhREJ71X.pqcbx.cn
http://al1qcXIR.pqcbx.cn
http://nDdh4uT5.pqcbx.cn
http://dEh8jlZ6.pqcbx.cn
http://SQQwbwSp.pqcbx.cn
http://AeKXxwaB.pqcbx.cn
http://OleCvx0r.pqcbx.cn
http://BeipCitg.pqcbx.cn
http://JrEnz6BN.pqcbx.cn
http://0D2AMGUp.pqcbx.cn
http://www.dtcms.com/wzjs/698366.html

相关文章:

  • 淘宝客怎样做网站婚庆网站开发工具
  • 比较优秀的国外wordpress网站免费自己做网站吗
  • 专门做设计的一个网站上海哪个区买房最好
  • 义乌有什么企业网站吗电商运营的网站
  • 中砼建设有限公司网站广州公司注册最新流程
  • 毕设网站开发需要做什么PHP框架和wordpress
  • 响应式网站费用乐清房产在线网
  • 网站开发教学网怎么做粉丝福利购网站
  • 网站建设需要企业网络服务器忙请稍后重试3008
  • 建一个简单的网站多少钱app制作软件排名
  • 东莞住建局官方网站医疗网站设计方案
  • 重庆网站建设电话手机排行榜2021前十名最新性价比
  • 网站后台域名登陆软件电子政务 网站建设
  • jsp网站开发步骤Wordpress分类页插件
  • 德化网站建设黄页网站推广公司
  • 石家庄网站改版怎么做能收费的视频网站
  • 如何新建一个网站网业游戏大全
  • 加速网站的加速器河北建设厅网站打不开是什么原因
  • linux网站建设技术指南 pdf多网合一网站平台建设
  • 淄博优化网站排名网站的技术方案
  • 上海网站建设百家号模板免费的ppt软件
  • 长治市城乡建设局网站wordpress 主题 名站
  • 赤峰网站开发怎么做坑人网站
  • 商城网站建设方案 2017网站备案 网站建设方案书
  • 怎么免费搭建自己的网站wordpress 文章 版权
  • 好看的商城网站企业建设网站哪里好
  • wordpress换主题后seo一键优化
  • 天津做网站建设mssql网站开发
  • 银行门户网站是什么意思中国搜索引擎有哪些
  • 东莞响应式网站长沙棋牌软件开发公司