Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ private WritableMap getEventParams(MapStatus mapStatus) {
target.putDouble("latitude", mapStatus.target.latitude);
target.putDouble("longitude", mapStatus.target.longitude);
writableMap.putMap("target", target);
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions ios/RCTBaiduMap/BaiduMapViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "BaiduMapViewManager.h"
#import "BMKPointAnnotationPro.h"

@implementation BaiduMapViewManager;

Expand All @@ -18,6 +19,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)
Expand Down Expand Up @@ -138,11 +140,11 @@ - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKA
annotationView.draggable = YES;
annotationView.annotation = annotation;
return annotationView;
} else if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:markerIdentifier];
newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
newAnnotationView.animatesDrop = YES;
return newAnnotationView;
} else if ([annotation isKindOfClass:[BMKPointAnnotationPro class]]) {
BMKPointAnnotationPro * annotationPro = annotation;
return annotationPro.getAnnotationView(annotation);
} else {
@throw [NSException exceptionWithName:@"必须用BMKPointAnnotationPro" reason:@"" userInfo:nil];
}
return nil;
}
Expand Down Expand Up @@ -174,14 +176,17 @@ - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>

- (void)mapStatusDidChanged: (BMKMapView *)mapView {
CLLocationCoordinate2D targetGeoPt = [mapView getMapStatus].targetGeoPt;
BMKCoordinateRegion region = mapView.region;
NSDictionary* event = @{
@"type": @"onMapStatusChange",
@"params": @{
@"target": @{
@"latitude": @(targetGeoPt.latitude),
@"longitude": @(targetGeoPt.longitude)
},
@"zoom": @"",
@"latitudeDelta": @(region.span.latitudeDelta),
@"longitudeDelta": @(region.span.longitudeDelta),
@"zoom": @(mapView.zoomLevel),
@"overlook": @""
}
};
Expand Down
1 change: 1 addition & 0 deletions ios/RCTBaiduMap/ViewManagers/OverlayMarkerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ @implementation OverlayMarkerManager
RCT_EXPORT_MODULE(BaiduMapOverlayMarker)
RCT_EXPORT_VIEW_PROPERTY(location, NSDictionary*)
RCT_EXPORT_VIEW_PROPERTY(title, NSString*)
RCT_EXPORT_VIEW_PROPERTY(icon, RCTImageSource*)

- (UIView *)view {
OverlayMarker *marker = [OverlayMarker new];
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTBaiduMap/Views/OverlayMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#import "OverlayUtils.h"
#import <React/RCTBridge.h>
#import <React/RCTConvert+CoreLocation.h>
#import <React/RCTImageSource.h>

@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
Expand Down
17 changes: 14 additions & 3 deletions ios/RCTBaiduMap/Views/OverlayMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

#import "OverlayMarker.h"
#import "BMKPointAnnotationPro.h"
#import <BaiduMapAPI_Map/BMKAnnotationView.h>
#import "RCBMImageAnnotView.h"

@implementation OverlayMarker

Expand All @@ -26,22 +29,30 @@ - (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;
} else {
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
16 changes: 11 additions & 5 deletions js/Overlay/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <BaiduMapOverlayMarker {...this.props} icon={icon} />;
} else {
let icon;
if (this.props.icon) {
icon = resolveAssetSource(this.props.icon) || {};
icon = icon.uri || this.props.icon;
}
return <BaiduMapOverlayMarker {...this.props} icon={icon} />;
}
return <BaiduMapOverlayMarker {...this.props} icon={icon} />;
}
}
const BaiduMapOverlayMarker = requireNativeComponent('BaiduMapOverlayMarker', Marker);