首页 > 解决方案 > ArcGIS JS-API,将 InfoTemplate 添加到现有图形

问题描述

如何infoTemplate向现有Graphic实例添加一个?

我正在做这个图形实例,但没有infoTemplate针对我所拥有的每一点:

const layerMarkers = new GraphicsLayer({id: layerId});
this.map.addLayer(layerMarkers);
// Some code
const graphic = new Graphic(point, imageSymbol, null, null );
layerMarkers.add(graphic);

然后我想在单击图形时调用一些 API:

layerMarkers.on('click', function(e) {
    console.log(e);
    console.log(this);
    //Here I can see the object, I need to do something here with it
});

我需要的是设置:

infoTemplate.setTitle(result.poi.nombre);
infoTemplate.setContent(this.getTooltip(result.poi));

然后我需要用infoTemplate

我不能这样做:

const graphic = new Graphic(point, imageSymbol, null, infoTemplate);

或者我会覆盖我的对象。

有小费吗?

标签: javascriptarcgis-js-api

解决方案


只需在图形层已经实例化后,在图形层上使用setInfoTemplate方法设置模板即可。

如果您只想在用户单击图形图层时显示信息窗口,那么只需在地图 InfoWindow 实例上使用 show 方法。

this.map.infoWindow.show(e.screenPoint,e.getInfoWindowAnchor(e.screenPoint));

设置内容后。

您还可以使用setFeatures将采用延迟(最终返回图形数组)

有很多方法可以根据用户交互的顺序以及您是否通过网络获取弹出窗口的数据来执行您想要的操作。


推荐阅读