Select to view content in your preferred language

Use the NSNotificationCenter to listen for ???MapDidEndPanning??? & ???MapDidEndZooming??? ?

991
8
07-09-2010 06:59 AM
AkhlaqRao
Emerging Contributor
Since the new update, I am unable to Use the NSNotificationCenter to listen for ???MapDidEndPanning??? & ???MapDidEndZooming???. I am not getting the results by using this code (below).

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processit:) name:@"atest" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"atest" object:nil];

- (void) processit: (NSNotification *) notification
{
    NSLog(@"atestfinished");
}

Can someone out there please help me about listening from ???MapDidEndPanning??? & ???MapDidEndZooming??? notifications.

Akhlaq Rao
GeoSurfInc
0 Kudos
8 Replies
NimeshJarecha
Esri Regular Contributor
Here is the code to listen to notifications...

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//create an instance of a tiled map service layer
//Add it to the map view
//release to avoid memory leaks
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
[tiledLayer release];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondTo:)name:@"MapDidEndPanning" object:nil];
}

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

//do something with the notification here
NSLog(@"MapDidEndPanning");
}

Hope this helps!

Regards,
Nimesh
0 Kudos
AkhlaqRao
Emerging Contributor
Hi Nimesh,

Thanks, it helped very well!

Regards
Akhlaq Rao
GeoSurfInc


Here is the code to listen to notifications...

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//create an instance of a tiled map service layer
//Add it to the map view
//release to avoid memory leaks
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
[tiledLayer release];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondTo:)name:@"MapDidEndPanning" object:nil];
}

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

//do something with the notification here
NSLog(@"MapDidEndPanning");
}

Hope this helps!

Regards,
Nimesh
0 Kudos
AkhlaqRao
Emerging Contributor
Hi Nemish,

So far so good, I had luck when user panned, but still not being lucky when user zoomed. I think it only turn off the autoPan property when user panned until unless I am not missing a point over here, would you mind double check and let me know if it does turn off the autoPan when user zoomed?. Below is a little peace of code where I am trying to listen "MapDidEndZooming" I do set autoPane=YES somewhere in a method and wait to check if it sets autoPane=NO upon user zoomed.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToZoomingname:@"MapDidEndZooming" object:nil];

- (void)respondToZoomingNSNotification *)notification
{
if(self.mapView.gps.autoPan == NO)
{
NSLog(@"User Did End Zooming");
}
}

Akhlaq Rao
GeoSurfInc


Here is the code to listen to notifications...

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//create an instance of a tiled map service layer
//Add it to the map view
//release to avoid memory leaks
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
[tiledLayer release];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondTo:)name:@"MapDidEndPanning" object:nil];
}

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

//do something with the notification here
NSLog(@"MapDidEndPanning");
}

Hope this helps!

Regards,
Nimesh
0 Kudos
NimeshJarecha
Esri Regular Contributor
I double checked, zoom and pan actions turn OFF autoPan property but you have to make sure your GPS is on. Here is the code I've used.

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//create an instance of a tiled map service layer
//Add it to the map view
//release to avoid memory leaks
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
[tiledLayer release];

//create an instance of a dynmaic map layer
//set visible layers
//name the layer. This is the name that is displayed if there was a property page, tocs, etc...
//set transparency
self.dynamicLayer = [[[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kDynamicMapServiceURL]] autorelease];
self.dynamicLayer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:2], nil];
self.dynamicLayerView = [self.mapView addMapLayer:self.dynamicLayer withName:@"Dynamic Layer"];
self.dynamicLayerView.alpha = 0.5;

self.mapView.gps.autoPan = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondTo:)name:@"MapDidEndPanning" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToZooming:)name:@"MapDidEndZooming" object:nil];
}

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

NSLog(@"MapDidEndPanning");
NSLog(@"autoPan = %@\n", (self.mapView.gps.autoPan ? @"YES" : @"NO"));
}

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

NSLog(@"MapDidEndZooming");
NSLog(@"autoPan = %@\n", (self.mapView.gps.autoPan ? @"YES" : @"NO")); 
}

Regards,
Nimesh
0 Kudos
AkhlaqRao
Emerging Contributor
Yeah, I copied your code as it is and the GPS is on, assume I  turn autoPan ON as soon as GPS is on, please see below the NSLog.

first test.
"GPS IS OFF"
2010-07-12 17:41:18.142 LoidApp1.0[1208:307] MapDidEndPanning
2010-07-12 17:41:18.174 LoidApp1.0[1208:307] autoPan = NO
2010-07-12 17:41:20.211 LoidApp1.0[1208:307] MapDidEndZooming
2010-07-12 17:41:20.234 LoidApp1.0[1208:307] autoPan = NO
"GPS IS ON"
2010-07-12 17:41:41.397 LoidApp1.0[1208:307] MapDidEndZooming
2010-07-12 17:41:41.558 LoidApp1.0[1208:307] autoPan = YES
"GPS IS ON & USER ZOOMING IN/OUT"
2010-07-12 17:42:38.227 LoidApp1.0[1208:307] MapDidEndZooming
2010-07-12 17:42:38.245 LoidApp1.0[1208:307] autoPan = NO
"It worked this time"

second test.
"GPS IS OFF"
2010-07-12 17:46:11.693 LoidApp1.0[1217:307] MapDidEndPanning
2010-07-12 17:46:11.723 LoidApp1.0[1217:307] autoPan = NO
2010-07-12 17:46:14.789 LoidApp1.0[1217:307] MapDidEndZooming
2010-07-12 17:46:14.816 LoidApp1.0[1217:307] autoPan = NO
"GPS IS ON"
2010-07-12 17:46:27.100 LoidApp1.0[1217:307] MapDidEndZooming
2010-07-12 17:46:27.151 LoidApp1.0[1217:307] autoPan = YES
"GPS IS ON & USER ZOOMING IN/OUT"
2010-07-12 17:46:59.276 LoidApp1.0[1217:307] MapDidEndZooming
2010-07-12 17:46:59.313 LoidApp1.0[1217:307] autoPan = YES
2010-07-12 17:47:05.189 LoidApp1.0[1217:307] MapDidEndZooming
2010-07-12 17:47:05.212 LoidApp1.0[1217:307] autoPan = NO
"It didn't work when I zoomed out but it did when I zoomed in"

third test.
"GPS IS OFF"
2010-07-12 17:50:39.142 LoidApp1.0[1222:307] MapDidEndPanning
2010-07-12 17:50:39.161 LoidApp1.0[1222:307] autoPan = NO
2010-07-12 17:50:44.296 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:50:44.322 LoidApp1.0[1222:307] autoPan = NO
"GPS IS ON"
2010-07-12 17:50:48.775 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:50:48.852 LoidApp1.0[1222:307] autoPan = YES
"GPS IS ON & USER ZOOMING IN/OUT"
2010-07-12 17:50:53.431 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:50:53.460 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:50:58.927 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:50:58.952 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:51:05.023 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:51:05.062 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:51:06.649 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:51:06.725 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:51:08.963 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:51:08.987 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:51:10.467 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:51:10.502 LoidApp1.0[1222:307] autoPan = YES
2010-07-12 17:51:12.745 LoidApp1.0[1222:307] MapDidEndZooming
2010-07-12 17:51:12.769 LoidApp1.0[1222:307] autoPan = YES
"It didn't work at all when I zoomed in/out"

so, there are three different tests and each of them are showing different results, I am not sure what is going on?.

Akhlaq Rao
GeoSurfInc.

I double checked, zoom and pan actions turn OFF autoPan property but you have to make sure your GPS is on. Here is the code I've used.

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//create an instance of a tiled map service layer
//Add it to the map view
//release to avoid memory leaks
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
[tiledLayer release];

//create an instance of a dynmaic map layer
//set visible layers
//name the layer. This is the name that is displayed if there was a property page, tocs, etc...
//set transparency
self.dynamicLayer = [[[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kDynamicMapServiceURL]] autorelease];
self.dynamicLayer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:2], nil];
self.dynamicLayerView = [self.mapView addMapLayer:self.dynamicLayer withName:@"Dynamic Layer"];
self.dynamicLayerView.alpha = 0.5;

self.mapView.gps.autoPan = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondTo:)name:@"MapDidEndPanning" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToZooming:)name:@"MapDidEndZooming" object:nil];
}

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

NSLog(@"MapDidEndPanning");
NSLog(@"autoPan = %@\n", (self.mapView.gps.autoPan ? @"YES" : @"NO"));
}

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

NSLog(@"MapDidEndZooming");
NSLog(@"autoPan = %@\n", (self.mapView.gps.autoPan ? @"YES" : @"NO")); 
}

Regards,
Nimesh
0 Kudos
NimeshJarecha
Esri Regular Contributor
Akhlaq,

Is it possible for you to attach your project so I can have a look?

Regards,
Nimesh
0 Kudos
NimeshJarecha
Esri Regular Contributor
Akhlaq,

Apologies, error in my test scenario. The autoPan property only turns OFF on pan actions and not zoom actions. It is been documented in the blog as following,

***autoPan: property now defaults to NO. You need to enable it if you want the map to keep centering at the reported GPS location. Also, the autoPan property is automatically disabled when the user pans the map.***

http://blogs.esri.com/Dev/blogs/mobilecentral/archive/2010/07/01/ArcGIS-API-for-iOS-_2800_Update-1_2...

Regards,
Nimesh
0 Kudos
AkhlaqRao
Emerging Contributor
Nimesh,

This is exactly what I was talking about, I think disabling the autoPan property automatically when the user pan is a good idea, also disabling the autoPan property automatically when the user zoom not bad either. Something to look at in the next update. Thanks for your cooperation though.

Regards
Akhlaq Rao
GeoSurfInc.


Akhlaq,

Apologies, error in my test scenario. The autoPan property only turns OFF on pan actions and not zoom actions. It is been documented in the blog as following,

***autoPan: property now defaults to NO. You need to enable it if you want the map to keep centering at the reported GPS location. Also, the autoPan property is automatically disabled when the user pans the map.***

http://blogs.esri.com/Dev/blogs/mobilecentral/archive/2010/07/01/ArcGIS-API-for-iOS-_2800_Update-1_2...

Regards,
Nimesh
0 Kudos