Commit 8d4247e8 authored by 放牛的园子's avatar 放牛的园子

平滑移动功能

parent c7ab4f9f
#import "AMapView.h"
#import "AMapCallout.h"
@interface AMapSmoothMoveMarker : UIView
@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 *)annotationView;
- (MAAnimatedAnnotation *)annotation;
- (void)setActive:(BOOL)active;
- (void)setMapView:(AMapView *)mapView;
- (void)lockToScreen:(int)x y:(int)y;
@end
#import <React/UIView+React.h>
#import "AMapSmoothMoveMarker.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
#pragma clang diagnostic ignored "-Woverriding-method-mismatch"
@implementation AMapSmoothMoveMarker {
MAAnimatedAnnotation *_annotation;//贴图标注
MAAnnotationView *_annotationView;//标注视图
MACustomCalloutView *_calloutView;//气泡视图
UIView *_customView;
__weak AMapView *_mapView;
MAPinAnnotationColor _pinColor;
UIImage *_image;
CGPoint _centerOffset;
BOOL _draggable;
BOOL _active;
BOOL _canShowCallout; //是否显示气泡
BOOL _enabled;
NSInteger _zIndex;
NSInteger _duration; //动画时间
}
- (instancetype)init {
_annotation = [MAAnimatedAnnotation new];
_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) {
_annotationView.image = _image;
}
}
- (void)setDescription:(NSString *)description {
_annotation.subtitle = description;
}
- (void)setCoordinates:(NSArray<Coordinate *> *)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) {
}];
}
- (void)setActive:(BOOL)active {
_active = active;
dispatch_async(dispatch_get_main_queue(), ^{
if (active) {
[_mapView selectAnnotation:_annotation animated:YES];
} else {
[_mapView deselectAnnotation:_annotation animated:YES];
}
});
}
- (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;
}
- (void)setMapView:(AMapView *)mapView {
_mapView = mapView;
}
- (void)_handleTap:(UITapGestureRecognizer *)recognizer {
[_mapView selectAnnotation:_annotation animated:YES];
}
- (MAAnnotationView *)annotationView {
if (_annotationView == nil) {
if (_customView) {
_customView.hidden = NO;
_annotationView = [[MAAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
_annotationView.bounds = _customView.bounds;
[_annotationView addSubview:_customView];
[_annotationView addGestureRecognizer:[
[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)]];
} else {
_annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
((MAPinAnnotationView *) _annotationView).pinColor = _pinColor;
}
_annotationView.enabled = _enabled;
_annotationView.canShowCallout = _canShowCallout;
_annotationView.draggable = _draggable;
_annotationView.customCalloutView = _calloutView;
_annotationView.centerOffset = _centerOffset;
if (_zIndex) {
_annotationView.zIndex = _zIndex;
}
if (_image != nil) {
_annotationView.image = _image;
}
[self setActive:_active];
}
return _annotationView;
}
- (void)didAddSubview:(UIView *)subview {
if ([subview isKindOfClass:[AMapCallout class]]) {
_calloutView = [[MACustomCalloutView alloc] initWithCustomView:subview];
_annotationView.customCalloutView = _calloutView;
} else {
_customView = subview;
_customView.hidden = YES;
}
}
- (void)lockToScreen:(int)x y:(int)y {
_annotation.lockedToScreen = YES;
_annotation.lockedScreenPoint = CGPointMake(x, y);
}
@end
#import <React/RCTUIManager.h>
#import "AMapSmoothMoveMarker.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapSmoothMoveMarkerManager : RCTViewManager
@end
@implementation AMapSmoothMoveMarkerManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapSmoothMoveMarker new];
}
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) {
AMapSmoothMoveMarker *marker = (AMapSmoothMoveMarker *) viewRegistry[reactTag];
[marker lockToScreen:x y:y];
}];
}
RCT_EXPORT_METHOD(active:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
AMapSmoothMoveMarker *marker = (AMapSmoothMoveMarker *) viewRegistry[reactTag];
marker.active = YES;
}];
}
@end
......@@ -8,11 +8,13 @@
@implementation AMapView {
NSMutableDictionary *_markers;
NSMutableDictionary *_smoothmarkers;
MAUserLocationRepresentation *_locationStyle;
}
- (instancetype)init {
_markers = [NSMutableDictionary new];
_smoothmarkers = [NSMutableDictionary new];
self = [super init];
return self;
}
......@@ -74,6 +76,14 @@
[self addAnnotation:marker.annotation];
});
}
if([subview isKindOfClass:[AMapSmoothMoveMarker class]]){
AMapSmoothMoveMarker *smoothmarker = (AMapSmoothMoveMarker *) subview;
marker.mapView = self;
_smoothmarker[[@(smoothmarker.annotation.hash) stringValue]] = smoothmarker;
dispatch_async(dispatch_get_main_queue(), ^{
[self addAnnotation:smoothmarker.annotation];
});
}
if ([subview isKindOfClass:[AMapOverlay class]]) {
[self addOverlay:(id <MAOverlay>) subview];
}
......@@ -85,6 +95,10 @@
AMapMarker *marker = (AMapMarker *) subview;
[self removeAnnotation:marker.annotation];
}
if ([subview isKindOfClass:[AMapSmoothMoveMarker class]]) {
AMapSmoothMoveMarker *smoothmarker = (AMapSmoothMoveMarker *) subview;
[self removeAnnotation:smoothmarker.annotation];
}
if ([subview isKindOfClass:[AMapOverlay class]]) {
[self removeOverlay:(id <MAOverlay>) subview];
}
......@@ -94,4 +108,8 @@
return _markers[[@(annotation.hash) stringValue]];
}
- (AMapSmoothMoveMarker *)getSmoothMarker:(id <MAAnimatedAnnotation>)annotation {
return _smoothmarkers[[@(annotation.hash) stringValue]];
}
@end
......@@ -2,6 +2,7 @@
#import "AMapView.h"
#import "AMapMarker.h"
#import "AMapOverlay.h"
#import "AMapSmoothMoveMarker.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
#pragma ide diagnostic ignored "-Woverriding-method-mismatch"
......@@ -108,6 +109,9 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
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