I'm developing a simple application where I have a map and for each user who logs a point is added on the map. I can not create the click event when I click on one of these points and open information about it.
You simply add the click event to the GraphicsLayer that you're adding your points.
<SPAN class="keyword token">var</SPAN> GLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">GraphicsLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> GLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"click"</SPAN><SPAN class="punctuation token">,</SPAN> runClickEvent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">runClickEvent</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//do something with the event</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
There is another way to do this, in addition. When you construct the graphic, you can add an InfoTemplate (in 3.x) or PopupTemplate (in 4.x). See this sample that shows how to incorporate the attributes and PopupTemplate into a graphics that is added to a map (in this case, the line).
got it. and how I do it?
The graphic itself can't get a click event, but you have to add that graphic to a layer, which does have a click event. Simply listen to the click event for that layer.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.