How set center of All Marker in AGSMap camera..??

644
1
Jump to solution
10-30-2019 05:43 AM
KishanSuthar
New Contributor

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...

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

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.setViewpointGeometry(graphicsOverlay.extent, completion: nil)‍‍

or to add a few pixels padding at the edge of your map…

 

mapView.setViewpointGeometry(graphicsOverlay.extent, padding: 30, completion: nil)‍‍

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.setViewpoint(AGSViewpoint(targetExtent: graphicsOverlay.extent))‍‍

 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…

 

if let extent = AGSGeometryEngine.combineExtents(ofGeometries: graphicsOverlay.graphics.compactMap({ ($0 as! AGSGraphic).geometry })) {
    mapView.setViewpointGeometry(extent, padding: 30, completion: nil)
}‍‍‍‍‍‍

 

Hope this helps.

View solution in original post

1 Reply
Nicholas-Furness
Esri Regular Contributor

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.setViewpointGeometry(graphicsOverlay.extent, completion: nil)‍‍

or to add a few pixels padding at the edge of your map…

 

mapView.setViewpointGeometry(graphicsOverlay.extent, padding: 30, completion: nil)‍‍

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.setViewpoint(AGSViewpoint(targetExtent: graphicsOverlay.extent))‍‍

 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…

 

if let extent = AGSGeometryEngine.combineExtents(ofGeometries: graphicsOverlay.graphics.compactMap({ ($0 as! AGSGraphic).geometry })) {
    mapView.setViewpointGeometry(extent, padding: 30, completion: nil)
}‍‍‍‍‍‍

 

Hope this helps.