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

相关文章

Spring如何使用注解@DependsOn控制Bean加载顺序

《Spring如何使用注解@DependsOn控制Bean加载顺序》:本文主要介绍Spring如何使用注解@DependsOn控制Bean加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录1.javascript 前言2. 代码实现总结1. 前言默认情况下,Spring加载Bean的顺

Qt如何实现文本编辑器光标高亮技术

《Qt如何实现文本编辑器光标高亮技术》这篇文章主要为大家详细介绍了Qt如何实现文本编辑器光标高亮技术,文中的示例代码讲解详细,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录实现代码函数作用概述代码详解 + 注释使用 QTextEdit 的高亮技术(重点)总结用到的关键技术点应用场景举例示例优化建议

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

IDEA下"File is read-only"可能原因分析及"找不到或无法加载主类"的问题

《IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题》:本文主要介绍IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题,具有很好的参... 目录1.File is read-only”可能原因2.“找不到或无法加载主类”问题的解决总结1.File

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示

在 PyQt 加载 UI 三种常见方法

《在PyQt加载UI三种常见方法》在PyQt中,加载UI文件通常指的是使用QtDesigner设计的.ui文件,并将其转换为Python代码,以便在PyQt应用程序中使用,这篇文章给大家介绍在... 目录方法一:使用 uic 模块动态加载 (不推荐用于大型项目)方法二:将 UI 文件编译为 python 模

VSCode中配置node.js的实现示例

《VSCode中配置node.js的实现示例》本文主要介绍了VSCode中配置node.js的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 目录一.node.js下载安装教程二.配置npm三.配置环境变量四.VSCode配置五.心得一.no

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component