init project

This commit is contained in:
Kuloud
2023-12-22 21:23:24 +08:00
commit 1fb3d91106
461 changed files with 58770 additions and 0 deletions

View File

@ -0,0 +1,32 @@
//
// FlutterMethodChannel+MethodCallDispatch.h
// amap_map
//
// Created by lly on 2020/11/16.
//
#import <Flutter/Flutter.h>
#import "AMapMethodCallDispatcher.h"
NS_ASSUME_NONNULL_BEGIN
@interface FlutterMethodChannel (MethodCallDispatch)
@property (nonatomic,strong,readonly) AMapMethodCallDispatcher* methodCallDispatcher;
/// 添加methodCall的回调注意使用该方法之后就不能再调用setMethodCallHandler: 方法了)
/// @param methodName methodName对应call的唯一方法名
/// @param handler 回调处理
- (void)addMethodName:(NSString *)methodName withHandler:(FlutterMethodCallHandler)handler;
/// 移除methodCall对应的回调
/// @param methodName 唯一的方法名
- (void)removeHandlerWithMethodName:(NSString *)methodName;
/// 清空所有的handler
- (void)clearAllHandler;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,42 @@
//
// FlutterMethodChannel+MethodCallDispatch.m
// amap_map
//
// Created by lly on 2020/11/16.
//
#import "FlutterMethodChannel+MethodCallDispatch.h"
#import <objc/runtime.h>
@implementation FlutterMethodChannel (MethodCallDispatch)
- (AMapMethodCallDispatcher *)methodCallDispatcher {
return objc_getAssociatedObject(self, @selector(methodCallDispatcher));
}
- (void)setMethodCallDispatcher:(AMapMethodCallDispatcher *)dispatcher {
objc_setAssociatedObject(self, @selector(methodCallDispatcher), dispatcher, OBJC_ASSOCIATION_RETAIN);
}
- (void)addMethodName:(NSString *)methodName withHandler:(FlutterMethodCallHandler)handler {
if (self.methodCallDispatcher == nil) {
self.methodCallDispatcher = [[AMapMethodCallDispatcher alloc] init];
__weak typeof(self) weakSelf = self;
[self setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
if (weakSelf.methodCallDispatcher) {
[weakSelf.methodCallDispatcher onMethodCall:call result:result];
}
}];
}
[self.methodCallDispatcher addMethodName:methodName withHandler:handler];
}
- (void)removeHandlerWithMethodName:(NSString *)methodName {
[self.methodCallDispatcher removeHandlerWithMethodName:methodName];
}
- (void)clearAllHandler {
[self.methodCallDispatcher clearAllHandler];
}
@end

View File

@ -0,0 +1,20 @@
//
// MAAnnotationView+Flutter.h
// amap_map
//
// Created by lly on 2020/11/5.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapMarker;
@interface MAAnnotationView (Flutter)
- (void)updateViewWithMarker:(AMapMarker *)marker;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,40 @@
//
// MAAnnotationView+Flutter.m
// amap_map
//
// Created by lly on 2020/11/5.
//
#import "MAAnnotationView+Flutter.h"
#import "AMapMarker.h"
#import "AMapInfoWindow.h"
@implementation MAAnnotationView (Flutter)
- (void)updateViewWithMarker:(AMapMarker *)marker {
if (marker == nil) {
return;
}
self.alpha = marker.alpha;
self.image = marker.image;
//anchorcenterOffset
if (self.image) {
CGSize imageSize = self.image.size;
//iOSannotationViewannotation,0.50.5
CGFloat offsetW = imageSize.width * (0.5 - marker.anchor.x);
CGFloat offsetH = imageSize.height * (0.5 - marker.anchor.y);
self.centerOffset = CGPointMake(offsetW, offsetH);
}
self.enabled = marker.clickable;
self.draggable = marker.draggable;
// marker.flat;//flatiOS
self.canShowCallout = marker.infoWindowEnable;
// TODO: iOScalloutOffset
// self.calloutOffset = marker.infoWindow.anchor;
//
self.imageView.transform = CGAffineTransformMakeRotation(marker.rotation / 180.f * M_PI);
self.hidden = (!marker.visible);
self.zIndex = marker.zIndex;
}
@end

View File

@ -0,0 +1,30 @@
//
// MAMapView+Flutter.h
// amap_map
//
// Created by lly on 2020/10/30.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapCameraPosition;
@class AMapOption;
@protocol FlutterPluginRegistrar;
@interface MAMapView (Flutter)
- (void)setCameraPosition:(AMapCameraPosition *)cameraPosition animated:(BOOL)animated duration:(CFTimeInterval)duration;
/// 获取地图的当前cameraPostion
- (AMapCameraPosition *)getCurrentCameraPosition;
/// 地图camera更新操作
- (void)setCameraUpdateDict:(NSDictionary *)updateDict;
- (void)updateMapViewOption:(NSDictionary *)dict withRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,222 @@
//
// MAMapView+Flutter.m
// amap_map
//
// Created by lly on 2020/10/30.
//
#import "MAMapView+Flutter.h"
#import "AMapCameraPosition.h"
#import "AMapConvertUtil.h"
#import "AMapJsonUtils.h"
#import <Flutter/Flutter.h>
@implementation MAMapView (Flutter)
- (void)setCameraPosition:(AMapCameraPosition *)cameraPosition animated:(BOOL)animated duration:(CFTimeInterval)duration {
if (cameraPosition == nil) {
return;
}
MAMapStatus *mapStatus = [MAMapStatus statusWithCenterCoordinate:cameraPosition.target
zoomLevel:cameraPosition.zoom
rotationDegree:cameraPosition.bearing
cameraDegree:cameraPosition.tilt
screenAnchor:self.screenAnchor];
[self setMapStatus:mapStatus animated:animated duration:duration];
}
- (AMapCameraPosition *)getCurrentCameraPosition {
AMapCameraPosition *position = [[AMapCameraPosition alloc] init];
position.target = self.centerCoordinate;
position.zoom = self.zoomLevel;
position.bearing = self.rotationDegree;
position.tilt = self.cameraDegree;
return position;
}
- (void)setCameraUpdateDict:(NSDictionary *)updateDict {
if (updateDict == nil || updateDict.count == 0) {
return;
}
BOOL animated;
if ([updateDict[@"animated"] isKindOfClass:[NSNull class]]) {
animated = NO;
} else {
animated = [updateDict[@"animated"] boolValue];
}
double duration;
if ([updateDict[@"duration"] isKindOfClass:[NSNull class]]) {
duration = 0;
} else {
duration = [updateDict[@"duration"] doubleValue]/1000.0;
}
NSArray *cameraUpdate = updateDict[@"cameraUpdate"];
//
NSAssert(cameraUpdate.count >= 1, @"cameraUpdate 参数错误");
NSString *operation = cameraUpdate.firstObject;
if ([operation isEqualToString:@"newCameraPosition"] && cameraUpdate.count == 2) {//cameraPositon
AMapCameraPosition *newCameraPosition = [AMapJsonUtils modelFromDict:cameraUpdate[1] modelClass:[AMapCameraPosition class]];
[self setCameraPosition:newCameraPosition animated:animated duration:duration];
} else if ([operation isEqualToString:@"newLatLng"] && cameraUpdate.count == 2) {//
CLLocationCoordinate2D position = [AMapConvertUtil coordinateFromArray:cameraUpdate[1]];
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.centerCoordinate = position;
[self setMapStatus:currentStatus animated:animated duration:duration];
} else if ([operation isEqualToString:@"newLatLngBounds"] && cameraUpdate.count == 3) {//
// TODO: 使duration
MAMapRect boundRect = [AMapConvertUtil mapRectFromArray:cameraUpdate[1]];
double padding = [cameraUpdate[2] doubleValue];
UIEdgeInsets inset = UIEdgeInsetsMake(padding, padding, padding, padding);
[self setVisibleMapRect:boundRect edgePadding:inset animated:animated];
} else if ([operation isEqualToString:@"newLatLngZoom"] && cameraUpdate.count == 3) {//zoomLevel
CLLocationCoordinate2D position = [AMapConvertUtil coordinateFromArray:cameraUpdate[1]];
CGFloat zoomLevel = [cameraUpdate[2] floatValue];
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.centerCoordinate = position;
currentStatus.zoomLevel = zoomLevel;
[self setMapStatus:currentStatus animated:animated duration:duration];
} else if ([operation isEqualToString:@"scrollBy"] && cameraUpdate.count == 3) {//
CGPoint pixelPointOffset = CGPointMake([cameraUpdate[1] doubleValue], [cameraUpdate[2] doubleValue]);
CGPoint updateCenter = CGPointMake(self.center.x + pixelPointOffset.x/[UIScreen mainScreen].scale, self.center.y + pixelPointOffset.y/[UIScreen mainScreen].scale);
CLLocationCoordinate2D centerCoord = [self convertPoint:updateCenter toCoordinateFromView:self];
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.centerCoordinate = centerCoord;
[self setMapStatus:currentStatus animated:animated duration:duration];
} else if ([operation isEqualToString:@"zoomIn"]) {
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.zoomLevel = currentStatus.zoomLevel + 1;
[self setMapStatus:currentStatus animated:animated duration:duration];
} else if ([operation isEqualToString:@"zoomOut"]) {
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.zoomLevel = currentStatus.zoomLevel - 1;
[self setMapStatus:currentStatus animated:animated duration:duration];
} else if ([operation isEqualToString:@"zoomTo"] && cameraUpdate.count == 2) {
MAMapStatus *currentStatus = [self getMapStatus];
currentStatus.zoomLevel = [cameraUpdate[1] doubleValue];
[self setMapStatus:currentStatus animated:animated duration:duration];
}
}
- (void)updateMapViewOption:(NSDictionary *)dict withRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
if ([dict isKindOfClass:[NSDictionary class]] == NO || dict == nil || dict.count == 0) {
return;
}
//
NSNumber *mapType = dict[@"mapType"];
if (mapType) {
self.mapType = mapType.integerValue;
}
NSDictionary *customStyleOptions = dict[@"customStyleOptions"];
if (customStyleOptions) {
BOOL customMapStyleEnabled = [customStyleOptions[@"enabled"] boolValue];
self.customMapStyleEnabled = customMapStyleEnabled;
if (customMapStyleEnabled) {
MAMapCustomStyleOptions *styleOption = [[MAMapCustomStyleOptions alloc] init];
styleOption.styleData = ((FlutterStandardTypedData*)customStyleOptions[@"styleData"]).data;
styleOption.styleExtraData = ((FlutterStandardTypedData*)customStyleOptions[@"styleExtraData"]).data;
[self setCustomMapStyleOptions:styleOption];
}
}
NSDictionary *locationStyleDict = dict[@"myLocationStyle"];
if (locationStyleDict) {
BOOL showUserLocation = [locationStyleDict[@"enabled"] boolValue];
self.showsUserLocation = showUserLocation;
if (showUserLocation) {
self.userTrackingMode = MAUserTrackingModeNone;//demo使
if (locationStyleDict[@"circleFillColor"] != nil
|| locationStyleDict[@"circleStrokeColor"] != nil
|| locationStyleDict[@"circleStrokeWidth"] != nil
|| locationStyleDict[@"icon"] != nil) {//
MAUserLocationRepresentation *locationStyle = [[MAUserLocationRepresentation alloc] init];
if (locationStyleDict[@"circleFillColor"]) {
locationStyle.fillColor = [AMapConvertUtil colorFromNumber:locationStyleDict[@"circleFillColor"]];
}
if (locationStyleDict[@"circleStrokeColor"]) {
locationStyle.strokeColor = [AMapConvertUtil colorFromNumber:locationStyleDict[@"circleStrokeColor"]];
}
if (locationStyleDict[@"circleStrokeWidth"]) {
locationStyle.lineWidth = [locationStyleDict[@"circleStrokeWidth"] doubleValue];
}
if (locationStyleDict[@"icon"]) {
locationStyle.image = [AMapConvertUtil imageFromRegistrar:registrar iconData:locationStyleDict[@"icon"]];
}
[self updateUserLocationRepresentation:locationStyle];
}
}
}
///
NSArray *screenAnchor = dict[@"screenAnchor"];
if (screenAnchor) {
CGPoint anchorPoint = [AMapConvertUtil pointFromArray:screenAnchor];
self.screenAnchor = anchorPoint;
}
//
NSArray* zoomData = dict[@"minMaxZoomPreference"];
if (zoomData) {
CGFloat minZoom = (zoomData[0] == [NSNull null]) ? 3.0 : [zoomData[0] doubleValue];
self.minZoomLevel = minZoom;
CGFloat maxZoom = (zoomData[1] == [NSNull null]) ? 20.0 : [zoomData[1] doubleValue];
self.maxZoomLevel = maxZoom;
}
NSArray *limitBounds = dict[@"limitBounds"];
if (limitBounds) {
MAMapRect limitRect = [AMapConvertUtil mapRectFromArray:limitBounds];
self.limitMapRect = limitRect;
}
//
NSNumber *showTraffic = dict[@"trafficEnabled"];
if (showTraffic) {
self.showTraffic = [showTraffic boolValue];
}
// poi
NSNumber *touchPOIEnable = dict[@"touchPoiEnabled"];
if (touchPOIEnable) {
self.touchPOIEnabled = [touchPOIEnable boolValue];
}
//3D
NSNumber *showBuilding = dict[@"buildingsEnabled"];
if (showBuilding) {
self.showsBuildings = [showBuilding boolValue];
}
//
NSNumber *showLable = dict[@"labelsEnabled"];
if (showLable) {
self.showsLabels = [showLable boolValue];
}
//
NSNumber *showCompass = dict[@"compassEnabled"];
if (showCompass) {
self.showsCompass = [showCompass boolValue];
}
//
NSNumber *showScale = dict[@"scaleEnabled"];
if (showScale) {
self.showsScale = [showScale boolValue];
}
//
NSNumber *zoomEnable = dict[@"zoomGesturesEnabled"];
if (zoomEnable) {
self.zoomEnabled = [zoomEnable boolValue];
}
//
NSNumber *scrollEnable = dict[@"scrollGesturesEnabled"];
if (scrollEnable) {
self.scrollEnabled = [scrollEnable boolValue];
}
//
NSNumber *rotateEnable = dict[@"rotateGesturesEnabled"];
if (rotateEnable) {
self.rotateEnabled = [rotateEnable boolValue];
}
//
NSNumber *rotateCameraEnable = dict[@"tiltGesturesEnabled"];
if (rotateCameraEnable) {
self.rotateCameraEnabled = [rotateCameraEnable boolValue];
}
}
@end

View File

@ -0,0 +1,29 @@
//
// MAPointAnnotation+Flutter.h
// amap_map
//
// Created by lly on 2020/11/9.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
/// AnnotationView的复用标识
extern NSString *const AMapFlutterAnnotationViewIdentifier;
/// 该拓展类型主要用于对地图原PointAnnotation添加一个唯一id,
/// 便于在地图回调代理中通过id快速找到对应的AMapMarker对象
/// 以此来构建对应的MAAnnotatioView
@interface MAPointAnnotation (Flutter)
//为Annotation拓展存储的flutter传入的markerId,便于快速查找对应的marker数据
@property (nullable,nonatomic,copy,readonly) NSString *markerId;
/// 使用MarkerId初始化对应的Annotation
/// @param markerId marker的唯一标识
- (instancetype)initWithMarkerId:(NSString *)markerId;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,31 @@
//
// MAPointAnnotation+Flutter.m
// amap_map
//
// Created by lly on 2020/11/9.
//
#import "MAPointAnnotation+Flutter.h"
#import <objc/runtime.h>
NSString *const AMapFlutterAnnotationViewIdentifier = @"AMapFlutterAnnotationViewIdentifier";
@implementation MAPointAnnotation (Flutter)
- (NSString *)markerId {
return objc_getAssociatedObject(self, @selector(markerId));
}
- (void)setMarkerId:(NSString * _Nonnull)markerId {
objc_setAssociatedObject(self, @selector(markerId), markerId, OBJC_ASSOCIATION_COPY);
}
- (instancetype)initWithMarkerId:(NSString *)markerId {
self = [super init];
if (self) {
self.markerId = markerId;
}
return self;
}
@end

View File

@ -0,0 +1,26 @@
//
// MAPolygon+Flutter.h
// amap_map
//
// Created by lly on 2020/11/12.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 该拓展类型主要用于对地图原MAPolygon添加一个唯一id,
/// 便于在地图回调代理中通过id快速找到对应的AMapPolyline对象
/// 以此来构建对应的polygonRender
@interface MAPolygon (Flutter)
@property (nonatomic,copy,readonly) NSString *polygonId;
/// 使用polygonId初始化对应的MAPolygon
/// @param polygonId polylgon的唯一标识
- (instancetype)initWithPolygonId:(NSString *)polygonId;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,29 @@
//
// MAPolygon+Flutter.m
// amap_map
//
// Created by lly on 2020/11/12.
//
#import "MAPolygon+Flutter.h"
#import <objc/runtime.h>
@implementation MAPolygon (Flutter)
- (NSString *)polygonId {
return objc_getAssociatedObject(self, @selector(polygonId));
}
- (void)setPolygonId:(NSString * _Nonnull)polygonId {
objc_setAssociatedObject(self, @selector(polygonId), polygonId, OBJC_ASSOCIATION_COPY);
}
- (instancetype)initWithPolygonId:(NSString *)polygonId {
self = [super init];
if (self) {
self.polygonId = polygonId;
}
return self;
}
@end

View File

@ -0,0 +1,20 @@
//
// MAPolygonRenderer+Flutter.h
// amap_map
//
// Created by lly on 2020/11/12.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapPolygon;
@interface MAPolygonRenderer (Flutter)
- (void)updateRenderWithPolygon:(AMapPolygon *)polygon;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,26 @@
//
// MAPolygonRenderer+Flutter.m
// amap_map
//
// Created by lly on 2020/11/12.
//
#import "MAPolygonRenderer+Flutter.h"
#import "AMapPolygon.h"
@implementation MAPolygonRenderer (Flutter)
- (void)updateRenderWithPolygon:(AMapPolygon *)polygon {
self.lineWidth = polygon.strokeWidth;
self.strokeColor = polygon.strokeColor;
self.fillColor = polygon.fillColor;
self.lineJoinType = polygon.joinType;
if (polygon.visible) {
self.alpha = 1.0;
} else {
self.alpha = 0;
}
}
@end

View File

@ -0,0 +1,26 @@
//
// MAPolyline+Flutter.h
// amap_map
//
// Created by lly on 2020/11/9.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 该拓展类型主要用于对地图原MAPolyline添加一个唯一id,
/// 便于在地图回调代理中通过id快速找到对应的AMapPolyline对象
/// 以此来构建对应的polylineRender
@interface MAPolyline (Flutter)
@property (nonatomic,copy,readonly) NSString *polylineId;
/// 使用polylineId初始化对应的MAPolyline
/// @param polylineId polyline的唯一标识
- (instancetype)initWithPolylineId:(NSString *)polylineId;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,29 @@
//
// MAPolyline+Flutter.m
// amap_map
//
// Created by lly on 2020/11/9.
//
#import "MAPolyline+Flutter.h"
#import <objc/runtime.h>
@implementation MAPolyline (Flutter)
- (NSString *)polylineId {
return objc_getAssociatedObject(self, @selector(polylineId));
}
- (void)setPolylineId:(NSString * _Nonnull)polylineId {
objc_setAssociatedObject(self, @selector(polylineId), polylineId, OBJC_ASSOCIATION_COPY);
}
- (instancetype)initWithPolylineId:(NSString *)polylineId {
self = [super init];
if (self) {
self.polylineId = polylineId;
}
return self;
}
@end

View File

@ -0,0 +1,20 @@
//
// MAPolylineRenderer+Flutter.h
// amap_map
//
// Created by lly on 2020/11/7.
//
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapPolyline;
@interface MAPolylineRenderer (Flutter)
- (void)updateRenderWithPolyline:(AMapPolyline *)polyline;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,30 @@
//
// MAPolylineRenderer+Flutter.m
// amap_map
//
// Created by lly on 2020/11/7.
//
#import "MAPolylineRenderer+Flutter.h"
#import "AMapPolyline.h"
@implementation MAPolylineRenderer (Flutter)
- (void)updateRenderWithPolyline:(AMapPolyline *)polyline {
self.lineWidth = polyline.width;
self.strokeColor = polyline.color;
if (polyline.visible) {//
self.alpha = polyline.alpha;
} else {
self.alpha = 0;
}
if (polyline.strokeImage) {
self.strokeImage = polyline.strokeImage;
}
self.lineDashType = polyline.dashLineType;
self.lineJoinType = polyline.joinType;
self.lineCapType = polyline.capType;
self.userInteractionEnabled = YES;//
}
@end