Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-1242] Support to draggable annotations (Drag & Drop) #1670

Merged
merged 5 commits into from Apr 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions iphone/Classes/MapModule.h
Expand Up @@ -19,6 +19,11 @@
@property(nonatomic,readonly) NSNumber *ANNOTATION_GREEN;
@property(nonatomic,readonly) NSNumber *ANNOTATION_PURPLE;

@property(nonatomic,readonly) NSNumber *ANNOTATION_DRAG_STATE_NONE;
@property(nonatomic,readonly) NSNumber *ANNOTATION_DRAG_STATE_START;
@property(nonatomic,readonly) NSNumber *ANNOTATION_DRAG_STATE_DRAG;
@property(nonatomic,readonly) NSNumber *ANNOTATION_DRAG_STATE_CANCEL;
@property(nonatomic,readonly) NSNumber *ANNOTATION_DRAG_STATE_END;

@end

Expand Down
6 changes: 6 additions & 0 deletions iphone/Classes/MapModule.m
Expand Up @@ -18,6 +18,12 @@ @implementation MapModule
MAKE_SYSTEM_PROP(ANNOTATION_GREEN,MKPinAnnotationColorGreen);
MAKE_SYSTEM_PROP(ANNOTATION_PURPLE,MKPinAnnotationColorPurple);

MAKE_SYSTEM_PROP(ANNOTATION_DRAG_STATE_NONE,MKAnnotationViewDragStateNone);
MAKE_SYSTEM_PROP(ANNOTATION_DRAG_STATE_START,MKAnnotationViewDragStateStarting);
MAKE_SYSTEM_PROP(ANNOTATION_DRAG_STATE_DRAG,MKAnnotationViewDragStateDragging);
MAKE_SYSTEM_PROP(ANNOTATION_DRAG_STATE_CANCEL,MKAnnotationViewDragStateCanceling);
MAKE_SYSTEM_PROP(ANNOTATION_DRAG_STATE_END,MKAnnotationViewDragStateEnding);

@end

#endif
6 changes: 6 additions & 0 deletions iphone/Classes/TiMapAnnotationProxy.m
Expand Up @@ -117,6 +117,12 @@ -(CLLocationCoordinate2D)coordinate
return result;
}

-(void)setCoordinate:(CLLocationCoordinate2D)coordinate
{
[self setValue:[NSNumber numberWithDouble:coordinate.latitude] forUndefinedKey:@"latitude"];
[self setValue:[NSNumber numberWithDouble:coordinate.longitude] forUndefinedKey:@"longitude"];
}

// Title and subtitle for use by selection UI.
- (NSString *)title
{
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiMapView.h
Expand Up @@ -54,6 +54,7 @@
-(void)zoom:(id)args;
-(void)addRoute:(id)args;
-(void)removeRoute:(id)args;
-(void)firePinChangeDragState:(MKAnnotationView *) pinview newState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState;

#pragma mark Framework
-(void)refreshAnnotation:(TiMapAnnotationProxy*)proxy readd:(BOOL)yn;
Expand Down
46 changes: 46 additions & 0 deletions iphone/Classes/TiMapView.m
Expand Up @@ -573,6 +573,47 @@ - (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];
}

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

NSDictionary * event = [NSDictionary dictionaryWithObjectsAndKeys:
viewProxy,@"annotation",
ourProxy,@"map",
title,@"title",
indexNumber,@"index",
NUMINT(newState),@"newState",
NUMINT(oldState),@"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])
Expand Down Expand Up @@ -685,6 +726,11 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
{
annView.rightCalloutAccessoryView = right;
}

BOOL draggable = [TiUtils boolValue: [ann valueForUndefinedKey:@"draggable"]];
if (draggable && [[MKAnnotationView class] instancesRespondToSelector:NSSelectorFromString(@"isDraggable")])
[annView performSelector:NSSelectorFromString(@"setDraggable:") withObject:[NSNumber numberWithBool:YES]];

annView.userInteractionEnabled = YES;
annView.tag = [ann tag];
return annView;
Expand Down