Vue.js2+Cesium1.103.0 六、标绘与测量

news2024/10/7 16:27:10

Vue.js2+Cesium1.103.0 六、标绘与测量

点,线,面的绘制,可实时编辑图形,点击折线或多边形边的中心点,可进行添加线段移动顶点位置等操作,并同时计算出点的经纬度,折线的距离和多边形的面积。

Demo

import PlotUtil from '@/utils/CesiumUtils/Plot/index.js'
export default {
  data () {
    return {
      plottingStatus: false,
      plotData: {},
      $PlotUtil: null,
      active: '',
      btns: [
        {
          name: 'point'
        },
        {
          name: 'polyline'
        },
        {
          name: 'polygon'
        }
        // {
        //   name: 'text'
        // }
      ]
    }
  },
  methods: {
    handleSave() {
      this.addGraphic(this.plotData)
      this.$PlotUtil.Destory()
    },
    addGraphic(data) {
      const _color = new Cesium.Color.fromCssColorString('#17E980')
      if (data.drawingMode === 'point') {
        viewer.entities.add({
          position: Cesium.Cartesian3.fromDegrees(data.centerPoint.longitude, data.centerPoint.latitude, data.centerPoint.altitude),
          point: {
            color: _color,
            // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 30000.0),
            scaleByDistance: new Cesium.NearFarScalar(1.0e2, 1.0, 0.7e4, 0.8),
            pixelSize: 14,
            outlineWidth: 2,
            outlineColor: Cesium.Color.fromCssColorString('#fff')
          },
          label: {
            text: `经度:${data.centerPoint.longitude}\n纬度:${data.centerPoint.latitude}\n海拔:${data.centerPoint.altitude}`,
            font: '30px sans-serif',
            // pixelOffset: new Cesium.Cartesian2(0.0, 45.0),
            // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            fillColor: Cesium.Color.fromCssColorString('#fff'),
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            outlineWidth: 2,
            outlineColor: Cesium.Color.fromCssColorString('#000'),
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 30000.0),
            scaleByDistance: new Cesium.NearFarScalar(1.0e2, 0.6, 0.7e4, 0.5)
          }
        })
      } else if (data.drawingMode === 'polyline') {
        viewer.entities.add({
          position: Cesium.Cartesian3.fromDegrees(data.centerPoint.longitude, data.centerPoint.latitude, data.centerPoint.altitude),
          label: {
            text: `${data.activeShapeComputed}m`,
            font: '30px sans-serif',
            // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            fillColor: Cesium.Color.fromCssColorString('#fff'),
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            outlineWidth: 2,
            outlineColor: Cesium.Color.fromCssColorString('#000'),
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 30000.0),
            scaleByDistance: new Cesium.NearFarScalar(1.0e2, 0.6, 0.7e4, 0.5)
          }
        })
        if (data.activeSubLine && data.activeSubLine.length > 0) {
          data.activeSubLine.map((line, lineIndex) => {
            if (line.distance <= 0) return
            const positions = Cesium.Cartesian3.fromDegreesArrayHeights(
              [
                line.start.longitude, line.start.latitude, line.start.altitude,
                line.end.longitude, line.end.latitude, line.end.altitude
              ]
            )
            viewer.entities.add({
              position: Cesium.Cartesian3.fromDegrees(line.centerPoint.longitude, line.centerPoint.latitude, line.centerPoint.altitude),
              polyline: {
                // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                positions: positions,
                material: _color,
                depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                  _color
                }),
                width: 5
              },
              label: {
                text: `${line.distance}`,
                font: '30px sans-serif',
                fillColor: Cesium.Color.fromCssColorString('#fff'),
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                outlineWidth: 2,
                outlineColor: Cesium.Color.fromCssColorString('#000'),
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 30000.0),
                scaleByDistance: new Cesium.NearFarScalar(1.0e2, 0.6, 0.7e4, 0.5)
              }
            })
          })
        }
      } else if (data.drawingMode === 'polygon') {
        const vertices = data.verticesPosition || data.activeShapePoints || []
        const _hierarchy = []
        if (vertices.length > 0) {
          vertices.map(point => {
            _hierarchy.push(Cesium.Cartesian3.fromDegrees(
              point.longitude,
              point.latitude,
              point.altitude
            ))
          })
        }
        if (_hierarchy.length > 0) {
          const dynamicPositions = new Cesium.CallbackProperty(function () {
            return new Cesium.PolygonHierarchy(_hierarchy)
          }, false) // 使贴地多边形在模型上有立体效果
          const center = data.centerPoint
          const altitudes = vertices.map(_ => _.altitude)
          const max = altitudes.sort()[altitudes.length - 1]
          center.altitude = max
          viewer.entities.add({
            position: Cesium.Cartesian3.fromDegrees(data.centerPoint.longitude, data.centerPoint.latitude, data.centerPoint.altitude),
            polygon: {
              // hierarchy: hierarchy,
              hierarchy: dynamicPositions,
              // extrudedHeight: 200,
              // perPositionHeight: true,
              // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
              material: new Cesium.ColorMaterialProperty(
                _color
              )
            },
            label: {
              text: `${data.activeShapeComputed}平方米`,
              font: '30px sans-serif',
              fillColor: Cesium.Color.fromCssColorString('#fff'),
              style: Cesium.LabelStyle.FILL_AND_OUTLINE,
              outlineWidth: 2,
              outlineColor: Cesium.Color.fromCssColorString('#000'),
              disableDepthTestDistance: Number.POSITIVE_INFINITY,
              // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
              // eyeOffset: new Cesium.Cartesian3(0, 0, -10000),
              // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 10000.0),
              scaleByDistance: new Cesium.NearFarScalar(1.0e2, 0.6, 0.7e4, 0.5)
            }
          })
        }
      } else if (data.drawingMode === 'text') {
        viewer.entities.add({
          position: Cesium.Cartesian3.fromDegrees(data.centerPoint.longitude, data.centerPoint.latitude, data.centerPoint.altitude),
          label: {
            text: text,
            font: _font,
            fillColor: _color,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 30000.0),
            scaleByDistance: new Cesium.NearFarScalar(1.0e2, 0.6, 0.7e4, 0.5),
            show: visible
          }
        })
      }
    },
    initPlotUtil() {
      const _this = this
      this.$PlotUtil = new PlotUtil({
        defaultColorValue: '#17E980',
        PlottingStatus: function (value) {
          _this.plottingStatus = value
          console.log('..................PlottingStatus', value)
        },
        Finish: function (data) {
          console.log('..................Finish', data)
          _this.plotData = data
        },
        VerticesFinish: function (data) {
          console.log('..................VerticesFinish', data)
        },
        CurrentEditVertice: function (data) {
          console.log('..................CurrentEditVertice', data)
        }
      })
    },
    handleClick (item) {
      this.active =
        this.active === item.name
          ? (this.active = '')
          : (this.active = item.name)
      if (this.active) {
        this.$PlotUtil.StartPlot(this.active)
      } else {
        this.$PlotUtil.Destory()
      }
    }
  }
}

      <div class="ul">
        <div v-for="(item, index) of btns" :key="index" class="li" :class="{ active: item.name === active }"
          @click="handleClick(item)">
          {{ item.name }}</div>
        <div class="li" :class="{ disabled: plottingStatus }" @click="handleSave">保存</div>
      </div>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/851232.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【机器学习】编码、创造和筛选特征

在机器学习和数据科学领域中&#xff0c;特征工程是提取、转换和选择原始数据以创建更具信息价值的特征的过程。假设拿到一份数据集之后&#xff0c;如何逐步完成特征工程呢&#xff1f; 文章目录 一、特性类型分析1.1 数值型特征1.2 类别型特征1.3 时间型特征1.4 文本型特征1.…

PHP8的跳转语句-PHP8知识详解

如果循环条件满足的时候&#xff0c;则程序会一直执行下去。如果需要强制跳出循环&#xff0c;则需要使用跳转语句来完成。PHP8的跳转语句包括break语句、continue语句和goto语句。 1、break语句 break语句的作用是完全终止循环&#xff0c;包括while、do…while、for、switch…

linux umask 详解

1. umask 定义 在 linux 系统中&#xff0c;umask 被定义在 /etc/profile 配置文件中&#xff0c;有一段 shell 脚本对 umask 是这么定义的。在 shell 会话输入命令&#xff1a; $ cat /etc/profile # 查看 /etc/profile 配置文件的内容 if [ $UID -gt 199 ] &&…

Prometheus技术文档-概念

Prometheus是一个开源的项目连接如下&#xff1a; Prometheus首页、文档和下载 - 服务监控系统 - OSCHINA - 中文开源技术交流社区 基本概念&#xff1a; Prometheus是一个开源的系统监控和告警系统&#xff0c;由Google的BorgMon监控系统发展而来。它主要用于监控和度量各种…

2.本地存储

2.1本地存储分类- localStorage 1.作用: 可以将数据永久存储在本地(用户的电脑)&#xff0c;除非手动删除&#xff0c;否则关闭页面也会存在 2.特性: ●可以多窗口(页面)共享(同一浏览器可以共享) ●以键值对的形式存储使用&#xff0c;键值除了数字型都要加引号 3.语法 存…

设计模式篇

工厂方法模式 简单工厂模式 工厂方法模式 抽象工厂模式 策略模式 责任链模式

Vue - 实现垂直菜单分类栏目 开箱即用

Vue - 实现垂直菜单分类栏目 开箱即用 今天发现需要做一个专栏分类的功能&#xff0c;要求光标悬浮到一级专栏时展示二级专栏&#xff0c;当光标移出时隐藏二级专栏。在网山找了一圈没有发现到合适的源代码&#xff0c;参考了一个博客才编写了下面的代码。将其粘贴到空的页面文…

如何将区块链新闻稿发布到海外媒体?

随着区块链技术的不断发展&#xff0c;越来越多的区块链项目涌现出来&#xff0c;各大媒体也开始关注和报道区块链新闻。然而&#xff0c;如何将区块链新闻稿发布到海外媒体成为了许多区块链项目所面临的难题。本文将介绍一些有效的方法&#xff0c;帮助区块链项目将新闻稿发布…

SIP协议之音/视频转换

在SIP通话应用场景中&#xff0c;有时需要在音频和视频通话中进行切换&#xff0c;这个功能实现的需要发送re-INVITE重新协商媒体&#xff0c;即重新协商媒体&#xff08;SDP)中是否允许视频。 一、实现原理 1.1 音频转视频 音频通话过程中&#xff0c;发起方重新发送INVITE消…

大数据Flink(五十七):Yarn集群环境(生产推荐)

文章目录 Yarn集群环境(生产推荐) 一、准备工作

python版《羊了个羊》游戏开发第一天

Python小型项目实战教学课《羊了个羊》 一、项目开发大纲&#xff08;初级&#xff09; 版本1.0&#xff1a;基本开发 课次 内容 技术 第一天 基本游戏地图数据 面向过程 第二天 鼠标点击和移动 面向对象 第三天 消除 设计模式&#xff1a;单例模式 第四天 完整…

换架 3D 飞机,继续飞呀飞

相信大多数图扑 HT 用户都曾见过这个飞机的 Demo&#xff0c;在图扑发展的这十年&#xff0c;这个 Demo 是许多学习 HT 用户一定会参考的经典 Demo 之一。 这个 Demo 用简洁的代码生动地展示了 OBJ 模型加载、数据绑定、动画和漫游等功能的实现。许多用户参考这个简单的 Demo 后…

算法练习--leetcode 链表

文章目录 合并两个有序链表删除排序链表中的重复元素 1删除排序链表中的重复元素 2环形链表1环形链表2相交链表反转链表 合并两个有序链表 将两个升序链表合并为一个新的 升序 链表并返回。 新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1&#xff1a; 输入&…

【IMX6ULL驱动开发学习】03.Linux驱动开发之GPIO子系统、中断、定时器

一、GPIO子系统 1.1 引脚编号 在硬件上如何确定GPIO引脚&#xff1f;它属于哪组GPIO&#xff1f;它是这组GPIO里的哪个引脚&#xff1f;需要2个参数。但是在Linux软件上&#xff0c;可以使用引脚编号来表示。以100ask_ imx6ull为例在开发板上执行如下命令查看已经在使用的GPI…

桥接模式-java实现

桥接模式 桥接模式的本质&#xff0c;是解决一个基类&#xff0c;存在多个扩展维度的的问题。 比如一个图形基类&#xff0c;从颜色方面扩展和从形状上扩展&#xff0c;我们都需要这两个维度进行扩展&#xff0c;这就意味着&#xff0c;我们需要创建一个图形子类的同时&#x…

手搓vue3组件_1.封装一个button

我的icepro参考地址,内有参考代码,有条件的割割点点star 实现要求: 基于vue3支持通过colors(更改颜色)支持点击事件…支持其他的自定义样式(例如圆角,size等等) 最基础的第一步: 父组件引入并使用: <template><div class"buttonLim">我的按钮:<ice-b…

Zabbix监控华为交换机DHCP接口地址池

一、背景 最近工作中遇到一个因为DHCP地址池满载、导致用户无法获取到IP地址的故障&#xff0c;所以在想通过zabbix 监控DHCP地址池的状态、当DHCP 地址池数量小于某个值时触发zabbix告警。 网上找了一下没有相关的文档、和对应的OID值、于是用Python 脚本的方式实现 二、实现效…

第二课-一键安装SD-Stable Diffusion 教程

前言 看完这篇文章并跟着操作,就可以在本地开始 SD 绘图了。 理论上来说,这篇课程结束,想要画什么图都可以画了。 启动器介绍 SD 是开源的,可以在 github 上找到。但直接下载源码安装,非常费劲,而且因为国内外差异,就是我这样的秃头程序员也难以应对。 所以,我们改…

Spring中Bean的“一生”(生命周期)

文章目录 一、图解二、文字解析总结 一、图解 >注&#xff1a;处于同一行的执行顺序是从左往右 二、文字解析 SpringBean的生命周期总体分为四个阶段&#xff1a;实例化>属性注入>初始化>销毁 Step1 实例化Bean&#xff1a;根据配置文件中Bean的定义&#xff0c;…

设计模式(3)装饰模式

一、介绍&#xff1a; 1、应用场景&#xff1a;把所需的功能按正确的顺序串联起来进行控制。动态地给一个对象添加一些额外的职责&#xff0c;就增加功能来说&#xff0c;装饰模式比生成子类更加灵活。 当需要给一个现有类添加附加职责&#xff0c;而又不能采用生成子类的方法…