MAOverlayRenderer.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. //
  2. // MAOverlayRenderer.h
  3. // MAMapKit
  4. //
  5. //
  6. // Copyright (c) 2011年 Amap. All rights reserved.
  7. //
  8. #import "MAConfig.h"
  9. #import <UIKit/UIKit.h>
  10. #import "MAOverlay.h"
  11. #import "MALineDrawType.h"
  12. ///虚线类型
  13. typedef NS_ENUM(NSUInteger, MALineDashType) {
  14. kMALineDashTypeNone = 0, ///<不画虚线
  15. kMALineDashTypeSquare, ///<方块样式
  16. kMALineDashTypeDot, ///<圆点样式
  17. };
  18. #define kMAOverlayRendererDefaultStrokeColor [UIColor colorWithRed:0.3 green:0.63 blue:0.89 alpha:0.8]
  19. #define kMAOverlayRendererDefaultFillColor [UIColor colorWithRed:0.77 green:0.88 blue:0.94 alpha:0.8]
  20. @protocol MAOverlayRenderDelegate;
  21. ///该类是地图覆盖物Renderer的基类, 提供绘制overlay的接口但并无实际的实现(render相关方法只能在重写后的glRender方法中使用)
  22. @interface MAOverlayRenderer : NSObject {
  23. @protected
  24. GLuint _strokeTextureID;
  25. BOOL _needsUpdate;
  26. BOOL _needsLoadStrokeTexture;
  27. }
  28. ///由地图添加时,不要手动设置。如果不是使用mapview进行添加,则需要手动设置。(since 5.1.0)
  29. @property (nonatomic, weak) id<MAOverlayRenderDelegate> rendererDelegate;
  30. ///关联的overlay对象
  31. @property (nonatomic, readonly, retain) id <MAOverlay> overlay;
  32. ///缓存的OpenGLES坐标
  33. @property (nonatomic) CGPoint *glPoints __attribute__((deprecated("已废弃")));
  34. ///缓存的OpenGLES坐标
  35. @property (nonatomic) NSUInteger glPointCount __attribute__((deprecated("已废弃")));
  36. ///用于生成笔触纹理id的图片(image需满足: 长宽相等,且宽度值为2的整数次幂; 如果您需要减轻绘制产生的锯齿,您可以参考AMap.bundle中的traffic_texture_blue.png的方式,在image两边增加部分透明像素.)。(since 5.3.0)
  37. @property (nonatomic, strong) UIImage *strokeImage;
  38. ///笔触纹理id, 修改纹理id参考, 如果strokeImage未指定、尚未加载或加载失败返回0
  39. @property (nonatomic, readonly) GLuint strokeTextureID;
  40. ///透明度[0,1],默认为1. 使用MAOverlayRenderer类提供的渲染接口会自动应用此属性。(since 5.1.0)
  41. @property (nonatomic, assign) CGFloat alpha;
  42. ///overlay渲染的scale。(since 5.1.0)
  43. @property (nonatomic, readonly) CGFloat contentScale;
  44. /**
  45. * @brief 初始化并返回一个Overlay Renderer
  46. * @param overlay 关联的overlay对象
  47. * @return 初始化成功则返回overlay view,否则返回nil
  48. */
  49. - (instancetype)initWithOverlay:(id <MAOverlay>)overlay;
  50. /**
  51. * @brief 获取当前地图view矩阵,数组长度为16,无需外界释放. 需要添加至地图后,才能获取有效矩阵数据,否则返回NULL
  52. * @return 矩阵数组
  53. */
  54. - (float *)getViewMatrix;
  55. /**
  56. * @brief 获取当前地图projection矩阵,数组长度为16,无需外界释放. 需要添加至地图后,才能获取有效矩阵数据,否则返回NULL
  57. * @return 矩阵数组
  58. */
  59. - (float *)getProjectionMatrix;
  60. /**
  61. * @brief 获取当前地图中心点偏移,用以把地图坐标转换为gl坐标。需要添加到地图获取才有效。(since 5.1.0)
  62. * @return 偏移
  63. */
  64. - (MAMapPoint)getOffsetPoint;
  65. /**
  66. * @brief 获取当前地图缩放级别,需要添加到地图获取才有效。(since 5.1.0)
  67. * @return 缩放级别
  68. */
  69. - (CGFloat)getMapZoomLevel;
  70. /**
  71. * @brief 将MAMapPoint转化为相对于receiver的本地坐标,deprecated
  72. * @param mapPoint 要转化的MAMapPoint
  73. * @return 相对于receiver的本地坐标
  74. */
  75. - (CGPoint)pointForMapPoint:(MAMapPoint)mapPoint __attribute__((deprecated("已废弃")));
  76. /**
  77. * @brief 将相对于receiver的本地坐标转化为MAMapPoint, deprecated
  78. * @param point 要转化的相对于receiver的本地坐标
  79. * @return MAMapPoint
  80. */
  81. - (MAMapPoint)mapPointForPoint:(CGPoint)point __attribute__((deprecated("已废弃")));
  82. /**
  83. * @brief 将MAMapRect转化为相对于receiver的本地rect, deprecated
  84. * @param mapRect 要转化的MAMapRect
  85. * @return 相对于receiver的本地rect
  86. */
  87. - (CGRect)rectForMapRect:(MAMapRect)mapRect __attribute__((deprecated("已废弃")));
  88. /**
  89. * @brief 将相对于receiver的本地rect转化为MAMapRect, deprecated
  90. * @param rect 要转化的相对于receiver的本地rect
  91. * @return MAMapRect
  92. */
  93. - (MAMapRect)mapRectForRect:(CGRect)rect __attribute__((deprecated("已废弃")));
  94. /**
  95. * @brief 将MAMapPoint转换为opengles可以直接使用的坐标
  96. * @param mapPoint MAMapPoint坐标
  97. * @return 直接支持的坐标
  98. */
  99. - (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint;
  100. /**
  101. * @brief 批量将MAMapPoint转换为opengles可以直接使用的坐标
  102. * @param mapPoints MAMapPoint坐标数据指针
  103. * @param count 个数
  104. * @return 直接支持的坐标数据指针(需要调用者手动释放)
  105. */
  106. - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count;
  107. /**
  108. * @brief 将屏幕尺寸转换为OpenGLES尺寸
  109. * @param windowWidth 屏幕尺寸
  110. * @return OpenGLES尺寸
  111. */
  112. - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth;
  113. /**
  114. * @brief OpenGLES坐标系发生改变, 重新计算缓存的OpenGLES坐标, deprecated
  115. */
  116. - (void)referenceDidChange __attribute__((deprecated("已废弃")));
  117. /**
  118. * @brief 使用OpenGLES 绘制线
  119. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  120. * @param pointCount 点个数
  121. * @param strokeColor 线颜色
  122. * @param lineWidth OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  123. * @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES
  124. */
  125. - (void)renderLinesWithPoints:(CGPoint *)points
  126. pointCount:(NSUInteger)pointCount
  127. strokeColor:(UIColor *)strokeColor
  128. lineWidth:(CGFloat)lineWidth
  129. looped:(BOOL)looped;
  130. /**
  131. * @brief 使用OpenGLES 绘制线
  132. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  133. * @param pointCount 点个数
  134. * @param strokeColor 线颜色
  135. * @param lineWidth OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  136. * @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES
  137. * @param lineJoinType 线连接点样式
  138. * @param lineCapType 线端点样式
  139. * @param lineDash 虚线类型
  140. */
  141. - (void)renderLinesWithPoints:(CGPoint *)points
  142. pointCount:(NSUInteger)pointCount
  143. strokeColor:(UIColor *)strokeColor
  144. lineWidth:(CGFloat)lineWidth
  145. looped:(BOOL)looped
  146. LineJoinType:(MALineJoinType)lineJoinType
  147. LineCapType:(MALineCapType)lineCapType
  148. lineDash:(MALineDashType)lineDash;
  149. /**
  150. * @brief 使用OpenGLES 按指定纹理绘制线
  151. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  152. * @param pointCount 点个数
  153. * @param lineWidth 线OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  154. * @param textureID 指定的纹理
  155. * @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES
  156. */
  157. - (void)renderTexturedLinesWithPoints:(CGPoint *)points
  158. pointCount:(NSUInteger)pointCount
  159. lineWidth:(CGFloat)lineWidth
  160. textureID:(GLuint)textureID
  161. looped:(BOOL)looped;
  162. /**
  163. * @brief 使用OpenGLES 绘制多纹理线
  164. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  165. * @param pointCount 点个数
  166. * @param lineWidth 线OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  167. * @param textureIDs 各段指定的纹理 使用- (BOOL)loadStrokeTextureImages:(NSArray *)textureImages;加载,在strokeTextureIDs属性中获取
  168. * @param drawStyleIndexes 纹理索引数组,成员为NSNumber,且为非负数,负数按0处理
  169. * @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES
  170. */
  171. - (void)renderTexturedLinesWithPoints:(CGPoint *)points
  172. pointCount:(NSUInteger)pointCount
  173. lineWidth:(CGFloat)lineWidth
  174. textureIDs:(NSArray *)textureIDs
  175. drawStyleIndexes:(NSArray *)drawStyleIndexes
  176. looped:(BOOL)looped;
  177. /**
  178. * @brief 使用OpenGLES 绘制多段颜色线
  179. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  180. * @param pointCount 点个数
  181. * @param strokeColors 各段指定的颜色
  182. * @param drawStyleIndexes 颜色索引数组,成员为NSNumber,且为非负数,负数按0处理
  183. * @param isGradient 颜色是否渐变
  184. * @param lineWidth 线OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  185. * @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES
  186. * @param lineJoinType 线连接点样式
  187. * @param lineCapType 线端点样式
  188. * @param lineDash 虚线类型
  189. */
  190. - (void)renderLinesWithPoints:(CGPoint *)points
  191. pointCount:(NSUInteger)pointCount
  192. strokeColors:(NSArray *)strokeColors
  193. drawStyleIndexes:(NSArray *)drawStyleIndexes
  194. isGradient:(BOOL)isGradient
  195. lineWidth:(CGFloat)lineWidth
  196. looped:(BOOL)looped
  197. LineJoinType:(MALineJoinType)lineJoinType
  198. LineCapType:(MALineCapType)lineCapType
  199. lineDash:(MALineDashType)lineDash;
  200. /**
  201. * @brief 使用OpenGLES 绘制区域
  202. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  203. * @param pointCount 点个数
  204. * @param fillColor 填充颜色
  205. * @param usingTriangleFan 若必为凸多边形输入YES,可能为凹多边形输入NO
  206. */
  207. - (void)renderRegionWithPoints:(CGPoint *)points
  208. pointCount:(NSUInteger)pointCount
  209. fillColor:(UIColor *)fillColor
  210. usingTriangleFan:(BOOL)usingTriangleFan;
  211. /**
  212. * @brief 使用OpenGLES 绘制区域(带轮廓线) \n注意:strokeLineWidth为0 或 strokeColor为nil 时不绘制轮廓线。
  213. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  214. * @param pointCount 点个数
  215. * @param fillColor 填充颜色
  216. * @param strokeColor 轮廓线颜色
  217. * @param strokeLineWidth 轮廓线宽。OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  218. * @param strokeLineJoinType 轮廓线连接点样式
  219. * @param strokeLineDash 轮廓虚线类型
  220. * @param usingTriangleFan 若必为凸多边形输入YES,可能为凹多边形输入NO
  221. */
  222. - (void)renderStrokedRegionWithPoints:(CGPoint *)points pointCount:(NSUInteger)pointCount
  223. fillColor:(UIColor *)fillColor
  224. strokeColor:(UIColor *)strokeColor
  225. strokeLineWidth:(CGFloat)strokeLineWidth
  226. strokeLineJoinType:(MALineJoinType)strokeLineJoinType
  227. strokeLineDash:(MALineDashType)strokeLineDash
  228. usingTriangleFan:(BOOL)usingTriangleFan;
  229. /**
  230. * @brief 使用OpenGLES 绘制区域(带纹理轮廓线) \n注意:strokeLineWidth为0 或 strokeTexture为0 时不绘制轮廓线。
  231. * @param points OpenGLES坐标系点指针, 参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  232. * @param pointCount 点个数
  233. * @param fillColor 填充颜色
  234. * @param strokeLineWidth 轮廓线宽。OpenGLES支持线宽尺寸, 参考 - (CGFloat)glWidthForWindowWidth:(CGFloat)windowWidth
  235. * @param strokeTexture 轮廓线纹理。使用- (void)loadStrokeTextureImage:(UIImage *)textureImage;加载
  236. * @param usingTriangleFan 若必为凸多边形输入YES,可能为凹多边形输入NO
  237. */
  238. - (void)renderTextureStrokedRegionWithPoints:(CGPoint *)points
  239. pointCount:(NSUInteger)pointCount
  240. fillColor:(UIColor *)fillColor
  241. strokeTineWidth:(CGFloat)strokeLineWidth
  242. strokeTextureID:(GLuint)strokeTexture
  243. usingTriangleFan:(BOOL)usingTriangleFan;
  244. /**
  245. * @brief 使用OpenGLES 绘制图片
  246. * @param textureID OpenGLES纹理ID
  247. * @param points OpenGLES坐标系点指针,纹理矩形的四个顶点坐标,其第一个坐标为图片左上角,依次顺时针传入其他顶点 ,参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  248. */
  249. - (void)renderIconWithTextureID:(GLuint)textureID points:(CGPoint *)points;
  250. /**
  251. * @brief 使用OpenGLES 绘制图片
  252. * @param textureID OpenGLES纹理ID
  253. * @param points OpenGLES坐标系点指针,纹理矩形的四个顶点坐标,其第一个坐标为图片左上角,依次顺时针传入其他顶点 ,参考- (CGPoint)glPointForMapPoint:(MAMapPoint)mapPoint, - (CGPoint *)glPointsForMapPoints:(MAMapPoint *)mapPoints count:(NSUInteger)count
  254. * @param modulateColor 调节颜色值, 最终颜色 = 纹理色 * modulateColor. 如只需要调节alpha的话就设置为[red=1, green=1, blue=1, alpha=0.5]
  255. */
  256. - (void)renderIconWithTextureID:(GLuint)textureID points:(CGPoint *)points modulateColor:(UIColor *)modulateColor;
  257. /**
  258. * @brief 绘制函数(子类需要重载来实现)
  259. */
  260. - (void)glRender;
  261. /**
  262. * @brief 加载纹理图片,纹理ID存储在成员strokeTextureID中。纹理图片为nil时,清空原有纹理
  263. * @param textureImage 纹理图片(需满足:长宽相等,且宽度值为2的次幂)。若为nil,则清空原有纹理
  264. * @return openGL纹理ID, 若纹理加载失败返回0
  265. */
  266. - (GLuint)loadStrokeTextureImage:(UIImage *)textureImage __attribute__((deprecated("已废弃, 请通过属性strokeImage设置")));
  267. /**
  268. * @brief 加载纹理图片(since 5.1.0)
  269. * @param textureImage 纹理图片(需满足:长宽相等,且宽度值为2的次幂)
  270. * @return openGL纹理ID, 若纹理加载失败返回0
  271. */
  272. - (GLuint)loadTexture:(UIImage *)textureImage;
  273. /**
  274. @brief 删除纹理(since 5.1.0)
  275. @param textureId 纹理ID
  276. */
  277. - (void)deleteTexture:(GLuint)textureId;
  278. /**
  279. * @brief 当关联overlay对象有更新时,调用此接口刷新. since 5.0.0
  280. */
  281. - (void)setNeedsUpdate;
  282. @end