Is there a replacement for GraphicsOverlay.HitTestAsync Method (ViewBase, Rect, Int32) in runtime 100.1?
I think you can use GeometryEngine methods then to see if your selection rectangle intersects with the graphic geometries.
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnSelect</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> RoutedEventArgs e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> rectangle <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>SketchEditor<SPAN class="punctuation token">.</SPAN><SPAN class="token function">StartAsync</SPAN><SPAN class="punctuation token">(</SPAN>SketchCreationMode<SPAN class="punctuation token">.</SPAN>Rectangle<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">false</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> overlay <SPAN class="keyword token">in</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>GraphicsOverlays<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> graphic <SPAN class="keyword token">in</SPAN> overlay<SPAN class="punctuation token">.</SPAN>Graphics<SPAN class="punctuation token">)</SPAN> graphic<SPAN class="punctuation token">.</SPAN>IsSelected <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Intersects</SPAN><SPAN class="punctuation token">(</SPAN>graphic<SPAN class="punctuation token">.</SPAN>Geometry<SPAN class="punctuation token">,</SPAN> rectangle<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>ex<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">,</SPAN> ex<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetType</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">)</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>
The v100.x equivalent for this method is IdentifyGraphicsOverlayAsync providing a tolerance parameter will create the rectangle with this height and width, you can also provide the number of maximum results you want returned. There's also an overload for identifying all graphics overlays versus this one where hit test (or identify) will be done on specified graphics overlay only.
Jennifer,
The IdentifyGraphicsOverlayAsync method only allows for a square to be specified where GraphicsOverlay.HitTestAsync Method (ViewBase, Rect, Int32) allows a rectangle.
Our use case is allowing the user to drag a selection rectangle on the map to select objects.
Thank you very much. I'll give that a try.
Your suggestion worked well. Thank you.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.