Skip to content

Commit d74c3d7

Browse files
lovebinglovebing
authored andcommitted
Fixed bug
1 parent 65886b3 commit d74c3d7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

ios/RCTBaiduMap/RCTBaiduMapView.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,38 @@ -(void)setMarker:(NSDictionary *)option {
4040

4141
-(void)setMarkers:(NSArray *)markers {
4242
int markersCount = [markers count];
43+
if(_annotations == nil) {
44+
_annotations = [[NSMutableArray alloc] init];
45+
}
4346
if(markers != nil) {
4447
for (int i = 0; i < markersCount; i++) {
4548
NSDictionary *option = [markers objectAtIndex:i];
4649

47-
BMKPointAnnotation *annotation = [_annotations objectAtIndex:i];
50+
BMKPointAnnotation *annotation = nil;
51+
if(i < [_annotations count]) {
52+
annotation = [_annotations objectAtIndex:i];
53+
}
4854
if(annotation == nil) {
4955
annotation = [[BMKPointAnnotation alloc]init];
5056
[self addMarker:annotation option:option];
57+
[_annotations addObject:annotation];
5158
}
5259
else {
5360
[self updateMarker:annotation option:option];
5461
}
5562
}
5663

5764
int _annotationsCount = [_annotations count];
65+
66+
NSString *smarkersCount = [NSString stringWithFormat:@"%d", markersCount];
67+
NSString *sannotationsCount = [NSString stringWithFormat:@"%d", _annotationsCount];
68+
NSLog(smarkersCount);
69+
NSLog(sannotationsCount);
70+
5871
if(markersCount < _annotationsCount) {
5972
int start = _annotationsCount - markersCount;
6073
for(int i = start; i < _annotationsCount; i++) {
74+
NSLog(@"forforforfor");
6175
BMKPointAnnotation *annotation = [_annotations objectAtIndex:i];
6276
[self removeAnnotation:annotation];
6377
[_annotations removeObject:annotation];
@@ -86,6 +100,9 @@ -(void)addMarker:(BMKPointAnnotation *)annotation option:(NSDictionary *)option
86100
-(void)updateMarker:(BMKPointAnnotation *)annotation option:(NSDictionary *)option {
87101
CLLocationCoordinate2D coor = [self getCoorFromMarkerOption:option];
88102
NSString *title = [RCTConvert NSString:option[@"title"]];
103+
if(title.length == 0) {
104+
title = nil;
105+
}
89106
annotation.coordinate = coor;
90107
annotation.title = title;
91108
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-baidu-map",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Baidu Map SDK For React Native, Support both Android and IOS.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)