MAOverlayRenderer.h 14 KB

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