欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > arcgis for js实现FeatureLayer图层弹窗展示所有field字段

arcgis for js实现FeatureLayer图层弹窗展示所有field字段

2025/2/22 2:21:13 来源:https://blog.csdn.net/qq_33982898/article/details/143721380  浏览:    关键词:arcgis for js实现FeatureLayer图层弹窗展示所有field字段

效果和说明

feature图层中的矢量要素包含很多的属性,在点击要素时popupTemplate弹窗显示所有field字段值

在这里插入图片描述

实现代码

<!DOCTYPE html>
<html lang="zn"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><style>body {margin: 0;}#mapview {position: absolute;width: 100%;height: 100%;}</style><link rel="stylesheet" href="https://js.arcgis.com/4.23/esri/themes/light/main.css" /><script src="https://js.arcgis.com/4.23/"></script></head><body><div id="mapview"></div><script>require(['esri/Map', 'esri/views/MapView', 'esri/layers/FeatureLayer'], function (Map,MapView,FeatureLayer) {// 初始化底图window.map = new Map({basemap: 'dark-gray-vector'})// 创建2维视图let view = new MapView({container: 'mapview',map: map,zoom: 11,center: [104.783916597735, 32.55699155692144] // 设置地图的初始化中心点坐标})let layer = new FeatureLayer({url: 'http://xxxxxxxx/MapServer', // 这里替换成自己的图层spatialReference: view.spatialReference,outFields: ['*'],hasM: true,hasZ: true})console.log(layer)map.add(layer)// 字段名称解析字典const keyMap = new Map()keyMap.set('XIAN', '县')keyMap.set('XIANG', '乡')// 图层加载完成后view.whenLayerView(layer).then(function (layerView) {const fields = layerView.layer.fields // 获取所有的字段对象// console.log(fields)const fieldInfos = []for (const { name } of fields) {// 排除不要的属性if (['FID', 'OID_'].includes(name)) {continue}fieldInfos.push({fieldName: name,label: name,// label: keyMap.get(name), // 如果字段名称需要转义isEditable: false,tooltip: '',visible: true,format: null,stringFieldOption: 'text-box'})}// console.log(fieldInfos)// 为图层绑定弹窗layer.popupTemplate = {title: '图层弹窗Title',content: [{ type: 'fields', fieldInfos: fieldInfos }]}})})</script></body>
</html>

在这里插入图片描述

如果要对字段弹窗字段值进行转义, 就必须通过其他方式来做了, 后续更新

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词