如何触发Graphic的点击事件?

asp*_*rin 3 javascript esri arcgis arcgis-js-api

我使用的是 Esri Javascript API 4.5

当地图加载时,我从外部源获取点坐标,然后使用Graphic类将其绘制在地图上并PopupTemplate为该图形分配一个。

案子

图形已成功绘制在地图上。但是为了查看弹出模板,我需要单击图形。

问题

有没有办法在将图形添加到地图时触发图形的单击事件,以便自动显示弹出模板?

编码

require([    
"esri/PopupTemplate",     
"esri/Graphic",
.
.
.
.
"dojo/domReady!"
],
function (
    PopupTemplate, Graphic, ....) {

var point = {
    type: "point",
    x: <some x>,
    y: <some y>
 };    

var symbol = {
   type: "picture-marker",
   url: "/euf/assets/nl/images/red-pin.png",
   width: "30px",
   height: "30px"
};

var template = new PopupTemplate({
    title: "New Title",
    content: "New Content"
});

var graphic = new Graphic({
    geometry: point,
    symbol: symbol,
    popupTemplate: template
});
view.graphics.add(graphic); // this works as I can see the marker on page

// now, how do I trigger its click event here?
});
Run Code Online (Sandbox Code Playgroud)

Gav*_*inR 5

您应该使用view.popup.open并传递属性locationfeatures

view.popup.open({
    location: point,
    features: [graphic]
});
Run Code Online (Sandbox Code Playgroud)

示例在这里