KVO to the rescue!You should attach a key-value-observer (KVO) to the panning/zooming properties of the mapview.When these properties toggle ON/OFF, your observer will automatically be informed. You can use that to update the text label.More info on KVO here : http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html
- (void)viewDidLoad { [super viewDidLoad]; //Init AGSTiledMapServiceLayer *serviceLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:[NSURL URLWithString:@"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"] ]; [self.mapView addMapLayer:serviceLayer withName:@Hello]; //KVO [self.mapView addObserver:self forKeyPath:@panning options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL]; [self.mapView addObserver:self forKeyPath:@zooming options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { //if panning changed if ([keyPath isEqual:@panning]){ NSLog(@Panning); } //if zooming changed if ([keyPath isEqual:@zooming]){ NSLog(@Zomming); } }
- (void)begin2log{ preVisibleArea = self.visibleArea; NSLog(@%@",self.visibleArea); NSLog(@%d,self.panning); NSLog(@A %d,self.animating); [super touchesEnded:panTouches withEvent:panEvent]; while (self.visibleArea != preVisibleArea) { NSLog(@YES); NSLog(@%d,self.panning); preVisibleArea = self.visibleArea; } while (self.animating) { NSLog(@YES); } NSLog(@%d,self.animating); NSLog(@%d,self.panning); NSLog(@End); NSLog(@%@",self.visibleArea); }
Could you please elaborate what you are trying to achieve?Regards,Nimesh
MapView posts notifications on panning and zooming, you can register for them with this:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scaleDidChange name:@MapDidEndZooming object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mapDidEndPanning name:@MapDidEndPanning object:nil];then implement the callback methods (these are your own custom methods):-(IBAction)scaleDidChange:(NSNotification *)notification { //do Something here } -(IBAction)mapDidEndPanning:(NSNotification *)notification { //do Something here }Is this what you were looking for?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scaleDidChange name:@MapDidEndZooming object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mapDidEndPanning name:@MapDidEndPanning object:nil];
-(IBAction)scaleDidChange:(NSNotification *)notification { //do Something here } -(IBAction)mapDidEndPanning:(NSNotification *)notification { //do Something here }
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.