Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a Graphic's click event?

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?
});
like image 350
asprin Avatar asked Jan 29 '23 21:01

asprin


1 Answers

You should use view.popup.open and pass the properties location and features:

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

Example here.

like image 145
GavinR Avatar answered Feb 01 '23 22:02

GavinR