In Application, there are 50 to 60 Marker added using AGSGraphic I want to set a camera position to set zoom level and show all markers in Map. there is any way to do this type of feature...
Your graphics all exist in an AGSGraphicsOverlay. You can get the graphics overlay's extent and use mapView.setViewpointGeometry() to set the extent.
Something like this:
mapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setViewpointGeometry</SPAN><SPAN class="punctuation token">(</SPAN>graphicsOverlay<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">,</SPAN> completion<SPAN class="punctuation token">:</SPAN> nil<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
or to add a few pixels padding at the edge of your map…
mapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setViewpointGeometry</SPAN><SPAN class="punctuation token">(</SPAN>graphicsOverlay<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">,</SPAN> padding<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">30</SPAN><SPAN class="punctuation token">,</SPAN> completion<SPAN class="punctuation token">:</SPAN> nil<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Note that both of those will animate to the extent of the graphics in the overlay. If there are no graphics in the overlay, nothing will happen (you may see a trapped error in your console log).
If you don't want to animate, you must create a viewpoint and set the viewpoint explicitly using the non-animating setViewpoint() method (you can tell it's non-animating because it doesn't have a completion callback block parameter)…
mapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setViewpoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">AGSViewpoint</SPAN><SPAN class="punctuation token">(</SPAN>targetExtent<SPAN class="punctuation token">:</SPAN> graphicsOverlay<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
The above dynamic extent property is a convenience when working with AGSGraphicsOverlays. You could also use the all-powerful AGSGeometryEngine to get the combined extent of all the graphics' geometries and set the viewpoint to that…
<SPAN class="keyword token">if</SPAN> <SPAN class="keyword token">let</SPAN> extent <SPAN class="operator token">=</SPAN> AGSGeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">combineExtents</SPAN><SPAN class="punctuation token">(</SPAN>ofGeometries<SPAN class="punctuation token">:</SPAN> graphicsOverlay<SPAN class="punctuation token">.</SPAN>graphics<SPAN class="punctuation token">.</SPAN><SPAN class="token function">compactMap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">(</SPAN>$<SPAN class="number token">0</SPAN> <SPAN class="keyword token">as</SPAN><SPAN class="operator token">!</SPAN> AGSGraphic<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>geometry <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> mapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setViewpointGeometry</SPAN><SPAN class="punctuation token">(</SPAN>extent<SPAN class="punctuation token">,</SPAN> padding<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">30</SPAN><SPAN class="punctuation token">,</SPAN> completion<SPAN class="punctuation token">:</SPAN> nil<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hope this helps.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.