How To Limit Zooming/Panning ?

3956
1
06-12-2014 02:24 AM
AhmedElAshker
New Contributor II
I'm using an AGSMapView with a AGSTiledMapServiceLayer for basemap layer as follows;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
    NSURL *basemapURL = [[NSURL alloc] initWithString:@"http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"];
   
    AGSTiledMapServiceLayer *basemapLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:basemapURL];
   
    [mapView addMapLayer:basemapLayer withName:@"Basemap Tiled Layer"];
   
    mapView.layerDelegate = self;
    mapView.touchDelegate = self;
}


The app opens up as in the first attached photo, and it can be zoomed out and panned like in the 2nd photo.

I read somewhere that setting the mapView's maxEnvelope property is the only way to limit zooming/panning, however I couldn't get my finger around the envelope value I should be setting and I tried [mapView toMapEnvelope:CGRect]. I also tried working with the base layer's minScale and maxScale values but that didn't work either.

I had a successful try with tracking the map scale via AGSMapViewDidEndZoomingNotification to restore it to fit the screen when zoomed out too much, however that didn't prevent me from seeing the outsider grid around the map for a while, and I didn't know which value to monitor if I decided to listen for AGSMapViewDidEndPanningNotification as well.
0 Kudos
1 Reply
AhmedElAshker
New Contributor II
I tried to set up AGSMapView's maxEnvelope property with tracked xmin, ymin, xmax and ymax values of mapAnchor property in each direction

/** The map coordinates of where the map display is anchored.
Usually this is the center of the map. However it could be different. For example, if the map is anchored on the location display, this will be the coordinate
of the location display.
@agssince{10.1.1, 10.2}
*/
@property (nonatomic, copy, readonly) AGSPoint *mapAnchor;

/** Limits the amount by which the map can be panned such that its anchor point (typically the center) never goes outside
this envelope. By default, this is the full envelope of the basemap layer. If you set a custom extent,
the envelope must have the same spatial reference as the map.
@agssince{2.1, 10.2}
*/
@property (nonatomic, strong, readwrite) AGSEnvelope *maxEnvelope;


Values:
xmin: -20031541, ymin: -19971868
xmax: 20032312, ymax: 19971819

It helped controlling the panning a little but only for a specific zoom level. At full extent the problem still exists (grid still shows) and there's still no clear solution to zooming out of extent.
0 Kudos