@@ -71,6 +71,7 @@ - (MKAnnotationView *)getAnnotationView
7171 // In this case, we want to render a platform "default" marker.
7272 if (_pinView == nil ) {
7373 _pinView = [[MKPinAnnotationView alloc ] initWithAnnotation: self reuseIdentifier: nil ];
74+ [self addGestureRecognizerToView: _pinView];
7475 _pinView.annotation = self;
7576 }
7677
@@ -167,6 +168,56 @@ - (void)showCalloutView
167168 animated: YES ];
168169}
169170
171+ #pragma mark - Tap Gesture & Events.
172+
173+ - (void )addTapGestureRecognizer {
174+ [self addGestureRecognizerToView: nil ];
175+ }
176+
177+ - (void )addGestureRecognizerToView : (UIView *)view {
178+ if (!view) {
179+ view = self;
180+ }
181+ UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (_handleTap: )];
182+ // setting this to NO allows the parent MapView to continue receiving marker selection events
183+ tapGestureRecognizer.cancelsTouchesInView = NO ;
184+ [view addGestureRecognizer: tapGestureRecognizer];
185+ }
186+
187+ - (void )_handleTap : (UITapGestureRecognizer *)recognizer {
188+ AIRMapMarker *marker = self;
189+ if (!marker) return ;
190+
191+ if (marker.selected ) {
192+ CGPoint touchPoint = [recognizer locationInView: marker.map.calloutView];
193+ if ([marker.map.calloutView hitTest: touchPoint withEvent: nil ]) {
194+
195+ // the callout got clicked, not the marker
196+ id event = @{
197+ @" action" : @" callout-press" ,
198+ };
199+
200+ if (marker.onCalloutPress ) marker.onCalloutPress (event);
201+ if (marker.calloutView && marker.calloutView .onPress ) marker.calloutView .onPress (event);
202+ if (marker.map .onCalloutPress ) marker.map .onCalloutPress (event);
203+ return ;
204+ }
205+ }
206+
207+ // the actual marker got clicked
208+ id event = @{
209+ @" action" : @" marker-press" ,
210+ @" id" : marker.identifier ?: @" unknown" ,
211+ @" coordinate" : @{
212+ @" latitude" : @(marker.coordinate .latitude ),
213+ @" longitude" : @(marker.coordinate .longitude )
214+ }
215+ };
216+
217+ if (marker.onPress ) marker.onPress (event);
218+ if (marker.map .onMarkerPress ) marker.map .onMarkerPress (event);
219+ }
220+
170221- (void )hideCalloutView
171222{
172223 // hide the callout view
@@ -232,7 +283,7 @@ - (void)setImageSrc:(NSString *)imageSrc
232283- (void )setPinColor : (UIColor *)pinColor
233284{
234285 _pinColor = pinColor;
235-
286+
236287 if ([_pinView respondsToSelector: @selector (setPinTintColor: )]) {
237288 _pinView.pinTintColor = _pinColor;
238289 }
0 commit comments