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 graphic is successfully plotted on the map. But in order to view to the popup template, I'm required to click on the graphic.
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?
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?
});
You should use view.popup.open and pass the properties location
and features
:
view.popup.open({
location: point,
features: [graphic]
});
Example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With