ArcGIS JSAPI 学习教程 - ArcGIS Maps SDK for JavaScript - 框选显示高亮几何对象

ArcGIS JSAPI 学习教程 - ArcGIS Maps SDK for JavaScript - 框选显示高亮对象

    • 核心代码
    • 完整代码:
    • 在线示例

在研究 ArcGIS JSAPI RenderNode 高亮(highlights)FBO 的时候,实现了一下框选高亮几何对象,这里分享一下。

本文包括核心代码、完整代码以及在线示例。


核心代码

实际上,就是通过标绘工具,创建矩形标绘,在判断矩形相交,然后高亮相交的几何对象。


// 监听标绘完成事件
sketchViewModel.on("create", async (event) => {if (event.state === "complete") {const queryGeometry = event.graphic.geometry;if (this.campusLayerView) {// 获取矩形内几何对象const results = await this.campusLayerView.queryFeatures({geometry: queryGeometry,});// 设置高亮results.features.forEach((feature) => {this.highlights.push(this.campusLayerView.highlight([feature.attributes.OID]));})}}
});

完整代码:


<html lang="en">
<head><meta charset="utf-8" /><meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /><title>框选显示高亮对象 | Sample | ArcGIS Maps SDK for JavaScript 4.29</title><script type="module" src="/arcgis_api/calcite-components/2.8.1/calcite.esm.js"></script><link rel="stylesheet" type="text/css" href="/arcgis_api/calcite-components/2.8.1/calcite.css" /><link rel="stylesheet" href="/arcgis_api/4.29/esri/themes/light/main.css" /><script src="/arcgis_api/4.29/init.js"></script><script>var _hmt = _hmt || [];(function () {var hm = document.createElement("script");hm.src = "https://hm.baidu.com/hm.js?f80a36f14f8a73bb0f82e0fdbcee3058";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm, s);})();</script><script>require(["esri/WebScene","esri/views/SceneView","esri/rest/support/Query","esri/widgets/Legend","esri/core/reactiveUtils","esri/views/3d/webgl/RenderNode","esri/layers/GraphicsLayer","esri/widgets/Sketch/SketchViewModel",],(WebScene,SceneView,Query,Legend,reactiveUtils,RenderNode,GraphicsLayer,SketchViewModel,) => {// 使用官方资源const webscene = new WebScene({portalItem: {// autocasts as new PortalItem()id: "fbbc829fa7d342e7ae8d18c54a5eab37"}});// Create a view and set the highlight optionsconst view = new SceneView({container: "viewDiv",map: webscene,popup: {dockOptions: {buttonEnabled: false}},qualityProfile: "high",environment: {lighting: {directShadowsEnabled: true}},// 设置默认高亮参数highlightOptions: {haloColor: [255, 38, 150],color: [255, 255, 255],fillOpacity: 0.3}});// This variable will store the highlight handle that is used to remove the highlightthis.highlights = [];// 创建标绘图层const polygonGraphicsLayer = new GraphicsLayer({elevationInfo: {// 注意,这里设置相对于地形,否则会遮挡mode: 'relative-to-ground'}});view.map.add(polygonGraphicsLayer);// add the select by rectangle button the viewview.ui.add("select-by-rectangle", "top-left");const selectButton = document.getElementById("select-by-rectangle");// 创建标绘工具const sketchViewModel = new SketchViewModel({view: view,layer: polygonGraphicsLayer});// 监听矩形标绘事件selectButton.addEventListener("click", () => {view.closePopup();// 标绘矩形sketchViewModel.create("rectangle");// 移除上一次操作polygonGraphicsLayer.removeAll();// 移除上一次高亮对象if(this.highlights){this.highlights.forEach((highlight) => {highlight.remove();});this.highlights = [];}});// 监听标绘完成事件sketchViewModel.on("create", async (event) => {if (event.state === "complete") {const queryGeometry = event.graphic.geometry;if (this.campusLayerView) {// 获取矩形内几何对象const results = await this.campusLayerView.queryFeatures({geometry: queryGeometry,});// 设置高亮results.features.forEach((feature) => {this.highlights.push(this.campusLayerView.highlight([feature.attributes.OID]));})}}});view.when(() => {// Get layer from webSceneconst campusSceneLayer = webscene.allLayers.filter((elem) => {return elem.title === "Buildings";}).items[0];// Define the attributes which are used in the querycampusSceneLayer.outFields = ["name"];// Get DOM element where list items will be placedconst container = document.getElementById("buildingsList");const buildingCount = document.getElementById("buildingCount");// Highlight is set on the layerView, so we need to detect when the layerView is readyview.whenLayerView(campusSceneLayer).then((campusLayerView) => {this.campusLayerView = campusLayerView;// Wait for the view to finish updatingreactiveUtils.when(() => !view.updating, () => {// Query the features available for drawing and get the attributesconst query = new Query();campusLayerView.queryFeatures(query).then((result) => {// Empty the list DOM elementcontainer.innerHTML = "";buildingCount.innerHTML = `Currently in view: ${result.features.length} buildings`;// For each returned feature create a list item and append it to the containerresult.features.forEach((feature) => {const attributes = feature.attributes;// Create list elementconst li = document.createElement("calcite-pick-list-item");li.setAttribute("label", attributes.name);li.addEventListener("click", (event) => {const target = event.target;const objectId = feature.attributes.OID;// Create an extent query on the layer view that will return the 3D extent of the featureconst queryExtent = new Query({objectIds: [objectId]});campusLayerView.queryExtent(queryExtent).then((result) => {// Zoom to the extent of the feature// Use the expand method to prevent zooming in too close to the featureif (result.extent) {view.goTo(result.extent.expand(4), {speedFactor: 0.5}).catch((error) => {if (error.name != "AbortError") {console.error(error);}});}});// Remove the previous highlightsif (highlight) {highlight.remove();}// Highlight the feature passing the objectId to the methodhighlight = campusLayerView.highlight([objectId]);});container.appendChild(li);});});});});});});</script><style>html,body,#viewDiv {height: 100%;width: 100%;margin: 0;padding: 0;}.panel-side {width: 250px;position: absolute;top: 14px;right: 14px;bottom: 28px;color: #323232;background-color: rgb(255, 255, 255);box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);overflow: auto;z-index: 60;font-size: 12px;text-align: center;}.panel-side h2 {padding: 0 20px;margin: 20px 0;font-size: 14px;font-weight: 600;}#buildingCount,h2 {text-align: center;}</style>
</head><body>
<div class="panel-side esri-widget"><h2>Campus buildings</h2><p id="buildingCount">Currently in view: 0 buildings</p><calcite-panel id="buildingsList"></calcite-panel>
</div>
<div id="viewDiv"></div>
<divid="select-by-rectangle"class="esri-widget esri-widget--button esri-widget esri-interactive"title="Select features by rectangle"
><span class="esri-icon-checkbox-unchecked"></span>
</div>
</body></html>

在这里插入图片描述


在线示例

ArcGIS Maps SDK for JavaScript 在线示例:框选显示高亮对象

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

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

相关文章

LlamaIndex三 配置

前言 在上篇LlamIndex二 RAG应用开发 - 掘金 (juejin.cn)中&#xff0c;我们学习到LlamaIndex对RAG的全面支持。这篇文章&#xff0c;我们就来细化这个过程&#xff0c;尝试各种配置选项&#xff0c;满足不同场景需求。学习过后&#xff0c;大家再开发RAG应用&#xff0c;会更…

Sketch语言设置指南:将英文版改成中文版的教程

Sketch版本的转换一直是困扰大家的关键问题。如今UI设计领域的UI设计软件很多&#xff0c;但大部分都是英文版。对于国内英语基础差的设计师来说&#xff0c;使用这样的软件无形中增加了工作量&#xff0c;往往需要在设计编辑的同时查阅翻译。即时设计详细介绍了Sketch英文版如…

单个python文件代码的车牌检测系统 使用pyqt做界面进行车牌检测,可以保存结果到excel文件

融合了hyperlpr3和opencv 来检测车牌 通过图片检测车牌的系统&#xff0c;使用了pyqt和hyperlpr3结合来进行检测&#xff0c;可以保存检测的结果到excel文件 亲自测试修改代码&#xff0c;运行正常并且不依赖百度网络api, 纯本地运行&#xff0c;融合了2个车牌检测模型, 第…

《计算机组成原理》笔记整理

第一章 计算机系统概论 计算机的硬件&#xff1a;计算机中的电子电路和物理装置&#xff1b;计算机硬件的五大部分&#xff1a;运算器、控制器、存储器、输入设备和输出设备&#xff1b;计算机的软件&#xff1a;计算机运行所需的程序及相关的资料&#xff1b;软件系统&#x…

2024年【起重机司机(限桥式起重机)】考试试卷及起重机司机(限桥式起重机)证考试

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 2024年【起重机司机(限桥式起重机)】考试试卷及起重机司机(限桥式起重机)证考试&#xff0c;包含起重机司机(限桥式起重机)考试试卷答案和解析及起重机司机(限桥式起重机)证考试练习。安全生产模拟考试一点通结合国家…

相对路径vs绝对路径 python文件的添加与删除

目录 一、路径问题 1.绝对路径 2.相对路径 3.在不同的操作系统中有不同的方法来查看当前路径&#xff1a; 3.1Windows 系统&#xff1a; 3.2 类 Unix 系统 3.3 pythoon如何查看当前路径 二、使用步骤 2.1 Python文件操作 2.2 cd”命令 2.2.1 cd 目录路径&#xff1a…

音视频开发17 FFmpeg 音频解码- 将 aac 解码成 pcm

这一节&#xff0c;接 音视频开发12 FFmpeg 解复用详情分析&#xff0c;前面我们已经对一个 MP4文件&#xff0c;或者 FLV文件&#xff0c;或者TS文件进行了 解复用&#xff0c;解出来的 视频是H264,音频是AAC&#xff0c;那么接下来就要对H264和AAC进行处理&#xff0c;这一节…

WebAPI AOP方式 异常方式

》》 自定义异常处理特性 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http.Filters;namespace WebApplication11 {/// <summary>/// 异常处理特性/// </sum…

005.FashionMNIST数据集简介

一、FashionMNIST数据集简介 FashionMNIST数据集&#xff0c;作为经典的MNIST数据集的现代替代品的数据集&#xff0c;是衣物分类数据集&#xff0c;由Zalando&#xff08;一家德国的在线时尚零售商&#xff09;发布。 FashionMNIST数据集和MNIST相比。图片尺寸相同&#xff0c…

后端 excel的导入

后端 excel导入 Apache POI 和 EasyExcel 是 Java 中常用的处理 Excel 文件的库。 EasyExcel 是阿里巴巴开源的一款专门针对大数据量 Excel 导入导出场景的工具&#xff0c;其设计目标在于简化开发、减少内存占用并提升处理速度。 以下是使用 EasyExcel 进行 Excel 导入的基本…

混凝土结构中最小配筋率45ft/fy怎么来的?

文章目录 0. 背景1. 原理解析2. 总结 0. 背景 上学的时候就对混凝土结构规范中关于最小配筋率“ 45 f t / f y 45f_t/f_y 45ft​/fy​”的表述很好奇&#xff0c;今天终于看到解释了。原文来自这里&#xff0c;喜欢的可以关注原作者。 按照原作者的说法&#xff0c;本文的解释…

I P协议

IPv4首部 4个字节的32 bit值以下面的次序传输&#xff1a;首先是 0&#xff5e;7 bit&#xff0c;其次8&#xff5e;15 bit&#xff0c;然后1 6&#xff5e;23 bit&#xff0c;最后是24~31 bit。这种传输次序称作 big endian字节序。由于TCP/IP首部中所有的二进制整数在网络中传…

简单聊聊大数据分析的方法有什么

大数据分析是指对规模巨大的数据集合进行的分析过程。 这些数据集合通常具有以下几个特点&#xff0c;可以概括为5个V&#xff1a; 1.数据量大&#xff08;Volume&#xff09;&#xff1a;大数据分析处理的数据量巨大&#xff0c;远远超出了传统数据处理软件的能力范围。 2.…

攻防世界testre做法(考点:base58)

在做这道题目之前&#xff0c;我们先来简单了解一下base64加密和base58加密&#xff0c;先来说一些预备知识&#xff0c;bit为1个位&#xff0c;即一个0或1&#xff0c;八个位组成一个字节&#xff0c;即八个二进制数。 base64编码原理&#xff1a;1&#xff0c;在使用base64加…

走进 Apache 世界的另一扇大门

引言 作为热爱技术的你&#xff0c;是否也羡慕 Apache PMC 或者 Committer&#xff0c;此篇文章渣渣皮带你迈出如何成为技术大牛的第一步。 当然我现在还是一枚小小的 code contributor&#xff0c;在成为 committer 的路上还在奋力打码中&#xff0c;写这篇文章也是为大家有…

MyBatis 入门详解

一、简介 1. 什么是 MyBatis MyBatis 是一款优秀的持久层框架&#xff0c;它支持自定义 SQL、存储过程以及高级映射。MyBatis 消除了几乎所有的 JDBC 代码和手动设置参数以及获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原生类型、接口和 Java 的 POJO&…

Windows搭建apache网站

1、官网下载安装包&#xff0c;注意下载服务器对应操作系统的安装包&#xff08;此案例为64位操作系统&#xff09; Apache VS17 binaries and modules downloadFor (business) webmasters, developers and home-users who want running always up to date Windows VS17 binar…

【机器学习】机器学习与智能交通在智慧城市中的融合应用与性能优化新探索

文章目录 引言机器学习与智能交通的基本概念机器学习概述监督学习无监督学习强化学习 智能交通概述交通流量预测交通拥堵管理智能信号控制智能停车管理 机器学习与智能交通的融合应用实时交通数据分析数据预处理特征工程 交通流量预测与优化模型训练模型评估 智能信号控制与优化…

pycharm安装openai报错

解决方案&#xff1a; Rust官网:http://rust-lang.org 下载安装包&#xff0c;下载后如下 双击这个exe文件 提示需要安装visual studio选择1进行安装即可。安装完成后会自动进行下一步 选择1进行安装 默认安装到C:\Users\用户名文件夹下 验证是否安装成功 由于这两个文件夹占…

k8s:实现一个pod两个容器

# 制作两个容器的镜像 通过以下Dockerfile创建一个镜像 cd /chz/install/docker vim Dockerfile <<<< 内容如下&#xff1a; FROM centosRUN sed -i -e "s|mirrorlist|#mirrorlist|g" /etc/yum.repos.d/CentOS-* RUN sed -i -e "s|#baseurlhttp:/…