案例一

let illigalMessage = {
title: "违建核查",
id: 'illigalMessage',
image: './src/assets/img/edit.png'
}
let illigalWordMessage = {
title: "图斑整治情况",
id: 'illigalWordMessage',
image: './src/assets/img/illigalWordMessage.png'
}
let historyMessage = {
title: "批转历史记录",
id: 'history',
image: './src/assets/img/history.png'
}
// 以上为按钮编辑
let template = {
title: '违建信息',
content: [{
type: 'fields',
fieldInfos: [
{
fieldName: 'ZJMC',
label: '所属镇'
},
{
fieldName: 'TBBM',
label: '图斑编号'
},
{
fieldName: 'QQZT',
label: '建筑状态'
},
{
fieldName: 'XZCMC',
label: '所属村'
},
{
fieldName: 'ZDMJ',
label: '面积',
format: {
places: 2,
digitSeparator: true
}
},
{
fieldName: 'expression/illigalExpression'
}
]
}],
expressionInfos: [{
name: "illigalExpression",
title: "是否核查",
expression: `
return Decode($feature.STATE,1,"已核查",0,"未核查","更新状态请刷新")
`
}],
actions: [illigalMessage, illigalWordMessage, historyMessage]
}
先编辑完按钮,然后加入popuptemplate的action中就行。
使用:
mainMap.view.popup.on("trigger-action",async function (event) {
if (event.action.id === "illigalMessage") {
// 业务代码
}
}
监听trigger-action变化就行。
三、如果想把原来的zoom to按钮给去除,只需要加上 featureLayer.popupTemplate.overwriteActions = true
案例二
-
<head> -
<meta charset="UTF-8"> -
<title>要素服务</title> -
<link type="text/css" rel="stylesheet" href="http://localhost/arcgis/esri/css/main.css"/> -
<link type="text/css" rel="stylesheet" href="css/index.css"/> -
<script> -
//高亮显示只能在WebGL渲染时才能生效,该功能目前处于beta阶段 -
var dojoConfig = { -
has: { -
"esri-featurelayer-webgl": 1 -
} -
} -
</script> -
<script src="http://localhost/arcgis/"></script> -
</head> -
<body> -
<div id="viewDiv"></div> -
<script> -
require(["esri/Map", "esri/views/MapView", "esri/config", "esri/layers/FeatureLayer", "dojo/domReady"], function (Map, MapView, esriConfig, FeatureLayer) { -
esriConfig.request.corsEnabledServers.push("localhost:6443");//设置地图服务器已允许跨域 -
esriConfig.request.corsEnabledServers.push("localhost:63342"); -
var map = new Map({ -
// basemap: "streets"//ESRI提供的底 图 -
basemap: "dark-gray" -
}); -
//二维视图,并初始化视图位置 -
var view = new MapView({ -
container: "viewDiv", -
map: map, -
extent: { -
xmin: 111.27418783887504, -
ymin: 27.65361115167269, -
xmax: 119.18589568326072, -
ymax: 30.663629324047992, -
spatialReference: 4326 -
} -
}); -
//乡镇级属性模版 -
var popupTemplate = { -
title: "乡镇数据", -
content: [{ -
type: "fields", -
fieldInfos: [{ -
fieldName: "name", -
label: "行政单位名称", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "code", -
label: "行政单位代码", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "supercode", -
label: "上级行政单位代码", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "level", -
label: "行政单位等级", -
format: { -
places: 0, -
digitSeparator: true -
} -
}] -
}] -
}; -
var town = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/0", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//乡镇级数据 -
popupTemplate.title = "县级数据"; -
var county = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/1", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//县级数据 -
popupTemplate.title = "市级数据"; -
var city = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/2", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//市级数据 -
popupTemplate.title = "省级数据"; -
var province = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/3", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//省级数据 -
map.add(town); -
map.add(county); -
map.add(city); -
map.add(province); -
//点击视窗进行碰撞检测,检测点击的目标graphic -
view.on("click", function (evt) { -
view.hitTest(evt).then(function (response) { -
var result = response.results[0]; -
if (result && result.graphic) { -
console.log(result); -
var graphic = result.graphic; -
//自定义高亮 -
//这里的几何图形是面状,配置graphic的symbol为fillSymbol -
graphic.symbol = { -
type: "simple-fill", -
color: "red", -
outline: { -
color: [128, 128, 128, 0.5], -
width: "0.5px" -
} -
}; -
view.graphics.removeAll();//清除上一次点击目标 -
view.graphics.add(graphic);//添加新的点击目标 -
} -
}) -
}); -
}) -
</script> -
</body> -
</html>
二维模式效果图:

三维模式代码:
-
<!DOCTYPE html> -
<html lang="en"> -
<head> -
<meta charset="UTF-8"> -
<title>要素服务</title> -
<link type="text/css" rel="stylesheet" href="http://localhost/arcgis/esri/css/main.css"/> -
<link type="text/css" rel="stylesheet" href="css/index.css"/> -
<script src="http://localhost/arcgis/init.js"></script> -
</head> -
<body> -
<div id="viewDiv"></div> -
<script> -
require(["esri/Map", "esri/views/SceneView", "esri/config", "esri/layers/FeatureLayer", "dojo/domReady"], function (Map, SceneView, esriConfig, FeatureLayer) { -
esriConfig.request.corsEnabledServers.push("localhost:6443");//设置地图服务器已允许跨域 -
esriConfig.request.corsEnabledServers.push("localhost:63342"); -
var map = new Map({ -
basemap: "dark-gray" -
}); -
//二维视图,并初始化视图位置 -
var view = new SceneView({ -
container: "viewDiv", -
map: map, -
extent: { -
xmin: 111.27418783887504, -
ymin: 27.65361115167269, -
xmax: 119.18589568326072, -
ymax: 30.663629324047992, -
spatialReference: 4326 -
} -
}); -
//乡镇级属性模版 -
var popupTemplate = { -
title: "乡镇数据", -
content: [{ -
type: "fields", -
fieldInfos: [{ -
fieldName: "name", -
label: "行政单位名称", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "code", -
label: "行政单位代码", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "supercode", -
label: "上级行政单位代码", -
format: { -
places: 0, -
digitSeparator: true -
} -
}, { -
fieldName: "level", -
label: "行政单位等级", -
format: { -
places: 0, -
digitSeparator: true -
} -
}] -
}] -
}; -
var town = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/0", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//乡镇级数据 -
popupTemplate.title = "县级数据"; -
var county = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/1", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//县级数据 -
popupTemplate.title = "市级数据"; -
var city = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/2", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//市级数据 -
popupTemplate.title = "省级数据"; -
var province = new FeatureLayer({ -
url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/3", -
outFields: ["*"], -
popupTemplate: popupTemplate -
});//省级数据 -
map.add(town); -
map.add(county); -
map.add(city); -
map.add(province); -
}) -
</script> -
</body> -
</html>
三维模式效果图:

本文介绍如何在 ArcGIS 中定制弹窗模板,包括按钮编辑、字段显示及表达式设置等,实现乡镇、县市等不同层级地理信息的个性化展示。
1万+





