Skip to content

Commit 5abb53f

Browse files
author
lovebing
committed
Fixed ios's bugs
1 parent a6cd259 commit 5abb53f

File tree

4 files changed

+13
-65
lines changed

4 files changed

+13
-65
lines changed

ios/RCTBaiduMap/BaiduMapModule.m

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,4 @@ @implementation BaiduMapModule {
1717

1818
RCT_EXPORT_MODULE();
1919

20-
RCT_EXPORT_METHOD(setMarker:(double)lat lng:(double)lng) {
21-
if(_annotation == nil) {
22-
_annotation = [[BMKPointAnnotation alloc]init];
23-
}
24-
else {
25-
[[self getBaiduMapView] removeAnnotation:_annotation];
26-
}
27-
28-
CLLocationCoordinate2D coor;
29-
coor.latitude = lat;
30-
coor.longitude = lng;
31-
_annotation.coordinate = coor;
32-
[[self getBaiduMapView] addAnnotation:_annotation];
33-
}
34-
35-
RCT_EXPORT_METHOD(setMapType:(int)type) {
36-
[[self getBaiduMapView] setMapType:type];
37-
}
38-
39-
RCT_EXPORT_METHOD(setZoom:(float)zoom) {
40-
[[self getBaiduMapView] setZoomLevel:zoom];
41-
}
42-
43-
RCT_EXPORT_METHOD(moveToCenter:(double)lat lng:(double)lng zoom:(float)zoom) {
44-
NSDictionary* center = @{
45-
@"lat": @(lat),
46-
@"lng": @(lng)
47-
};
48-
[[self getBaiduMapView] setCenterLatLng:center];
49-
[[self getBaiduMapView] setZoomLevel:zoom];
50-
}
51-
52-
-(RCTBaiduMapView *) getBaiduMapView {
53-
return [RCTBaiduMapViewManager getBaiduMapView];
54-
}
55-
5620
@end

ios/RCTBaiduMap/GeolocationModule.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,5 @@ -(CLLocationCoordinate2D)getBaiduCoor:(double)lat lng:(double)lng {
186186
return baiduCoor;
187187
}
188188

189-
-(RCTBaiduMapView *) getBaiduMapView {
190-
return [RCTBaiduMapViewManager getBaiduMapView];
191-
}
192189

193190
@end

ios/RCTBaiduMap/RCTBaiduMapViewManager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
+(void)initSDK:(NSString *)key;
1717

18-
-(void)sendEvent:(NSDictionary *) params;
19-
20-
+(RCTBaiduMapView *) getBaiduMapView;
18+
-(void)sendEvent:(RCTBaiduMapView *) mapView params:(NSDictionary *) params;
2119

2220
@end
2321

ios/RCTBaiduMap/RCTBaiduMapViewManager.m

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#import "RCTBaiduMapViewManager.h"
1010

11-
static RCTBaiduMapView* _mapView;
12-
1311
@implementation RCTBaiduMapViewManager;
1412

1513
RCT_EXPORT_MODULE(RCTBaiduMapView)
@@ -38,13 +36,9 @@ +(void)initSDK:(NSString*)key {
3836
}
3937

4038
- (UIView *)view {
41-
NSLog(@"RCTBaiduMapView");
42-
if(_mapView != nil) {
43-
[_mapView removeFromSuperview];
44-
}
45-
_mapView = [[RCTBaiduMapView alloc] init];
46-
_mapView.delegate = self;
47-
return _mapView;
39+
RCTBaiduMapView* mapView = [[RCTBaiduMapView alloc] init];
40+
mapView.delegate = self;
41+
return mapView;
4842
}
4943

5044
-(void)mapview:(BMKMapView *)mapView
@@ -57,7 +51,7 @@ -(void)mapview:(BMKMapView *)mapView
5751
@"longitude": @(coordinate.longitude)
5852
}
5953
};
60-
[self sendEvent:event];
54+
[self sendEvent:mapView params:event];
6155
}
6256

6357
-(void)mapView:(BMKMapView *)mapView
@@ -70,15 +64,15 @@ -(void)mapView:(BMKMapView *)mapView
7064
@"longitude": @(coordinate.longitude)
7165
}
7266
};
73-
[self sendEvent:event];
67+
[self sendEvent:mapView params:event];
7468
}
7569

7670
-(void)mapViewDidFinishLoading:(BMKMapView *)mapView {
7771
NSDictionary* event = @{
7872
@"type": @"onMapLoaded",
7973
@"params": @{}
8074
};
81-
[self sendEvent:event];
75+
[self sendEvent:mapView params:event];
8276
}
8377

8478
-(void)mapView:(BMKMapView *)mapView
@@ -93,7 +87,7 @@ -(void)mapView:(BMKMapView *)mapView
9387
}
9488
}
9589
};
96-
[self sendEvent:event];
90+
[self sendEvent:mapView params:event];
9791
}
9892

9993
- (void) mapView:(BMKMapView *)mapView
@@ -108,7 +102,7 @@ - (void) mapView:(BMKMapView *)mapView
108102
@"longitude": @(mapPoi.pt.longitude)
109103
}
110104
};
111-
[self sendEvent:event];
105+
[self sendEvent:mapView params:event];
112106
}
113107

114108
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation {
@@ -135,19 +129,14 @@ -(void)mapStatusDidChanged: (BMKMapView *)mapView {
135129
@"overlook": @""
136130
}
137131
};
138-
[self sendEvent:event];
139-
132+
[self sendEvent:mapView params:event];
140133
}
141134

142-
-(void)sendEvent:(NSDictionary *) params {
143-
if (!_mapView.onChange) {
135+
-(void)sendEvent:(RCTBaiduMapView *) mapView params:(NSDictionary *) params {
136+
if (!mapView.onChange) {
144137
return;
145138
}
146-
_mapView.onChange(params);
147-
}
148-
149-
+(RCTBaiduMapView *) getBaiduMapView {
150-
return _mapView;
139+
mapView.onChange(params);
151140
}
152141

153142
@end

0 commit comments

Comments
 (0)