From 561234ab50f7f32ce2347d70a2297762b95831f5 Mon Sep 17 00:00:00 2001 From: Benjamin Toueg Date: Wed, 26 Oct 2016 17:29:56 +0200 Subject: [PATCH] Fix Anchor point on Google Maps iOS --- docs/marker.md | 4 ++-- ios/AirGoogleMaps/AIRGoogleMapMarker.h | 1 + ios/AirGoogleMaps/AIRGoogleMapMarker.m | 9 ++++++--- ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/marker.md b/docs/marker.md index 557490ab4..60da4c0f7 100644 --- a/docs/marker.md +++ b/docs/marker.md @@ -9,9 +9,9 @@ | `image` | `ImageSource` | | A custom image to be used as the marker's icon. Only local image resources are allowed to be used. | `pinColor` | `Color` | | If no custom marker view or custom image is provided, the platform default pin will be used, which can be customized by this color. Ignored if a custom marker is being used. | `coordinate` | `LatLng` | | The coordinate for the marker. -| `centerOffset` | `Point` | | The offset (in points) at which to display the view.

By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.

For android, see the `anchor` prop. +| `centerOffset` | `Point` | | The offset (in points) at which to display the view.

By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.

For Google Maps, see the `anchor` prop. | `calloutOffset` | `Point` | | The offset (in points) at which to place the callout bubble.

This property determines the additional distance by which to move the callout bubble. When this property is set to (0, 0), the anchor point of the callout bubble is placed on the top-center point of the marker view’s frame. Specifying positive offset values moves the callout bubble down and to the right, while specifying negative values moves it up and to the left.

For android, see the `calloutAnchor` prop. -| `anchor` | `Point` | | Sets the anchor point for the marker.

The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.

The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).

For ios, see the `centerOffset` prop. +| `anchor` | `Point` | | Sets the anchor point for the marker.

The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.

The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).

For MapKit on iOS, see the `centerOffset` prop. | `calloutAnchor` | `Point` | | Specifies the point in the marker image at which to anchor the callout when it is displayed. This is specified in the same coordinate system as the anchor. See the `anchor` prop for more details.

The default is the top middle of the image.

For ios, see the `calloutOffset` prop. | `flat` | `Boolean` | | Sets whether this marker should be flat against the map true or a billboard facing the camera false. | `identifier` | `String` | | An identifier used to reference this marker at a later date. diff --git a/ios/AirGoogleMaps/AIRGoogleMapMarker.h b/ios/AirGoogleMaps/AIRGoogleMapMarker.h index ff1a54508..8f1018b05 100644 --- a/ios/AirGoogleMaps/AIRGoogleMapMarker.h +++ b/ios/AirGoogleMaps/AIRGoogleMapMarker.h @@ -26,6 +26,7 @@ @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subtitle; @property (nonatomic, strong) UIColor *pinColor; +@property (nonatomic, assign) CGPoint anchor; @property (nonatomic, assign) NSInteger zIndex; @property (nonatomic, assign) BOOL draggable; diff --git a/ios/AirGoogleMaps/AIRGoogleMapMarker.m b/ios/AirGoogleMaps/AIRGoogleMapMarker.m index a31a13efc..d9fa3eb44 100644 --- a/ios/AirGoogleMaps/AIRGoogleMapMarker.m +++ b/ios/AirGoogleMaps/AIRGoogleMapMarker.m @@ -225,9 +225,6 @@ - (void)setImageSrc:(NSString *)imageSrc _iconImageView = imageView; [self iconViewInsertSubview:imageView atIndex:0]; - - // TODO: This could be a prop - //_realMarker.groundAnchor = CGPointMake(0.75, 1); }); }]; } @@ -253,6 +250,12 @@ - (void)setPinColor:(UIColor *)pinColor { _realMarker.icon = [GMSMarker markerImageWithColor:pinColor]; } +- (void)setAnchor:(CGPoint)anchor { + _anchor = anchor; + _realMarker.groundAnchor = anchor; +} + + - (void)setZIndex:(NSInteger)zIndex { _zIndex = zIndex; diff --git a/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m b/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m index 8e7c43622..ee138c25f 100644 --- a/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +++ b/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m @@ -33,6 +33,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(title, NSString) RCT_REMAP_VIEW_PROPERTY(description, subtitle, NSString) RCT_EXPORT_VIEW_PROPERTY(pinColor, UIColor) +RCT_EXPORT_VIEW_PROPERTY(anchor, CGPoint) RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger) RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL) RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTDirectEventBlock)