AGSMapView zoom to geometry randomly fails

871
2
07-25-2017 07:20 AM
AnkitShah
New Contributor II

Hello,

We are using following code to zoom to specific layer extent, 

we are adding a layer using following code,

var aPNsGraphicsLayer = AGSGraphicsOverlay()

var agsBoundaryPolygon: AGSPolygon!

//Polygon co-ordinates array

func addLayerOnArcGisMap(_ Locations: [AGSPoint]) {

        let polygonBuilder = AGSPolygonBuilder(spatialReference: AGSSpatialReference.wgs84())

        polygonBuilder.addPart(with: Locations)

        self.agsBoundaryPolygon = polygonBuilder.toGeometry()

        let grapichs: AGSGraphic = AGSGraphic(geometry: self.agsBoundaryPolygon, symbol: self.barrierSymbol(1), attributes: nil)

        self.aPNsGraphicsLayer.graphics.add(grapichs) //addGraphic(grapichs)

        self.aPNsGraphicsLayer.isVisible = true

}

// To set zoom to added layer

self.agsMapView.setViewpointGeometry(self.aPNsGraphicsLayer.extent, padding: 50, completion: { (finished) -> Void in

})

Randomly this is not working and the map showing default zoom, on next attempt, it's working, so is there any way to fix this issue.

Tags (2)
0 Kudos
2 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Ankit Shah,

 

Sounds like the issue is related to the timing since the issue is intermittent happened.

I would suggest try to take a look about this sample and try to compare with your code especially setup some break point to check if when is the "addLayerOnArcGisMap" function in your code is called.

Here is our sample code from github:

Change viewpoint github sample 

Hope this can help.

MarkDostal
Esri Contributor

I don't see it in your code above, but make sure you are adding the graphics overlay to the map view:

self.mapView.graphicsOverlays.add(aPNsGraphicsLayer)

Also, double check that the map is loaded when you're adding the layer; if it's not loaded yet, the extent may be off.