[GIS] How to trigger a Graphic’s click event when it gets added to map

arcgis-javascript-apijavascript

I'm using Esri Javascript API 4.5

When the map loads, I'm fetching point coordinates from external source and then plotting it on the map using Graphic class and assigning a PopupTemplate to that graphic.

The Case

The graphic is successfully plotted on the map. But in order to view to the popup template, I'm required to click on the graphic.

The Issue

Is there way where I can trigger the graphic's click event when it gets added to the map so that the popup template shows up automatically?

The Code

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?
});

Best Answer

You can use the view's default Popup object. Set the location property using the point graphic's geometry.

....
view.graphics.add(graphic);

var popup = view.popup;
popup.title = 'My Popup';                    
popup.content = 'My Popup Content';
popup.location = graphic.geometry;      
popup.open();