[ios] Added centerOffset to MGLAnnotationView (#5062)
* [ios] Added centerOffset to MGLAnnotationView * [ios] Reposition immediately after changing the centerOffset closes #5059
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user