zoomTo methods of AGSMapView don't work if animated is set to NO

4487
9
11-20-2014 08:57 AM
JimDabrowski
New Contributor II

Whenever I try to use one of the zoomTo methods on my AGSMapView, if I set the animated property to NO, the map fails to zoom to the provided envelope, scale, factor, etc. If I set the animated property to YES, it works just fine. Any thoughts as to what I could be doing wrong or is this normal behavior for the AGSMapView on iOS?

0 Kudos
9 Replies
MengyiGuo
Occasional Contributor

I tested the following code and it works for both animated true and false.

AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:@"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"]];

    [self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];

   

[self.mapView zoomToEnvelope:[[AGSEnvelope alloc]initWithXmin:-14225623 ymin:3997718 xmax:-12139951 ymax:5041807 spatialReference:[[AGSSpatialReference alloc] initWithWKID:102100] ] animated:false];

Please also check Navigating the map—ArcGIS Runtime SDK for iOS | ArcGIS for Developers

Is there anything different in your code?

0 Kudos
JimDabrowski
New Contributor II

Thanks for replying. My code is different in detail but not in concept.

I instantiate and load all my map layers (11 total, 5 feature layers from our own ags server and 6 graphics layers), then in the mapViewDidLoad delegate method I decide which point to center and zoom on (depends on what type of thing is being viewed in my program), create an AGSPoint object out of pre-saved coordinates and then call zoomToScale:withCenterPoint:animated.

At this point, if the animated property is set to NO, the map will not zoom to the  given point and oftentimes ends up at (0,0), or sometimes stops somewhere in northern Canada. If I set the animated property to YES, it always works just fine. I've tried other zoomTo methods and the result tends to be the same.

I will probably try to create a separate app and try to replicate and narrow down what is happening. Perhaps what I described above will give you some additional insight into my particular problem.

Thanks for helping out.

0 Kudos
MengyiGuo
Occasional Contributor

Thank you for providing additional information. From what you described, I think maybe check spacial reference of your basemap, layers and the point. You can also post your simplified code here so that I can get a better idea of what happened.

0 Kudos
by Anonymous User
Not applicable

Jim,

Please make sure the map has been loaded before calling the zoom method. Have you tried the simple sample at Esri/arcgis-runtime-samples-ios · GitHub ?

Hope this helps

Cheers

Al

0 Kudos
JimDabrowski
New Contributor II

Thanks for the advice. I do check mapView.loaded before doing any of these things.

0 Kudos
by Anonymous User
Not applicable

And if you set the animation flag to YES it works? But if the flag is set to NO it doesn't work?

0 Kudos
JimDabrowski
New Contributor II

Exactly.

Inspired by what Mengyi Guo stated above, I did try to convert my AGSPoint objects into AGSGeometry objects and re-project them specifically to the map's spatial reference. I then used the zoomToGeometry:withPadding:animated method and it worked with the animated property set to NO. This leads me to think the problem may be related to point and map spatial references not being aligned. But I find it curious that it works when animated, but not when not animated.

by Anonymous User
Not applicable

Using your code we can reproduce that issue. Support will submit a bug, thanks so much for reporting it.

To summarize:

This zooms to the correct point:

AGSPoint *zoomPoint = [AGSPoint pointWithX:-13161494 y:4040965 spatialReference:[AGSSpatialReference webMercatorSpatialReference]];

    [self.mapView zoomToScale:18035.742100270665 withCenterPoint:zoomPoint animated:YES];

This zooms to point 0,0 in the map:

AGSPoint *zoomPoint = [AGSPoint pointWithX:-13161494 y:4040965 spatialReference:[AGSSpatialReference webMercatorSpatialReference]];

    [self.mapView zoomToScale:18035.742100270665 withCenterPoint:zoomPoint animated:NO];

The only difference is the animated flag. A workaround for now is to create a AGSPolygon from that point or an AGSGeometry.

Thanks again for reporting this.

AkhilChoran_Balan
New Contributor

I have the same issue. Anyone got any sample code for the work around? How do I get the AGSGeometry from point and zoom scale?

0 Kudos