summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorfrederoni <bjorn.fredrik.karlsson@gmail.com>2016-05-18 09:47:54 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-05-18 09:47:54 -0700
commite8ea7483a7ed44d2786e2e4d5a1979cc8a1e32b6 (patch)
treeead4667f11b4ecd122cdf3799365dcfb94c3e2ec /platform
parent8ee222c45e31413b03d1c83006cf4eadc0e6d3a7 (diff)
downloadqtlocation-mapboxgl-e8ea7483a7ed44d2786e2e4d5a1979cc8a1e32b6.tar.gz
[ios] Added centerOffset to MGLAnnotationView (#5062)
* [ios] Added centerOffset to MGLAnnotationView * [ios] Reposition immediately after changing the centerOffset closes #5059
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/ios/Mapbox.playground/Contents.swift1
-rw-r--r--platform/ios/src/MGLAnnotationView.h8
-rw-r--r--platform/ios/src/MGLAnnotationView.m13
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.