I would like to be able to draw/sketch a polygon on the map and then identify all graphics within that polygon area. The 'identify' functions appear to only take in a single point. Is there a way to identify graphics within a geometry?
If you want to take a set of AGSGraphics and see if they are within a polygon, you can use AGSGeometryEngine and the polygon and filter them out with something like this…
func <SPAN class="token function">filterGraphics</SPAN><SPAN class="punctuation token">(</SPAN>graphics<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>AGSGraphic<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> within polygon<SPAN class="punctuation token">:</SPAN> AGSPolygon<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">[</SPAN>AGSGraphic<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> graphics<SPAN class="punctuation token">.</SPAN>filter <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="keyword token">let</SPAN> geom <SPAN class="operator token">=</SPAN> $<SPAN class="number token">0</SPAN><SPAN class="punctuation token">.</SPAN>geometry <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> AGSGeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">geometry</SPAN><SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">,</SPAN> within<SPAN class="punctuation token">:</SPAN> polygon<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">false</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>
I'm pretty sure that's what you're after.
I'm checking because we use Identify to mean a very specific thing in ArcGIS: respond to a user interaction with the map (usually a tap or click) looking to get more information about a feature the user can see in the map. But I don't think that's what you're looking for. If it is, let me know.
it's not super fast because I have to give it all of the graphics that are currently on that layer to sift through, but it does work.
Nick, I un-marked this as correct because I'm not sure this answers my question (unless the answer is no). In your example your function takes a set of graphics to sort through, but this is what I'm looking for a map function to give me if possible. I don't want to have to sort through ALL graphics on the map, I'm looking for a quicker way I guess.
Are they graphics in graphics overlays, or are they features in feature layers? Are their geometries points, lines, or polygons? And how many do you have?
I've used the above approach on a few thousand (animated) AGSPoints stored as AGSGraphics testing against an AGSPolygon and it's pretty real-time whether the graphic is in or not on modern hardware.
They are point graphics in graphics overlays. There could be a few or many (20k +).
Travis Yordi wrote:Nick, I un-marked this as correct because I'm not sure this answers my question (unless the answer is no). In your example your function takes a set of graphics to sort through, but this is what I'm looking for a map function to give me if possible. I don't want to have to sort through ALL graphics on the map, I'm looking for a quicker way I guess.
Travis Yordi wrote:
Also, no, there is no single call against a AGSGraphicsOverlay.
What you could consider is using a AGSFeatureCollectionLayer and AGSFeatureCollectionTable instead of an AGSGraphicsOverlay, and then calling queryFeatures on the AGSeatureCollectionTable. In the AGSQueryParameters you pass to queryFeatures, set the geometry to your polygon and set the spatialRelationship to .intersects.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.