Skip to content

Commit

Permalink
当marker属性变化时更新annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovebing committed May 17, 2020
1 parent 479d161 commit 0df205d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ios/RCTBaiduMap/BaiduMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void)removeReactSubview:(UIView *)subview {
}

- (void)didSetProps:(NSArray<NSString *> *) props {
NSLog(@"didSetProps: %d", _childrenCount);
NSLog(@"mapView didSetProps: %@", props);
[super didSetProps:props];
}

Expand All @@ -87,6 +87,7 @@ - (void)didUpdateReactSubviews {
[overlayView update];
}
}
[super didUpdateReactSubviews];
NSLog(@"didUpdateReactSubviews:%d", [self.reactSubviews count]);
}

Expand Down
18 changes: 12 additions & 6 deletions ios/RCTBaiduMap/Views/OverlayMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @implementation OverlayMarker {
RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
UIImageView *_imageView;
BMKMapView *_mapView;
UIImage *_iconImage;
}

- (NSString *)getType {
Expand Down Expand Up @@ -50,7 +51,7 @@ - (void)updateAnnotation:(BMKPointAnnotationPro *)annotation {
annotation.title = _title;
}
_annotation.coordinate = [OverlayUtils getCoorFromOption:_location];
if (_icon != nil) {
if (_iconImage == nil && _icon != nil) {
if (_reloadImageCancellationBlock) {
_reloadImageCancellationBlock();
_reloadImageCancellationBlock = nil;
Expand All @@ -65,9 +66,10 @@ - (void)updateAnnotation:(BMKPointAnnotationPro *)annotation {
completionBlock:^(NSError *error, UIImage *image) {
if (error) {
NSLog(@"download image error: %@", error);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self updateAnnotationView:annotation image:image];
[self updateAnnotationView:annotation image:image];
NSLog(@"download image success: %@", image);
});
}];
Expand All @@ -78,6 +80,7 @@ - (void)updateAnnotation:(BMKPointAnnotationPro *)annotation {

- (void)updateAnnotationView:(BMKPointAnnotationPro *) annotation image:(UIImage *)image {
annotation.annotationView.image = image;
_iconImage = image;
NSLog(@"annotationView width: %f, height: %f", _icon.size.width, _icon.size.height);
if (_icon.size.height > 0 && _icon.size.width > 0) {
annotation.annotationView.image = NULL;
Expand Down Expand Up @@ -115,25 +118,28 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
[_annotation updatePaopaoView];
});
}
[super insertReactSubview:subview atIndex:atIndex];
}

- (void)removeReactSubview:(UIView *)subview {
NSLog(@"removeReactSubview");
if ([subview isKindOfClass:[InfoWindow class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
_annotation.customPopView.backgroundColor = [UIColor redColor];
[_annotation.customPopView addSubview:subview];
_annotation.annotationView = nil;
});
}
[super removeReactSubview:subview];
}

- (void)didSetProps:(NSArray<NSString *> *) props {
NSLog(@"didSetProps");
- (void)didSetProps:(NSArray<NSString *> *)props {
NSLog(@"marker didSetProps:%@", props);
[super didSetProps:props];
[self update];
}

- (void)didUpdateReactSubviews {
NSLog(@"didUpdateReactSubviews:%lu", (unsigned long)[self.reactSubviews count]);
[super didUpdateReactSubviews];
}

@end

0 comments on commit 0df205d

Please sign in to comment.