From 0df205d5f49335544a8bc74734f3be87b7102158 Mon Sep 17 00:00:00 2001 From: lovebing Date: Sun, 17 May 2020 22:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93marker=E5=B1=9E=E6=80=A7=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E6=9B=B4=E6=96=B0annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/RCTBaiduMap/BaiduMapView.m | 3 ++- ios/RCTBaiduMap/Views/OverlayMarker.m | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ios/RCTBaiduMap/BaiduMapView.m b/ios/RCTBaiduMap/BaiduMapView.m index 4e356ea1..1c4a99b7 100644 --- a/ios/RCTBaiduMap/BaiduMapView.m +++ b/ios/RCTBaiduMap/BaiduMapView.m @@ -75,7 +75,7 @@ - (void)removeReactSubview:(UIView *)subview { } - (void)didSetProps:(NSArray *) props { - NSLog(@"didSetProps: %d", _childrenCount); + NSLog(@"mapView didSetProps: %@", props); [super didSetProps:props]; } @@ -87,6 +87,7 @@ - (void)didUpdateReactSubviews { [overlayView update]; } } + [super didUpdateReactSubviews]; NSLog(@"didUpdateReactSubviews:%d", [self.reactSubviews count]); } diff --git a/ios/RCTBaiduMap/Views/OverlayMarker.m b/ios/RCTBaiduMap/Views/OverlayMarker.m index 910d070c..1aab1ca4 100644 --- a/ios/RCTBaiduMap/Views/OverlayMarker.m +++ b/ios/RCTBaiduMap/Views/OverlayMarker.m @@ -15,6 +15,7 @@ @implementation OverlayMarker { RCTImageLoaderCancellationBlock _reloadImageCancellationBlock; UIImageView *_imageView; BMKMapView *_mapView; + UIImage *_iconImage; } - (NSString *)getType { @@ -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; @@ -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); }); }]; @@ -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; @@ -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 *) props { - NSLog(@"didSetProps"); +- (void)didSetProps:(NSArray *)props { + NSLog(@"marker didSetProps:%@", props); + [super didSetProps:props]; + [self update]; } - (void)didUpdateReactSubviews { NSLog(@"didUpdateReactSubviews:%lu", (unsigned long)[self.reactSubviews count]); + [super didUpdateReactSubviews]; } @end