Commit 4c40aece authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS marker 事件接口

parent 2532d141
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h> #import <MAMapKit/MAMapKit.h>
#import <React/RCTComponent.h>
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
@class AMapView; @class AMapView;
...@@ -8,8 +11,14 @@ ...@@ -8,8 +11,14 @@
@property(nonatomic, assign) CLLocationCoordinate2D coordinate; @property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title; @property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle; @property(nonatomic, copy) NSString *subtitle;
@property(nonatomic, assign) BOOL _active;
@property(nonatomic, strong) AMapView *mapView; @property(nonatomic, strong) AMapView *mapView;
@property(nonatomic, assign) BOOL _active;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onInfoWindowPress;
@property (nonatomic, copy) RCTBubblingEventBlock onDragStart;
@property (nonatomic, copy) RCTBubblingEventBlock onDrag;
@property (nonatomic, copy) RCTBubblingEventBlock onDragEnd;
- (MAAnnotationView *)getAnnotationView; - (MAAnnotationView *)getAnnotationView;
- (BOOL)active; - (BOOL)active;
......
#import "AMapMarker.h" #import "AMapMarker.h"
#import "AMapView.h" #import "AMapView.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapMarker { @implementation AMapMarker {
MAAnnotationView *_pinView; MAAnnotationView *_pinView;
} }
......
...@@ -26,4 +26,10 @@ RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL) ...@@ -26,4 +26,10 @@ RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
RCT_EXPORT_VIEW_PROPERTY(infoWindowEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(infoWindowEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger) RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onInfoWindowPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onDrag, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onDragEnd, RCTBubblingEventBlock)
@end @end
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
#import <React/RCTComponent.h> #import <React/RCTComponent.h>
@interface AMapView : MAMapView @interface AMapView : MAMapView
@property (nonatomic, copy) RCTBubblingEventBlock onReady;
@property (nonatomic, copy) RCTBubblingEventBlock onLocation; @property(nonatomic, copy) RCTBubblingEventBlock onReady;
@property (nonatomic, copy) RCTBubblingEventBlock onPress; @property(nonatomic, copy) RCTBubblingEventBlock onLocation;
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress; @property(nonatomic, copy) RCTBubblingEventBlock onPress;
@property(nonatomic, copy) RCTBubblingEventBlock onLongPress;
@end @end
\ No newline at end of file
...@@ -23,85 +23,62 @@ RCT_EXPORT_MODULE() ...@@ -23,85 +23,62 @@ RCT_EXPORT_MODULE()
} }
RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL) 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)
RCT_EXPORT_VIEW_PROPERTY(showsIndoorMap, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsIndoorMap, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsLabels, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsLabels, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsTraffic, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsTraffic, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsBuildings, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsBuildings, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zoomLevel, CGFloat) RCT_EXPORT_VIEW_PROPERTY(zoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, CGFloat) RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, CGFloat) RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(rotateEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(rotateEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(tiltEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(tiltEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mapType, MAMapType) RCT_EXPORT_VIEW_PROPERTY(mapType, MAMapType)
RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D) 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(onReady, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
#pragma mark MAMapViewDelegate #pragma mark MAMapViewDelegate
- (void)mapInitComplete:(AMapView *)mapView { - (void)mapInitComplete:(AMapView *)mapView {
if (!mapView.onReady) { if (mapView.onReady) {
return;
}
mapView.onReady(@{}); mapView.onReady(@{});
}
} }
- (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate { - (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (!mapView.onPress) { if (mapView.onPress) {
return;
}
mapView.onPress(@{ mapView.onPress(@{
@"latitude": @(coordinate.latitude), @"latitude": @(coordinate.latitude),
@"longitude": @(coordinate.longitude), @"longitude": @(coordinate.longitude),
}); });
}
} }
- (void)mapView:(AMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate { - (void)mapView:(AMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (!mapView.onLongPress) { if (mapView.onLongPress) {
return;
}
mapView.onLongPress(@{ mapView.onLongPress(@{
@"latitude": @(coordinate.latitude), @"latitude": @(coordinate.latitude),
@"longitude": @(coordinate.longitude), @"longitude": @(coordinate.longitude),
}); });
}
} }
- (void)mapView:(AMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation { - (void)mapView:(AMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation {
if (!mapView.onLocation) { if (mapView.onLocation) {
return;
}
mapView.onLocation(@{ mapView.onLocation(@{
@"latitude": @(userLocation.coordinate.latitude), @"latitude": @(userLocation.coordinate.latitude),
@"longitude": @(userLocation.coordinate.longitude), @"longitude": @(userLocation.coordinate.longitude),
@"accuracy": @((userLocation.location.horizontalAccuracy + userLocation.location.verticalAccuracy) / 2), @"accuracy": @((userLocation.location.horizontalAccuracy + userLocation.location.verticalAccuracy) / 2),
}); });
}
} }
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(AMapMarker *)marker { - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(AMapMarker *)marker {
...@@ -111,4 +88,35 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) ...@@ -111,4 +88,35 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
return [marker getAnnotationView]; return [marker getAnnotationView];
} }
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view {
AMapMarker *marker = (AMapMarker *) view.annotation;
if (marker.onPress) {
marker.onPress(@{});
}
}
- (void)mapView:(MAMapView *)mapView didAnnotationViewCalloutTapped:(MAAnnotationView *)view {
AMapMarker *marker = (AMapMarker *) view.annotation;
if (marker.onInfoWindowPress) {
marker.onInfoWindowPress(@{});
}
}
- (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view didChangeDragState:(MAAnnotationViewDragState)newState
fromOldState:(MAAnnotationViewDragState)oldState {
AMapMarker *marker = (AMapMarker *) view.annotation;
if (newState == MAAnnotationViewDragStateStarting && marker.onDragStart) {
marker.onDragStart(@{});
}
if (newState == MAAnnotationViewDragStateDragging && marker.onDrag) {
marker.onDrag(@{});
}
if (newState == MAAnnotationViewDragStateEnding && marker.onDragEnd) {
marker.onDragEnd(@{
@"latitude": @(marker.coordinate.latitude),
@"longitude": @(marker.coordinate.longitude),
});
}
}
@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