diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/Mapbox.playground/Contents.swift | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLAnnotationView.h | 8 | ||||
-rw-r--r-- | platform/ios/src/MGLAnnotationView.m | 13 |
4 files changed, 23 insertions, 0 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 68ee6179e8..1613e51efe 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -26,6 +26,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CON - Removed unused SVG files from the SDK’s resource bundle. ([#4641](https://github.com/mapbox/mapbox-gl-native/pull/4641)) - Deprecated `-[MGLMapView emptyMemoryCache]`. ([#4725](https://github.com/mapbox/mapbox-gl-native/pull/4725)) - Added `MGLCoordinateInCoordinateBounds()`, a function that tests whether or not a coordinate is in a given bounds. ([#5053](https://github.com/mapbox/mapbox-gl-native/pull/5053)) +- An MGLAnnotationView can be repositioned in relation to the associated MGLAnnotation.coordinate by changing its `centerOffset` property. ([#5059](https://github.com/mapbox/mapbox-gl-native/issues/5059)) ## 3.2.2 diff --git a/platform/ios/Mapbox.playground/Contents.swift b/platform/ios/Mapbox.playground/Contents.swift index 14dba0cc4e..514cb10160 100644 --- a/platform/ios/Mapbox.playground/Contents.swift +++ b/platform/ios/Mapbox.playground/Contents.swift @@ -52,6 +52,7 @@ class MapDelegate: NSObject, MGLMapViewDelegate { if (annotationView == nil) { let av = PlaygroundAnnotationView(reuseIdentifier: "annotation") av.frame = CGRect(x: 0, y: 0, width: 30, height: 30) + av.centerOffset = CGVector(dx: -15, dy: -15) let centerView = UIView(frame: CGRectInset(av.bounds, 3, 3)) centerView.backgroundColor = UIColor.whiteColor() av.addSubview(centerView) diff --git a/platform/ios/src/MGLAnnotationView.h b/platform/ios/src/MGLAnnotationView.h index bc2494e9fc..4d267636d1 100644 --- a/platform/ios/src/MGLAnnotationView.h +++ b/platform/ios/src/MGLAnnotationView.h @@ -26,6 +26,14 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, nullable) NSString *reuseIdentifier; +/** + Annotation view is centered at the coordinate point of the associated annotation. + + By changing this property you can reposition the view as needed. The offset is measured in points. + Positive offset moves the annotation view towards the bottom right, while negative offset moves it towards the top left. + */ +@property (nonatomic) CGVector centerOffset; + /** Called when the view is removed from the reuse queue. diff --git a/platform/ios/src/MGLAnnotationView.m b/platform/ios/src/MGLAnnotationView.m index 9a82a8b332..e0775194eb 100644 --- a/platform/ios/src/MGLAnnotationView.m +++ b/platform/ios/src/MGLAnnotationView.m @@ -27,6 +27,19 @@ // Intentionally left blank. The default implementation of this method does nothing. } +- (void)setCenterOffset:(CGVector)centerOffset +{ + _centerOffset = centerOffset; + self.center = self.center; +} + +- (void)setCenter:(CGPoint)center +{ + center.x += _centerOffset.dx; + center.y += _centerOffset.dy; + [super setCenter:center]; +} + - (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event { // Allow mbgl to drive animation of this view’s bounds. |