Trigger "onClick" of graphics layer programmatically

798
1
Jump to solution
02-20-2013 07:33 AM
KenDoman
Occasional Contributor II
How do you trigger a graphicslayer's onclick event without clicking?

I've got an app that adds graphics on the map's graphics layer. I know the default behavior of a clicked graphic is to show the infoWindow with it's infoTemplate. Basically, I want to show the infoTemplate of the first graphic after all the graphics have been added to the map. Is there a way to trigger the "onClick" event on either the map or graphics layer without clicking?

Thanks,
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
You don't need to actually fire the click event, you can grab the first graphic from the graphics array, or save it however you want and use that to show the infowindow with the content you have set.
Something like
var g = map.graphics.graphics[0]; var ctr = g.geometry.getExtent().getCenter(); map.infoWindow.setContent(g.getContent()); map.infoWindow.show(ctr);


Here is a sample.
http://jsfiddle.net/odoe/pGmWY/6/

There's a sample for this too
http://help.arcgis.com/EN/webapi/javascript/arcgis/jssamples/#sample/query_showinfowindow

View solution in original post

1 Reply
ReneRubalcava
Frequent Contributor
You don't need to actually fire the click event, you can grab the first graphic from the graphics array, or save it however you want and use that to show the infowindow with the content you have set.
Something like
var g = map.graphics.graphics[0]; var ctr = g.geometry.getExtent().getCenter(); map.infoWindow.setContent(g.getContent()); map.infoWindow.show(ctr);


Here is a sample.
http://jsfiddle.net/odoe/pGmWY/6/

There's a sample for this too
http://help.arcgis.com/EN/webapi/javascript/arcgis/jssamples/#sample/query_showinfowindow