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

cesium-水平测距

cesium测量两点间的距离

<template><div id="cesiumContainer" style="height: 100vh;"></div><div id="toolbar" style="position: fixed;top:20px;left:220px;"><el-breadcrumb><el-breadcrumb-item>量测</el-breadcrumb-item><el-breadcrumb-item>水平距离</el-breadcrumb-item></el-breadcrumb><el-row class="mb-4" style="margin-top: 15px"><el-button type="primary" @click="handleDrawPolyline">画线</el-button><el-button type="primary" @click="handleDrawPolylineCancel">清除</el-button></el-row></div><s-mousetip v-if="tip.visible">{{ tip.text }}</s-mousetip>
</template>
<script setup>
import {onMounted, ref} from "vue";
import * as Cesium from "cesium";
import InitCesium from "../js/InitCesiumHide.js";
import DrawStraightLineDistance from "@/assets/utils/measure/DrawStraightLineDistance.js";
import SMousetip from '@/view/cesiumDemo/components/s-mousetip.vue'let viewer = null;
let drawStraightLine = null;
let tip = ref({text: '',visible: false
})onMounted(() => {let initCesium = new InitCesium('cesiumContainer')viewer = initCesium.initViewer({});flyToRight2();
})const handleDrawPolyline = () => {tip.value.text = '左键点击确定起点,再次点击确定终点并结束';tip.value.visible = true;drawStraightLine = new DrawStraightLineDistance({Cesium: Cesium, viewer: viewer, callback: handleDrawPolylineEnd});drawStraightLine.startCreate();
}const handleDrawPolylineEnd = (polylineData) => {tip.value.text = '';tip.value.visible = false;
}const handleDrawPolylineCancel = () => {drawStraightLine.clear();
}const flyToRight2 = () => {let camera = viewer.scene.camera;camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(115.2766, 36.5522, 1500.34),});
}
</script>
<style scoped>
#cesiumContainer {overflow: hidden;
}
</style>
<style>
.el-breadcrumb__inner {color: #ffffff !important;
}
</style>
DrawStraightLineDistance.js
/* 绘制直线  水平距离 */
class DrawStraightLineDistance {constructor(arg) {this.viewer = arg.viewer;this.Cesium = arg.Cesium;this.callback = arg.callback;this._polyline = null; //活动线this._polylineLast = null; //最后一条线this._positions = [];  //活动点this._entities_point = [];  //脏数据this._entities_md_point = [];  //脏数据this._entities_md1_point = [];  //脏数据this._entities_line = [];  //脏数据this._polylineData = null; //用于构造线数据}//返回最后活动线get line() {return this._polylineLast;}//返回线数据用于加载线getData() {return this._polylineData;}//加载线loadPolyline(data) {let that = this;let polyline = that.viewer.entities.add({polyline: {positions: data,show: true,material: that.Cesium.Color.RED,width: 3,clampToGround: true}});return polyline;}//开始创建startCreate() {let that = this;that.handler = new that.Cesium.ScreenSpaceEventHandler(that.viewer.scene.canvas);that.handler.setInputAction(function (evt) { //单击开始绘制//屏幕坐标转地形上坐标let cartesian = that.getCatesian3FromPX(evt.position);if (that._positions.length === 0) {that._positions.push(cartesian.clone());}that._positions.push(cartesian);that.createPoint(cartesian);// 绘制点if (that._positions.length > 2) {if (!that._polyline) {return;}that._positions.pop();// that._positions.push(cartesian);that.createPoint(cartesian);// 绘制点that._polylineData = that._positions.concat();that.viewer.entities.remove(that._polyline); //移除that._polyline = null;that._positions = [];let line = that.loadPolyline(that._polylineData); //加载线that._entities_line.push(line);that._polylineLast = line;if (typeof that.callback == "function") {that.callback(that._polylineData);}for (let i = 0; i < that._entities_md1_point.length; i++) {that.viewer.entities.remove(that._entities_md1_point[i]);}let distance = that.Cesium.Cartesian3.distance(that._polylineData[0], that._polylineData[1]).toFixed(2);// let midPoint = that.Cesium.Cartesian3.midpoint(that._polylineData[0], that._polylineData[1]);let midPoint = that.Cesium.BoundingSphere.fromPoints(that._polylineData).centerthat.createMdPoint(midPoint, distance);that.handler.destroy();that.handler = null;}}, that.Cesium.ScreenSpaceEventType.LEFT_CLICK);this.handler.setInputAction(function (evt) { //移动时绘制线if (that._positions.length < 1) return;let cartesian = that.getCatesian3FromPX(evt.endPosition);if (!that.Cesium.defined(that._polyline)) {that._polyline = that.createPolyline();}if (that._polyline) {that._positions.pop();that._positions.push(cartesian);}let distance = that.Cesium.Cartesian3.distance(that._positions[0], that._positions[1]).toFixed(2);// let midPoint = that.Cesium.Cartesian3.midpoint(that._polylineData[0], that._polylineData[1]);let midPoint = that.Cesium.BoundingSphere.fromPoints(that._positions).centerthat.createMdPoint11(midPoint, distance);}, that.Cesium.ScreenSpaceEventType.MOUSE_MOVE);}//创建点createPoint(cartesian) {let that = this;let point = this.viewer.entities.add({position: cartesian,point: {pixelSize: 10,color: that.Cesium.Color.YELLOW,}});that._entities_point.push(point);return point;}//创建点createMdPoint(cartesian, distance) {let that = this;let point = this.viewer.entities.add({position: cartesian,point: {pixelSize: 1,color: that.Cesium.Color.YELLOW,},label: {text: '水平距离:' + distance + '米',    //描述内容font: '14px Sans-Serif',   //字体大小 类型fillColor: that.Cesium.Color.fromCssColorString('#ffffff'),  //颜色outlineColor: that.Cesium.Color.GOLD,//设置背景颜色透明backgroundColor: new that.Cesium.Color(0, 0, 0, 0.7),//打开背景  打开背景 (不会被线段覆盖)showBackground: true,// scaleByDistance: new that.Cesium.NearFarScalar(1000, 1.0, 2000, 0.01),// disableDepthTestDistance: Number.POSITIVE_INFINITY}});that._entities_md_point.push(point);return point;}//创建点createMdPoint11(cartesian, distance) {let that = this;for (let i = 0; i < that._entities_md1_point.length; i++) {that.viewer.entities.remove(that._entities_md1_point[i]);}let point = this.viewer.entities.add({position: cartesian,point: {pixelSize: 1,color: that.Cesium.Color.YELLOW,},label: {text: '水平距离:' + distance + '米',    //描述内容font: '14px Sans-Serif',   //字体大小 类型fillColor: that.Cesium.Color.fromCssColorString('#ffffff'),  //颜色outlineColor: that.Cesium.Color.GOLD,//设置背景颜色透明backgroundColor: new that.Cesium.Color(0, 0, 0, 0.7),//打开背景  打开背景 (不会被线段覆盖)showBackground: true,// scaleByDistance: new that.Cesium.NearFarScalar(1000, 1.0, 2000, 0.01),// disableDepthTestDistance: Number.POSITIVE_INFINITY}});that._entities_md1_point.push(point);return point;}//创建线createPolyline() {let that = this;let polyline = this.viewer.entities.add({polyline: {//使用cesium的peopertypositions: new that.Cesium.CallbackProperty(function () {return that._positions}, false),show: true,material: that.Cesium.Color.RED,width: 3,clampToGround: true}});that._entities_line.push(polyline);return polyline;}//销毁destroy() {if (this.handler) {this.handler.destroy();this.handler = null;}}//清空实体对象clear() {for (let i = 0; i < this._entities_point.length; i++) {this.viewer.entities.remove(this._entities_point[i]);}for (let i = 0; i < this._entities_md_point.length; i++) {this.viewer.entities.remove(this._entities_md_point[i]);}for (let i = 0; i < this._entities_md1_point.length; i++) {this.viewer.entities.remove(this._entities_md1_point[i]);}for (let i = 0; i < this._entities_line.length; i++) {this.viewer.entities.remove(this._entities_line[i]);}this._polyline = null;this._positions = [];this._entities_point = [];  //脏数据this._entities_md_point = [];  //脏数据this._entities_md1_point = [];  //脏数据this._entities_line = [];  //脏数据this._polylineData = null; //用于构造线数据this._polylineLast = null;this.destroy();}getCatesian3FromPX(px) {let cartesian;let ray = this.viewer.camera.getPickRay(px);if (!ray) return null;cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);return cartesian;}
}export default DrawStraightLineDistance

效果图 

InitCesiumHide.js

import * as Cesium from "cesium";class InitCesiumHide {constructor(cesiumContainer, options) {this.cesiumContainer = cesiumContainer;}initViewer(options) {Cesium.Ion.defaultAccessToken = 'token';// 西南东北,默认显示中国Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);return new Cesium.Viewer(this.cesiumContainer, {animation: false, // 隐藏动画控件baseLayerPicker: false, // 隐藏图层选择控件fullscreenButton: false, // 隐藏全屏按钮vrButton: false, // 隐藏VR按钮,默认falsegeocoder: false, // 隐藏地名查找控件  地理编码homeButton: false, // 隐藏Home按钮infoBox: false, // 隐藏点击要素之后显示的信息窗口sceneModePicker: false, // 隐藏场景模式选择控件selectionIndicator: false, // 显示实体对象选择框,默认truetimeline: false, // 隐藏时间线控件navigationHelpButton: false, // 隐藏帮助按钮scene3DOnly: true, // 每个几何实例将只在3D中呈现,以节省GPU内存shouldAnimate: true, // 开启动画自动播放sceneMode: 3, // 初始场景模式 1:2D 2:2D循环 3:3D,默认3requestRenderMode: true, // 减少Cesium渲染新帧总时间并减少Cesium在应用程序中总体CPU使用率...options});}
}export default InitCesiumHide

 

相关文章:

cesium-水平测距

cesium测量两点间的距离 <template><div id"cesiumContainer" style"height: 100vh;"></div><div id"toolbar" style"position: fixed;top:20px;left:220px;"><el-breadcrumb><el-breadcrumb-item&…...

【Android-Compose】手势检测实现按下、单击、双击、长按事件,以及避免频繁单击事件的简单方法

目录&#xff1a; 1 不需要双击事件 规避频繁单击事件2 需要双击事件&#xff08;常规写法&#xff09;3 后记&#xff1a;不建议使用上面的代码自定义按钮 1 不需要双击事件 规避频繁单击事件 var firstClickTime by remember { mutableStateOf(System.currentTimeMillis()…...

AUTOSAR汽车电子嵌入式编程精讲300篇-基于神经网络的CAN总线负载率优化(续)

目录 3.3 SA 算法 3.3.1 SA 算法原理 3.3.2 基于 SA 算法 CAN 总线负载率优化分析...

python爬虫6—高性能异步爬虫

如果有多个URL等待我们爬取&#xff0c;我们通常是一次只能爬取一个&#xff0c;爬取效率低&#xff0c;异步爬虫可以提高爬取效率&#xff0c;可以一次多多个URL同时同时发起请求 异步爬虫方式&#xff1a; 一、多线程、多进程&#xff08;不建议&#xff09;&#xff1a;可以…...

日历功能——C语言

实现日历功能&#xff0c;输入年份月份&#xff0c;输出日历 #include<stdio.h>int leap_year(int year) {if(year % 4 0 && year % 100 ! 0 || year % 400 0){return 1;}else{return 0;} }int determine_year_month_day(int *day,int month,int year) {if(mo…...

GPIO中断

1.EXTI简介 EXTI是External Interrupt的缩写&#xff0c;指外部中断。在嵌入式系统中&#xff0c;外部中断是一种用于处理外部事件的机制。当外部事件发生时&#xff08;比如按下按钮、传感器信号变化等&#xff09;&#xff0c;外部中断可以立即打断正在执行的程序&#xff0…...

springboot完成一个线上图片存放地址+实现前后端上传图片+回显

1.路径 注意路径 2.代码&#xff1a;&#xff08;那个imagePath没什么用&#xff0c;懒的删了&#xff09;&#xff0c;注意你的本地文件夹要有图片&#xff0c;才可以在线上地址中打开查看 package com.xxx.common.config;import org.springframework.beans.factory.annotat…...

编程思维与生活琐事的内在关联及其应用价值

随着科技的日益普及和信息化时代的到来&#xff0c;编程作为一种现代技能&#xff0c;其影响已不再局限于专业领域&#xff0c;而是逐步渗透到人们的日常生活之中。探讨编程与生活琐事之间的关系&#xff0c;有助于我们更好地理解如何将技术智慧应用于日常管理&#xff0c;提升…...

OSPF排错

目录 实验拓扑图 实验要求 实验排错 故障一 故障现象 故障分析 故障解决 故障二 故障现象 故障分析 故障解决 故障三 故障现象 故障分析 故障解决 故障四 故障现象 故障分析 故障解决 故障五 故障现象 故障分析 故障解决 故障六 故障现象 故障分析 …...

day07-CSS高级

01-定位 作用&#xff1a;灵活的改变盒子在网页中的位置 实现&#xff1a; 1.定位模式&#xff1a;position 2.边偏移&#xff1a;设置盒子的位置 left right top bottom 相对定位 position: relative 特点&#xff1a; 不脱标&#xff0c;占用自己原来位置 显示模…...

05 MP之ActiveRecord模式+SimpleQuery

1. ActiveRecord ActiveRecord(活动记录&#xff0c;简称AR)&#xff0c;是一种领域模型模式&#xff0c;特点是一个模型类对应关系型数据库中的一个表&#xff0c;而模型类的一个实例对应表中的一行记录。 其目标是通过围绕一个数据对象, 进行全部的CRUD操作。 1.1 让实体类…...

git diff查看比对两次不同时间点提交的异同

git diff查看比对两次不同时间点提交的异同 用 git diff命令&#xff1a; git diff commit-id-1 commit-id-2 不同commit-id在不同的时间点提交产生&#xff0c;因为也可以认为git diff是比对两个不同时间点的代码异同。 git diff比较不同commit版本的代码文件异同_git diff c…...

基于muduo网络库开发服务器程序和CMake构建项目 笔记

跟着施磊老师做C项目&#xff0c;施磊老师_腾讯课堂 (qq.com) 一、基于muduo网络库开发服务器程序 组合TcpServer对象创建EventLoop事件循环对象的指针明确TcpServer构造函数需要什么参数,输出ChatServer的构造函数在当前服务器类的构造函数当中,注册处理连接的回调函数和处理…...

前端支持下载模板、导入数据、导出数据(excel格式)

前言 xlsx是由SheetJS开发的一个处理excel文件的npm库,适用于前端开发者实现下载模板、导入导出excel文件等需求&#xff0c;演示的项目的技术栈为vue3 elementPlus 一. 引入xlsx 安装xlsx npm install xlsx引入xlsx import * as XLSX from xlsx;二. 下载模板 const han…...

编译Faiss-gpu【InterMKL】C++ 按步骤操作 基本不会有问题的 python原理相同。

编译Faiss-gpu C++ 基本介绍 使用Faiss版本【1.7.4】 该项目依赖于BLAS 组件 OpenBLAS 和 IntelMKL BLAS 【官方支持】 IntelMKL 会比 OpenBLAS 快的多。 【来自官方结论】 本机环境 Cuda :11.1 Cuda-Driver: 515 InterMKL: 2021.2.0 Faiss :1.7.4 注意:faiss仅…...

conn.execute的用法详解

conn.execute的用法详解 大家好&#xff0c;我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天&#xff0c;我们将深入研究数据库连接中conn.execute的用法&#xff0c;解析它的功能、…...

GetBuffer() 与 ReleaseBuffer() 使用详解

GetBuffer() 与 ReleaseBuffer() 使用详解 大家好&#xff0c;我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天&#xff0c;我们将深入研究在编程中常用的GetBuffer()与ReleaseBuff…...

Flink CEP(基本概念)

Flink CEP 在Flink的学习过程中&#xff0c;我们已经掌握了从基本原理和核心层的DataStream API到底层的处理函数&#xff0c;再到应用层的Table API和SQL的各种手段&#xff0c;可以应对实际应用开发的各种需求。然而&#xff0c;在实际应用中&#xff0c;还有一类更为复…...

[AIGC] Spring Gateway与 nacos 简介

文章目录 Spring Gateway简介主要特性优点总结 Nacos简介主要特性优点总结 Spring Gateway 简介 Spring Gateway是一个基于Spring Framework的工具&#xff0c;用于构建和管理微服务架构中的网关。它提供了一种简单而灵活的方式来路由和过滤请求&#xff0c;以及在微服务之间…...

2024-2-3-复习作业

1> 要求&#xff1a; 效果图&#xff1a; 2> 要求&#xff1a; 效果图&#xff1a; 3> 要求&#xff1a; 效果图&#xff1a; 源代码&#xff1a; #include <stdio.h> #include <stdlib.h> typedef int datatype; typedef struct Node {datatype data…...

SkyWalking 10.2.0 SWCK 配置过程

SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外&#xff0c;K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案&#xff0c;全安装在K8S群集中。 具体可参…...

大型活动交通拥堵治理的视觉算法应用

大型活动下智慧交通的视觉分析应用 一、背景与挑战 大型活动&#xff08;如演唱会、马拉松赛事、高考中考等&#xff09;期间&#xff0c;城市交通面临瞬时人流车流激增、传统摄像头模糊、交通拥堵识别滞后等问题。以演唱会为例&#xff0c;暖城商圈曾因观众集中离场导致周边…...

(二)TensorRT-LLM | 模型导出(v0.20.0rc3)

0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述&#xff0c;后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作&#xff0c;其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

什么是EULA和DPA

文章目录 EULA&#xff08;End User License Agreement&#xff09;DPA&#xff08;Data Protection Agreement&#xff09;一、定义与背景二、核心内容三、法律效力与责任四、实际应用与意义 EULA&#xff08;End User License Agreement&#xff09; 定义&#xff1a; EULA即…...

MySQL用户和授权

开放MySQL白名单 可以通过iptables-save命令确认对应客户端ip是否可以访问MySQL服务&#xff1a; test: # iptables-save | grep 3306 -A mp_srv_whitelist -s 172.16.14.102/32 -p tcp -m tcp --dport 3306 -j ACCEPT -A mp_srv_whitelist -s 172.16.4.16/32 -p tcp -m tcp -…...

C/C++ 中附加包含目录、附加库目录与附加依赖项详解

在 C/C 编程的编译和链接过程中&#xff0c;附加包含目录、附加库目录和附加依赖项是三个至关重要的设置&#xff0c;它们相互配合&#xff0c;确保程序能够正确引用外部资源并顺利构建。虽然在学习过程中&#xff0c;这些概念容易让人混淆&#xff0c;但深入理解它们的作用和联…...

【Linux】自动化构建-Make/Makefile

前言 上文我们讲到了Linux中的编译器gcc/g 【Linux】编译器gcc/g及其库的详细介绍-CSDN博客 本来我们将一个对于编译来说很重要的工具&#xff1a;make/makfile 1.背景 在一个工程中源文件不计其数&#xff0c;其按类型、功能、模块分别放在若干个目录中&#xff0c;mak…...

WPF八大法则:告别模态窗口卡顿

⚙️ 核心问题&#xff1a;阻塞式模态窗口的缺陷 原始代码中ShowDialog()会阻塞UI线程&#xff0c;导致后续逻辑无法执行&#xff1a; var result modalWindow.ShowDialog(); // 线程阻塞 ProcessResult(result); // 必须等待窗口关闭根本问题&#xff1a…...

aardio 自动识别验证码输入

技术尝试 上周在发学习日志时有网友提议“在网页上识别验证码”&#xff0c;于是尝试整合图像识别与网页自动化技术&#xff0c;完成了这套模拟登录流程。核心思路是&#xff1a;截图验证码→OCR识别→自动填充表单→提交并验证结果。 代码在这里 import soImage; import we…...