Arcgis api for js通过json添加点,显示弹框信息

数据

格式

1
2
3
4
5
{
"china":[
{"id":"1","city":"上海","x":"121.4648","y":"31.2891"}
]
}
完整数据下载

模块

"esri/InfoTemplate", "dojo/store/JsonRest"

调用,弹框代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
map.on("load", () => {
var store = new JsonRest({ target: "china1.json" });
var infoTemplate = new InfoTemplate("${id}", "城市:${city}</br>X坐标:${X}</br>Y坐标:${Y}");
store.query({ "id": "*" }).then(function (result, request) {
var items = result.china;
// console.log(items);
for (var i = 0; i < items.length; i++) {
var attr = {
"id": i,
"name": items[i].city,
"X": items[i].x,
"Y": items[i].y
};

var locPoint = new Point(items[i].x, items[i].y, new SpatialReference({ wkid: 4326 }));
var graphic = new Graphic(locPoint, markerSym, attr, infoTemplate); // markerSym为点符号样式

// 将图形添加到地图中
map.graphics.add(graphic)

}
})

})