MAOverlayRenderer.h 14 KB

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