-
Notifications
You must be signed in to change notification settings - Fork 697
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
deselectAnnotation and annotationsPopUpEnabled #418
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d68b325
implementation of deselectAnnotation and annotationsPopUpEnabled
577ae45
ANDROID: implementation of deselectAnnotation() and annotationsPopUpD…
d907a79
IOS: code refactoring
b6775aa
add deselectAnnotation() and annotationsPopUpEnabled to index.js and …
e24a5ce
Merge branch 'master' into deselectHidePopUp
dapetcu21 3ce20a6
[ios] Remove _selectedAnnotation and _annotationsPopUpEnabled
dapetcu21 aa4cc96
Add deselectAnnotation in example
dapetcu21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,13 @@ @implementation RCTMapboxGL { | |
BOOL _showsUserLocation; | ||
NSURL *_styleURL; | ||
int _userTrackingMode; | ||
RCTMGLAnnotation *_selectedAnnotation; | ||
BOOL _attributionButton; | ||
BOOL _logo; | ||
BOOL _compass; | ||
UIEdgeInsets _contentInset; | ||
MGLAnnotationVerticalAlignment _userLocationVerticalAlignment; | ||
|
||
BOOL _annotationsPopUpEnabled; | ||
/* So we don't fire onChangeUserTracking mode when triggered by props */ | ||
BOOL _isChangingUserTracking; | ||
} | ||
|
@@ -68,12 +69,12 @@ - (void)createMapIfNeeded | |
) { | ||
return; | ||
} | ||
|
||
if (![MGLAccountManager accessToken]) { | ||
RCTLogError(@"You need an access token to use Mapbox. Register to mapbox.com to obtain one, then run Mapbox.setAccessToken(yourToken) before mounting this component"); | ||
return; | ||
} | ||
|
||
_map = [[MGLMapView alloc] initWithFrame:self.bounds]; | ||
_map.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
_map.delegate = self; | ||
|
@@ -107,7 +108,7 @@ - (void)createMapIfNeeded | |
for (NSString * annotationId in _annotations) { | ||
[_map addAnnotation:_annotations[annotationId]]; | ||
} | ||
|
||
[self addSubview:_map]; | ||
[self layoutSubviews]; | ||
} | ||
|
@@ -133,7 +134,7 @@ - (void)upsertAnnotation:(RCTMGLAnnotation *) annotation { | |
RCTLogError(@"field `id` is required on all annotations"); | ||
return; | ||
} | ||
|
||
RCTMGLAnnotation * oldAnnotation = [_annotations objectForKey:identifier]; | ||
[_annotations setObject:annotation forKey:identifier]; | ||
[_map addAnnotation:annotation]; | ||
|
@@ -156,6 +157,11 @@ - (void)removeAllAnnotations | |
[_annotations removeAllObjects]; | ||
} | ||
|
||
- (void)deselectAnnotation | ||
{ | ||
[_map deselectAnnotation:_selectedAnnotation animated:YES]; | ||
} | ||
|
||
- (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(RCTMGLAnnotationPolyline *)shape | ||
{ | ||
if ([shape isKindOfClass:[RCTMGLAnnotationPolyline class]]) { | ||
|
@@ -189,6 +195,7 @@ - (UIColor *)mapView:(MGLMapView *)mapView fillColorForPolygonAnnotation:(RCTMGL | |
} | ||
|
||
- (BOOL)mapView:(RCTMapboxGL *)mapView annotationCanShowCallout:(id <MGLAnnotation>)annotation { | ||
if (!_annotationsPopUpEnabled) { return NO; } | ||
NSString *title = [(RCTMGLAnnotation *) annotation title]; | ||
NSString *subtitle = [(RCTMGLAnnotation *) annotation subtitle]; | ||
return ([title length] != 0 || [subtitle length] != 0); | ||
|
@@ -206,16 +213,16 @@ - (UIButton *)mapView:(MGLMapView *)mapView rightCalloutAccessoryViewForAnnotati | |
- (void)mapView:(MGLMapView *)mapView annotation:(id<MGLAnnotation>)annotation calloutAccessoryControlTapped:(UIControl *)control | ||
{ | ||
if (annotation.title && annotation.subtitle) { | ||
|
||
NSString *id = [(RCTMGLAnnotation *) annotation id]; | ||
|
||
NSDictionary *event = @{ @"target": self.reactTag, | ||
@"src": @{ @"title": annotation.title, | ||
@"subtitle": annotation.subtitle, | ||
@"id": id, | ||
@"latitude": @(annotation.coordinate.latitude), | ||
@"longitude": @(annotation.coordinate.longitude)} }; | ||
|
||
[_eventDispatcher sendInputEventWithName:@"onRightAnnotationTapped" body:event]; | ||
} | ||
} | ||
|
@@ -224,11 +231,11 @@ - (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id<MGL | |
{ | ||
NSDictionary *source = [(RCTMGLAnnotation *) annotation annotationImageSource]; | ||
if (!source) { return nil; } | ||
|
||
CGSize imageSize = [(RCTMGLAnnotation *) annotation annotationImageSize]; | ||
NSString *reuseIdentifier = source[@"uri"]; | ||
MGLAnnotationImage *annotationImage = [mapView dequeueReusableAnnotationImageWithIdentifier:reuseIdentifier]; | ||
|
||
if (!annotationImage) { | ||
UIImage *image = imageFromSource(source); | ||
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0); | ||
|
@@ -237,7 +244,7 @@ - (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id<MGL | |
UIGraphicsEndImageContext(); | ||
annotationImage = [MGLAnnotationImage annotationImageWithImage:newImage reuseIdentifier:reuseIdentifier]; | ||
} | ||
|
||
return annotationImage; | ||
} | ||
|
||
|
@@ -301,6 +308,11 @@ - (void)setPitchEnabled:(BOOL)pitchEnabled | |
if (_map) { _map.pitchEnabled = pitchEnabled; } | ||
} | ||
|
||
- (void)setAnnotationsPopUpEnabled:(BOOL)annotationsPopUpEnabled | ||
{ | ||
_annotationsPopUpEnabled = annotationsPopUpEnabled; | ||
} | ||
|
||
- (void)setShowsUserLocation:(BOOL)showsUserLocation | ||
{ | ||
if (_showsUserLocation == showsUserLocation) { return; } | ||
|
@@ -432,6 +444,7 @@ - (void)selectAnnotation:(NSString*)selectedId animated:(BOOL)animated; | |
{ | ||
RCTMGLAnnotation * annotation = [_annotations objectForKey:selectedId]; | ||
if (!annotation) { return; } | ||
_selectedAnnotation = annotation; | ||
[_map selectAnnotation:annotation animated:animated]; | ||
} | ||
|
||
|
@@ -442,7 +455,7 @@ -(void)mapView:(MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingM | |
{ | ||
if (_isChangingUserTracking) { return; } | ||
if (!_onChangeUserTrackingMode) { return; } | ||
|
||
_onChangeUserTrackingMode(@{ @"target": self.reactTag, | ||
@"src": @(mode) }); | ||
} | ||
|
@@ -470,7 +483,11 @@ - (void)mapView:(MGLMapView *)mapView didFailToLocateUserWithError:(NSError *)er | |
|
||
-(void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation | ||
{ | ||
if (!annotation.title || !annotation.subtitle) { return; } | ||
if (!annotation.title || !annotation.subtitle) { | ||
_selectedAnnotation = nil; | ||
return; | ||
} | ||
_selectedAnnotation = annotation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MGLMapView has a selectedAnnotations property for this. |
||
if (!_onOpenAnnotation) { return; } | ||
_onOpenAnnotation(@{ @"target": self.reactTag, | ||
@"src": @{ @"title": annotation.title, | ||
|
@@ -513,7 +530,7 @@ - (void)mapView:(RCTMapboxGL *)mapView regionWillChangeAnimated:(BOOL)animated | |
- (void)handleSingleTap:(UITapGestureRecognizer *)sender | ||
{ | ||
if (!_onTap) { return; } | ||
|
||
CLLocationCoordinate2D location = [_map convertPoint:[sender locationInView:_map] toCoordinateFromView:_map]; | ||
CGPoint screenCoord = [sender locationInView:_map]; | ||
|
||
|
@@ -528,7 +545,7 @@ - (void)handleLongPress:(UITapGestureRecognizer *)sender | |
{ | ||
if (!_onLongPress) { return; } | ||
if (sender.state != UIGestureRecognizerStateBegan) { return; } | ||
|
||
CLLocationCoordinate2D location = [_map convertPoint:[sender locationInView:_map] toCoordinateFromView:_map]; | ||
CGPoint screenCoord = [sender locationInView:_map]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a property so you don't need to implement the setter yourself.