前言
在工作中,需要在点击数据条时进行定位并显示弹窗。如下图所示:
实现代码示例
map.graphics.clear();
let infoTemplate = new InfoTemplate("${NAME}",
"所在县区: ${ADMINNAME} <br/>" +
"所在地址: ${OLDADDRESS} <br/>" +
"所在地址: ${ADDRESS}");
let attr = {
"NAME": obj.NAME,
"ADMINNAME": obj.ADMINNAME,
"ADDRESS": obj.ADDRESS,
"OLDADDRESS": obj.OLDADDRESS
};
let itempoint = new Point(obj.ZBX, obj.ZBY, new SpatialReference({ wkid: wmtsOption.wkid }));
let graphic = new Graphic(itempoint, picSymbol, attr, infoTemplate);
map.graphics.add(graphic);
// 设置弹窗自动显示
map.infoWindow.show(itempoint);
map.infoWindow.setFeatures([graphic]);
map.centerAt(itempoint);