ArcGIS JS API popup弹窗

2024-02-21 13:38
文章标签 arcgis js api 弹窗 popup

本文主要是介绍ArcGIS JS API popup弹窗,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

*使用ArcGIS JS API 4.19

一、要素服务popup

原始弹窗由popup微件控制,view对象都自带默认的popup,格式可以由Featurelayer的popupTemplate属性控制。

测试代码(Vue中):

<template><div id="viewDiv"><InfoWindow v-show="this.showWindow"></InfoWindow></div></template><script>
import {loadModules} from 'esri-loader'export default {name: 'Identify',data (){return {option :{url: '/4.19/init.js',css: '/4.19/esri/themes/light/main.css'},cdUrl: " ",currentView: {},}},methods :{_createView (){const self =this;loadModules(["esri/Map","esri/views/MapView","esri/layers/MapImageLayer","esri/layers/FeatureLayer","esri/config"],self.option).then(([Map,MapView,MapImageLayer,FeatureLayer,esriConfig])=>{const cdUrl = "http://localhost:6080/arcgis/rest/services/xzqhFS/FeatureServer/0";self.cdUrl = cdUrl;const cdLayer = new FeatureLayer({url: cdUrl,popupTemplate: {title: "{DISTRICT}",lastEditInfoEnabled: false,content: [{type: "fields",fieldInfos: [{fieldName: "DISTRICT"}]}]}})const map = new Map({basemap: 'satellite'});map.add(cdLayer);const view = new MapView({map: map,container: "viewDiv",center: [104.07,30.67],zoom: 7});self.currentView = view;}).catch((e)=>{console.log(e);});},},mounted (){this._createView ();},}
</script><style lang='stylus' scoped>#viewDivwidth: 100%height: 100%</style>

效果:
在这里插入图片描述
另外,可以自定义一些按钮和事件,通过actions控制,参考官网示例:
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=popup-actions
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=popup-custom-action

二、 动态地图服务popup

动态地图服务MapImageLayer是没有popTemplate属性的,所以可能需要自己写弹窗来显示信息。

测试代码(Vue中):

<template><div id="viewDiv"><InfoWindow v-show="this.showWindow"></InfoWindow></div></template><script>
import {loadModules} from 'esri-loader'
import InfoWindow from '@/components/InfoWindow'export default {name: 'Identify',data (){return {option :{url: '/4.19/init.js',css: '/4.19/esri/themes/light/main.css'},cdUrl: " ",currentView: {},showWindow: false,sPX: 0,sPY: 0,geometryArr: []}},components:{InfoWindow},methods :{_createView (){const self =this;loadModules(["esri/Map","esri/views/MapView","esri/layers/MapImageLayer"],self.option).then(([Map,MapView,MapImageLayer])=>{const cdUrl = "http://localhost:6080/arcgis/rest/services/mapcd/MapServer/";self.cdUrl = cdUrl;const cdLayer = new MapImageLayer({url: cdUrl})const map = new Map({basemap: 'osm'});map.add(cdLayer);const view = new MapView({map: map,container: "viewDiv",center: [104.07,30.67],zoom: 7});self.currentView = view;view.when(function(){// executeIdentifyTask() is called each time the view is clicked\// view.on("click",self.executeIdentifyTask);view.on("click",function (event) {self.executeIdentifyTask(event);//self.queryFeature(event);});});}).catch((e)=>{console.log(e);});},// Executes each time the view is clickedexecuteIdentifyTask (event){//console.log(event);const self = this;// Set the geometry to the location of the view click\loadModules(["esri/views/MapView","esri/tasks/IdentifyTask","esri/Graphic","esri/tasks/support/IdentifyParameters"],self.option).then(function([MapView,IdentifyTask,Graphic,IdentifyParameters]){// Create identify task for the specified map serviceconsole.log('event',event);console.log(self.cdUrl);const identifyTask = new IdentifyTask(self.cdUrl);// Set the parameters for the Identifyconst params = new IdentifyParameters();params.tolerance = 3;params.layerIds = [0];params.layerOption = "top";params.width = self.currentView.width;params.height = self.currentView.height;params.returnGeometry = true; // Set the geometry to the location of the view clickparams.geometry= event.mapPoint;console.log('point',event.mapPoint);params.mapExtent = self.currentView.extent;console.log(params);//transform mappoint to screen pointlet sPoint = self.currentView.toScreen(event.mapPoint);//获取弹出框窗口的屏幕位置self.sPX = sPoint.x +50;self.sPY = sPoint.y -40;console.log('spoint',sPoint);document.getElementById("viewDiv").style.cursor="wait";// This function returns a promise that resolves to an array of features// A custom popupTemplate is set for each feature based on the layer it// originates fromidentifyTask.execute(params).then(function(res){const results = res.results;console.log('results',results);if (results.length>0){self.showWindow =true;}else if(results.length==0){self.showWindow =false;}self.geometryArr = [];return results.map(function(result){const feature = result.feature;//获取存储点击要素的geometryself.geometryArr.push(feature.geometry);//定义feature的template内容console.log('info',feature);let info  = feature.attributes.COUTRICT;console.log(info);feature.popupTemplate ={title: "行政区",content: info};return feature;});}).then(showPopup);// Send the array of features to showPopup()// Shows the results of the Identify in a popup once the promise is resolvedfunction showPopup(response) {//定义获取弹窗的位置if (response.length > 0) {let temp = document.getElementById("test");temp.innerHTML = `<p>${response[0].popupTemplate.title}</p><br><p>${response[0].popupTemplate.content}</p>`;temp.style.textAlign="center";temp.style.left = `${self.sPX}px`;temp.style.right = `${self.sPX}px`;}//获取点击要素geometry高亮显示self.currentView.graphics.removeAll();if (event && self.geometryArr.length) {console.log(888,self.geometryArr);self.geometryArr.forEach(function(geometry){self.currentView.graphics.add(new Graphic({geometry: geometry,symbol: {type: "simple-fill",style: "none",outline: {color: "#6600FF",width: 2}}}));});}document.getElementById("viewDiv").style.cursor = "auto";}}).catch((e)=>{console.log(e);});}},mounted (){this._createView ();},}
</script><style lang='stylus' scoped>#viewDivwidth: 100%height: 100%</style>

自定义窗口组件:

<template><div id="test" class="testWindow">22222</div>
</template><script>
export default {}
</script><style lang='stylus' scoped>.testWindowposition: absolutetop: 100pxright: 30pxwidth: 200pxheight: 200pxbackground-color: white</style>

效果:
在这里插入图片描述

三、其他参考

弹窗统计数据:https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=popuptemplate-promise

这篇关于ArcGIS JS API popup弹窗的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

springboot项目中常用的工具类和api详解

《springboot项目中常用的工具类和api详解》在SpringBoot项目中,开发者通常会依赖一些工具类和API来简化开发、提高效率,以下是一些常用的工具类及其典型应用场景,涵盖Spring原生... 目录1. Spring Framework 自带工具类(1) StringUtils(2) Coll

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

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

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

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

基于Flask框架添加多个AI模型的API并进行交互

《基于Flask框架添加多个AI模型的API并进行交互》:本文主要介绍如何基于Flask框架开发AI模型API管理系统,允许用户添加、删除不同AI模型的API密钥,感兴趣的可以了解下... 目录1. 概述2. 后端代码说明2.1 依赖库导入2.2 应用初始化2.3 API 存储字典2.4 路由函数2.5 应

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

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

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll