Skip to content
Browse files

Create methods to call/listen events from annotation

  • Loading branch information...
1 parent 93c8517 commit 525e02b99ef7e996c72eacc9526c49989f8e879a @rafaelks rafaelks committed Mar 14, 2012
Showing with 59 additions and 0 deletions.
  1. +59 −0 iphone/Classes/TiMapView.m
View
59 iphone/Classes/TiMapView.m
@@ -573,6 +573,65 @@ - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacem
[map addAnnotation:placemark];
}
+- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
+{
+ [self firePinChangeDragState:annotationView newState:newState fromOldState:oldState];
+}
+
+- (NSString *)annotationViewDragStateToString:(MKAnnotationViewDragState)state
+{
+ switch(state)
+ {
+ case MKAnnotationViewDragStateStarting:
+ return @"starting";
+ case MKAnnotationViewDragStateDragging:
+ return @"dragging";
+ case MKAnnotationViewDragStateCanceling:
+ return @"canceling";
+ case MKAnnotationViewDragStateEnding:
+ return @"ending";
+ }
+ return @"none";
+}
+
+- (void)firePinChangeDragState:(MKAnnotationView *) pinview newState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
+{
+ TiMapAnnotationProxy *viewProxy = [self proxyForAnnotation:pinview];
+
+ if (viewProxy == nil)
+ return;
+
+ TiProxy * ourProxy = [self proxy];
+ BOOL parentWants = [ourProxy _hasListeners:@"pinchangedragstate"];
+ BOOL viewWants = [viewProxy _hasListeners:@"pinchangedragstate"];
+
+ if(!parentWants && !viewWants)
+ return;
+
+ id title = [viewProxy title];
+ if (title == nil)
+ title = [NSNull null];
+
+ NSNumber * indexNumber = NUMINT([pinview tag]);
+ NSString * newStateValue = [self annotationViewDragStateToString:newState];
+ NSString * oldStateValue = [self annotationViewDragStateToString:oldState];
+
+ NSDictionary * event = [NSDictionary dictionaryWithObjectsAndKeys:
+ viewProxy,@"annotation",
+ ourProxy,@"map",
+ title,@"title",
+ indexNumber,@"index",
+ newStateValue,@"newState",
+ oldStateValue,@"oldState",
+ nil];
+
+ if (parentWants)
+ [ourProxy fireEvent:@"pinchangedragstate" withObject:event];
+
+ if (viewWants)
+ [viewProxy fireEvent:@"pinchangedragstate" withObject:event];
+}
+
- (TiMapAnnotationProxy*)proxyForAnnotation:(MKAnnotationView*)pinview
{
for (id annotation in [map annotations])

0 comments on commit 525e02b

Please sign in to comment.
Something went wrong with that request. Please try again.