Commit 2b481e32 authored by 放牛的园子's avatar 放牛的园子

完成SmoothMoveMarker动画插件开发

parent 8d4247e8
#import <React/UIView+React.h>
#import "AMapSmoothMoveMarker.h"
#import "Coordinate.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
#pragma clang diagnostic ignored "-Woverriding-method-mismatch"
......@@ -8,6 +9,7 @@
MAAnimatedAnnotation *_annotation;//贴图标注
MAAnnotationView *_annotationView;//标注视图
MACustomCalloutView *_calloutView;//气泡视图
NSMutableArray<Coordinate *> *_coordinates;//
UIView *_customView;
__weak AMapView *_mapView;
MAPinAnnotationColor _pinColor;
......@@ -23,43 +25,17 @@
- (instancetype)init {
_annotation = [MAAnimatedAnnotation new];
_coordinates = [[NSMutableArray alloc] init];
_enabled = YES;
_canShowCallout = YES;
self = [super init];
return self;
}
- (NSString *)title {
return _annotation.title;
}
- (NSString *)subtitle {
return _annotation.subtitle;
}
- (void)setTitle:(NSString *)title {
_annotation.title = title;
}
- (void)setDuration:(NSInteger)duration {
_duration = duration;
}
- (void)setColor:(MAPinAnnotationColor)color {
_pinColor = color;
((MAPinAnnotationView *) _annotationView).pinColor = color;
}
- (void)setDraggable:(BOOL)draggable {
_draggable = draggable;
_annotationView.draggable = draggable;
}
- (void)setCenterOffset:(CGPoint)centerOffset {
_centerOffset = centerOffset;
_annotationView.centerOffset = centerOffset;
}
- (void)setImage:(NSString *)name {
_image = [UIImage imageNamed:name];
if (_image != nil) {
......@@ -67,17 +43,18 @@
}
}
- (void)setDescription:(NSString *)description {
_annotation.subtitle = description;
}
- (void)setCoordinates:(NSArray<Coordinate *> *)coordinates {
[_coordinates removeAllObjects];
[_coordinates addObjectsFromArray:coordinates];
CLLocationCoordinate2D coords[coordinates.count];
for (NSUInteger i = 0; i < coordinates.count; i++) {
coords[i] = coordinates[i].coordinate;
}
[_annotation addMoveAnimationWithKeyCoordinates coordinates:coords count:coordinates.count withDuration:_duration withName:nil completeCallback:^(BOOL isFinished) {
}];
_annotation.coordinate = coords[0];
_annotation.title = @"I can fly!";
if(_annotationView != nil) {
[_annotation addMoveAnimationWithKeyCoordinates:coords count:coordinates.count withDuration:_duration withName:nil completeCallback:^(BOOL isFinished) { }];
}
}
- (void)setActive:(BOOL)active {
......@@ -91,21 +68,6 @@
});
}
- (void)setInfoWindowDisabled:(BOOL)disabled {
_canShowCallout = !disabled;
_annotationView.canShowCallout = !disabled;
}
- (void)setClickDisabled:(BOOL)disabled {
_enabled = !disabled;
_annotationView.enabled = !disabled;
}
- (void)setZIndex:(NSInteger)zIndex {
_zIndex = zIndex;
_annotationView.zIndex = zIndex;
}
- (MAAnimatedAnnotation *)annotation {
return _annotation;
}
......@@ -145,8 +107,12 @@
if (_image != nil) {
_annotationView.image = _image;
}
[self setActive:_active];
CLLocationCoordinate2D coords[_coordinates.count];
for (NSUInteger i = 0; i < _coordinates.count; i++) {
coords[i] = _coordinates[i].coordinate;
}
[_annotation addMoveAnimationWithKeyCoordinates:coords count:_coordinates.count withDuration:_duration withName:nil completeCallback:^(BOOL isFinished) { }];
[self setActive:_active];
}
return _annotationView;
}
......
......@@ -17,22 +17,10 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(coordinates, CoordinateArray)
RCT_EXPORT_VIEW_PROPERTY(duration, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(centerOffset, CGPoint)
RCT_EXPORT_VIEW_PROPERTY(title, NSString)
RCT_EXPORT_VIEW_PROPERTY(description, NSString)
RCT_EXPORT_VIEW_PROPERTY(active, BOOL)
RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
RCT_EXPORT_VIEW_PROPERTY(clickDisabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(infoWindowDisabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(color, MAPinAnnotationColor)
RCT_EXPORT_VIEW_PROPERTY(image, NSString)
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)
RCT_EXPORT_METHOD(lockToScreen:(nonnull NSNumber *)reactTag x:(int)x y:(int)y) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
......
#import <MAMapKit/MAMapKit.h>
@class AMapMarker;
@class AMapSmoothMoveMarker;
@interface AMapView : MAMapView
......@@ -14,5 +15,5 @@
@property(nonatomic) MACoordinateRegion initialRegion;
- (AMapMarker *)getMarker:(id <MAAnnotation>)annotation;
- (AMapSmoothMoveMarker *)getSmoothMarker:(id <MAAnnotation>)annotation;
@end
\ No newline at end of file
#import <React/UIView+React.h>
#import "AMapView.h"
#import "AMapMarker.h"
#import "AMapSmoothMoveMarker.h"
#import "AMapPolyline.h"
#import "LocationStyle.h"
......@@ -78,8 +79,8 @@
}
if([subview isKindOfClass:[AMapSmoothMoveMarker class]]){
AMapSmoothMoveMarker *smoothmarker = (AMapSmoothMoveMarker *) subview;
marker.mapView = self;
_smoothmarker[[@(smoothmarker.annotation.hash) stringValue]] = smoothmarker;
smoothmarker.mapView = self;
_smoothmarkers[[@(smoothmarker.annotation.hash) stringValue]] = smoothmarker;
dispatch_async(dispatch_get_main_queue(), ^{
[self addAnnotation:smoothmarker.annotation];
});
......@@ -108,7 +109,7 @@
return _markers[[@(annotation.hash) stringValue]];
}
- (AMapSmoothMoveMarker *)getSmoothMarker:(id <MAAnimatedAnnotation>)annotation {
- (AMapSmoothMoveMarker *)getSmoothMarker:(id <MAAnnotation>)annotation {
return _smoothmarkers[[@(annotation.hash) stringValue]];
}
......
......@@ -106,12 +106,13 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
}
- (MAAnnotationView *)mapView:(AMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation {
if ([annotation isKindOfClass:[MAAnimatedAnnotation class]]) {
AMapSmoothMoveMarker *marker = [mapView getSmoothMarker:annotation];
return marker.annotationView;
}
if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
AMapMarker *marker = [mapView getMarker:annotation];
return marker.annotationView;
} else if ([annotation isKindOfClass:[MAAnimatedAnnotation class]]) {
AMapSmoothMoveMarker *marker = [mapView getSmoothMarker:annotation];
return marker.annotationView;
}
return nil;
}
......
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