Skip To Content

Navigate the map

In this topic

Users of your apps can control the visible map area by zooming, panning, and rotating the map's extent using the trackpad, the Magic Mouse and the keyboard. The tables below define these gestures and keyboard actions.

Trackpad gestures

These are the supported gestures for the trackpad:

Map actionUser action

Pan

Two finger swipe

Pan

Click and swipe

Zoom in/out

Pinch-apart/together

Zoom in/out

OPT two finger up/down

Zoom in (by fixed amount)

One finger double press

Zoom out (by fixed amount)

Two finger double tap

Rotate the map

Two finger twist

Rotate the map

OPT two finger left/right

Display the magnifier

Click (hold down)

Note:
To allow the two finger twist gesture to rotate the map, enable the allowRotationByPinching property on AGSMapView. To display the magnifier when you tap and hold, enable the showMagnifierOnTapAndHold property on AGSMapView.

Magic Mouse gestures

These are the supported gestures for the Magic Mouse:

Map actionUser action

Pan

One finger swipe

Pan

Click and drag mouse

Zoom in/out

OPT finger up/down

Zoom in (by fixed amount)

One finger double press

Zoom out (by fixed amount)

Single finger double tap (If Smart Zoom is switched on).

Rotate the map

OPT finger left/right

Display the magnifier

Click (hold down)

Note:
To display the magnifier when you tap and hold, enable the showMagnifierOnTapAndHold property on AGSMapView. To switch on Smart Zoom go to System Preferences > Trackpad > Scroll & Zoom > Smart Zoom.

Keyboard

These are the supported gestures for the keyboard:

Map actionUser action

Pan

Up, down, left and right arrows

Zoom in/out

OPT up/down arrows

Zoom in/out (by fixed amount)

CMD +/-

Rotate the map

OPT left/right arrows

Rotate map to North

CMD up arrow

Set the map extent

By default, the first layer added to a map sets the map's spatial reference, full and initial extent. If you want to specify a different map extent, use the zoomToEnvelope:animated: method passing in an envelope geometry.

-(void)viewDidLoad{
  [super viewDidLoad];

 //add a layer to the map
 AGSTiledMapServiceLayer*tiledLayer=[AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:[NSURLURLWithString:@"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"]];
[self.mapViewaddMapLayer:tiledLayerwithName:@"Tiled Layer"];

  //zoom to an area
 AGSEnvelope *envelope = [AGSEnvelope envelopeWithXmin:-124.83145667 ymin:30.49849464 xmax:-113.91375495  ymax:44.69150688  spatialReference:mapView.spatialReference];
 [self.mapView zoomToEnvelope:envelope animated:NO];
}

Alternatively, you can zoom to a geometry on the map (such as the shape of a country or river) using the zoomToGeometry:withPadding:animated: method. You can also center the map at a given point using the map view's centerAtPoint:animated: method:

AGSPoint *newPoint = [AGSPoint pointWithX:-93.032201 y:49.636213 spatialReference:self.mapView.spatialReference];
[self.mapView centerAtPoint:newPoint animated:NO];

Note:

In all cases, the envelope or geometry must have the same spatial reference as that of the map.

Get the map extent

If you want to return the area of the map that is visible to the user, call the visibleArea method. This returns a rectangular polygon of the map's extent, starting with the top-left corner, progressing in a clockwise direction.

AGSPolygon* mapExtent = self.mapView.visibleArea;

The map extent will not be known until the map has loaded; therefore, put the first call to this method in the mapViewDidLoad method on AGSMapViewLayerDelegate. The mapView also has a property called visibleAreaEnvelope.

If the map has not been rotated, the area represented by the visibleArea polygon coincides exactly with the envelope returned by visibleAreaEnvelope. However, you can use the visibleArea polygon or the visibleAreaEnvelope envelope as the map's extent.

Note:

If the map has been rotated, the visibleArea polygon and the visibleAreaEnvelope will not coincide. The envelope represents a larger area that entirely contains the rotated visibleArea polygon. In rotated maps, only use the visibleArea polygon to return the visible extent.

Track panning and zooming

The map view provides two notifications for extent changes, AGSMapViewDidEndPanningNotification and AGSMapViewDidEndZoomingNotification. These notifications are broadcast after the map has been panned or zoomed. The following code is an example of how to listen for these notifications. The new map extent, retrieved from the visibleAreaEnvelope property of the map view, prints in the console:

- (void)mapViewDidLoad:(AGSMapView *)mapView  {

  // register for pan notifications
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:)
    name:AGSMapViewDidEndPanningNotification object:nil];

  // register for zoom notifications
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:) 
    name:AGSMapViewDidEndZoomingNotification object:nil];

  ...
}

// The method that should be called when the notification arises
- (void)respondToEnvChange: (NSNotification*) notification {

 NSString* theString = [[NSString alloc] initWithFormat:@"xmin = %f,ymin =%f,xmax = %f,ymax = %f",
  self.mapView.visibleAreaEnvelope.xmin,
  self.mapView.visibleAreaEnvelope.ymin, 
  self.mapView.visibleAreaEnvelope.xmax,
  self.mapView.visibleAreaEnvelope.ymax];
    
 NSLog(@"The visible extent = %@", theString);


}

These notifications are broadcast when the processor is idle; therefore, there might be a slight delay between when the user finished performing the action and when the notification was raised. Since notificatons are delievered on the main thread do not block this thread by performing expensive tasks; otherwise, your application appears sluggish to the user.