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,40 @@
//
// AMapMarkerController.h
// amap_map
//
// Created by lly on 2020/11/3.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapMarker;
@interface AMapMarkerController : NSObject
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar;
- (nullable AMapMarker *)markerForId:(NSString *)markerId;
- (void)addMarkers:(NSArray*)markersToAdd;
- (void)changeMarkers:(NSArray*)markersToChange;
- (void)removeMarkerIds:(NSArray*)markerIdsToRemove;
//MARK: Marker的回调
- (BOOL)onMarkerTap:(NSString*)markerId;
- (BOOL)onMarker:(NSString *)markerId endPostion:(CLLocationCoordinate2D)position;
//- (BOOL)onInfoWindowTap:(NSString *)markerId;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,153 @@
//
// AMapMarkerController.m
// amap_map
//
// Created by lly on 2020/11/3.
//
#import "AMapMarkerController.h"
#import "AMapMarker.h"
#import "AMapJsonUtils.h"
#import "AMapConvertUtil.h"
#import "MAAnnotationView+Flutter.h"
#import "FlutterMethodChannel+MethodCallDispatch.h"
@interface AMapMarkerController ()
@property (nonatomic,strong) NSMutableDictionary<NSString*,AMapMarker*> *markerDict;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,strong) NSObject<FlutterPluginRegistrar> *registrar;
@property (nonatomic,strong) MAMapView *mapView;
@end
@implementation AMapMarkerController
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar {
self = [super init];
if (self) {
_methodChannel = methodChannel;
_mapView = mapView;
_markerDict = [NSMutableDictionary dictionaryWithCapacity:1];
_registrar = registrar;
__weak typeof(self) weakSelf = self;
[_methodChannel addMethodName:@"markers#update" withHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
id markersToAdd = call.arguments[@"markersToAdd"];
if ([markersToAdd isKindOfClass:[NSArray class]]) {
[weakSelf addMarkers:markersToAdd];
}
id markersToChange = call.arguments[@"markersToChange"];
if ([markersToChange isKindOfClass:[NSArray class]]) {
[weakSelf changeMarkers:markersToChange];
}
id markerIdsToRemove = call.arguments[@"markerIdsToRemove"];
if ([markerIdsToRemove isKindOfClass:[NSArray class]]) {
[weakSelf removeMarkerIds:markerIdsToRemove];
}
result(nil);
}];
}
return self;
}
- (nullable AMapMarker *)markerForId:(NSString *)markerId {
return _markerDict[markerId];
}
- (void)addMarkers:(NSArray*)markersToAdd {
for (NSDictionary* marker in markersToAdd) {
AMapMarker *markerModel = [AMapJsonUtils modelFromDict:marker modelClass:[AMapMarker class]];
//bitmapDescUIImage
if (markerModel.icon) {
markerModel.image = [AMapConvertUtil imageFromRegistrar:self.registrar iconData:markerModel.icon];
}
// marker
if (markerModel.id_) {
_markerDict[markerModel.id_] = markerModel;
}
[self.mapView addAnnotation:markerModel.annotation];
}
}
- (void)changeMarkers:(NSArray*)markersToChange {
for (NSDictionary* markerToChange in markersToChange) {
NSLog(@"changeMarker:%@",markerToChange);
AMapMarker *markerModelToChange = [AMapJsonUtils modelFromDict:markerToChange modelClass:[AMapMarker class]];
AMapMarker *currentMarkerModel = _markerDict[markerModelToChange.id_];
NSAssert(currentMarkerModel != nil, @"需要修改的marker不存在");
//
if ([AMapConvertUtil checkIconDescriptionChangedFrom:currentMarkerModel.icon to:markerModelToChange.icon]) {
UIImage *image = [AMapConvertUtil imageFromRegistrar:self.registrar iconData:markerModelToChange.icon];
currentMarkerModel.icon = markerModelToChange.icon;
currentMarkerModel.image = image;
}
//
[currentMarkerModel updateMarker:markerModelToChange];
MAAnnotationView *view = [self.mapView viewForAnnotation:currentMarkerModel.annotation];
if (view) {//View
[view updateViewWithMarker:currentMarkerModel];
} //viewDidAddview
}
}
- (void)removeMarkerIds:(NSArray*)markerIdsToRemove {
for (NSString* markerId in markerIdsToRemove) {
if (!markerId) {
continue;
}
AMapMarker* marker = _markerDict[markerId];
if (!marker) {
continue;
}
[self.mapView removeAnnotation:marker.annotation];
[_markerDict removeObjectForKey:markerId];
}
}
//MARK: Marker
- (BOOL)onMarkerTap:(NSString*)markerId {
if (!markerId) {
return NO;
}
AMapMarker* marker = _markerDict[markerId];
if (!marker) {
return NO;
}
[_methodChannel invokeMethod:@"marker#onTap" arguments:@{@"markerId" : markerId}];
return YES;
}
- (BOOL)onMarker:(NSString *)markerId endPostion:(CLLocationCoordinate2D)position {
if (!markerId) {
return NO;
}
AMapMarker* marker = _markerDict[markerId];
if (!marker) {
return NO;
}
[_methodChannel invokeMethod:@"marker#onDragEnd"
arguments:@{@"markerId" : markerId, @"position" : [AMapConvertUtil jsonArrayFromCoordinate:position]}];
return YES;
}
//- (BOOL)onInfoWindowTap:(NSString *)markerId {
// if (!markerId) {
// return NO;
// }
// AMapMarker* marker = _markerDict[markerId];
// if (!marker) {
// return NO;
// }
// [_methodChannel invokeMethod:@"infoWindow#onTap" arguments:@{@"markerId" : markerId}];
// return YES;
//}
@end

View File

@ -0,0 +1,33 @@
//
// AMapPolygonController.h
// amap_map
//
// Created by lly on 2020/11/12.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapPolyline;
@class AMapPolygon;
@interface AMapPolygonController : NSObject
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar;
- (nullable AMapPolygon *)polygonForId:(NSString *)polygonId;
- (void)addPolygons:(NSArray*)polygonsToAdd;
- (void)changePolygons:(NSArray*)polygonsToChange;
- (void)removePolygonIds:(NSArray*)polygonIdsToRemove;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,99 @@
//
// AMapPolygonController.m
// amap_map
//
// Created by lly on 2020/11/12.
//
#import "AMapPolygonController.h"
#import "AMapPolygon.h"
#import "AMapJsonUtils.h"
#import "MAPolygon+Flutter.h"
#import "MAPolygonRenderer+Flutter.h"
#import "FlutterMethodChannel+MethodCallDispatch.h"
@interface AMapPolygonController ()
@property (nonatomic,strong) NSMutableDictionary<NSString*,AMapPolygon*> *polygonDict;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,strong) NSObject<FlutterPluginRegistrar> *registrar;
@property (nonatomic,strong) MAMapView *mapView;
@end
@implementation AMapPolygonController
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar {
self = [super init];
if (self) {
_methodChannel = methodChannel;
_mapView = mapView;
_polygonDict = [NSMutableDictionary dictionaryWithCapacity:1];
_registrar = registrar;
__weak typeof(self) weakSelf = self;
[_methodChannel addMethodName:@"polygons#update" withHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
id polygonsToAdd = call.arguments[@"polygonsToAdd"];
if ([polygonsToAdd isKindOfClass:[NSArray class]]) {
[weakSelf addPolygons:polygonsToAdd];
}
id polygonsToChange = call.arguments[@"polygonsToChange"];
if ([polygonsToChange isKindOfClass:[NSArray class]]) {
[weakSelf changePolygons:polygonsToChange];
}
id polygonIdsToRemove = call.arguments[@"polygonIdsToRemove"];
if ([polygonIdsToRemove isKindOfClass:[NSArray class]]) {
[weakSelf removePolygonIds:polygonIdsToRemove];
}
result(nil);
}];
}
return self;
}
- (nullable AMapPolygon *)polygonForId:(NSString *)polygonId {
return _polygonDict[polygonId];
}
- (void)addPolygons:(NSArray*)polygonsToAdd {
for (NSDictionary* polygonDict in polygonsToAdd) {
AMapPolygon *polygon = [AMapJsonUtils modelFromDict:polygonDict modelClass:[AMapPolygon class]];
// overlay
if (polygon.id_) {
_polygonDict[polygon.id_] = polygon;
}
[self.mapView addOverlay:polygon.polygon];
}
}
- (void)changePolygons:(NSArray*)polygonsToChange {
for (NSDictionary* polygonDict in polygonsToChange) {
AMapPolygon *polygon = [AMapJsonUtils modelFromDict:polygonDict modelClass:[AMapPolygon class]];
AMapPolygon *currentPolygon = _polygonDict[polygon.id_];
NSAssert(currentPolygon != nil, @"需要修改的Polygon不存在");
[currentPolygon updatePolygon:polygon];
MAOverlayRenderer *render = [self.mapView rendererForOverlay:currentPolygon.polygon];
if (render && [render isKindOfClass:[MAPolygonRenderer class]]) { // render
[(MAPolygonRenderer *)render updateRenderWithPolygon:currentPolygon];
}
}
}
- (void)removePolygonIds:(NSArray*)polygonIdsToRemove {
for (NSString* polygonId in polygonIdsToRemove) {
if (!polygonId) {
continue;
}
AMapPolygon* polygon = _polygonDict[polygonId];
if (!polygon) {
continue;
}
[self.mapView removeOverlay:polygon.polygon];
[_polygonDict removeObjectForKey:polygonId];
}
}
@end

View File

@ -0,0 +1,34 @@
//
// AMapPolylineController.h
// amap_map
//
// Created by lly on 2020/11/6.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import <MAMapKit/MAMapKit.h>
NS_ASSUME_NONNULL_BEGIN
@class AMapPolyline;
@interface AMapPolylineController : NSObject
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar;
- (nullable AMapPolyline *)polylineForId:(NSString *)polylineId;
- (void)addPolylines:(NSArray*)polylinesToAdd;
- (void)changePolylines:(NSArray*)polylinesToChange;
- (void)removePolylineIds:(NSArray*)polylineIdsToRemove;
- (BOOL)onPolylineTap:(NSString*)polylineId;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,125 @@
//
// AMapPolylineController.m
// amap_map
//
// Created by lly on 2020/11/6.
//
#import "AMapPolylineController.h"
#import "AMapPolyline.h"
#import "AMapJsonUtils.h"
#import "AMapMarker.h"
#import "MAPolyline+Flutter.h"
#import "MAPolylineRenderer+Flutter.h"
#import "AMapConvertUtil.h"
#import "FlutterMethodChannel+MethodCallDispatch.h"
@interface AMapPolylineController ()
@property (nonatomic,strong) NSMutableDictionary<NSString*,AMapPolyline*> *polylineDict;
@property (nonatomic,strong) FlutterMethodChannel *methodChannel;
@property (nonatomic,strong) NSObject<FlutterPluginRegistrar> *registrar;
@property (nonatomic,strong) MAMapView *mapView;
@end
@implementation AMapPolylineController
- (instancetype)init:(FlutterMethodChannel*)methodChannel
mapView:(MAMapView*)mapView
registrar:(NSObject<FlutterPluginRegistrar>*)registrar {
self = [super init];
if (self) {
_methodChannel = methodChannel;
_mapView = mapView;
_polylineDict = [NSMutableDictionary dictionaryWithCapacity:1];
_registrar = registrar;
__weak typeof(self) weakSelf = self;
[_methodChannel addMethodName:@"polylines#update" withHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
id polylinesToAdd = call.arguments[@"polylinesToAdd"];
if ([polylinesToAdd isKindOfClass:[NSArray class]]) {
[weakSelf addPolylines:polylinesToAdd];
}
id polylinesToChange = call.arguments[@"polylinesToChange"];
if ([polylinesToChange isKindOfClass:[NSArray class]]) {
[weakSelf changePolylines:polylinesToChange];
}
id polylineIdsToRemove = call.arguments[@"polylineIdsToRemove"];
if ([polylineIdsToRemove isKindOfClass:[NSArray class]]) {
[weakSelf removePolylineIds:polylineIdsToRemove];
}
result(nil);
}];
}
return self;
}
- (nullable AMapPolyline *)polylineForId:(NSString *)polylineId {
return _polylineDict[polylineId];
}
- (void)addPolylines:(NSArray*)polylinesToAdd {
for (NSDictionary* polyline in polylinesToAdd) {
AMapPolyline *polylineModel = [AMapJsonUtils modelFromDict:polyline modelClass:[AMapPolyline class]];
if (polylineModel.customTexture) {
polylineModel.strokeImage = [AMapConvertUtil imageFromRegistrar:self.registrar iconData:polylineModel.customTexture];
}
// overlay
if (polylineModel.id_) {
_polylineDict[polylineModel.id_] = polylineModel;
}
[self.mapView addOverlay:polylineModel.polyline];
}
}
- (void)changePolylines:(NSArray*)polylinesToChange {
for (NSDictionary* polylineToChange in polylinesToChange) {
AMapPolyline *polyline = [AMapJsonUtils modelFromDict:polylineToChange modelClass:[AMapPolyline class]];
AMapPolyline *currentPolyline = _polylineDict[polyline.id_];
NSAssert(currentPolyline != nil, @"需要修改的Polyline不存在");
//
if ([AMapConvertUtil checkIconDescriptionChangedFrom:currentPolyline.customTexture to:polyline.customTexture]) {
currentPolyline.strokeImage = [AMapConvertUtil imageFromRegistrar:self.registrar iconData:polyline.customTexture];
currentPolyline.customTexture = polyline.customTexture;
}
//
[currentPolyline updatePolyline:polyline];
MAOverlayRenderer *render = [self.mapView rendererForOverlay:currentPolyline.polyline];
if (render && [render isKindOfClass:[MAPolylineRenderer class]]) { // render
[(MAPolylineRenderer *)render updateRenderWithPolyline:currentPolyline];
}
}
}
- (void)removePolylineIds:(NSArray*)polylineIdsToRemove {
for (NSString* polylineId in polylineIdsToRemove) {
if (!polylineId) {
continue;
}
AMapPolyline* polyline = _polylineDict[polylineId];
if (!polyline) {
continue;
}
[self.mapView removeOverlay:polyline.polyline];
[_polylineDict removeObjectForKey:polylineId];
}
}
//MARK: Marker
- (BOOL)onPolylineTap:(NSString*)polylineId {
if (!polylineId) {
return NO;
}
AMapPolyline* polyline = _polylineDict[polylineId];
if (!polyline) {
return NO;
}
[_methodChannel invokeMethod:@"polyline#onTap" arguments:@{@"polylineId" : polylineId}];
return YES;
}
@end