Commit f4a53798 authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS 基本事件接口

parent 20d84519
...@@ -149,9 +149,9 @@ import MapView from 'react-native-amap3d' ...@@ -149,9 +149,9 @@ import MapView from 'react-native-amap3d'
- [x] 室内地图 - [x] 室内地图
- [ ] 内置地图控件(指南针和比例尺通过内置接口提供支持,定位按钮、缩放按钮需要自行实现) - [ ] 内置地图控件(指南针和比例尺通过内置接口提供支持,定位按钮、缩放按钮需要自行实现)
- [x] 手势交互(平移、缩放、旋转、倾斜) - [x] 手势交互(平移、缩放、旋转、倾斜)
- [x] 中心坐标、缩放级别、倾斜度 🚀 - [x] 中心坐标、缩放级别、倾斜度
- [ ] 地图事件(onPress、onLongPress、onLocation) - [x] 地图事件(onPress、onLongPress、onLocation)
- [ ] 地图标记(Marker) - [ ] 地图标记(Marker)🚀
- [ ] 基本属性及事件 - [ ] 基本属性及事件
- [ ] 自定义信息窗体 - [ ] 自定义信息窗体
- [ ] 自定义图标 - [ ] 自定义图标
......
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h> #import <MAMapKit/MAMapKit.h>
#import <RCTComponent.h>
@interface AMapView : MAMapView @interface AMapView : MAMapView
@property (nonatomic, copy) RCTBubblingEventBlock onReady;
@property (nonatomic, copy) RCTBubblingEventBlock onLocation;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
@end @end
\ No newline at end of file
#import "AMapView.h" #import "AMapView.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapView { @implementation AMapView {
} }
- (void)setShowsTraffic:(BOOL)shows { - (void)setShowsTraffic:(BOOL)shows {
[super setShowTraffic:shows]; super.showTraffic = shows;
} }
- (void)setTiltEnabled:(BOOL)enabled { - (void)setTiltEnabled:(BOOL)enabled {
[super setRotateCameraEnabled:enabled]; super.rotateCameraEnabled = enabled;
}
- (void)setLocationEnabled:(BOOL)enabled {
super.showsUserLocation = enabled;
} }
- (void)setCoordinate:(CLLocationCoordinate2D)json { - (void)setCoordinate:(CLLocationCoordinate2D)json {
......
...@@ -3,22 +3,26 @@ ...@@ -3,22 +3,26 @@
#import "AMapView.h" #import "AMapView.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection" #pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapViewManager : RCTViewManager
@interface AMapViewManager : RCTViewManager <MAMapViewDelegate>
@end @end
@implementation AMapViewManager { @implementation AMapViewManager {
AMapView *mapView; AMapView *_mapView;
} }
RCT_EXPORT_MODULE() RCT_EXPORT_MODULE()
- (UIView *)view { - (UIView *)view {
mapView = [[AMapView alloc] init]; _mapView = [[AMapView alloc] init];
mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9042, 116.4074); _mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9042, 116.4074);
mapView.zoomLevel = 10; _mapView.zoomLevel = 10;
return mapView; _mapView.delegate = self;
return _mapView;
} }
RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsCompass, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsCompass, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsScale, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsScale, BOOL)
...@@ -51,4 +55,53 @@ RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D) ...@@ -51,4 +55,53 @@ RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D)
RCT_EXPORT_VIEW_PROPERTY(tilt, CGFloat) RCT_EXPORT_VIEW_PROPERTY(tilt, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(onReady, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
#pragma mark MAMapViewDelegate
- (void)mapInitComplete:(AMapView *)mapView {
if (!mapView.onReady) {
return;
}
mapView.onReady(@{});
}
- (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (!mapView.onPress) {
return;
}
mapView.onPress(@{
@"latitude": @(coordinate.latitude),
@"longitude": @(coordinate.longitude),
});
}
- (void)mapView:(AMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (!mapView.onLongPress) {
return;
}
mapView.onLongPress(@{
@"latitude": @(coordinate.latitude),
@"longitude": @(coordinate.longitude),
});
}
- (void)mapView:(AMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation {
NSLog(@"location");
if (!mapView.onLocation) {
return;
}
mapView.onLocation(@{
@"latitude": @(userLocation.coordinate.latitude),
@"longitude": @(userLocation.coordinate.longitude),
@"accuracy": @((userLocation.location.horizontalAccuracy + userLocation.location.verticalAccuracy) / 2),
});
}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment