【超图 SuperMap3D】【基础API使用示例】52、超图SuperMap3D - 绘制点|线|多边形面的缓冲区

news2024/9/23 22:37:31

前言

引擎下载地址:[添加链接描述](http://support.supermap.com.cn/DownloadCenter/DownloadPage.aspx?id=2524)
绘制缓冲区主要依赖[turfjs](https://turfjs.org/docs/#buffer)
先根据点线面的数据+turfjs计算得到缓冲区的坐标数据,再行绘制

效果

在这里插入图片描述

完整代码

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  <title></title>

  <link href="https://www.supermapol.com/webgl/Build/SuperMap3D/Widgets/widgets.css" rel="stylesheet">
  <link href="https://www.supermapol.com/webgl/examples/webgl/css/pretty.css" rel="stylesheet">
  <link href="https://www.supermapol.com/webgl/examples/webgl/style/colorCorrection.css" rel="stylesheet">
  <link href="https://www.supermapol.com/webgl/examples/webgl/css/bootstrap-select.min.css" rel="stylesheet">
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/jquery.min.js"></script>
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/bootstrap.min.js"></script>
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/bootstrap-select.min.js"></script>
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/tooltip.js"></script>
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/slider.js"></script>
  <script src="https://www.supermapol.com/webgl/examples/webgl/js/config.js"></script>
  <script type="text/javascript" src="https://www.supermapol.com/webgl/Build/SuperMap3D/SuperMap3D.js"></script>

  <link rel="stylesheet" href="https://www.supermapol.com/webgl/web/libs/bootstrap/css/bootstrap.min.css">
  <link href="https://www.supermapol.com/webgl/examples/webgl/style/flood.css" rel="stylesheet">
  <script src="https://unpkg.com/@turf/turf/turf.min.js"></script>
  <style>
    .circle {
      position: fixed;
      left: 100px;
      top: 100px;
    }

    .circle.active {
      color: red;
    }

    .custom-panel {
      position: fixed;
      left: -1000px;
      top: -1000px;
      z-index: 1;
      border-radius: 10px;
      display: none;
      color: #fff;
      background-color: rgba(0, 0, 0, 0.3);
    }

    .tips {
      position: fixed;
      left: 100px;
      top: 200px;
      color: #fff;
    }

    input {
      color: #000;
    }
  </style>
</head>

<body>
  <div id="Container"></div>

  <script type="text/javascript">
    let viewer, handler
    const initMouseOperate = {}
    const customPanel = document.querySelector('.custom-panel')
    const circle = document.querySelector('.circle')
    function onload (SuperMap3D) {
      var EngineType = getEngineType()
      viewer = new SuperMap3D.Viewer('Container', {
        navigation: false, // 默认为true,是否显示导航罗盘控件。隐藏可在初始化场景时设置为false
        animation: true, //是否创建动画小器件,左下角仪表
        contextOptions: {
          contextType: Number(2)  // Webgl2:2  WebGPU:3
        }
      })

      viewer.scenePromise.then(function (scene) {
        init(SuperMap3D, scene, viewer)

        eventHandler()
        drawPointBufferHandler()
        drawLineBufferHandler()
        drawPolygonBufferHandler()

        setTimeout(() => {
          flyTo({
            x: -1520391.2517026903,
            y: 4801874.506984832,
            z: 3926626.7742098756,
            heading: 0.24220323846765268,
            pitch: -1.570572787555335,
            roll: 0,
            duration: 2
          })
        }, 2000);
      })
    }

    function init (SuperMap3D, scene, viewer) {
      viewer.imageryLayers.addImageryProvider(new SuperMap3D.BingMapsImageryProvider({
        url: 'https://dev.virtualearth.net',
        mapStyle: SuperMap3D.BingMapsStyle.AERIAL,
        key: URL_CONFIG.BING_MAP_KEY//当场景出现黑球时可至官网(https://www.bingmapsportal.com/)申请key
      }))
    }

    function eventHandler () {
      handler = new SuperMap3D.ScreenSpaceEventHandler(viewer.scene.canvas) // event事件处理程序
      handler.setInputAction((e) => {
        const panelPosition = viewer.scene.pickPosition(e.position)
        console.log(panelPosition);
      }, SuperMap3D.ScreenSpaceEventType.LEFT_CLICK)
    }

    // 绘制点缓冲区
    function drawPointBufferHandler () {
      const point = viewer.entities.add({
        point: {
          color: new SuperMap3D.Color(255, 0, 0, 255),
          pixelSize: 2
        },
        position: { x: -1512322.4558270602, y: 4787938.387670586, z: 3919903.201159994 },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      })
      const latlng = turf.point(convertion1({ x: -1512322.4558270602, y: 4787938.387670586, z: 3919903.201159994 }))
      const buffered = turf.buffer(latlng, 1, { units: 'kilometers' });
      const result = []
      buffered.geometry.coordinates[0].forEach(c => {
        result.push(convertion2(c[0], c[1]))
      })
      viewer.entities.add({
        polygon: {
          hierarchy: result,
          material: new SuperMap3D.StripeMaterialProperty({
            evenColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            oddColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            offset: 0.0,
            repeat: 5.0
          })
        }
      })
    }

    // 绘制线缓冲区
    function drawLineBufferHandler () {
      const poss = [
        { x: -1522237.9046121538, y: 4786234.572753863, z: 3918152.515072906 },
        { x: -1522612.688882305, y: 4786790.672703787, z: 3917332.84709323 }
      ]
      const line = viewer.entities.add({
        polyline: {
          positions: poss, // 曲线 bezierPoss
          material: SuperMap3D.Color.RED,
          width: 3
        },
        disableDepthTestDistance: Number.POSITIVE_INFINITY
      })
      const latlngs = []

      poss.forEach((c) => {
        latlngs.push(convertion1(c))
      })

      const polyline = turf.lineString(latlngs)
      const buffered = turf.buffer(polyline, 100 / 1000, { units: 'kilometers' });
      const result = []
      buffered.geometry.coordinates[0].forEach(c => {
        result.push(convertion2(c[0], c[1]))
      })
      viewer.entities.add({
        polygon: {
          hierarchy: result,
          material: new SuperMap3D.StripeMaterialProperty({
            evenColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            oddColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            offset: 0.0,
            repeat: 5.0
          })
        }
      })
      // viewer.flyTo(line)
    }

    // 绘制面缓冲区
    function drawPolygonBufferHandler () {
      const poss = [
        { x: -1512123.7645718136, y: 4793263.7218275955, z: 3913503.8097187434 },
        { x: -1513447.674567177, y: 4792746.065483553, z: 3913627.80841923 },
        { x: -1513407.4898382805, y: 4793516.069820738, z: 3912703.06333416 },
        { x: -1512816.7021667513, y: 4793679.2934803255, z: 3912731.690398276 },
        { x: -1512231.997214621, y: 4793643.150004599, z: 3913000.318535814 },
        { x: -1512123.7645718136, y: 4793263.7218275955, z: 3913503.8097187434 }
      ]
      const polygon = viewer.entities.add({
        polygon: {
          hierarchy: poss,
          material: new SuperMap3D.StripeMaterialProperty({
            evenColor: SuperMap3D.Color.RED,
            oddColor: SuperMap3D.Color.RED,
            offset: 0.0,
            repeat: 5.0
          })
        }
      })

      const latlngs = []

      poss.forEach((c) => {
        latlngs.push(convertion1(c))
      })

      const polygonLatlng = turf.polygon([latlngs])
      const buffered = turf.buffer(polygonLatlng, 100 / 1000, { units: 'kilometers' });
      const result = []
      buffered.geometry.coordinates[0].forEach(c => {
        result.push(convertion2(c[0], c[1]))
      })
      viewer.entities.add({
        polygon: {
          hierarchy: result,
          material: new SuperMap3D.StripeMaterialProperty({
            evenColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            oddColor: SuperMap3D.Color.BLUE.withAlpha(0.5),
            offset: 0.0,
            repeat: 5.0
          })
        }
      })
    }

    function convertion1 ({ x, y, z }) {
      const ellipsoid = viewer.scene.globe.ellipsoid
      const cartesian3 = new SuperMap3D.Cartesian3(x, y, z)
      const cartographic = ellipsoid.cartesianToCartographic(cartesian3)
      const lat = SuperMap3D.Math.toDegrees(cartographic.latitude)
      const lon = SuperMap3D.Math.toDegrees(cartographic.longitude)
      const alt = cartographic.height
      return [lon, lat]
    }

    function convertion2 (lat, lng) {
      return SuperMap3D.Cartesian3.fromDegrees(lat, lng)
    }

    function flyTo (viewParams) {
      const { x, y, z, heading, pitch, roll, duration } = viewParams
      viewer.camera.flyTo({
        destination: new SuperMap3D.Cartesian3(x, y, z),
        orientation: {
          heading,
          pitch,
          roll
        },
        duration,
        complete: () => {
          console.log('complete');
        },
        cancel: () => {
          console.log('cancel');
        }
      });
    }

    if (typeof SuperMap3D !== 'undefined') {
      window.startupCalled = true
      onload(SuperMap3D)
    }
  </script>
</body>

</html>

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

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

相关文章

docker访问宿主机的localhost

前言 在我们使用docker的时候我们会发现访问宿主机的ip的地址是一件比较麻烦的事情&#xff0c;因为宿主机如果处于不同的网段中他的ip地址是在不断的改变之中&#xff0c;那么如何访问宿主机的本地地址localhost成为了一件比较麻烦的事情&#xff0c;本文就介绍一种最简单访问…

JVM篇详细分析

JVM总体图 程序计数器&#xff1a; 线程私有的&#xff0c;每个线程一份&#xff0c;内部保存字节码的行号&#xff0c;用于记录正在执行字节码指令的地址。&#xff08;可通过javap -v XX.class命令查看&#xff09; java堆&#xff1a; 线程共享的区域&#xff0c;用来保存对…

【文献分享】WimPyDD 程序:用于计算 WIMP 直接检测信号的面向对象的 Python 代码

题目&#xff1a;WimPyDD: An object–oriented Python code for the calculation of WIMP direct detection signals 链接&#xff1a;DOI: 10.1016/j.cpc.2022.108342 Program Title: WimPyDD (first release: v1.6.1) CPC Library link to program files: https://doi.…

Arcgis根据要素面获取要素中心点并计算中心点坐标

一、要素面获取要素中心点 1、加载数据 2、找到“要素转点”工具 打开ArcTool box工具&#xff0c;数据管理工具—要素—要素转点&#xff0c;或者打开搜索器直接搜索“要素转点”即可 3、要素转点 弹出转换界面之后&#xff0c;输入面状要素&#xff0c;设置保存路径&#…

《手把手教你》系列技巧篇(五十三)-java+ selenium自动化测试-上传文件-上篇(详细教程)

1.简介 在实际工作中&#xff0c;我们进行web自动化的时候&#xff0c;文件上传是很常见的操作&#xff0c;例如上传用户头像&#xff0c;上传身份证信息等。所以宏哥打算按上传文件的分类对其进行一下讲解和分享。 2.为什么selenium没有提供API&#xff1f; 想必小伙伴们或者…

OSCP靶场--Codo

OSCP靶场–Codo 考点 1.nmap扫描 ## ┌──(root㉿kali)-[~/Desktop] └─# nmap 192.168.229.23 -Pn -sV -sC --min-rate 2500 Starting Nmap 7.92 ( https://nmap.org ) at 2024-03-25 05:04 EDT Nmap scan report for 192.168.229.23 Host is up (0.35s latency). Not sh…

网络七层模型之网络层:理解网络通信的架构(三)

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

postgresql多选功能实现

一、背景介绍 在一所乡村小学&#xff0c;教师资源紧张&#xff0c;所以会出现一个教师身兼多职的情况&#xff0c;既是语文老师又是数学老师甚至还是体育老师&#xff0c;这个系统就是为各个班级分配老师&#xff0c;这样一个场景实现 二、代码实现及效果 后端country_teac…

拥有超小型领先工艺射频微波电子元器件厂商兆讯授权世强硬创代理

射频前端芯片在模拟芯片中&#xff0c;属于进入门槛较高、设计难度较大的细分领域&#xff0c;由于国内射频前端芯片行业起步较晚&#xff0c;其市场份额主要被外企所占据&#xff0c;而在国产化浪潮的推动下&#xff0c;上游厂商的射频前端产品及技术逐渐具备领先的竞争优势。…

搜维尔科技:「工业仿真」煤炭矿井模拟仿真救援项目实施

煤炭矿井模拟救援系统满足煤矿企业在紧急避险应急演练方面的实际需要&#xff0c;在不耽误井下正常生产的情况下&#xff0c;高效率、低成本地实现对本矿区入井人员进行避灾演练培训&#xff0c;并学会正确的避灾自救互救方法。并可在本系统中直观的看到人员定位系统、监控系统…

MySQL进阶45讲【35】什么时候会使用内部临时表?

1 前言 在MySQL进阶45讲【15】“order by“是怎么工作的&#xff1f;和MySQL进阶45讲【32】到底可不可以使用join&#xff1f;文章中&#xff0c;分别介绍了sort buffer、内存临时表和join buffer。这三个数据结构都是用来存放语句执行过程中的中间数据&#xff0c;以辅助SQL语…

qt学习第三天,qt设计师的第一个简单案例

3月25&#xff0c;应用qt设计师&#xff0c;手动设计界面形状 ​ 如何启动qt设计师&#xff0c;找到对应的安装地点&#xff0c;对应你自己安装的pyside6或其他qt的安装路径来找 ​ 应用qt设计师的优点是不用敲代码然后慢慢调节框框大小&#xff0c;位置等、可以直接修改…

2015年认证杯SPSSPRO杯数学建模C题(第一阶段)荒漠区动植物关系的研究全过程文档及程序

2015年认证杯SPSSPRO杯数学建模 C题 荒漠区动植物关系的研究 原题再现&#xff1a; 环境与发展是当今世界所普遍关注的重大问题, 随着全球与区域经济的迅猛发展, 人类也正以前所未有的规模和强度影响着环境、改变着环境, 使全球的生命支持系统受到了严重创伤, 出现了全球变暖…

机器学习的步骤

机器学习项目的成功实施依赖于一系列定义良好的步骤。 1. 定义问题 问题理解&#xff1a;首先要明确机器学习能够解决的问题。这包括对业务需求的理解&#xff0c;以及如何通过数据驱动的方式来解决这些需求。目标设定&#xff1a;明确项目的目标&#xff0c;包括预期的输出、…

网络: 套接字

套接字: 在网络上进行进程间通信 网络字节序与主机字节序的转化 sockaddr sockaddr struct sockaddr {sa_family_t sa_family; // 地址族char sa_data[14]; // 地址数据&#xff0c;具体内容与地址族相关 };sockaddr_in :主要是地址类型, 端口号, IP地址. 基于IPv4编程…

openGauss学习笔记-251 openGauss性能调优-使用Plan Hint进行调优-行数的Hint

文章目录 openGauss学习笔记-251 openGauss性能调优-使用Plan Hint进行调优-行数的Hint251.1 功能描述251.2 语法格式251.3 参数说明251.4 建议251.5 示例 openGauss学习笔记-251 openGauss性能调优-使用Plan Hint进行调优-行数的Hint 251.1 功能描述 指明中间结果集的大小&a…

初识C++(三)构造函数和析构函数

目录 一、构造函数&#xff1a; 1.构造函数的概念&#xff1a; 2.构造函数的特性&#xff1a; 3.构造函数的形式&#xff1a; 4.为什么要引出构造函数这一概念 5.默认构造函数包括&#xff1a; 6.对默认生成的构造函数不处理内置类型的成员这事的解决办法&#xff1a; …

Adobe Illustrator和Photoshop哪个难学?另一款好用设计软件上位!

当设计开始时&#xff0c;几乎没有人不知道。 Adobe 公司的两大设计软件&#xff1a;Adobe Illustrator 和 Photoshop。虽然 Adobe Illustrator和 Photoshop 很有名&#xff0c;有一定设计经验的设计师在前期探索使用后可以对 Adobe Illustrator和 Photoshop 的使用差异有一个大…

拓展 Amazon S3 技术边界: Amazon S3 Express One Zone 的创新之路

自 Amazon S3 服务推出以来&#xff0c;一直是全球各行各业数百万客户钟爱的云存储服务。然而&#xff0c;随着新兴用例的不断涌现&#xff0c;传统存储方式面临性能瓶颈&#xff0c;尤其是对于对延迟极为敏感的应用程序。为前不久展开的亚马逊云科技 re:Invent 2023 大会上发布…

AI:154-利用机器学习进行电力系统故障检测与预测

本文收录于专栏:精通AI实战千例专栏合集 从基础到实践,深入学习。无论你是初学者还是经验丰富的老手,对于本专栏案例和项目实践都有参考学习意义。 每一个案例都附带关键代码,详细讲解供大家学习,希望可以帮到大家。正在不断更新中~ 一.利用机器学习进行电力系统故障检测…