2010年8月31日周二_Navigating the map_7.3

/**********************************************************/

//Navigating the map

//2010年8月31日

/**********************************************************/

Resource Center » Maps

The ArcGIS iPhone MapView control includes options for defining and changing the map extent as well as the user experience when the extent is modified. It is important to note that the first layer in a Map's layer collection will define the follow properties for the map:

  • Initial extent
  • Spatial reference

While initial extent can be modified, the spatial reference cannot be changed explicitly. This document will discuss both developer and end-user solutions for working with map extent.

ArcGIS Iphone MapView 控件包括 定义和改变地图显示范围的选项,和地图视图重定义后的用户体验一样。有一个很重要的地方需要我们注意:layer collection 中的第一个图层定义了属于地图的下面的属性:

初始化显示范围

空间参考

Setting the map extent

To set the map extent, use the zoomToEnvelope:animated: method on the map view. Note that the map view needs to have been loaded before calling zoomToEnvelope:animated: or the call will have no effect. You can use the mapViewDidLoad method of the AGSMapViewDelegate protocol to know when the map has been loaded and then set the initial map extent from there. The following steps describe the process of implementing the AGSMapViewDelegate protocol and using the zoomToEnvelope:animated: map view method to set an initial map extent:

设置地图显示范围

    为了设置地图显示的范围,使用zoomToEnvelope,它是地图视图的方法。 注意:在调用zoomToEnvelope方法之前,map view 需要下载,否则调用方法后将不会有任何的效果。

    你可以使用AGSMapViewDelegate的mapViewDidLoad方法来获知什么时间地图已经加载完成,随后设置初始化地图显示范围。下面的步骤描述了使AGSMapViewDelegate protocol

    实施和使用zoomToEnvelope:animated的过程。Animated:是一个用来初始化地图显示范围的地图视图方法。

  1. Add the AGSMapViewDelegate protocol to the protocol list in your view controller's interface definition:  

添加AGSMapViewDelegate protocol 到你的view controller 的接口定义中的protocol 列表。

 @interface MyViewController : UIViewController

<AGSMapViewDelegate> }

...

Note that all of the methods on the AGSMapViewDelegate are optional, so you only have to implement the ones you are actually using.

注意:AGSMapViewDelegate中所有的方法都是可选的,因此你只需要实现你真正需要的方法。

  1. In the view controller's viewDidLoad implementation, set the map view's mapViewDelegate property to self. This will allow the map view control to call any implemented methods of the AGSMapViewDelegate protocol in your view controller.

在view controller的viewDidLoad的实现中,设置map view 的mapViewDelegate属性为自身。 这就允许地图视图控件在你的view controller.中调用AGSMapViewDelegate的任何方法的实现。

                                  self.mapView.mapViewDelegate = self;

3. Add the implementation for the AGSMapViewDelegate mapViewDidLoad method in the view controller’s implementation (.m) file. This method will be called after the map view has been loaded. In mapViewDidLoad, define an AGSEnvelope describing the new map extent and call the map view’s zoomToEnvelope:animated: method to set the map extent:

添加AGSMapViewDelegate的mapViewDidLoad方法的实现到iew controller 的实施文件。当地图视图加载后,这个方法就会被调用。在mapViewDidLoad中,定义一个AGSEnvelope描述新的地图视图范围以及调用地图视图的zoomToEnvelope方法设置地图的现实范围

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

//create extent to be used as default

 AGSEnvelope *envelope = [AGSEnvelope envelopeWithXmin:-124.83145667 ymin:30.49849464 xmax:-113.91375495  ymax:44.69150688  spatialReference:mapView.spatialReference];

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

}

                          

Now, after the map view has been loaded, the extent will be set to the coordinates of the envelope created.

现在,地图视图已经加载,地图范围也会被设置到创建的Envelope的坐标系。

Getting the map extent

You may not know the extent of the map until runtime. You can use the envelope property of the map view to get the extent of the map:

                                  AGSEnvelope* mapExtent = self.mapView.envelope;

The map view must have been loaded for the envelope property to be valid.

获取地图范围

    你可能一直不知道地图的显示范围直到地图开始运行。 你可以使用地图视图的envelope属性获取地图的显示范围。

Tracking(小路;跑道;轨道;车辙,踪迹 vt.跟踪) panning and zooming

The Map View control provides two notifications(通知) for extent changes, "MapViewDidEndPanning" and "MapViewDidEndZooming". These notifications are broadcast after the map has been panned or zoomed, respectively(.各自地,各个地,分别地). The following code is an example of how to listen for notifications when the user pans or zooms the map. It displays an alert showing the new map extent retrieved from the envelope property of the map view:

地图视图控件提供了两个通知用于范围的改变,“MapViewDidEndPanning”和“MapViewDidEndZooming”,这些通知在地图完成平移和缩放后就分别被广播。 下面的代码就是一个当用户平移或者缩放地图的时候如何去侦听这些通知的例子。它通过一个弹出的窗口显示从Map view的envelope属性中重新获取的地图显示范围。

 

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

         // register for "MapDidEndPanning" notifications

         [[NSNotificationCenter defaultCenter] addObserver:self

                                                                                                                                                                                                                 selector:@selector(respondToEnvChange:)

                                                                                                                                                                                                                   name:@"MapDidEndPanning" object:nil];

 

         // register for "MapDidEndZooming" notifications

         [[NSNotificationCenter defaultCenter] addObserver:self

                                                                                                                                                                                                                 selector:@selector(respondToEnvChange:)

                                                                                                                                                                                                                   name:@"MapDidEndZooming" object:nil];

 

...

}

 

// The method that should be called when the notification arises

- (void)respondToEnvChange: (NSNotification*) notification {

 

         //create the string containing the new map extent NSString*

         theString = [[NSString alloc] initWithFormat:@"xmin = %f,\nymin =

         %f,\nxmax = %f,\nymax = %f", mapView.envelope.xmin,

         mapView.envelope.ymin, mapView.envelope.xmax,

         mapView.envelope.ymax];

 

   //display the new map extent in a simple alert

   UIAlertView* alertView = [[UIAlertView alloc]   initWithTitle:@"mapViewDidEndPanning"

                                                                                                                                                                     message:theString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

 [alertView show];

   [alertView release];

}

You should note that these notifications are broadcast when the processor is idle, thus there might be a slight delay between when the user finished performing the action and when the notification was raised. Also, notificatons are delievered on the main thread. You should not block this thread by pefroming expensive tasks otherwise your application will appear sluggish to the user.

你应该注意到这些通知时在processor空闲的时候广播的,因此在用户完成当前操作和培育下一个通知之间会有一个短暂的延迟。通知是在主线程交付,你不能通过运行大于消耗巨大的任务来封锁这个线程,否则你的程序就会表现的非常缓慢。

Changing the map extent

As mentioned previously, you can use the zoomToEnvelope:animated: method on a map view to set a map view's extent. You can also center the map at a given point using the map view's centerAtPoint:animated: method:

改变地图显示范围

就像前面提到的那样,你可以在地图视图上使用zoomToEnvelope:Animated方法设置一个地图视图的显示范围。 你也可以使用Map view centerAtPoint方法 让地图居中显示在一个给定的point,

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

[self.mapView centerAtPoint:newPoint animated:NO];

User gestures(姿势,手势;姿态,表示 v.作手势))

The user can perform several gestures which change the map view's extent at run-time. All of these will trigger either the AGSMapViewDelegate mapViewDidEndPanning or mapViewDidEndZooming methods.

用户可以执行若干个姿势在运行的时候改变地图的显示范围。 所有的这些都将触发AGSMapViewDelegate mapViewDidEndPanning或者mapViewDidEndZooming 方法

User Action

Map Action

Notification raised

Pinch-In

Zoom out on map

MapDidEndZooming

Pinch-Out

Zoom in on map

MapDidEndZooming

Double Tap

Zoom in on map

MapDidEndZooming

Swipe (any direction)

Pan map in direction of swipe

MapDidEndPanning

原文地址:https://www.cnblogs.com/xingchen/p/1813342.html