Commit d6de8829 authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS polyline 基本接口

parent 949816bb
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h> #import <MAMapKit/MAMapKit.h>
#import <React/RCTComponent.h>
#import "AMapView.h" #import "AMapView.h"
#import "AMapOverlay.h" #import "AMapOverlay.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@interface AMapMarker : UIView <MAAnnotation, AMapOverlayDelegate> @interface AMapMarker : UIView <MAAnnotation, AMapOverlayDelegate>
@property (nonatomic, copy) RCTBubblingEventBlock onPress; @property(nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onInfoWindowPress; @property(nonatomic, copy) RCTBubblingEventBlock onInfoWindowPress;
@property (nonatomic, copy) RCTBubblingEventBlock onDragStart; @property(nonatomic, copy) RCTBubblingEventBlock onDragStart;
@property (nonatomic, copy) RCTBubblingEventBlock onDrag; @property(nonatomic, copy) RCTBubblingEventBlock onDrag;
@property (nonatomic, copy) RCTBubblingEventBlock onDragEnd; @property(nonatomic, copy) RCTBubblingEventBlock onDragEnd;
- (BOOL)active;
- (CLLocationCoordinate2D)coordinate; - (CLLocationCoordinate2D)coordinate;
- (NSString *)title; - (NSString *)title;
- (NSString *)subtitle; - (NSString *)subtitle;
- (BOOL)active;
- (MAAnnotationView *)annotationView; - (MAAnnotationView *)annotationView;
- (void)setMapView:(AMapView *)mapView; - (void)setMapView:(AMapView *)mapView;
......
#import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h>
@interface AMapPolyline : UIView <MAOverlay>
@property(nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property(nonatomic, readonly) MAMapRect boundingMapRect;
- (MAOverlayRenderer *)renderer;
@end
\ No newline at end of file
#import "AMapPolyline.h"
#import "Coordinate.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapPolyline {
MAPolyline *_polyline;
MAPolylineRenderer *_renderer;
CGFloat _width;
UIColor *_color;
BOOL _dashed;
}
- (void)setCoordinates:(NSArray<Coordinate *> *)coordinates {
CLLocationCoordinate2D coords[coordinates.count];
for (NSUInteger i = 0; i < coordinates.count; i++) {
coords[i] = coordinates[i].coordinate;
}
_polyline = [MAPolyline polylineWithCoordinates:coords count:coordinates.count];
if (_color == nil) {
_color = UIColor.blackColor;
}
_renderer = [[MAPolylineRenderer alloc] initWithPolyline:_polyline];
_renderer.lineWidth = _width;
_renderer.strokeColor = _color;
_renderer.lineDash = _dashed;
}
- (void)setWidth:(CGFloat)width {
_width = width;
_renderer.lineWidth = width;
}
- (void)setColor:(UIColor *)color {
_color = color;
_renderer.strokeColor = color;
}
- (void)setDottedLine:(BOOL)dashed {
_dashed = dashed;
_renderer.lineDash = dashed;
}
- (CLLocationCoordinate2D)coordinate {
return _polyline.coordinate;
}
- (MAMapRect)boundingMapRect {
return _polyline.boundingMapRect;
}
- (MAOverlayRenderer *)renderer {
return _renderer;
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapPolyline.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapPolylineManager : RCTViewManager <MAMapViewDelegate>
@end
@implementation AMapPolylineManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapPolyline new];
}
RCT_EXPORT_VIEW_PROPERTY(coordinates, CoordinateArray)
RCT_EXPORT_VIEW_PROPERTY(width, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
RCT_EXPORT_VIEW_PROPERTY(dottedLine, BOOL)
@end
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h" #import "AMapMarker.h"
#import "AMapPolyline.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection" #pragma ide diagnostic ignored "OCUnusedMethodInspection"
...@@ -26,14 +27,17 @@ ...@@ -26,14 +27,17 @@
super.cameraDegree = degree; super.cameraDegree = degree;
} }
- (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex { - (void)insertReactSubview:(id <RCTComponent>)subview atIndex:(NSInteger)atIndex {
if ([subview isKindOfClass:[AMapMarker class]]) { if ([subview isKindOfClass:[AMapMarker class]]) {
((AMapMarker *) subview).mapView = self; ((AMapMarker *) subview).mapView = self;
[self addAnnotation:(id <MAAnnotation>) subview]; [self addAnnotation:(id <MAAnnotation>) subview];
} }
if ([subview isKindOfClass:[AMapPolyline class]]) {;
[self addOverlay:(id <MAOverlay>) subview];
}
} }
- (void)removeReactSubview:(id<RCTComponent>)subview { - (void)removeReactSubview:(id <RCTComponent>)subview {
if ([subview isKindOfClass:[AMapMarker class]]) { if ([subview isKindOfClass:[AMapMarker class]]) {
[self removeAnnotation:(id <MAAnnotation>) subview]; [self removeAnnotation:(id <MAAnnotation>) subview];
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h" #import "AMapMarker.h"
#import "AMapPolyline.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection" #pragma ide diagnostic ignored "OCUnusedClassInspection"
#pragma ide diagnostic ignored "-Woverriding-method-mismatch" #pragma ide diagnostic ignored "-Woverriding-method-mismatch"
...@@ -45,8 +46,6 @@ RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) ...@@ -45,8 +46,6 @@ 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
- (void)mapInitComplete:(AMapView *)mapView { - (void)mapInitComplete:(AMapView *)mapView {
if (mapView.onReady) { if (mapView.onReady) {
mapView.onReady(@{}); mapView.onReady(@{});
...@@ -92,6 +91,13 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) ...@@ -92,6 +91,13 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
return nil; return nil;
} }
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay {
if ([overlay isKindOfClass:[AMapPolyline class]]) {
return ((AMapPolyline *)overlay).renderer;
}
return nil;
}
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view { - (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view {
AMapMarker *marker = (AMapMarker *) view.annotation; AMapMarker *marker = (AMapMarker *) view.annotation;
if (marker.onPress) { if (marker.onPress) {
......
#import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h>
@interface Coordinate : NSObject
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate;
@end
\ No newline at end of file
#import "Coordinate.h"
@implementation Coordinate {
}
- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
self = [super init];
self.coordinate = coordinate;
return self;
}
@end
\ No newline at end of file
...@@ -3,10 +3,4 @@ ...@@ -3,10 +3,4 @@
@implementation RCTConvert (AMapMarker) @implementation RCTConvert (AMapMarker)
RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
@"red": @(MAPinAnnotationColorRed),
@"green": @(MAPinAnnotationColorGreen),
@"purple": @(MAPinAnnotationColorPurple),
}), MAPinAnnotationColorRed, integerValue)
@end @end
#import <MAMapKit/MAMapView.h> #import <MAMapKit/MAMapView.h>
#import <React/RCTConvert.h> #import <React/RCTConvert.h>
#import <React/RCTConvert+CoreLocation.h>
#import "Coordinate.h"
@implementation RCTConvert (AMapView) @implementation RCTConvert (AMapView)
...@@ -11,4 +13,16 @@ RCT_ENUM_CONVERTER(MAMapType, (@{ ...@@ -11,4 +13,16 @@ RCT_ENUM_CONVERTER(MAMapType, (@{
@"bus": @(MAMapTypeBus), @"bus": @(MAMapTypeBus),
}), MAMapTypeStandard, integerValue) }), MAMapTypeStandard, integerValue)
RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
@"red": @(MAPinAnnotationColorRed),
@"green": @(MAPinAnnotationColorGreen),
@"purple": @(MAPinAnnotationColorPurple),
}), MAPinAnnotationColorRed, integerValue)
+ (Coordinate *)Coordinate:(id)json {
return [[Coordinate alloc] initWithCoordinate: [self CLLocationCoordinate2D:json]];
}
RCT_ARRAY_CONVERTER(Coordinate)
@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