直接上代码
<html>
<head>
<meta name="description" content="DevLab: Configure a popup">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>ArcGIS API for JavaScript Tutorials: Display a pop-up (JSAPI)</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.18/"></script>
</head>
<script>
require([
"esri/config",
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer"
],
function(esriConfig,Map, MapView, FeatureLayer){
esriConfig.apiKey = "YOUR-API-KEY";
const map = new Map({
});
const view = new MapView({
container: "viewDiv",
map: map,
center: [113.986, 30.568],//Longitude, latitude
zoom: 20
});
// 弹出框设置
const popupTrailheads = {
"title": "宅基地信息",
"content": "<b>OBJECTID:</b> {OBJECTID}<br><b>不动产单元号:</b> {不动产单元号}<br><b>宅基地坐落:</b> {宗地坐落}<br><b>宅基地面积:</b> {宅基地面积}<br><b>宗地代码:</b> {宗地代码}<br><b>房屋结构:</b> {房屋结构}"
}
//定义图层
const trailheads = new FeatureLayer({
url: "http://localhost:6080/arcgis/rest/services/Test/%E5%86%9C%E6%9D%91%E5%AE%85%E5%9F%BA%E5%9C%B0/MapServer/0",
outFields: ["OBJECTID", "不动产单元号", "宗地坐落", "宅基地面积", "宗地代码", "房屋结构"],
popupTemplate: popupTrailheads
});
map.add(trailheads);
});
</script>
<body>
<div id="viewDiv"></div>
</body>
</html>
发布地图的字段
结果