Skip to content

Commit

Permalink
Merge pull request #110 from hansemannn/TIMOB-19215
Browse files Browse the repository at this point in the history
[TIMOB-19215] Fix click events
  • Loading branch information
cheekiatng committed Aug 13, 2015
2 parents a50dd64 + c0c5966 commit 80f6185
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
8 changes: 2 additions & 6 deletions apidoc/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,9 @@ events:
Note that only one annotation can be selected at any given time.
The `click` event includes a value, `clicksource`, which describes the part of the
annotation that was clicked. The `clicksource` can be one of `pin`, `title`,
`subtitle`, `leftPane`, `rightPane`, `infoWindow` or `null`. If the user clicks anywhere in
the info window other than `title`, `subtitle`, `leftPane` or `rightPane`, the
`clicksource` will be `infoWindow`. If the user deselects an annotation
The `click` event includes a value, `clicksource`, which describes the part of the annotation that was clicked. The `clicksource` can be one of `pin`, `leftButton` or `rightButton` on iOS and pin`, `title`, `subtitle`, `leftPane`, `rightPane`, `infoWindow` or `null` on Android. If the user deselects an annotation
by clicking on the pin, `clicksource` is `pin`. If the user deselects the
annotation by clicking elsewhere in the map view, `clicksource` is `null`.
annotation by clicking elsewhere in the map view, `clicksource` is `map`.
For polygon, polyline or circle, The `click` event includes the following values.
`clicksource` is a string describing the shape type. `map` is the map view instance.
Expand Down
60 changes: 33 additions & 27 deletions ios/Classes/TiMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,30 @@ -(MKMapView*)map

-(void)registerTouchEvents
{

UILongPressGestureRecognizer *longPressInterceptor = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressOnMap:)];

// Any press to see if shape intersection
WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
__block TiMapView *weakSelf = self; // to avoid leaking inside touchesBeganCallback
__block MKMapView *weakMap = map;
tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:weakMap];

CLLocationCoordinate2D coord = [weakMap convertPoint:point toCoordinateFromView:weakMap];
MKMapPoint mapPoint = MKMapPointForCoordinate(coord);
[weakSelf handlePolygonClick:mapPoint];
[weakSelf handleCircleClick:mapPoint];
[weakSelf handlePolylineClick:mapPoint];
};


UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleOverlayTap:)];
tap.cancelsTouchesInView = NO;

[map addGestureRecognizer:tap];
[map addGestureRecognizer:longPressInterceptor];
[map addGestureRecognizer:tapInterceptor];


[longPressInterceptor release];
[tapInterceptor release];
[tap release];
}

-(void)handleOverlayTap: (UIGestureRecognizer*)tap
{
CGPoint tapPoint = [tap locationInView:self.map];

CLLocationCoordinate2D tapCoord = [self.map convertPoint:tapPoint toCoordinateFromView:self.map];
MKMapPoint mapPoint = MKMapPointForCoordinate(tapCoord);
CGPoint mapPointAsCGP = CGPointMake(mapPoint.x, mapPoint.y);

[self handlePolygonClick:mapPoint];
[self handlePolylineClick:mapPoint];
[self handleCircleClick:mapPoint];
}

- (id)accessibilityElement
{
Expand Down Expand Up @@ -885,25 +884,25 @@ - (TiMapAnnotationProxy*)proxyForAnnotation:(MKAnnotationView*)pinview
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if ([view conformsToProtocol:@protocol(TiMapAnnotation)])
{

BOOL isSelected = [view isSelected];
MKAnnotationView<TiMapAnnotation> *ann = (MKAnnotationView<TiMapAnnotation> *)view;
[self fireClickEvent:view source:isSelected?@"pin":[ann lastHitName]];
return;
}
}
}

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view{
if ([view conformsToProtocol:@protocol(TiMapAnnotation)])
{
BOOL isSelected = [view isSelected];
BOOL isSelected = [TiUtils boolValue:[view isSelected] def:NO];
MKAnnotationView<TiMapAnnotation> *ann = (MKAnnotationView<TiMapAnnotation> *)view;
[self fireClickEvent:view source:isSelected?@"pin":[ann lastHitName]];
return;
[self fireClickEvent:view source:isSelected ? @"pin" : @"map"];
}
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)aview calloutAccessoryControlTapped:(UIControl *)control
{
if ([aview conformsToProtocol:@protocol(TiMapAnnotation)])
if ([aview conformsToProtocol:@protocol(TiMapAnnotation)])
{
MKPinAnnotationView *pinview = (MKPinAnnotationView*)aview;
NSString * clickSource = @"unknown";
Expand Down Expand Up @@ -968,11 +967,13 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
pinview.animatesDrop = [ann animatesDrop] && ![(TiMapAnnotationProxy *)annotation placed];
annView.calloutOffset = CGPointMake(-8, 0);
}
annView.canShowCallout = [TiUtils boolValue:[ann valueForUndefinedKey:@"canShowCallout"] def:YES];;
annView.canShowCallout = [TiUtils boolValue:[ann valueForUndefinedKey:@"canShowCallout"] def:YES];
annView.enabled = YES;
annView.centerOffset = ann.offset;

UIView *left = [ann leftViewAccessory];
UIView *right = [ann rightViewAccessory];

if (left!=nil) {
annView.leftCalloutAccessoryView = left;
}
Expand All @@ -982,11 +983,13 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
annView.leftCalloutAccessoryView = nil;
}
}

if (right!=nil) {
annView.rightCalloutAccessoryView = right;
}
else {
//ios7 requires this to be explicitly set as nil if nil

if (![TiUtils isIOS8OrGreater]) {
annView.rightCalloutAccessoryView = nil;
}
Expand All @@ -995,8 +998,10 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnno
[annView setDraggable: [TiUtils boolValue: [ann valueForUndefinedKey:@"draggable"]]];
annView.userInteractionEnabled = YES;
annView.tag = [ann tag];

return annView;
}

return nil;
}

Expand Down Expand Up @@ -1040,6 +1045,7 @@ - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
id<MKAnnotation> result = nil;
for (UIView* subview in [view subviews]) {

if (![subview pointInside:[self convertPoint:point toView:subview] withEvent:nil]) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.3.2
version: 2.3.3
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: External version of Map module
Expand Down

0 comments on commit 80f6185

Please sign in to comment.