MAMapView.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. //
  2. // MAMapView.h
  3. // MAMapKit
  4. //
  5. // Created by 翁乐 on 3/17/16.
  6. // Copyright © 2016 Amap. All rights reserved.
  7. //
  8. #import "MAConfig.h"
  9. #import <Foundation/Foundation.h>
  10. #import <UIKit/UIKit.h>
  11. #import "MAOverlay.h"
  12. #import "MAOverlayRenderer.h"
  13. #import "MAAnnotationView.h"
  14. #import "MACircle.h"
  15. #import "MAUserLocation.h"
  16. #import "MAMapStatus.h"
  17. #import "MAIndoorInfo.h"
  18. #import "MAUserLocationRepresentation.h"
  19. #import "MAMapCustomStyleOptions.h"
  20. ///地图类型
  21. typedef NS_ENUM(NSInteger, MAMapType)
  22. {
  23. MAMapTypeStandard = 0, ///< 普通地图
  24. MAMapTypeSatellite, ///< 卫星地图
  25. MAMapTypeStandardNight, ///< 夜间视图
  26. MAMapTypeNavi, ///< 导航视图
  27. MAMapTypeBus ///< 公交视图
  28. };
  29. ///用户跟踪模式
  30. typedef NS_ENUM(NSInteger, MAUserTrackingMode)
  31. {
  32. MAUserTrackingModeNone = 0, ///< 不追踪用户的location更新
  33. MAUserTrackingModeFollow = 1, ///< 追踪用户的location更新
  34. MAUserTrackingModeFollowWithHeading = 2 ///< 追踪用户的location与heading更新
  35. };
  36. ///交通拥堵状态
  37. typedef NS_ENUM(NSInteger, MATrafficStatus)
  38. {
  39. MATrafficStatusSmooth = 1, ///< 1 通畅
  40. MATrafficStatusSlow, ///< 2 缓行
  41. MATrafficStatusJam, ///< 3 阻塞
  42. MATrafficStatusSeriousJam, ///< 4 严重阻塞
  43. };
  44. ///绘制overlay的层级
  45. typedef NS_ENUM(NSInteger, MAOverlayLevel) {
  46. MAOverlayLevelAboveRoads = 0, ///< 在地图底图标注和兴趣点图标之下绘制overlay
  47. MAOverlayLevelAboveLabels ///< 在地图底图标注和兴趣点图标之上绘制overlay
  48. };
  49. #pragma mark - 动画相关的key
  50. ///中心点(MAMapPoint)key, 封装成[NSValue valueWithMAMapPoint:]
  51. extern NSString * const kMAMapLayerCenterMapPointKey;
  52. ///缩放级别key, 范围[minZoomLevel, maxZoomLevel], 封装成NSNumber
  53. extern NSString * const kMAMapLayerZoomLevelKey;
  54. ///旋转角度key, 范围[0, 360), 封装成NSNumber
  55. extern NSString * const kMAMapLayerRotationDegreeKey;
  56. ///摄像机俯视角度, 范围[0, 45], 封装成NSNumber
  57. extern NSString * const kMAMapLayerCameraDegreeKey;
  58. @protocol MAMapViewDelegate;
  59. @interface MAMapView : UIView
  60. ///地图view的delegate
  61. @property (nonatomic, weak) id<MAMapViewDelegate> delegate;
  62. ///地图类型
  63. @property (nonatomic) MAMapType mapType;
  64. ///当前地图的中心点,改变该值时,地图的比例尺级别不会发生变化
  65. @property (nonatomic) CLLocationCoordinate2D centerCoordinate;
  66. ///当前地图的经纬度范围,设定的该范围可能会被调整为适合地图窗口显示的范围
  67. @property (nonatomic) MACoordinateRegion region;
  68. ///可见区域, 设定的该范围可能会被调整为适合地图窗口显示的范围
  69. @property (nonatomic) MAMapRect visibleMapRect;
  70. ///设置可见地图区域的矩形边界,如限制地图只显示北京市范围
  71. @property (nonatomic, assign) MACoordinateRegion limitRegion;
  72. ///设置可见地图区域的矩形边界,如限制地图只显示北京市范围
  73. @property (nonatomic, assign) MAMapRect limitMapRect;
  74. ///缩放级别(默认3-19,有室内地图时为3-20)
  75. @property (nonatomic) CGFloat zoomLevel;
  76. ///最小缩放级别
  77. @property (nonatomic) CGFloat minZoomLevel;
  78. ///最大缩放级别(有室内地图时最大为20,否则为19)
  79. @property (nonatomic) CGFloat maxZoomLevel;
  80. ///设置地图旋转角度(逆时针为正向)
  81. @property (nonatomic) CGFloat rotationDegree;
  82. ///设置地图相机角度(范围为[0.f, 60.f],但高于40度的角度需要在16级以上才能生效)
  83. @property (nonatomic) CGFloat cameraDegree;
  84. ///是否以screenAnchor点作为锚点进行缩放,默认为YES。如果为NO,则以手势中心点作为锚点
  85. @property (nonatomic, assign) BOOL zoomingInPivotsAroundAnchorPoint;
  86. ///是否支持缩放, 默认YES
  87. @property (nonatomic, getter = isZoomEnabled) BOOL zoomEnabled;
  88. ///是否支持平移, 默认YES
  89. @property (nonatomic, getter = isScrollEnabled) BOOL scrollEnabled;
  90. ///是否支持旋转, 默认YES
  91. @property (nonatomic, getter = isRotateEnabled) BOOL rotateEnabled;
  92. ///是否支持camera旋转, 默认YES
  93. @property (nonatomic, getter = isRotateCameraEnabled) BOOL rotateCameraEnabled;
  94. ///是否支持天空模式,默认为YES. 开启后,进入天空模式后,annotation重用可视范围会缩减
  95. @property (nonatomic, getter = isSkyModelEnabled) BOOL skyModelEnable __attribute((deprecated("已废弃 since 6.0.0")));
  96. ///是否显示楼块,默认为YES
  97. @property (nonatomic, getter = isShowsBuildings) BOOL showsBuildings;
  98. ///是否显示底图标注, 默认为YES
  99. @property (nonatomic, assign, getter = isShowsLabels) BOOL showsLabels;
  100. ///是否显示交通路况图层, 默认为NO
  101. @property (nonatomic, getter = isShowTraffic) BOOL showTraffic;
  102. ///设置实时交通颜色,key为 MATrafficStatus
  103. @property (nonatomic, copy) NSDictionary <NSNumber *, UIColor *> *trafficStatus;
  104. ///设置实时交通线宽系数,默认线宽系数为0.8,范围为[0 - 1] (since 5.3.0)
  105. @property (nonatomic, assign) CGFloat trafficRatio __attribute((deprecated("已废弃 since 6.0.0, 不再支持修改实时交通线宽")));
  106. ///是否支持单击地图获取POI信息(默认为YES), 对应的回调是 -(void)mapView:(MAMapView *) didTouchPois:(NSArray *)
  107. @property (nonatomic, assign) BOOL touchPOIEnabled;
  108. ///是否显示指南针, 默认YES
  109. @property (nonatomic, assign) BOOL showsCompass;
  110. ///指南针原点位置
  111. @property (nonatomic, assign) CGPoint compassOrigin;
  112. ///指南针的宽高
  113. @property (nonatomic, readonly) CGSize compassSize;
  114. ///是否显示比例尺, 默认YES
  115. @property (nonatomic, assign) BOOL showsScale;
  116. ///比例尺原点位置
  117. @property (nonatomic, assign) CGPoint scaleOrigin;
  118. ///比例尺的最大宽高
  119. @property (nonatomic, readonly) CGSize scaleSize;
  120. ///logo位置, 必须在mapView.bounds之内,否则会被忽略
  121. @property (nonatomic, assign) CGPoint logoCenter;
  122. ///logo的宽高
  123. @property (nonatomic, readonly) CGSize logoSize;
  124. ///在当前缩放级别下, 基于地图中心点, 1 screen point 对应的距离(单位是米)
  125. @property (nonatomic, readonly) double metersPerPointForCurrentZoom;
  126. ///标识当前地图中心位置是否在中国范围外。此属性不是精确判断,不能用于边界区域
  127. @property (nonatomic, readonly) BOOL isAbroad;
  128. ///最大帧数,有效的帧数为:60、30、20、10等能被60整除的数。默认为60
  129. @property (nonatomic, assign) NSUInteger maxRenderFrame;
  130. ///是否允许降帧,默认为YES
  131. @property (nonatomic, assign) BOOL isAllowDecreaseFrame;
  132. ///停止/开启 OpenGLES绘制, 默认NO. 对应回调是 - (void)mapView:(MAMapView *) didChangeOpenGLESDisabled:(BOOL)
  133. @property (nonatomic, assign) BOOL openGLESDisabled;
  134. ///地图的视图锚点。坐标系归一化,(0, 0)为MAMapView左上角,(1, 1)为右下角。默认为(0.5, 0.5),即当前地图的视图中心 (since 5.0.0)
  135. @property (nonatomic, assign) CGPoint screenAnchor;
  136. ///地图渲染的runloop mode,默认为NSRunLoopCommonModes。如果是和UIScrollView一起使用且不希望地图在scrollView拖动时渲染,请设置此值为NSDefaultRunLoopMode。(since 5.1.0)
  137. @property (nonatomic, copy) NSRunLoopMode runLoopMode;
  138. ///是否显示海外地图,默认为@NO. 注意:必须先在官网申请开通海外权限
  139. @property (nonatomic, getter=isShowsWorldMap) NSNumber *showsWorldMap;
  140. ///设置语言。中文:@0: 英文:@1. 英文使用注意事项:1、不能和自定义地图样式同时使用;2、英文状态只在MAMapTypeStandard生效
  141. @property (nonatomic, strong) NSNumber *mapLanguage;
  142. /**
  143. * @brief 设定当前地图的经纬度范围,该范围可能会被调整为适合地图窗口显示的范围
  144. * @param region 要设定的经纬度范围
  145. * @param animated 是否动画设置
  146. */
  147. - (void)setRegion:(MACoordinateRegion)region animated:(BOOL)animated;
  148. /**
  149. * @brief 根据当前地图视图frame的大小调整region范围
  150. * @param region 要调整的经纬度范围
  151. * @return 调整后的经纬度范围
  152. */
  153. - (MACoordinateRegion)regionThatFits:(MACoordinateRegion)region;
  154. /**
  155. * @brief 设置可见区域
  156. * @param mapRect 要设定的可见区域
  157. * @param animated 是否动画设置
  158. */
  159. - (void)setVisibleMapRect:(MAMapRect)mapRect animated:(BOOL)animated;
  160. /**
  161. * @brief 重新计算可见地图矩形区域,使之匹配mapview长宽比
  162. * @param mapRect 要调整的地图矩形区域
  163. * @return 调整后的地图矩形区域
  164. */
  165. - (MAMapRect)mapRectThatFits:(MAMapRect)mapRect;
  166. /**
  167. * @brief 根据边缘插入来调整地图矩形区域,使之匹配mapview加insets后的长宽比
  168. * @param mapRect 要调整的地图矩形区域
  169. * @param insets 边缘插入
  170. * @return 调整后的地图矩形区域
  171. */
  172. - (MAMapRect)mapRectThatFits:(MAMapRect)mapRect edgePadding:(UIEdgeInsets)insets;
  173. /**
  174. * @brief 设置可见地图矩形区域
  175. * @param insets 边缘插入
  176. * @param mapRect 要显示的地图矩形区域
  177. * @param animated 是否动画效果
  178. */
  179. - (void)setVisibleMapRect:(MAMapRect)mapRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
  180. /**
  181. * @brief 设置当前地图的中心点,改变该值时,地图的比例尺级别不会发生变化
  182. * @param coordinate 要设置的中心点
  183. * @param animated 是否动画设置
  184. */
  185. - (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
  186. /**
  187. * @brief 设置缩放级别(默认3-19,有室内地图时为3-20)
  188. * @param zoomLevel 要设置的缩放级别
  189. * @param animated 是否动画设置
  190. */
  191. - (void)setZoomLevel:(CGFloat)zoomLevel animated:(BOOL)animated;
  192. /**
  193. * @brief 根据指定的枢纽点来缩放地图
  194. * @param zoomLevel 缩放级别
  195. * @param pivot 枢纽点(基于地图view的坐标系)
  196. * @param animated 是否动画
  197. */
  198. - (void)setZoomLevel:(CGFloat)zoomLevel atPivot:(CGPoint)pivot animated:(BOOL)animated;
  199. /**
  200. * @brief 设置地图旋转角度(逆时针为正向)
  201. * @param rotationDegree 旋转角度, 如当前角度是0,720表示逆时针旋转2周,-720表示正时针旋转2周
  202. * @param animated 动画
  203. * @param duration 动画时间
  204. */
  205. - (void)setRotationDegree:(CGFloat)rotationDegree animated:(BOOL)animated duration:(CFTimeInterval)duration;
  206. /**
  207. * @brief 设置地图相机角度(范围为[0.f, 60.f],但高于40度的角度需要在16级以上才能生效)
  208. * @param cameraDegree 要设置的相机角度
  209. * @param animated 是否动画
  210. * @param duration 动画时间
  211. */
  212. - (void)setCameraDegree:(CGFloat)cameraDegree animated:(BOOL)animated duration:(CFTimeInterval)duration;
  213. /**
  214. * @brief 获取地图状态
  215. * @return 地图状态
  216. */
  217. - (MAMapStatus *)getMapStatus;
  218. /**
  219. * @brief 设置地图状态
  220. * @param status 要设置的地图状态
  221. * @param animated 是否动画
  222. */
  223. - (void)setMapStatus:(MAMapStatus *)status animated:(BOOL)animated;
  224. /**
  225. * @brief 设置地图状态
  226. * @param status 要设置的地图状态
  227. * @param animated 是否动画
  228. * @param duration 动画时间,默认动画时间为0.35s
  229. */
  230. - (void)setMapStatus:(MAMapStatus *)status
  231. animated:(BOOL)animated
  232. duration:(CFTimeInterval)duration;
  233. /**
  234. * @brief 设置指南针的图片
  235. * @param image 新的指南针图片
  236. */
  237. - (void)setCompassImage:(UIImage *)image;
  238. /**
  239. * @brief 在指定区域内截图(默认会包含该区域内的annotationView),注意不要在地图回调方法内直接调用
  240. * @param rect 指定的区域
  241. * @return 截图image
  242. */
  243. - (UIImage *)takeSnapshotInRect:(CGRect)rect __attribute((deprecated("已废弃,请使用takeSnapshotInRect:withCompletionBlock:方法 since 6.0.0")));
  244. /**
  245. * @brief 异步在指定区域内截图(默认会包含该区域内的annotationView), 地图载入完整时回调
  246. * @param rect 指定的区域
  247. * @param block 回调block(resultImage:返回的图片,state:0载入不完整,1完整)
  248. */
  249. - (void)takeSnapshotInRect:(CGRect)rect withCompletionBlock:(void (^)(UIImage *resultImage, NSInteger state))block;
  250. /**
  251. * @brief 在指定的缩放级别下, 基于地图中心点, 1 screen point 对应的距离(单位是米).
  252. * @param zoomLevel 指定的缩放级别, 在[minZoomLevel, maxZoomLevel]范围内.
  253. * @return 对应的距离(单位是米)
  254. */
  255. - (double)metersPerPointForZoomLevel:(CGFloat)zoomLevel;
  256. /**
  257. * @brief 将经纬度转换为指定view坐标系的坐标
  258. * @param coordinate 经纬度
  259. * @param view 指定的view
  260. * @return 基于指定view坐标系的坐标
  261. */
  262. - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view;
  263. /**
  264. * @brief 将指定view坐标系的坐标转换为经纬度
  265. * @param point 指定view坐标系的坐标
  266. * @param view 指定的view
  267. * @return 经纬度
  268. */
  269. - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view;
  270. /**
  271. * @brief 将经纬度region转换为指定view坐标系的rect
  272. * @param region 经纬度region
  273. * @param view 指定的view
  274. * @return 指定view坐标系的rect
  275. */
  276. - (CGRect)convertRegion:(MACoordinateRegion)region toRectToView:(UIView *)view;
  277. /**
  278. * @brief 将指定view坐标系的rect转换为经纬度region
  279. * @param rect 指定view坐标系的rect
  280. * @param view 指定的view
  281. * @return 经纬度region
  282. */
  283. - (MACoordinateRegion)convertRect:(CGRect)rect toRegionFromView:(UIView *)view;
  284. /**
  285. * @brief 重新加载地图
  286. *
  287. * 将离线地图解压到 Documents/3dvmap/ 目录下后,调用此函数使离线数据生效,
  288. * 对应的回调分别是 offlineDataWillReload:(MAMapView *)mapView, offlineDataDidReload:(MAMapView *)mapView.
  289. */
  290. - (void)reloadMap;
  291. /**
  292. * @brief 清除所有磁盘上缓存的地图数据(不包括离线地图)
  293. */
  294. - (void)clearDisk;
  295. /**
  296. * @brief 重新加载内部纹理,在纹理被错误释放时可以执行此方法。(since 5.4.0)
  297. */
  298. - (void)reloadInternalTexture;
  299. /**
  300. * @brief 获取地图审图号。如果启用了“自定义样式”功能(customMapStyleEnabled 为 YES),则返回nil。(since 5.4.0)
  301. * @return 地图审图号
  302. */
  303. - (NSString *)mapContentApprovalNumber;
  304. /**
  305. * @brief 获取卫星图片审图号。(since 5.4.0)
  306. * @return 卫星图片审图号
  307. */
  308. - (NSString *)satelliteImageApprovalNumber;
  309. /**
  310. * @brief 添加CAKeyframeAnimation动画。(since 6.0.0)
  311. * @param mapCenterAnimation 地图中心点动画
  312. * @param zoomAnimation 放大缩小动画
  313. * @param rotateAnimation 旋转动画
  314. * @param cameraDegreeAnimation 仰角动画
  315. */
  316. - (void)addAnimationWith:(CAKeyframeAnimation *)mapCenterAnimation
  317. zoomAnimation:(CAKeyframeAnimation *)zoomAnimation
  318. rotateAnimation:(CAKeyframeAnimation *)rotateAnimation
  319. cameraDegreeAnimation:(CAKeyframeAnimation *)cameraDegreeAnimation;
  320. /**
  321. * @brief 强制刷新。(since 6.0.0)
  322. */
  323. - (void)forceRefresh;
  324. @end
  325. @interface MAMapView (Annotation)
  326. ///所有添加的标注, 注意从5.3.0开始返回数组内不再包含定位蓝点userLocation
  327. @property (nonatomic, readonly) NSArray *annotations;
  328. ///处于选中状态的标注数据数据(其count == 0 或 1)
  329. @property (nonatomic, copy) NSArray *selectedAnnotations;
  330. ///annotation 可见区域
  331. @property (nonatomic, readonly) CGRect annotationVisibleRect;
  332. ///是否允许对annotationView根据zIndex进行排序,默认为NO 注意:如果设置为YES,慎重重载MAAnnoationView的willMoveToSuperview:,内部排序时会调用removeFromSuperView. 注:从5.3.0版本开启此属性废弃,如果添加的annotationView有zIndex不为0的,则自动开启为YES,否则为NO。删除所有annotation后会重置。zIndex属性只有在viewForAnnotation或者didAddAnnotationViews回调中设置有效。
  333. @property (nonatomic, assign) BOOL allowsAnnotationViewSorting __attribute((deprecated("已废弃 since 5.3.0")));
  334. /**
  335. * @brief 向地图窗口添加标注,需要实现MAMapViewDelegate的-mapView:viewForAnnotation:函数来生成标注对应的View
  336. * @param annotation 要添加的标注
  337. */
  338. - (void)addAnnotation:(id <MAAnnotation>)annotation;
  339. /**
  340. * @brief 向地图窗口添加一组标注,需要实现MAMapViewDelegate的-mapView:viewForAnnotation:函数来生成标注对应的View
  341. * @param annotations 要添加的标注数组
  342. */
  343. - (void)addAnnotations:(NSArray *)annotations;
  344. /**
  345. * @brief 移除标注
  346. * @param annotation 要移除的标注
  347. */
  348. - (void)removeAnnotation:(id <MAAnnotation>)annotation;
  349. /**
  350. * @brief 移除一组标注
  351. * @param annotations 要移除的标注数组
  352. */
  353. - (void)removeAnnotations:(NSArray *)annotations;
  354. /**
  355. * @brief 获取指定投影矩形范围内的标注
  356. * @param mapRect 投影矩形范围
  357. * @return 标注集合
  358. */
  359. - (NSSet *)annotationsInMapRect:(MAMapRect)mapRect;
  360. /**
  361. * @brief 根据标注数据获取标注view
  362. * @param annotation 标注数据
  363. * @return 对应的标注view
  364. */
  365. - (MAAnnotationView *)viewForAnnotation:(id <MAAnnotation>)annotation;
  366. /**
  367. * @brief 从复用内存池中获取制定复用标识的annotation view
  368. * @param identifier 复用标识
  369. * @return annotation view
  370. */
  371. - (MAAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
  372. /**
  373. * @brief 选中标注数据对应的view。注意:如果annotation对应的annotationView因不在屏幕范围内而被移入复用池,为了完成选中操作,会将对应的annotationView添加到地图上,并将地图中心点移至annotation.coordinate的位置。
  374. * @param annotation 标注数据
  375. * @param animated 是否有动画效果
  376. */
  377. - (void)selectAnnotation:(id <MAAnnotation>)annotation animated:(BOOL)animated;
  378. /**
  379. * @brief 取消选中标注数据对应的view
  380. * @param annotation 标注数据
  381. * @param animated 是否有动画效果
  382. */
  383. - (void)deselectAnnotation:(id <MAAnnotation>)annotation animated:(BOOL)animated;
  384. /**
  385. * @brief 设置地图使其可以显示数组中所有的annotation, 如果数组中只有一个则直接设置地图中心为annotation的位置。
  386. * @param annotations 需要显示的annotation
  387. * @param animated 是否执行动画
  388. */
  389. - (void)showAnnotations:(NSArray *)annotations animated:(BOOL)animated;
  390. /**
  391. * @brief 设置地图使其可以显示数组中所有的annotation, 如果数组中只有一个则直接设置地图中心为annotation的位置。
  392. * @param annotations 需要显示的annotation
  393. * @param insets insets 嵌入边界
  394. * @param animated 是否执行动画
  395. */
  396. - (void)showAnnotations:(NSArray *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
  397. @end
  398. @interface MAMapView (UserLocation)
  399. ///是否显示用户位置
  400. @property (nonatomic) BOOL showsUserLocation;
  401. ///当前的位置数据
  402. @property (nonatomic, readonly) MAUserLocation *userLocation;
  403. ///是否自定义用户位置精度圈(userLocationAccuracyCircle)对应的 view, 默认为 NO.\n 如果为YES: 会调用 - (MAOverlayRenderer *)mapView (MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay 若返回nil, 则不加载.\n 如果为NO : 会使用默认的样式.
  404. @property (nonatomic) BOOL customizeUserLocationAccuracyCircleRepresentation;
  405. ///用户位置精度圈 对应的overlay
  406. @property (nonatomic, readonly) MACircle *userLocationAccuracyCircle;
  407. ///定位用户位置的模式, 注意:在follow模式下,设置地图中心点、设置可见区域、滑动手势、选择annotation操作会取消follow模式,并触发 - (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated;
  408. @property (nonatomic) MAUserTrackingMode userTrackingMode;
  409. ///当前位置再地图中是否可见
  410. @property (nonatomic, readonly, getter=isUserLocationVisible) BOOL userLocationVisible;
  411. ///设定定位的最小更新距离。默认为kCLDistanceFilterNone,会提示任何移动
  412. @property (nonatomic) CLLocationDistance distanceFilter;
  413. ///设定定位精度。默认为kCLLocationAccuracyBest
  414. @property (nonatomic) CLLocationAccuracy desiredAccuracy;
  415. ///设定最小更新角度。默认为1度,设定为kCLHeadingFilterNone会提示任何角度改变
  416. @property (nonatomic) CLLocationDegrees headingFilter;
  417. ///指定定位是否会被系统自动暂停
  418. @property (nonatomic) BOOL pausesLocationUpdatesAutomatically;
  419. ///是否允许后台定位。默认为NO。只在iOS 9.0之后起作用。\n 设置为YES的时候必须保证 Background Modes 中的 Location updates处于选中状态,否则会抛出异常。\n 注意:定位必须在停止的状态下设置(showsUserLocation = NO),否则无效
  420. @property (nonatomic) BOOL allowsBackgroundLocationUpdates;
  421. /**
  422. * @brief 设置定位用户位置的模式
  423. * @param mode 要设置的模式
  424. * @param animated 是否动画设置
  425. */
  426. - (void)setUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated;
  427. /**
  428. * @brief 设定UserLocationView样式。如果用户自定义了userlocation的annotationView,或者该annotationView还未添加到地图上,此方法将不起作用
  429. * @param representation 样式信息对象
  430. */
  431. - (void)updateUserLocationRepresentation:(MAUserLocationRepresentation *)representation;
  432. @end
  433. @interface MAMapView (Overlay)
  434. ///所有添加的Overlay
  435. @property (nonatomic, readonly) NSArray *overlays;
  436. /**
  437. * @brief 取位于level下的overlays
  438. * @param level 层级
  439. */
  440. - (NSArray *)overlaysInLevel:(MAOverlayLevel)level;
  441. /**
  442. * @brief 向地图窗口添加Overlay。
  443. * 需要实现MAMapViewDelegate的-mapView:rendererForOverlay:函数来生成标注对应的Renderer。
  444. * 默认添加层级:MAGroundOverlay默认层级为MAOverlayLevelAboveRoads,其余overlay类型默认层级为MAOverlayLevelAboveLabels
  445. * @param overlay 要添加的overlay
  446. */
  447. - (void)addOverlay:(id <MAOverlay>)overlay;
  448. /**
  449. * @brief 向地图窗口添加一组Overlay,需要实现MAMapViewDelegate的-mapView:rendererForOverlay:函数来生成标注对应的Renderer
  450. * 默认添加层级:MAOverlayLevelAboveLabels
  451. * @param overlays 要添加的overlay数组
  452. */
  453. - (void)addOverlays:(NSArray *)overlays;
  454. /**
  455. * @brief 向地图窗口添加Overlay,需要实现MAMapViewDelegate的-mapView:rendererForOverlay:函数来生成标注对应的Renderer
  456. * @param overlay 要添加的overlay
  457. * @param level 添加的overlay所在层级
  458. */
  459. - (void)addOverlay:(id <MAOverlay>)overlay level:(MAOverlayLevel)level;
  460. /**
  461. * @brief 向地图窗口添加一组Overlay,需要实现MAMapViewDelegate的-mapView:rendererForOverlay:函数来生成标注对应的Renderer
  462. * @param overlays 要添加的overlay数组
  463. * @param level 添加的overlay所在层级
  464. */
  465. - (void)addOverlays:(NSArray *)overlays level:(MAOverlayLevel)level;
  466. /**
  467. * @brief 移除Overlay
  468. * @param overlay 要移除的overlay
  469. */
  470. - (void)removeOverlay:(id <MAOverlay>)overlay;
  471. /**
  472. * @brief 移除一组Overlay
  473. * @param overlays 要移除的overlay数组
  474. */
  475. - (void)removeOverlays:(NSArray *)overlays;
  476. /**
  477. * @brief 在指定层级的指定的索引处添加一个Overlay
  478. * @param overlay 要添加的overlay
  479. * @param index 指定的索引
  480. * @param level 指定的层级
  481. * 注:各个层级的索引分开计数;
  482. * 若index大于level层级的最大索引,则添加至level层级的最大索引之后。
  483. */
  484. - (void)insertOverlay:(id <MAOverlay>)overlay atIndex:(NSUInteger)index level:(MAOverlayLevel)level;
  485. /**
  486. * @brief 在指定的Overlay之上插入一个overlay
  487. * @param overlay 带添加的Overlay
  488. * @param sibling 用于指定相对位置的Overlay
  489. */
  490. - (void)insertOverlay:(id <MAOverlay>)overlay aboveOverlay:(id <MAOverlay>)sibling;
  491. /**
  492. * @brief 在指定的Overlay之下插入一个overlay
  493. * @param overlay 带添加的Overlay
  494. * @param sibling 用于指定相对位置的Overlay
  495. */
  496. - (void)insertOverlay:(id <MAOverlay>)overlay belowOverlay:(id <MAOverlay>)sibling;
  497. /**
  498. * @brief 在指定的索引处添加一个Overlay
  499. * @param overlay 要添加的overlay
  500. * @param index 指定的索引
  501. */
  502. - (void)insertOverlay:(id <MAOverlay>)overlay atIndex:(NSUInteger)index;
  503. /**
  504. * @brief 在MAOverlayLevelAboveLabels上交换指定索引处的Overlay
  505. * @param index1 索引1
  506. * @param index2 索引2
  507. */
  508. - (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2;
  509. /**
  510. * @brief 交换指定索引处的Overlay
  511. * @param index1 索引1
  512. * @param index2 索引2
  513. * @param level 所处层级
  514. */
  515. - (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2 atLevel:(MAOverlayLevel)level;
  516. /**
  517. * @brief 交换两个overlay
  518. * @param overlay1 overlay1
  519. * @param overlay2 overlay2
  520. */
  521. - (void)exchangeOverlay:(id <MAOverlay>)overlay1 withOverlay:(id <MAOverlay>)overlay2;
  522. /**
  523. * @brief 查找指定overlay对应的Renderer,如果该View尚未创建,返回nil
  524. * @param overlay 指定的overlay
  525. * @return 指定overlay对应的Renderer
  526. */
  527. - (MAOverlayRenderer *)rendererForOverlay:(id <MAOverlay>)overlay;
  528. /**
  529. * @brief 设置地图使其可以显示数组中所有的overlay, 如果数组中只有一个则直接设置地图中心为overlay的位置。
  530. * @param overlays 需要显示的overlays
  531. * @param animated 是否执行动画
  532. */
  533. - (void)showOverlays:(NSArray *)overlays animated:(BOOL)animated;
  534. /**
  535. * @brief 设置地图使其可以显示数组中所有的overlay, 如果数组中只有一个则直接设置地图中心为overlay的位置。
  536. * @param overlays 需要显示的overlays
  537. * @param insets insets 嵌入边界
  538. * @param animated 是否执行动画
  539. */
  540. - (void)showOverlays:(NSArray *)overlays edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
  541. @end
  542. #if MA_INCLUDE_INDOOR
  543. @interface MAMapView (Indoor)
  544. ///是否显示室内地图, 默认NO
  545. @property (nonatomic, getter = isShowsIndoorMap) BOOL showsIndoorMap;
  546. ///是否显示室内地图默认控件, 默认YES
  547. @property (nonatomic, getter = isShowsIndoorMapControl) BOOL showsIndoorMapControl;
  548. ///默认室内地图控件的最大宽高
  549. @property (nonatomic, readonly) CGSize indoorMapControlSize;
  550. /**
  551. * @brief 设置默认室内地图控件位置
  552. * @param origin 左上角点位置
  553. */
  554. - (void)setIndoorMapControlOrigin:(CGPoint)origin;
  555. /**
  556. * @brief 设置当前室内地图楼层数
  557. * @param floorIndex 要设置的楼层数
  558. */
  559. - (void)setCurrentIndoorMapFloorIndex:(NSInteger)floorIndex;
  560. /**
  561. * @brief 清空室内地图缓存
  562. */
  563. - (void)clearIndoorMapCache;
  564. @end
  565. #endif
  566. ///自定义样式
  567. @interface MAMapView (CustomMapStyle)
  568. ///是否开启自定义样式, 默认NO. since 5.0.0
  569. @property (nonatomic, assign) BOOL customMapStyleEnabled;
  570. /**
  571. * @brief 自定义地图样式, 目前仅支持自定义标准类型. 默认不生效,调用customMapStyleEnabled=YES使生效.
  572. * @param customJson 自定义的JSON格式数据.
  573. */
  574. - (void)setCustomMapStyle:(NSData *)customJson __attribute((deprecated("已废弃, 请使用 setCustomMapStyleWithWebData: since 5.7.0")));
  575. /**
  576. * @brief 根据web导出数据设置地图样式, 目前仅支持自定义标准类型. 默认不生效,调用customMapStyleEnabled=YES使生效. since 5.2.0
  577. * @param data 高德web端工具导出的地图样式数据.
  578. */
  579. - (void)setCustomMapStyleWithWebData:(NSData *)data __attribute((deprecated("已废弃, 请使用 setCustomMapStyleOptions: since 6.6.0")));
  580. /**
  581. * @brief 设置自定义纹理. since 5.7.0
  582. * @param customTextureResourcePath 自定义纹理文件路径.
  583. */
  584. - (void)setCustomTextureResourcePath:(NSString *)customTextureResourcePath __attribute((deprecated("已废弃, 请使用 setCustomMapStyleOptions: since 6.6.0")));
  585. /**
  586. * @brief 自定义地图样式id, 官网发布后下次开启自定义样式便可生效,目前仅支持自定义标准类型. 默认不生效,调用customMapStyleEnabled=YES使生效. since 6.0.0
  587. * @param customMapStyleID 自定义样式ID,从官网获取
  588. */
  589. - (void)setCustomMapStyleID:(NSString *)customMapStyleID __attribute((deprecated("已废弃, 请使用 setCustomMapStyleOptions: since 6.6.0")));
  590. /**
  591. * @brief 自定义地图样式设置,可以支持分级样式配置,如控制不同级别显示不同的颜色(自6.6.0开始使用新版样式,旧版样式无法在新版接口setCustomMapStyleOptions:(MAMapCustomStyleOptions *)styleOptions中使用,请到官网(lbs.amap.com)更新新版样式文件)
  592. * @param styleOptions 自定义样式options. since 6.6.0
  593. */
  594. - (void)setCustomMapStyleOptions:(MAMapCustomStyleOptions *)styleOptions;
  595. @end
  596. #pragma mark - MAMapViewDelegate
  597. @protocol MAMapViewDelegate <NSObject>
  598. @optional
  599. /**
  600. * @brief 地图区域改变过程中会调用此接口 since 4.6.0
  601. * @param mapView 地图View
  602. */
  603. - (void)mapViewRegionChanged:(MAMapView *)mapView;
  604. /**
  605. * @brief 地图区域即将改变时会调用此接口
  606. * @param mapView 地图View
  607. * @param animated 是否动画
  608. */
  609. - (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
  610. /**
  611. * @brief 地图区域改变完成后会调用此接口
  612. * @param mapView 地图View
  613. * @param animated 是否动画
  614. */
  615. - (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
  616. /**
  617. * @brief 地图将要发生移动时调用此接口
  618. * @param mapView 地图view
  619. * @param wasUserAction 标识是否是用户动作
  620. */
  621. - (void)mapView:(MAMapView *)mapView mapWillMoveByUser:(BOOL)wasUserAction;
  622. /**
  623. * @brief 地图移动结束后调用此接口
  624. * @param mapView 地图view
  625. * @param wasUserAction 标识是否是用户动作
  626. */
  627. - (void)mapView:(MAMapView *)mapView mapDidMoveByUser:(BOOL)wasUserAction;
  628. /**
  629. * @brief 地图将要发生缩放时调用此接口
  630. * @param mapView 地图view
  631. * @param wasUserAction 标识是否是用户动作
  632. */
  633. - (void)mapView:(MAMapView *)mapView mapWillZoomByUser:(BOOL)wasUserAction;
  634. /**
  635. * @brief 地图缩放结束后调用此接口
  636. * @param mapView 地图view
  637. * @param wasUserAction 标识是否是用户动作
  638. */
  639. - (void)mapView:(MAMapView *)mapView mapDidZoomByUser:(BOOL)wasUserAction;
  640. /**
  641. * @brief 地图开始加载
  642. * @param mapView 地图View
  643. */
  644. - (void)mapViewWillStartLoadingMap:(MAMapView *)mapView;
  645. /**
  646. * @brief 地图加载成功
  647. * @param mapView 地图View
  648. */
  649. - (void)mapViewDidFinishLoadingMap:(MAMapView *)mapView;
  650. /**
  651. * @brief 地图加载失败
  652. * @param mapView 地图View
  653. * @param error 错误信息
  654. */
  655. - (void)mapViewDidFailLoadingMap:(MAMapView *)mapView withError:(NSError *)error;
  656. /**
  657. * @brief 根据anntation生成对应的View。
  658. 注意:
  659. 1、5.1.0后由于定位蓝点增加了平滑移动功能,如果在开启定位的情况先添加annotation,需要在此回调方法中判断annotation是否为MAUserLocation,从而返回正确的View。
  660. if ([annotation isKindOfClass:[MAUserLocation class]]) {
  661. return nil;
  662. }
  663. 2、请不要在此回调中对annotation进行select和deselect操作,此时annotationView还未添加到mapview。
  664. * @param mapView 地图View
  665. * @param annotation 指定的标注
  666. * @return 生成的标注View
  667. */
  668. - (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation;
  669. /**
  670. * @brief 当mapView新添加annotation views时,调用此接口
  671. * @param mapView 地图View
  672. * @param views 新添加的annotation views
  673. */
  674. - (void)mapView:(MAMapView *)mapView didAddAnnotationViews:(NSArray *)views;
  675. /**
  676. * @brief 当选中一个annotation view时,调用此接口. 注意如果已经是选中状态,再次点击不会触发此回调。取消选中需调用-(void)deselectAnnotation:animated:
  677. * @param mapView 地图View
  678. * @param view 选中的annotation view
  679. */
  680. - (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view;
  681. /**
  682. * @brief 当取消选中一个annotation view时,调用此接口
  683. * @param mapView 地图View
  684. * @param view 取消选中的annotation view
  685. */
  686. - (void)mapView:(MAMapView *)mapView didDeselectAnnotationView:(MAAnnotationView *)view;
  687. /**
  688. * @brief 在地图View将要启动定位时,会调用此函数
  689. * @param mapView 地图View
  690. */
  691. - (void)mapViewWillStartLocatingUser:(MAMapView *)mapView;
  692. /**
  693. * @brief 在地图View停止定位后,会调用此函数
  694. * @param mapView 地图View
  695. */
  696. - (void)mapViewDidStopLocatingUser:(MAMapView *)mapView;
  697. /**
  698. * @brief 位置或者设备方向更新后,会调用此函数
  699. * @param mapView 地图View
  700. * @param userLocation 用户定位信息(包括位置与设备方向等数据)
  701. * @param updatingLocation 标示是否是location数据更新, YES:location数据更新 NO:heading数据更新
  702. */
  703. - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation;
  704. /**
  705. * @brief 当plist配置NSLocationAlwaysUsageDescription或者NSLocationAlwaysAndWhenInUseUsageDescription,并且[CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined,会调用代理的此方法。
  706. 此方法实现调用后台权限API即可( 该回调必须实现 [locationManager requestAlwaysAuthorization] ); since 6.8.0
  707. * @param locationManager 地图的CLLocationManager。
  708. */
  709. - (void)mapViewRequireLocationAuth:(CLLocationManager *)locationManager;
  710. /**
  711. * @brief 定位失败后,会调用此函数
  712. * @param mapView 地图View
  713. * @param error 错误号,参考CLError.h中定义的错误号
  714. */
  715. - (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error;
  716. /**
  717. * @brief 拖动annotation view时view的状态变化
  718. * @param mapView 地图View
  719. * @param view annotation view
  720. * @param newState 新状态
  721. * @param oldState 旧状态
  722. */
  723. - (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view didChangeDragState:(MAAnnotationViewDragState)newState
  724. fromOldState:(MAAnnotationViewDragState)oldState;
  725. /**
  726. * @brief 根据overlay生成对应的Renderer
  727. * @param mapView 地图View
  728. * @param overlay 指定的overlay
  729. * @return 生成的覆盖物Renderer
  730. */
  731. - (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay;
  732. /**
  733. * @brief 当mapView新添加overlay renderers时,调用此接口
  734. * @param mapView 地图View
  735. * @param overlayRenderers 新添加的overlay renderers
  736. */
  737. - (void)mapView:(MAMapView *)mapView didAddOverlayRenderers:(NSArray *)overlayRenderers;
  738. /**
  739. * @brief 标注view的accessory view(必须继承自UIControl)被点击时,触发该回调
  740. * @param mapView 地图View
  741. * @param view callout所属的标注view
  742. * @param control 对应的control
  743. */
  744. - (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
  745. /**
  746. * @brief 标注view的calloutview整体点击时,触发该回调。只有使用默认calloutview时才生效。
  747. * @param mapView 地图的view
  748. * @param view calloutView所属的annotationView
  749. */
  750. - (void)mapView:(MAMapView *)mapView didAnnotationViewCalloutTapped:(MAAnnotationView *)view;
  751. /**
  752. * @brief 标注view被点击时,触发该回调。(since 5.7.0)
  753. * @param mapView 地图的view
  754. * @param view annotationView
  755. */
  756. - (void)mapView:(MAMapView *)mapView didAnnotationViewTapped:(MAAnnotationView *)view;
  757. /**
  758. * @brief 当userTrackingMode改变时,调用此接口
  759. * @param mapView 地图View
  760. * @param mode 改变后的mode
  761. * @param animated 动画
  762. */
  763. - (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated;
  764. /**
  765. * @brief 当openGLESDisabled变量改变时,调用此接口
  766. * @param mapView 地图View
  767. * @param openGLESDisabled 改变后的openGLESDisabled
  768. */
  769. - (void)mapView:(MAMapView *)mapView didChangeOpenGLESDisabled:(BOOL)openGLESDisabled;
  770. /**
  771. * @brief 当touchPOIEnabled == YES时,单击地图使用该回调获取POI信息
  772. * @param mapView 地图View
  773. * @param pois 获取到的poi数组(由MATouchPoi组成)
  774. */
  775. - (void)mapView:(MAMapView *)mapView didTouchPois:(NSArray *)pois;
  776. /**
  777. * @brief 单击地图回调,返回经纬度
  778. * @param mapView 地图View
  779. * @param coordinate 经纬度
  780. */
  781. - (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate;
  782. /**
  783. * @brief 长按地图,返回经纬度
  784. * @param mapView 地图View
  785. * @param coordinate 经纬度
  786. */
  787. - (void)mapView:(MAMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate;
  788. /**
  789. * @brief 地图初始化完成(在此之后,可以进行坐标计算)
  790. * @param mapView 地图View
  791. */
  792. - (void)mapInitComplete:(MAMapView *)mapView;
  793. #if MA_INCLUDE_INDOOR
  794. /**
  795. * @brief 室内地图出现,返回室内地图信息
  796. *
  797. * @param mapView 地图View
  798. * @param indoorInfo 室内地图信息
  799. */
  800. - (void)mapView:(MAMapView *)mapView didIndoorMapShowed:(MAIndoorInfo *)indoorInfo;
  801. /**
  802. * @brief 室内地图楼层发生变化,返回变化的楼层
  803. *
  804. * @param mapView 地图View
  805. * @param indoorInfo 变化的楼层
  806. */
  807. - (void)mapView:(MAMapView *)mapView didIndoorMapFloorIndexChanged:(MAIndoorInfo *)indoorInfo;
  808. /**
  809. * @brief 室内地图消失后,返回室内地图信息
  810. *
  811. * @param mapView 地图View
  812. * @param indoorInfo 室内地图信息
  813. */
  814. - (void)mapView:(MAMapView *)mapView didIndoorMapHidden:(MAIndoorInfo *)indoorInfo;
  815. #endif //end of MA_INCLUDE_INDOOR
  816. /**
  817. * @brief 离线地图数据将要被加载, 调用reloadMap会触发该回调,离线数据生效前的回调.
  818. * @param mapView 地图View
  819. */
  820. - (void)offlineDataWillReload:(MAMapView *)mapView;
  821. /**
  822. * @brief 离线地图数据加载完成, 调用reloadMap会触发该回调,离线数据生效后的回调.
  823. * @param mapView 地图View
  824. */
  825. - (void)offlineDataDidReload:(MAMapView *)mapView;
  826. @end