BMKOverlayView.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * BMKOverlayView.h
  3. * BMapKit
  4. *
  5. * Copyright 2011 Baidu Inc. All rights reserved.
  6. *
  7. */
  8. #import <UIKit/UIKit.h>
  9. #import "BMKOverlay.h"
  10. /// 该类是地图覆盖物View的基类,提供绘制overlay的接口但本身并无实现,所有地图覆盖物View需要继承自此类
  11. @interface BMKOverlayView : UIView
  12. {
  13. @package
  14. id <BMKOverlay> _overlay;
  15. BMKMapRect _boundingMapRect;
  16. CGAffineTransform _mapTransform;
  17. id _geometryDelegate;
  18. id _canDrawCache;
  19. BOOL keepScale;
  20. CFTimeInterval _lastTile;
  21. CFRunLoopTimerRef _scheduledScaleTimer;
  22. struct {
  23. unsigned int keepAlive:1;
  24. unsigned int levelCrossFade:1;
  25. unsigned int drawingDisabled:1;
  26. unsigned int usesTiledLayer:1;
  27. } _flags;
  28. //@private
  29. // int geometrylayerID;
  30. }
  31. /// 设置该overlay的GeometryDelegate
  32. - (void)setOverlayGeometryDelegate:(id)delegate;
  33. /**
  34. *初始化并返回一个overlay view
  35. *@param overlay 关联的overlay对象
  36. *@return 初始化成功则返回overlay view,否则返回nil
  37. */
  38. - (id)initWithOverlay:(id <BMKOverlay>)overlay;
  39. ///关联的overlay对象
  40. @property (nonatomic, readonly) id <BMKOverlay> overlay;
  41. /**
  42. *将直角坐标转为overlay view坐标
  43. *@param mapPoint 直角坐标
  44. *@return 对应的view坐标
  45. */
  46. - (CGPoint)pointForMapPoint:(BMKMapPoint)mapPoint;
  47. /**
  48. *将overlay view坐标转为直角坐标
  49. *@param point view坐标
  50. *@return 对应的直角坐标
  51. */
  52. - (BMKMapPoint)mapPointForPoint:(CGPoint)point;
  53. /**
  54. *将二维地图投影矩形转为overlay view矩形
  55. *@param mapRect 二维地图投影矩形
  56. *@return 对应的view矩形
  57. */
  58. - (CGRect)rectForMapRect:(BMKMapRect)mapRect;
  59. /**
  60. *将overlay view区域转为二维地图投影区域
  61. *@param rect 指定的view矩形
  62. *@return 对应的二维地图投影矩形
  63. */
  64. - (BMKMapRect)mapRectForRect:(CGRect)rect;
  65. /**
  66. *判断ovlerlay view是否准备绘制内容
  67. *默认返回YES,如果用户设为NO,当需要绘制内容时要显示调用setNeedsDisplayInMapRect:zoomScale:方法
  68. *@param mapRect 需要更新的地图矩形区域
  69. *@param zoomScale 当前的缩放因子
  70. *@return 如果view准备好绘制内容,返回YES,否则返回NO
  71. */
  72. - (BOOL)canDrawMapRect:(BMKMapRect)mapRect zoomScale:(BMKZoomScale)zoomScale;
  73. /**
  74. *绘制overlay view内容
  75. *该方法默认不做任何事,子类需要重载该方法来绘制view的内容
  76. *@param mapRect 需要更新的地图矩形区域
  77. *@param zoomScale 当前的缩放因子
  78. *@param context 使用的graphics context
  79. */
  80. - (void)drawMapRect:(BMKMapRect)mapRect zoomScale:(BMKZoomScale)zoomScale inContext:(CGContextRef)context;
  81. /**
  82. *使view在给定矩形的区域无效,系统将重绘该区域
  83. *@param mapRect 需要更新的区域
  84. */
  85. - (void)setNeedsDisplayInMapRect:(BMKMapRect)mapRect;
  86. /**
  87. *使用OpenGLES 绘制线
  88. @param points 直角坐标点
  89. @param pointCount 点个数
  90. @param strokeColor 线颜色
  91. @param lineWidth OpenGLES支持线宽尺寸
  92. @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES.
  93. */
  94. - (void)renderLinesWithPoints:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount strokeColor:(UIColor *)strokeColor lineWidth:(CGFloat)lineWidth looped:(BOOL)looped;
  95. /**
  96. *使用OpenGLES 绘制线
  97. @param points 直角坐标点
  98. @param pointCount 点个数
  99. @param strokeColor 线颜色
  100. @param lineWidth OpenGLES支持线宽尺寸
  101. @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES.
  102. @param lineDash 是否虚线样式
  103. */
  104. - (void)renderLinesWithPoints:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount strokeColor:(UIColor *)strokeColor lineWidth:(CGFloat)lineWidth looped:(BOOL)looped lineDash:(BOOL)lineDash;
  105. /**
  106. *使用OpenGLES 按指定纹理绘制线
  107. @param points 直角坐标点
  108. @param pointCount 点个数
  109. @param lineWidth OpenGLES支持线宽尺寸
  110. @param textureID 纹理ID,使用- (void)loadStrokeTextureImage:(UIImage *)textureImage;加载
  111. @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES.
  112. */
  113. - (void)renderTexturedLinesWithPoints:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount lineWidth:(CGFloat)lineWidth textureID:(GLuint)textureID looped:(BOOL)looped;
  114. /**
  115. *使用OpenGLES 按指定纹理绘制线
  116. @param points 直角坐标点
  117. @param pointCount 点个数
  118. @param lineWidth OpenGLES支持线宽尺寸
  119. @param textureID 纹理ID,使用- (void)loadStrokeTextureImage:(UIImage *)textureImage;加载
  120. @param looped 是否闭合, 如polyline会设置NO, polygon会设置YES.
  121. @param tileTexture 是否纹理图片平铺绘制
  122. @param keepScale 纹理图片是否缩放(tileTexture为YES时生效)
  123. */
  124. - (void)renderTexturedLinesWithPoints:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount lineWidth:(CGFloat)lineWidth textureID:(GLuint)textureID strokeColor:(UIColor *)strokeColor looped:(BOOL)looped tileTexture:(BOOL) tileTexture keepScale:(BOOL) keepScale;
  125. /**
  126. *使用OpenGLES 分段纹理绘制线
  127. @param partPt 分段直角坐标点
  128. @param lineWidth OpenGLES支持线宽尺寸
  129. @param textureIndexs 分段纹理索引,使用- (void)loadStrokeTextureImage:(UIImage *)textureImage;加载
  130. @param isFoucs 是否使用分段纹理绘制
  131. */
  132. -(void)renderTexturedLinesWithPartPoints:(NSArray*)partPt lineWidth:(CGFloat)lineWidth textureIndexs:(NSArray*)textureIndexs isFocus:(BOOL) isFoucs;
  133. /**
  134. *使用OpenGLES 分段纹理绘制线/分段颜色绘制线
  135. @param partPt 分段直角坐标点
  136. @param lineWidth OpenGLES支持线宽尺寸
  137. @param textureIndexs 分段纹理索引,使用- (BOOL)loadStrokeTextureImages:(UIImage *)textureImage;加载
  138. @param isFoucs 是否使用分段纹理绘制
  139. @param tileTexture 是否纹理图片平铺绘制
  140. @param keepScale 纹理图片是否缩放(tileTexture为YES时生效)
  141. */
  142. -(void)renderTexturedLinesWithPartPoints:(NSArray*)partPt lineWidth:(CGFloat)lineWidth textureIndexs:(NSArray*)textureIndexs isFocus:(BOOL) isFoucs tileTexture:(BOOL) tileTexture keepScale:(BOOL) keepScale;
  143. /**
  144. *使用OpenGLES 绘制区域
  145. @param points 直角坐标点
  146. @param pointCount 点个数
  147. @param fillColor 填充颜色
  148. @param usingTriangleFan YES对应GL_TRIANGLE_FAN, NO对应GL_TRIANGLES
  149. */
  150. - (void)renderRegionWithPoints:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount fillColor:(UIColor *)fillColor usingTriangleFan:(BOOL)usingTriangleFan;
  151. /**
  152. *使用OpenGLES 绘制区域(支持凹多边形)
  153. @param points 直角坐标点
  154. @param pointCount 点个数
  155. @param fillColor 填充颜色
  156. @param usingTriangleFan YES对应GL_TRIANGLE_FAN, NO对应GL_TRIANGLES
  157. */
  158. - (void)renderATRegionWithPoint:(BMKMapPoint *)points pointCount:(NSUInteger)pointCount fillColor:(UIColor *)fillColor usingTriangleFan:(BOOL)usingTriangleFan;
  159. /**
  160. *绘制函数(子类需要重载来实现)
  161. */
  162. - (void)glRender;
  163. ///关联的纹理对象ID
  164. @property (nonatomic, readonly) GLuint strokeTextureID;
  165. /**
  166. *加载纹理图片
  167. @param textureImage 图片对象,opengl要求图片宽高必须是2的n次幂,如果图片对象为nil,则清空原有纹理
  168. @return openGL纹理ID, 若纹理加载失败返回0
  169. */
  170. - (GLuint)loadStrokeTextureImage:(UIImage *)textureImage;
  171. /**
  172. *加载分段纹理绘制 所需的纹理图片
  173. @param textureImages 必须UIImage数组,opengl要求图片宽高必须是2的n次幂,否则,返回NO,无法分段纹理绘制
  174. @return 是否成功
  175. */
  176. - (BOOL)loadStrokeTextureImages:(NSArray *)textureImages;
  177. /// 使用分段颜色绘制时,必须设置(内容必须为UIColor)
  178. /// 注:请使用 - (UIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; 初始化UIColor。使用[UIColor ***Color]初始化时,个别case转换成RGB后会有问题
  179. @property (nonatomic, strong) NSArray *colors;
  180. @end