AGSMapView zoomToEnvelope does not zoom as expected

3165
4
09-17-2014 07:48 AM
JamesEyre
New Contributor II

I am developing an app where I have a small map in a view. I have two points on the map, and I would like to zoom to those two features. I have tried the following, but the map does not zoom to the expected extent.

    AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];

    AGSPoint* gpsPoint = (AGSPoint*)[engine projectGeometry:currentLocation

                                          toSpatialReference:self.mapView.spatialReference];

    NSArray* geometries = [NSArray arrayWithObjects:gpsPoint, point, nil];

    AGSMutableMultipoint* multipoint = (AGSMutableMultipoint*)[engine unionGeometries:geometries];

    AGSEnvelope* envelope = multipoint.envelope;

   

    [self.mapView zoomToEnvelope: envelope animated:NO];

The two points (gpsPoint and point) make an envelope that is wide but not very high.  The map in the view is pretty much a square. When I call the zoomToEnvelope, I get an extent which does not show my features. It is a small envelope somewhere between my features. I do not see the features on the map.

Is there a function which allows me to zoom to an envelope, that will automatically expand itself to an envelope which contains the whole envelope I desire to zoom to?

Cheers,

Jamie

0 Kudos
4 Replies
by Anonymous User
Not applicable

Instead of creating a multipoint, adding points and then using the extent. Use the extent of the points to create a polygon, then just zoom to the polygon you created with the extent of both points.

0 Kudos
JamesEyre
New Contributor II

I tried this, but I get the same effect. It still zooms to a small extent between the two points. I have verified that the polygon's minx,maxx,miny,maxy are set correctly in the debugger. Any other ideas?

0 Kudos
by Anonymous User
Not applicable

Any chance you can share a very small project with the reproducible case? I would recommend to add it on the MapViewDemo sample app and send it my way apascual@esri.com

0 Kudos
JamesEyre
New Contributor II

I figured out the problem. I set the autoPanMode on the locationDisplay to AGSLocationDisplayAutoPanModeDefault.

self.mapView.locationDisplay.autoPanMode = AGSLocationDisplayAutoPanModeDefault;

Thanks for the help.

0 Kudos