如何触发Graphic的点击事件?

时间:2018-01-09 07:09:22

标签: javascript arcgis esri 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?
});

2 个答案:

答案 0 :(得分:2)

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

view.popup.open({
    location: point,
    features: [graphic]
});

Example here

答案 1 :(得分:0)

这是我用多边形的infoWindow做的一个例子。

wq1 := i.wq1