From 1af023415d46df6b9d17b1c54e7ad7df7b8c7e5b Mon Sep 17 00:00:00 2001 From: lmeng Date: Mon, 9 Dec 2019 23:11:33 +0800 Subject: [PATCH 1/5] enhance baidu map --- .../reactnative/baidumap/listener/MapListener.java | 8 ++++++++ .../reactnative/baidumap/uimanager/MapViewManager.java | 5 +++++ ios/RCTBaiduMap/BaiduMapViewManager.m | 1 + 3 files changed, 14 insertions(+) diff --git a/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java b/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java index b69f2a68..7c600340 100644 --- a/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java +++ b/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java @@ -116,6 +116,14 @@ private WritableMap getEventParams(MapStatus mapStatus) { target.putDouble("latitude", mapStatus.target.latitude); target.putDouble("longitude", mapStatus.target.longitude); writableMap.putMap("target", target); + WritableMap northeast = Arguments.createMap(); + northeast.putDouble("latitude", mapStatus.bound.northeast.latitude); + northeast.putDouble("longitude", mapStatus.bound.northeast.longitude); + writableMap.putMap("northeast", northeast); + WritableMap southwest = Arguments.createMap(); + southwest.putDouble("latitude", mapStatus.bound.southwest.latitude); + southwest.putDouble("longitude", mapStatus.bound.southwest.longitude); + writableMap.putMap("southwest", southwest); writableMap.putDouble("zoom", mapStatus.zoom); writableMap.putDouble("overlook", mapStatus.overlook); return writableMap; diff --git a/android/src/main/java/org/lovebing/reactnative/baidumap/uimanager/MapViewManager.java b/android/src/main/java/org/lovebing/reactnative/baidumap/uimanager/MapViewManager.java index 6a540fde..7a26e13f 100644 --- a/android/src/main/java/org/lovebing/reactnative/baidumap/uimanager/MapViewManager.java +++ b/android/src/main/java/org/lovebing/reactnative/baidumap/uimanager/MapViewManager.java @@ -115,6 +115,11 @@ public void setShowsUserLocation(MapView mapView, boolean showsUserLocation) { mapView.getMap().setMyLocationEnabled(showsUserLocation); } + @ReactProp(name = "showMapPoi") + public void showMapPoi(MapView mapView, boolean showMapPoi) { + mapView.getMap().showMapPoi(showMapPoi); + } + @ReactProp(name = "locationData") public void setLocationData(MapView mapView, ReadableMap readableMap) { LocationData locationData = ConvertUtils.convert(readableMap, LocationData.class); diff --git a/ios/RCTBaiduMap/BaiduMapViewManager.m b/ios/RCTBaiduMap/BaiduMapViewManager.m index 34991d30..eabf00cb 100644 --- a/ios/RCTBaiduMap/BaiduMapViewManager.m +++ b/ios/RCTBaiduMap/BaiduMapViewManager.m @@ -18,6 +18,7 @@ @implementation BaiduMapViewManager; RCT_EXPORT_VIEW_PROPERTY(mapType, int) RCT_EXPORT_VIEW_PROPERTY(zoom, float) RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL); +RCT_EXPORT_VIEW_PROPERTY(showMapPoi, BOOL); RCT_EXPORT_VIEW_PROPERTY(scrollGesturesEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(zoomGesturesEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(trafficEnabled, BOOL) From 69b1e02651d23dae7895261869488c854fb7feab Mon Sep 17 00:00:00 2001 From: lmeng Date: Sun, 5 Jan 2020 21:30:20 +0800 Subject: [PATCH 2/5] refactor --- .../reactnative/baidumap/listener/MapListener.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java b/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java index 7c600340..a0025d68 100644 --- a/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java +++ b/android/src/main/java/org/lovebing/reactnative/baidumap/listener/MapListener.java @@ -116,14 +116,8 @@ private WritableMap getEventParams(MapStatus mapStatus) { target.putDouble("latitude", mapStatus.target.latitude); target.putDouble("longitude", mapStatus.target.longitude); writableMap.putMap("target", target); - WritableMap northeast = Arguments.createMap(); - northeast.putDouble("latitude", mapStatus.bound.northeast.latitude); - northeast.putDouble("longitude", mapStatus.bound.northeast.longitude); - writableMap.putMap("northeast", northeast); - WritableMap southwest = Arguments.createMap(); - southwest.putDouble("latitude", mapStatus.bound.southwest.latitude); - southwest.putDouble("longitude", mapStatus.bound.southwest.longitude); - writableMap.putMap("southwest", southwest); + writableMap.putDouble("latitudeDelta", mapStatus.bound.northeast.latitude - mapStatus.bound.southwest.latitude); + writableMap.putDouble("longitudeDelta", mapStatus.bound.northeast.longitude - mapStatus.bound.southwest.longitude); writableMap.putDouble("zoom", mapStatus.zoom); writableMap.putDouble("overlook", mapStatus.overlook); return writableMap; From cbf1875a93b8b08bd57beb6fe15f0762bfc6492f Mon Sep 17 00:00:00 2001 From: lmeng Date: Sun, 9 Feb 2020 23:25:31 +0800 Subject: [PATCH 3/5] refactor --- ios/RCTBaiduMap/BaiduMapViewManager.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/RCTBaiduMap/BaiduMapViewManager.m b/ios/RCTBaiduMap/BaiduMapViewManager.m index eabf00cb..6061a011 100644 --- a/ios/RCTBaiduMap/BaiduMapViewManager.m +++ b/ios/RCTBaiduMap/BaiduMapViewManager.m @@ -175,6 +175,7 @@ - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id - (void)mapStatusDidChanged: (BMKMapView *)mapView { CLLocationCoordinate2D targetGeoPt = [mapView getMapStatus].targetGeoPt; + BMKCoordinateRegion region = mapView.region; NSDictionary* event = @{ @"type": @"onMapStatusChange", @"params": @{ @@ -182,13 +183,16 @@ - (void)mapStatusDidChanged: (BMKMapView *)mapView { @"latitude": @(targetGeoPt.latitude), @"longitude": @(targetGeoPt.longitude) }, - @"zoom": @"", + @"latitudeDelta": @(region.span.latitudeDelta), + @"longitudeDelta": @(region.span.longitudeDelta), + @"zoom": @(mapView.zoomLevel), @"overlook": @"" } }; [self sendEvent:mapView params:event]; } + - (void)sendEvent:(BaiduMapView *)mapView params:(NSDictionary *)params { if (!mapView.onChange) { return; From 5a73e1e8aba4805c98fffbba84fb6760a6c4055d Mon Sep 17 00:00:00 2001 From: lmeng Date: Mon, 10 Feb 2020 10:44:28 +0800 Subject: [PATCH 4/5] refactor --- ios/RCTBaiduMap/BaiduMapViewManager.m | 1 - 1 file changed, 1 deletion(-) diff --git a/ios/RCTBaiduMap/BaiduMapViewManager.m b/ios/RCTBaiduMap/BaiduMapViewManager.m index 6061a011..1ab51d01 100644 --- a/ios/RCTBaiduMap/BaiduMapViewManager.m +++ b/ios/RCTBaiduMap/BaiduMapViewManager.m @@ -192,7 +192,6 @@ - (void)mapStatusDidChanged: (BMKMapView *)mapView { [self sendEvent:mapView params:event]; } - - (void)sendEvent:(BaiduMapView *)mapView params:(NSDictionary *)params { if (!mapView.onChange) { return; From 8e971d42f74c7c315167234046275b2ef2068b25 Mon Sep 17 00:00:00 2001 From: lmeng <42997455@qq.com> Date: Mon, 13 Apr 2020 19:31:43 +0800 Subject: [PATCH 5/5] refactor --- ios/RCTBaiduMap/BaiduMapViewManager.m | 11 ++++++----- .../ViewManagers/OverlayMarkerManager.m | 1 + ios/RCTBaiduMap/Views/OverlayMarker.h | 2 ++ ios/RCTBaiduMap/Views/OverlayMarker.m | 17 ++++++++++++++--- js/Overlay/Marker.js | 16 +++++++++++----- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ios/RCTBaiduMap/BaiduMapViewManager.m b/ios/RCTBaiduMap/BaiduMapViewManager.m index 1ab51d01..f5cd89aa 100644 --- a/ios/RCTBaiduMap/BaiduMapViewManager.m +++ b/ios/RCTBaiduMap/BaiduMapViewManager.m @@ -7,6 +7,7 @@ // #import "BaiduMapViewManager.h" +#import "BMKPointAnnotationPro.h" @implementation BaiduMapViewManager; @@ -139,11 +140,11 @@ - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id #import +#import @interface OverlayMarker : OverlayView @property (nonatomic, weak) RCTBridge *bridge; @property (nonatomic, strong) NSDictionary *location; @property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) RCTImageSource *icon; @property (nonatomic, strong) BMKPointAnnotation *annotation; @end diff --git a/ios/RCTBaiduMap/Views/OverlayMarker.m b/ios/RCTBaiduMap/Views/OverlayMarker.m index 059730a8..e3fef628 100644 --- a/ios/RCTBaiduMap/Views/OverlayMarker.m +++ b/ios/RCTBaiduMap/Views/OverlayMarker.m @@ -7,6 +7,9 @@ // #import "OverlayMarker.h" +#import "BMKPointAnnotationPro.h" +#import +#import "RCBMImageAnnotView.h" @implementation OverlayMarker @@ -26,15 +29,15 @@ - (void)removeFromMap:(BMKMapView *)mapView { [mapView removeAnnotation:[self getAnnotation]]; } -- (BMKPointAnnotation *)getAnnotation { +- (BMKPointAnnotationPro *)getAnnotation { if (_annotation == nil) { - _annotation = [[BMKPointAnnotation alloc] init]; + _annotation = [[BMKPointAnnotationPro alloc] init]; [self updateAnnotation:_annotation]; } return _annotation; } -- (void)updateAnnotation:(BMKPointAnnotation *)annotation { +- (void)updateAnnotation:(BMKPointAnnotationPro *)annotation { CLLocationCoordinate2D coor = [OverlayUtils getCoorFromOption:_location]; if(_title.length == 0) { annotation.title = nil; @@ -42,6 +45,14 @@ - (void)updateAnnotation:(BMKPointAnnotation *)annotation { annotation.title = _title; } annotation.coordinate = coor; + + annotation.getAnnotationView = ^BMKAnnotationView * _Nonnull(BMKPointAnnotation * _Nonnull annotation) { + RCBMImageAnnotView *annotV = [[RCBMImageAnnotView alloc] initWithAnnotation:annotation reuseIdentifier:@"dontCare"]; + annotV.bridge = self.bridge; + NSLog(@"self.icon:%@",self.icon); + annotV.source = self.icon; + return annotV; + }; } @end diff --git a/js/Overlay/Marker.js b/js/Overlay/Marker.js index 1b64ea05..4e8f464a 100644 --- a/js/Overlay/Marker.js +++ b/js/Overlay/Marker.js @@ -40,13 +40,19 @@ export default class Marker extends Component { super(); } + //对icon的处理方式不同,ios上需要完整的object(包括uri size scale),android上只要uri render() { - let icon; - if (this.props.icon) { - icon = resolveAssetSource(this.props.icon) || {}; - icon = icon.uri || this.props.icon; + if (Platform.OS === 'ios') { + const icon = resolveAssetSource(this.props.icon); + return ; + } else { + let icon; + if (this.props.icon) { + icon = resolveAssetSource(this.props.icon) || {}; + icon = icon.uri || this.props.icon; + } + return ; } - return ; } } const BaiduMapOverlayMarker = requireNativeComponent('BaiduMapOverlayMarker', Marker);