当前位置: 首页 > 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…...

C++初阶-list的底层

目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...

Golang 面试经典题:map 的 key 可以是什么类型?哪些不可以?

Golang 面试经典题&#xff1a;map 的 key 可以是什么类型&#xff1f;哪些不可以&#xff1f; 在 Golang 的面试中&#xff0c;map 类型的使用是一个常见的考点&#xff0c;其中对 key 类型的合法性 是一道常被提及的基础却很容易被忽视的问题。本文将带你深入理解 Golang 中…...

【Oracle APEX开发小技巧12】

有如下需求&#xff1a; 有一个问题反馈页面&#xff0c;要实现在apex页面展示能直观看到反馈时间超过7天未处理的数据&#xff0c;方便管理员及时处理反馈。 我的方法&#xff1a;直接将逻辑写在SQL中&#xff0c;这样可以直接在页面展示 完整代码&#xff1a; SELECTSF.FE…...

Qt Widget类解析与代码注释

#include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this); }Widget::~Widget() {delete ui; }//解释这串代码&#xff0c;写上注释 当然可以&#xff01;这段代码是 Qt …...

抖音增长新引擎:品融电商,一站式全案代运营领跑者

抖音增长新引擎&#xff1a;品融电商&#xff0c;一站式全案代运营领跑者 在抖音这个日活超7亿的流量汪洋中&#xff0c;品牌如何破浪前行&#xff1f;自建团队成本高、效果难控&#xff1b;碎片化运营又难成合力——这正是许多企业面临的增长困局。品融电商以「抖音全案代运营…...

2021-03-15 iview一些问题

1.iview 在使用tree组件时&#xff0c;发现没有set类的方法&#xff0c;只有get&#xff0c;那么要改变tree值&#xff0c;只能遍历treeData&#xff0c;递归修改treeData的checked&#xff0c;发现无法更改&#xff0c;原因在于check模式下&#xff0c;子元素的勾选状态跟父节…...

Nuxt.js 中的路由配置详解

Nuxt.js 通过其内置的路由系统简化了应用的路由配置&#xff0c;使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...

【Go】3、Go语言进阶与依赖管理

前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课&#xff0c;做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程&#xff0c;它的核心机制是 Goroutine 协程、Channel 通道&#xff0c;并基于CSP&#xff08;Communicating Sequential Processes&#xff0…...

CocosCreator 之 JavaScript/TypeScript和Java的相互交互

引擎版本&#xff1a; 3.8.1 语言&#xff1a; JavaScript/TypeScript、C、Java 环境&#xff1a;Window 参考&#xff1a;Java原生反射机制 您好&#xff0c;我是鹤九日&#xff01; 回顾 在上篇文章中&#xff1a;CocosCreator Android项目接入UnityAds 广告SDK。 我们简单讲…...

论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(一)

宇树机器人多姿态起立控制强化学习框架论文解析 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架&#xff08;一&#xff09; 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化…...