ArcGIS for js 4.x FeatureLayer 加载、点选、高亮

2024-06-07 15:36

本文主要是介绍ArcGIS for js 4.x FeatureLayer 加载、点选、高亮,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安装arcgis for js 4.x 依赖:

npm install @arcgis/core

一、FeatureLayer 加载

代码如下:

<template><view id="mapView"></view></template><script setup>import "@arcgis/core/assets/esri/themes/light/main.css";
import Map from '@arcgis/core/Map.js';
import MapView from '@arcgis/core/views/MapView.js';
import TileLayer from '@arcgis/core/layers/TileLayer.js'
import WebTileLayer from '@arcgis/core/layers/WebTileLayer.js'
import FeatureLayer from "@arcgis/core/layers/FeatureLayer.js"
import Graphic from "@arcgis/core/Graphic.js";
import SimpleFillSymbol from "@arcgis/core/symbols/SimpleFillSymbol.js";
import { onMounted } from "vue";onMounted(()=>{initTDTMap();});// 天地图加载
const initTDTMap = () =>{let webLayer = new WebTileLayer({urlTemplate: "http://{subDomain}.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={col}&TILEROW={row}&TILEMATRIX={level}&tk=352d4b1313777a8643542046a28d17e5",subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7']});const map = new Map({basemap:{baseLayers:[webLayer]}});const mapView = new MapView({// 默认中心点位center: [125.338, 43.882],map: map,// 初始层级zoom: 10,container: "mapView",constraints: {minZoom: 9,// 最小层级maxZoom: 17// 最大层级},});// 清除底部powered by ESRI
mapView.ui.remove("attribution");// 加载FeatureLayerconst featureLayer = new FeatureLayer({url:"http://116.141.0.114:48080/geoscene/rest/services/%E8%80%95%E4%BF%9D/%E5%8F%8C%E9%98%B3%E5%8C%BA%E5%9B%BE%E6%96%91/FeatureServer/0",outFields: ["*"], //加载所有要素字段opacity:0.5,//透明度//popupTemplate: TuCeng03TC, //加载模板,//definitionExpression: "",// 筛查// 渲染renderer: {type: "simple",symbol: {type: "simple-fill",//simple-line(线)、simple-fill(面)style: "solid",// solid 全部填充、cross十字交错、diamond菱形、square矩形、triangle三角形color: [255,20,60, 0.4],outline: {color: [255, 0, 0, 1],width: 2,},},}});// 添加featureLayer(两种方法都可以)//mapView.map.add(featureLayer);map.add(featureLayer);</script><style lang="scss" scoped>#mapView{width: 100%;height:100vh;}</style>

二、点选FeatureLayer

代码如下:

    // featureLayer图斑点击事件mapView.on(['click'],function(event){mapView.hitTest(event).then(function(response){if (response.results.length) {let clickLayer = response.results.filter((result) => {return result.graphic.layer === featureLayer;});// 获取绘制let graphic = clickLayer[0].graphic;// 点击后定位mapView.goTo(graphic);// 如果点选到图层上的要素,则输出要素的IDvar objId = response.results.map(function(result) {return result.graphic.attributes[result.graphic.layer.objectIdField];});console.log("点选到的要素ID: ", objId);// 如果点选到图层上的要素,则输出全部属性var attributes = response.results.map(function(result) {return result.graphic.attributes;});console.log("点选到的attributes: ", attributes);}else{console.log("点选无果");}})});

三、高亮

1、默认高亮

	// featureLayer图斑点击事件let highlight;// 默认高亮对象mapView.on(['click'],function(event){mapView.hitTest(event).then(function(response){// 清空上一次高亮-默认 /* if(highlight)highlight.remove(); */// 清空上一次高亮-自定义mapView.graphics.removeAll();if (response.results.length) {let clickLayer = response.results.filter((result) => {return result.graphic.layer === featureLayer;});// 获取绘制let graphic = clickLayer[0].graphic;// 点击后定位mapView.goTo(graphic);/* // 如果点选到图层上的要素,则输出要素的IDvar objId = response.results.map(function(result) {return result.graphic.attributes[result.graphic.layer.objectIdField];});console.log("点选到的要素ID: ", objId);// 如果点选到图层上的要素,则输出全部属性var attributes = response.results.map(function(result) {return result.graphic.attributes;});console.log("点选到的attributes: ", attributes);*/// 默认选中高亮mapView.whenLayerView(graphic.layer).then((layerView)=>{highlight = layerView.highlight(graphic)});// 自定义选中高亮/* var symbol = new SimpleFillSymbol({color: [255, 255, 0, 0.5], // 黄色半透明填充outline: {color: [255, 0, 0], // 红色边框width: 2}});graphic.symbol = symbol;mapView.graphics.add(graphic); */}else{console.log("点选无果");}})});

2、自定义高亮

// featureLayer图斑点击事件//let highlight;// 默认高亮对象mapView.on(['click'],function(event){mapView.hitTest(event).then(function(response){// 清空上一次高亮-默认 /* if(highlight)highlight.remove(); */// 清空上一次高亮-自定义mapView.graphics.removeAll();if (response.results.length) {let clickLayer = response.results.filter((result) => {return result.graphic.layer === featureLayer;});// 获取绘制let graphic = clickLayer[0].graphic;// 点击后定位mapView.goTo(graphic);/* // 如果点选到图层上的要素,则输出要素的IDvar objId = response.results.map(function(result) {return result.graphic.attributes[result.graphic.layer.objectIdField];});console.log("点选到的要素ID: ", objId);// 如果点选到图层上的要素,则输出全部属性var attributes = response.results.map(function(result) {return result.graphic.attributes;});console.log("点选到的attributes: ", attributes);*/// 默认选中高亮/* mapView.whenLayerView(graphic.layer).then((layerView)=>{highlight = layerView.highlight(graphic)}); */// 自定义选中高亮var symbol = new SimpleFillSymbol({color: [255, 255, 0, 0.5], // 黄色半透明填充outline: {color: [255, 0, 0], // 红色边框width: 2}});graphic.symbol = symbol;mapView.graphics.add(graphic);}else{console.log("点选无果");}})});

这篇关于ArcGIS for js 4.x FeatureLayer 加载、点选、高亮的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1039584

相关文章

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

Node.js 数据库 CRUD 项目示例详解(完美解决方案)

《Node.js数据库CRUD项目示例详解(完美解决方案)》:本文主要介绍Node.js数据库CRUD项目示例详解(完美解决方案),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考... 目录项目结构1. 初始化项目2. 配置数据库连接 (config/db.js)3. 创建模型 (models/

使用Node.js制作图片上传服务的详细教程

《使用Node.js制作图片上传服务的详细教程》在现代Web应用开发中,图片上传是一项常见且重要的功能,借助Node.js强大的生态系统,我们可以轻松搭建高效的图片上传服务,本文将深入探讨如何使用No... 目录准备工作搭建 Express 服务器配置 multer 进行图片上传处理图片上传请求完整代码示例

用js控制视频播放进度基本示例代码

《用js控制视频播放进度基本示例代码》写前端的时候,很多的时候是需要支持要网页视频播放的功能,下面这篇文章主要给大家介绍了关于用js控制视频播放进度的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言html部分:JavaScript部分:注意:总结前言在javascript中控制视频播放

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法

《SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法》本文主要介绍了SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录方法1:更改IDE配置方法2:在Eclipse中清理项目方法3:使用Maven命令行在开发Sprin

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

mac安装nvm(node.js)多版本管理实践步骤

《mac安装nvm(node.js)多版本管理实践步骤》:本文主要介绍mac安装nvm(node.js)多版本管理的相关资料,NVM是一个用于管理多个Node.js版本的命令行工具,它允许开发者在... 目录NVM功能简介MAC安装实践一、下载nvm二、安装nvm三、安装node.js总结NVM功能简介N