Map view IS panning or zooming

3267
9
08-27-2012 04:06 PM
FrankLin1
New Contributor
Hi,

ArcGIS Runtime SDK for iOS v2.3 provides "panning" & "zooming" in "AGSMapView" for deciding whether mapView is panning or zooming , but how can I use them ?

Frank
0 Kudos
9 Replies
NimeshJarecha
Esri Regular Contributor
You cannot use them. It's just for information purpose only.

Regards,
Nimesh
0 Kudos
FrankLin1
New Contributor
But how can I update something like label when map is panning...
0 Kudos
NimeshJarecha
Esri Regular Contributor
Could you please elaborate what you are trying to achieve?

Regards,
Nimesh
0 Kudos
ChristopherEbright
New Contributor III
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?
0 Kudos
FrankLin1
New Contributor
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?



Sorry , I'm looking for the MapView "panning" not "End Pan".
I have some UILabel added to the AGSMapView as subview , and I wanna update the label's positon when the map is panning , rotating and zooming . So I'm looking for some methods exactly called when the AGSMapView is panning.
0 Kudos
FrankLin1
New Contributor
Could you please elaborate what you are trying to achieve?

Regards,
Nimesh


I just want to show graphic symbol (Annotation) on the Map View , but I found no way to do a good job.

If I use AGSGraphicsLayer to add graphic , and subclass the AGSMapView to catch it's touch methods , when it's rotating , I have to update the GraphicsLayer by called "datachanged" , it gave a bad performance.

If I use UILabel to present the text symbol , and added to the AGSMapView as sub view , it will have a good performance when rotating , but when panning , particularly when user swipe to pan , I have no way to catch the panning operation so I can't update the label after swipe panning.

If I use the AGSDynamicLayerView to add the UILabel by:

UIView<AGSLayerView> *myDynamicLayerView = [self.mapView addMapLayer:[AGSGraphicsLayer graphicsLayer] withName:@"..."];

[myDynamicLayerView addSubView:myUILabelView];

It did a good job to attach the baseMap when swipe to pan , but when zooming or rotating , I have to do a complex transform to UILabel.

...So , any way else ?

Please help me...

Thanks

Frank Lin
0 Kudos
DiveshGoyal
Esri Regular Contributor
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/KeyValueObs...
0 Kudos
FrankLin1
New Contributor
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/KeyValueObs...


Hi ~ Have you ever tried to use KVO for panning/zooming ?

I implement the following code in the sub class of AGSMapView when touch ended.

- (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);
}


By these code , I found panning/zooming is just the info when touch begin , and after the swipe touch end (and the map is panning), the map view's visibleArea/panning/zooming immediately changed , but the map is still panning .

By double check the API document , I found map view has a property named animating , and this is what the property I'm looking for , but when I track this property , the map view stops animating panning/zooming.

I guess in the SDK , the code holds panning/zooming is just an animation.

Does Esri plan to put ArcGIS Runtime SDK for iOS on the Github so that we can develop it together and make it better ?

Thanks for your reply
 
  Best regards

  Frank Lin
0 Kudos
FrankLin1
New Contributor
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/KeyValueObs...


By implement following code , nothing happens.


- (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");
       
    }
}
0 Kudos