I'm working with WPF. In the attached example I have a map with four points. I have a handler that gets called when the user clicks on one of the points. Since the point clicked on may have slightly different coordinates from the one that I used to display it, how can I tell which point is the one the user clicked on?
Hi Daniel,
I notice you're using a Multipoint to hold your graphics. Multipoint geometries are rarely used for this kind of purpose. It's better to just use separate MapPoint graphics as this makes it easier to tell them apart.
Here's a quick sample with your data that should give correct Identify results:
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> Envelope _extent <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Envelope</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">118.36</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.81</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">118.39</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.90</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> List<SPAN class="operator token"><</SPAN>Graphic<SPAN class="operator token">></SPAN> _schools <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>Graphic<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">118.386499</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.844753</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Dictionary</SPAN><SPAN class="operator token"><</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">object</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Redondo High"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">118.389740</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.873542</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Dictionary</SPAN><SPAN class="operator token"><</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">object</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Mira Costa"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">118.362154</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.895733</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Dictionary</SPAN><SPAN class="operator token"><</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">object</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Lawndale"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">118.369451</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">33.813457</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Dictionary</SPAN><SPAN class="operator token"><</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">object</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"South"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> GraphicsOverlay _schoolsOveraly<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="token function">MainWindow</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">InitializeComponent</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>Map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Map</SPAN><SPAN class="punctuation token">(</SPAN>Basemap<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateImagery</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>InitialViewpoint <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Viewpoint</SPAN><SPAN class="punctuation token">(</SPAN>_extent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Schools Graphics</SPAN> <SPAN class="keyword token">var</SPAN> symbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleMarkerSymbol</SPAN><SPAN class="punctuation token">(</SPAN>SimpleMarkerSymbolStyle<SPAN class="punctuation token">.</SPAN>Circle<SPAN class="punctuation token">,</SPAN> Colors<SPAN class="punctuation token">.</SPAN>Red<SPAN class="punctuation token">,</SPAN> 10d<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> _schoolsOveraly <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">GraphicsOverlay</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Renderer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleRenderer</SPAN><SPAN class="punctuation token">(</SPAN>symbol<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> school <SPAN class="keyword token">in</SPAN> _schools<SPAN class="punctuation token">)</SPAN> _schoolsOveraly<SPAN class="punctuation token">.</SPAN>Graphics<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>school<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>GraphicsOverlays<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>_schoolsOveraly<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>GeoViewTapped <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> MyMapView_GeoViewTapped<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">MyMapView_GeoViewTapped</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> GeoViewInputEventArgs e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> results <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IdentifyGraphicsOverlayAsync</SPAN><SPAN class="punctuation token">(</SPAN> _schoolsOveraly<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">.</SPAN>Position<SPAN class="punctuation token">,</SPAN> 1d<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> school <SPAN class="operator token">=</SPAN> results<SPAN class="punctuation token">.</SPAN>Graphics<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>school <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>school<SPAN class="punctuation token">.</SPAN>Attributes<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Graphic Tapped"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Also note that reprojection isn't necessary for your graphics, that will happen on-the-fly.
Hope that helps.
Thanks for your help!
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.