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

相关文章

Knife4j+Axios+Redis前后端分离架构下的 API 管理与会话方案(最新推荐)

《Knife4j+Axios+Redis前后端分离架构下的API管理与会话方案(最新推荐)》本文主要介绍了Swagger与Knife4j的配置要点、前后端对接方法以及分布式Session实现原理,... 目录一、Swagger 与 Knife4j 的深度理解及配置要点Knife4j 配置关键要点1.Spri

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

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

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

使用Python实现调用API获取图片存储到本地的方法

《使用Python实现调用API获取图片存储到本地的方法》开发一个自动化工具,用于从JSON数据源中提取图像ID,通过调用指定API获取未经压缩的原始图像文件,并确保下载结果与Postman等工具直接... 目录使用python实现调用API获取图片存储到本地1、项目概述2、核心功能3、环境准备4、代码实现

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

python通过curl实现访问deepseek的API

《python通过curl实现访问deepseek的API》这篇文章主要为大家详细介绍了python如何通过curl实现访问deepseek的API,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编... API申请和充值下面是deepeek的API网站https://platform.deepsee

Java对接Dify API接口的完整流程

《Java对接DifyAPI接口的完整流程》Dify是一款AI应用开发平台,提供多种自然语言处理能力,通过调用Dify开放API,开发者可以快速集成智能对话、文本生成等功能到自己的Java应用中,本... 目录Java对接Dify API接口完整指南一、Dify API简介二、准备工作三、基础对接实现1.

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

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

一文详解如何在Vue3中封装API请求

《一文详解如何在Vue3中封装API请求》在现代前端开发中,API请求是不可避免的一部分,尤其是与后端交互时,下面我们来看看如何在Vue3项目中封装API请求,让你在实现功能时更加高效吧... 目录为什么要封装API请求1. vue 3项目结构2. 安装axIOS3. 创建API封装模块4. 封装API请求

Android 实现一个隐私弹窗功能

《Android实现一个隐私弹窗功能》:本文主要介绍Android实现一个隐私弹窗功能,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 效果图如下:1. 设置同意、退出、点击用户协议、点击隐私协议的函数参数2. 《用户协议》、《隐私政策》设置成可点击的,且颜色要区分出来res/l