04-ArcGIS For JavaScript的可视域分析功能

news2024/10/6 5:54:41

文章目录

  • 综述
  • 代码实现
  • 代码解析
  • 结果

在这里插入图片描述

综述

在数字孪生或者实景三维的项目中,视频融合和可视域分析,一直都是热点问题。Cesium中,支持对阴影的后处理操作,通过重新编写GLSL代码就能实现视域和视频融合的功能。ArcGIS之前支持的可视域分析只要是通过GP服务的方式去实现,并且只针对地形有相应的效果,并不能直接叠加到建模模型上。
ArcGIS for JavaScript最新发布了4.30版本的api,其中新增了对于模型场景的视域分析,并且提供了很好的交互功能,使其在项目应用中又有了更多的可能性。

代码实现

直接上代码,或者直接去官网看。

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

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  <title>Interactive viewshed analysis | Sample | ArcGIS Maps SDK for JavaScript 4.30</title>
  <style>
    html,
    body,
    html,
    body,
    #viewDiv {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
    }
    #viewshedComponent {
      width: 270px;
    }
    #viewshedComponent calcite-button {
      display: flex;
    }
    #promptText {
      margin-top: 0.4rem;
    }
  </style>
  <link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" />
  <script src="https://js.arcgis.com/4.30/"></script>
  <script type="module" src="https://js.arcgis.com/calcite-components/2.8.5/calcite.esm.js"></script>
  <link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/2.8.5/calcite.css" />
  <script>
    require([
      "esri/Map",
      "esri/views/SceneView",
      "esri/geometry/SpatialReference",
      "esri/core/promiseUtils",
      "esri/core/reactiveUtils",
      "esri/views/3d/environment/SunLighting",
      "esri/analysis/ViewshedAnalysis",
      "esri/analysis/Viewshed"
    ], function (
      Map,
      SceneView,
      SpatialReference,
      promiseUtils,
      reactiveUtils,
      SunLighting,
      ViewshedAnalysis,
      Viewshed
    ) {
      const view = new SceneView({
        container: "viewDiv",
        camera: {
          position: {
            spatialReference: SpatialReference.WebMercator,
            x: -9753837.742627423,
            y: 5140806.202422867,
            z: 995.4546383377165
          },
          heading: 1.2311944909542853,
          tilt: 70.07900968078631
        },
        map: new Map({
          basemap: "topo-3d",
          ground: "world-elevation"
        }),
        environment: {
          lighting: new SunLighting({
            date: new Date("January 18, 2024 12:50:00 UTC-6"),
            directShadowsEnabled: true
          })
        }
      });

      view.when(async () => {
        // Hide the 3D basemap's labels layer.
        const labelsLayer = view.map.basemap.referenceLayers.find(
          (layer) => layer.title === "Places and Labels"
        );
        labelsLayer.visible = false;

        // Create the viewshed shape.
        const viewshed = new Viewshed({
          observer: {
            spatialReference: SpatialReference.WebMercator,
            x: -9754426,
            y: 5143111,
            z: 330
          },
          farDistance: 900, // In meters
          tilt: 84, // Tilt of 0 looks down, tilt of 90 looks parallel to the ground, tilt of 180 looks up to the sky
          heading: 63, // Counted clockwise from North
          horizontalFieldOfView: 85,
          verticalFieldOfView: 52
        });
        // Initialize viewshed analysis with the created viewshed shape and add it to the view.
        const viewshedAnalysis = new ViewshedAnalysis({ viewsheds: [viewshed] });
        view.analyses.add(viewshedAnalysis);

        // Access the viewshed's analysis view.
        const analysisView = await view.whenAnalysisView(viewshedAnalysis);
        // Make the existing analysis interactive and select the created viewshed.
        analysisView.interactive = true;
        analysisView.selectedViewshed = viewshed;

        // Add interactivity to the custom UI component's buttons.
        const createButton = document.getElementById("createButton");
        const cancelButton = document.getElementById("cancelButton");
        const promptText = document.getElementById("promptText");

        // Controller which allows to cancel an ongoing viewshed creation operation.
        let abortController = null;

        createButton.addEventListener("click", () => {
          // Cancel any pending creation operation.
          stopCreating();

          // Create a new abort controller for the new operation.
          abortController = new AbortController();

          updateUI();

          // Save current number of viewsheds to track whenever a new one is created.
          const viewshedCounter = viewshedAnalysis.viewsheds.length;
          // Watch whenever the a new viewshed is created and selected and then stop the creation method.
          reactiveUtils.when(
            () => viewshedAnalysis.viewsheds.length > viewshedCounter && analysisView.selectedViewshed,
            () => {
              stopCreating();
              updateUI();
            }
          );

          // Pass the controller as an argument to the interactive creation method
          // and schedule the updateUI function after creating viewsheds is finished.
          analysisView
            .createViewsheds(abortController)
            .catch((e) => {
              // When the operation is cancelled, don't do anything. Any other errors are thrown.
              if (!promiseUtils.isAbortError(e)) {
                throw e;
              }
            })
            .finally(() => {
              // Update the UI to reflect the non-creating mode.
              updateUI();
            });
        });

        cancelButton.addEventListener("click", () => {
          // Pressing the Cancel button stops the viewshed creation process and updates the UI accordingly.
          stopCreating();
          updateUI();
        });
        // Cancel the creation process and updates the UI when ESC is pressed.
        view.on("key-down", (event) => {
          if ((event.key = "Escape")) {
            stopCreating();
            updateUI();
          }
        });

        // Cancel any pending viewshed creation operation.
        function stopCreating() {
          abortController?.abort();
          abortController = null;
        }

        // Update the UI component according to whether there is a pending operation.
        function updateUI() {
          const creating = abortController != null;
          createButton.style.display = !creating ? "flex" : "none";
          cancelButton.style.display = creating ? "flex" : "none";
          promptText.style.display = creating ? "flex" : "none";
        }

        // Add the component to the UI.
        view.ui.add("viewshedComponent", "top-right");
      });

    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
  <calcite-card id="viewshedComponent">
    <calcite-button id="createButton">Create viewshed</calcite-button>
    <calcite-button id="cancelButton" style="display:none">Cancel </calcite-button>
    <div id="promptText" style="display: none">
      <em>Start the analysis by clicking in the scene to place the observer point and set the target.</em>
    </div>
  </calcite-card>
</body>

</html>

代码解析

ArcGIS for JavaScript提供了新的对象Viewshed和ViewshedAnalysis。
在这里插入图片描述
在这里插入图片描述

Viewshed定义了Viewshed分析的几何形状。视域由位置、距离、方向(由头部和倾斜定义)和视野角度决定。
ViewshedAnalysis允许在3D SceneView中创建和显示viewshed和view dome类型的可见性分析。该分析功能可以包含多个视图。它们可以以交互方式或编程方式创建,并且可以将分析直接添加到SceneView.analyses中。

const viewshed = new Viewshed({
   observer: {
     spatialReference: {
       latestWkid: 3857,
       wkid: 102100
     },
     x: -9754426,
     y: 5143111,
     z: 330
   },
   farDistance: 900,
   heading: 64,
   tilt: 84,
   horizontalFieldOfView: 85,
   verticalFieldOfView: 52
 });
 const viewshedAnalysis = new ViewshedAnalysis({
   viewsheds: [viewshed],
 });

 view.analyses.add(viewshedAnalysis);
···

上面方法是直接去创建可视域的功能,当然也可以通过交互的方式去创建可视域。

```javascript
		const analysisView = await 		 view.whenAnalysisView(viewshedAnalysis);
        // Make the existing analysis interactive and select the created viewshed.
        analysisView.interactive = true;
        analysisView.selectedViewshed = viewshed;
analysisView
            .createViewsheds(abortController)
            .catch((e) => {
              // When the operation is cancelled, don't do anything. Any other errors are thrown.
              if (!promiseUtils.isAbortError(e)) {
                throw e;
              }
            })
            .finally(() => {
              // Update the UI to reflect the non-creating mode.
              updateUI();
            });

结果

在这里插入图片描述

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

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

相关文章

Vue+Xterm.js+WebSocket+JSch实现Web Shell终端

一、需求 在系统中使用Web Shell连接集群的登录节点 二、实现 前端使用Vue&#xff0c;WebSocket实现前后端通信&#xff0c;后端使用JSch ssh通讯包。 1. 前端核心代码 <template><div class"shell-container"><div id"shell"/>&l…

day01-切片和索引

day01-切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改&#xff0c;与 Python 中list 的切片操作一样。 ndarray数组可以基于0-n的下标进行索引 注意&#xff0c;数组切片并不像列表切片会重新开辟一片空间&#xff0c;而是地址引用&#xff0c;需要使用.copy()…

【Threejs进阶教程-着色器篇】2. Uniform的基本用法与Uniform的调试

Uniform的基本用法与Uniform的调试 关于本Shader教程优化上一篇的效果优化光栅栏高度让透明度和颜色变的更平滑pow()函数借助数学工具更好的理解函数 Unifoms简介编写uniforms修改片元着色器代码借助lil.gui调试uniforms使用uniform控制颜色继续在uniforms添加颜色在着色器中接…

动态住宅代理IP的3个优点

在大数据时代的背景下&#xff0c;代理IP成为了很多企业顺利开展的重要工具。代理IP地址可以分为住宅代理IP地址和数据中心代理IP地址。选择住宅代理IP的好处是可以实现真正的高匿名性&#xff0c;而使用数据中心代理IP可能会暴露自己使用代理的情况。 住宅代理IP是指互联网服务…

JavaScript中location对象的主要属性和方法

属性 href&#xff1a;获取或设置整个URL。protocol&#xff1a;获取URL的协议部分&#xff0c;如"http:"或"https:"。host&#xff1a;获取URL的主机名&#xff08;包括端口号&#xff0c;如果有的话&#xff09;。hostname&#xff1a;获取URL的主机名&…

Android studio 打包低版本的Android项目报错

一、报错内容 Execution failed for task :app:packageRelease. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade> com.android.ide.common.signing.KeytoolException: Failed to read key key0 from store "…

【Portswigger 学院】路径遍历

路径遍历&#xff08;Path traversal&#xff09;又称目录遍历&#xff08;Directory traversal&#xff09;&#xff0c;允许攻击者通过应用程序读取或写入服务器上的任意文件&#xff0c;例如读取应用程序源代码和数据、凭证和操作系统文件&#xff0c;或写入应用程序所访问或…

10 Posix API与网络协议栈

POSIX概念 POSIX是由IEEE指定的一系列标准,用于澄清和统一Unix-y操作系统提供的应用程序编程接口(以及辅助问题,如命令行shell实用程序),当您编写程序以依赖POSIX标准时,您可以非常肯定能够轻松地将它们移植到大量的Unix衍生产品系列中(包括Linux,但不限于此!)。 如…

奇瑞被曝强制加班,“896”成常态且没有加班费

ChatGPT狂飙160天&#xff0c;世界已经不是之前的样子。 更多资源欢迎关注 7 月 2 日消息&#xff0c;一位认证为“奇瑞员工”的网友近期发帖引发热议&#xff0c;奇瑞汽车内部存在强制加班行为&#xff0c;每周加班时长需大于 20 小时并且没有加班费&#xff0c;仅补贴 10 元…

人口萎缩,韩国釜山“进入消失阶段”

KlipC报道&#xff1a;调查显示&#xff0c;随着低生育率和人口老化&#xff0c;釜山人口逐渐萎缩&#xff0c;韩国第二大城市釜山显现出“进入消失阶段”的迹象。 据悉&#xff0c;“消失风险指数”是将20岁至39岁女性人口总数除以65岁及以上人口得到的数值。当该指数大于1.5…

第T3周:天气识别

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 一、前期工作 本文将采用CNN实现多云、下雨、晴、日出四种天气状态的识别。较上篇文章&#xff0c;本文为了增加模型的泛化能力&#xff0c;新增了Dropout层并…

【计算机体系结构】缓存的false sharing

在介绍缓存的false sharing之前&#xff0c;本文先介绍一下多核系统中缓存一致性是如何维护的。 目前主流的多核系统中的缓存一致性协议是MESI协议及其衍生协议。 MESI协议 MESI协议的4种状态 MESI协议有4种状态。MESI是4种状态的首字母缩写&#xff0c;缓存行的4种状态分别…

snap和apt的区别简单了解

Linux中没有tree命令的时候提示安装的时候出现了两个命令&#xff0c;简单看了看两者有何区别&#xff08;一般用apt就可以了&#xff09;&#xff1a; sudo snap install tree 和 sudo apt install tree 这两个命令都是用来安装 tree 命令行工具的&#xff0c;但它们使用的是不…

uniapp零基础入门Vue3组合式API语法版本开发咸虾米壁纸项目实战

嗨&#xff0c;大家好&#xff0c;我是爱搞知识的咸虾米。 今天给大家带来的是零基础入门uniapp&#xff0c;课程采用的是最新的Vue3组合式API版本&#xff0c;22年发布的uniappVue2版本获得了官方推荐&#xff0c;有很多同学等着我这个vue3版本的那&#xff0c;如果没有学过vu…

数字信号处理教程(2)——时域离散信号与时域离散系统

上回书说到数字信号处理中基本的一个通用模型框架图。今天咱们继续&#xff0c;可以说今天要讲的东西必须是学习数字信号处理必备的观念——模拟与数字&#xff0c;连续和离散。 时域离散序列 由于数字信号基本都来自模拟信号&#xff0c;所以先来谈谈模拟信号。模拟信号就是…

umi项目中的一些趣事

前言 出于某些安全问题&#xff0c;需要把HTML中框架注入的umi版本信息去掉&#xff0c;那要怎么搞呢~ 方案 查找官方文档&#xff0c;没发现可以去掉注入信息的方法&#xff0c;但在一番折腾后&#x1f609;终究还是解决了~ 发现 版本信息是从这里注入的~ Object.define…

企业短视频-直播运营团队打造课,手把手带你从0-1 搭建运营团队-15节

如何获取精准客户? 一套抖音营销系统打造课 能定位 懂运营 建团队 持续获客 课程目录 1-01、每个老板都应该学习博商团队的打造方法1.mp4 2-02、如何从0-1快速搭建运营团队1.mp4 3-03、怎么才能招聘到运营人才&#xff1f;1.mp4 4-04、怎么才能快速筛选简历招到符合要求…

程序烧录原理

程序烧录原理 ISP(In System Programming)&#xff0c;在系统编程&#xff0c;单片机不须脱离应用系统而直接在产品上烧写/升级程序。 条件&#xff1a;系统须引出单片机的串口引脚&#xff08;TXD、RXD&#xff09;ISP相对于传统的编程方式&#xff0c;在传统的编程方式中我们…

kvm虚拟机启用console登录

kvm虚拟机console登录&#xff0c;就是执行 virsh console 的时候&#xff0c;宿主机可以控制虚拟机。 一、centos7的kvm虚拟机开启console登录&#xff08;在虚拟中操作&#xff09; 1、备份文件 [roothadoop51 ~]# cp /etc/grub2.cfg /etc/grub2.cfg_back 2、用下面命令可…

2024 AIGC 技术创新应用研讨会暨数字造型设计师高级研修班通知

尊敬的老师、领导您好! 为深入响应国家关于教育综合改革的战略部署&#xff0c;深化职业教育、高等教育改革&#xff0c;发挥企业主体重要作用&#xff0c;促进人才培养供给侧和产业需求侧结构要素全方位融合&#xff0c;充分把握人工智能创意式生成(AIGC)技术在教育领域的发展…