@@ -71,6 +71,7 @@ - (MKAnnotationView *)getAnnotationView
71
71
// In this case, we want to render a platform "default" marker.
72
72
if (_pinView == nil ) {
73
73
_pinView = [[MKPinAnnotationView alloc ] initWithAnnotation: self reuseIdentifier: nil ];
74
+ [self addGestureRecognizerToView: _pinView];
74
75
_pinView.annotation = self;
75
76
}
76
77
@@ -167,6 +168,56 @@ - (void)showCalloutView
167
168
animated: YES ];
168
169
}
169
170
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
+
170
221
- (void )hideCalloutView
171
222
{
172
223
// hide the callout view
0 commit comments