Select to view content in your preferred language

How to catch AGSMapView touch gestures?

3364
4
08-25-2011 06:23 PM
lynnwang
Deactivated User
hi,all!

    I need to fire some event everytime mapview pans or zooms.

    In the ViewController,I tried realise (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;  Other views in the ViewController can response to it. Only mapview can't.
    I tried [mapView addGestureRecognizer:...],mapview still do not response to it,or even crash.

    Is there any method to realise it?
     Thank you!~
0 Kudos
4 Replies
BedaKuster
Deactivated User
Hi,

Create a new MapView and inherit from AGSMapView. Now you can Overwrite all 4 touch Functions, but do not forget to call them on super-instance. After you have created the class, change the class of your mapView in InterfaceBuilder / XCode from AGSMapView to your new created class. (see attachement)


//Header file
@interface TouchableMapView : AGSMapView {

 ...
}

//Mainfile

@implementation TouchableMapView

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 [super touchesBegan:touches withEvent:event];
 ......
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 
 [super touchesMoved:touches withEvent:event];
 .......
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 [super touchesEnded:touches withEvent:event];
 
 ......
 
 
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
 [super touchesCancelled:touches withEvent:event];

         ........

}

@end




If you only want to track endpanning and endzooming you can attach your observer-object like this:

In this case "self" is an UIViewController which has function mapViewDidEndPanning:(NSNotification *) notification.


//Is called when map did end panning
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(mapViewDidEndPanning:)  name:@"MapDidEndPanning" object:nil];


//is called when map did end zooming
 [[NSNotificationCenter defaultCenter] addObserver:self          selector:@selector(mapViewDidEndPanning:) name:@"MapDidEndZooming" object:nil];




handler function:

-(void) mapViewDidEndPanning:(NSNotification *) notification
{
 //Check name of notification:
     if([[notification name] isEqualToString:@"MapDidEndZooming"])
    {
          ... 
    }else{
          ...
    }

}


0 Kudos
lynnwang
Deactivated User
thank you very much,it really works!`
0 Kudos
lynnwang
Deactivated User
but, after end touch and before end zooming,how to catch event in the animation time ?
0 Kudos
lynnwang
Deactivated User
and,,,if I want to catch AGSSketchGraphicsLayer click-at-a-point event,is that available?:confused:
0 Kudos