Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/marker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| `title` | `String` | | The title of the marker. This is only used if the <Marker /> component has no children that are an `<MapView.Callout />`, in which case the default callout behavior will be used, which will show both the `title` and the `description`, if provided.
| `description` | `String` | | The description of the marker. This is only used if the <Marker /> component has no children that are an `<MapView.Callout />`, in which case the default callout behavior will be used, which will show both the `title` and the `description`, if provided.
| `image` | `ImageSource` | | A custom image to be used as the marker's icon. Only local image resources are allowed to be used.
| `icon` | `ImageSource` | | Marker icon to render (equivalent to `icon` property of GMSMarker Class).
| `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.<br/><br/> 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.<br/><br/> For Google Maps, see the `anchor` prop.
Expand All @@ -17,6 +18,7 @@
| `identifier` | `String` | | An identifier used to reference this marker at a later date.
| `rotation` | `Float` | | A float number indicating marker's rotation angle, in degrees.
| `draggable` | `<null>` | | This is a non-value based prop. Adding this allows the marker to be draggable (re-positioned).
| `tracksViewChanges` | `Boolean` | | Controls whether the icon for this marker should be redrawn every frame.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhamBaTho Is this prop iOS only?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only applicable for iOS. Android don't have issues with that.


## Events

Expand Down
20 changes: 20 additions & 0 deletions lib/components/MapMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ const propTypes = {
*/
image: PropTypes.any,

/**
* Marker icon to render (equivalent to `icon` property of GMSMarker Class).
* Using this property has an advantage over `image` in term of performance, battery usage...
* because it doesn't trigger tracksViewChanges.
* (tracksViewChanges is set to YES by default if iconView is not nil).
*/
icon: PropTypes.any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhamBaTho Can you give this a more specific prop type?


/**
* Opacity level of view/image based markers
*/
Expand All @@ -60,6 +68,11 @@ const propTypes = {
*/
pinColor: PropTypes.string,

/**
* Controls whether the icon for the marker should be redrawn every frame.
*/
tracksViewChanges: PropTypes.bool,

/**
* The coordinate for the marker.
*/
Expand Down Expand Up @@ -260,13 +273,20 @@ class MapMarker extends React.Component {
image = image.uri;
}

let icon;
if (this.props.icon) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would refactor this to ternary if statement :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

icon = resolveAssetSource(this.props.icon) || {};
icon = icon.uri;
}

const AIRMapMarker = this.getAirComponent();

return (
<AIRMapMarker
ref={ref => { this.marker = ref; }}
{...this.props}
image={image}
icon={icon}
style={[styles.marker, this.props.style]}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
@property (nonatomic, copy) RCTDirectEventBlock onDrag;
@property (nonatomic, copy) RCTDirectEventBlock onDragEnd;
@property (nonatomic, copy) NSString *imageSrc;
@property (nonatomic, copy) NSString *iconSrc;
@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) double opacity;
@property (nonatomic, assign) BOOL draggable;
@property (nonatomic, assign) BOOL tracksViewChanges;

- (void)showCalloutView;
- (void)hideCalloutView;
Expand Down
36 changes: 36 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ - (void)setOpacity:(double)opacity
_realMarker.opacity = opacity;
}

- (void)setIconSrc:(NSString *)iconSrc
{
_iconSrc = iconSrc;

if (_reloadImageCancellationBlock) {
_reloadImageCancellationBlock();
_reloadImageCancellationBlock = nil;
}

_reloadImageCancellationBlock =
[_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_iconSrc]
size:self.bounds.size
scale:RCTScreenScale()
clipped:YES
resizeMode:RCTResizeModeCenter
progressBlock:nil
partialLoadBlock:nil
completionBlock:^(NSError *error, UIImage *image) {
if (error) {
// TODO(lmr): do something with the error?
NSLog(@"%@", error);
}
dispatch_async(dispatch_get_main_queue(), ^{
_realMarker.icon = image;
});
}];
}

- (void)setImageSrc:(NSString *)imageSrc
{
_imageSrc = imageSrc;
Expand Down Expand Up @@ -295,4 +323,12 @@ - (BOOL)draggable {
return _realMarker.draggable;
}

- (void)setTracksViewChanges:(BOOL)tracksViewChanges {
_realMarker.tracksViewChanges = tracksViewChanges;
}

- (BOOL)tracksViewChanges {
return _realMarker.tracksViewChanges;
}

@end
2 changes: 2 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(rotation, CLLocationDegrees)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_REMAP_VIEW_PROPERTY(image, imageSrc, NSString)
RCT_REMAP_VIEW_PROPERTY(icon, iconSrc, NSString)
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(tracksViewChanges, BOOL)
RCT_EXPORT_VIEW_PROPERTY(opacity, double)
RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onDrag, RCTDirectEventBlock)
Expand Down