iOS 热图包
LFHeatMap 是一个简单的 UIImage
生成器。生成的对象可以像任何其他 UIImage
一样使用,无论是独立使用还是插入到 UIImageView
中。虽然它可以在 MKMapView
上叠加,但它并不与这个特定的组件强相关,因此不提供比更复杂的 MKOverlayRenderer
实现更多的优势。
或者,您可以直接将 LFHeatMap
文件夹添加到您的项目中。
这个演示绘制了 2011 年 弗吉尼亚地震 测量的振幅。
数据存储在 quake.plist
中,这是一个简单的 plist 文件,存储每个测量的纬度、经度和振幅。点(位置)和重量(振幅)存储在 LFHeatMapDemoViewController
的 viewDidLoad
中的两个 NSArray
对象中。
主要动作发生在 sliderChanged:
函数中。移动滑块确定新的提升值并生成新的热图图像。图像的尺寸与 self.mapView
对象相同,点(位置)和重量由两个数据数组提供。然后将图像传递给叠加的 UIImageView
,位于地图的顶部。
这个类包含用于生成热图的三种基本静态函数。
提供所需的图像尺寸和提升,以及点/值数组。这两个数组之间应是一对一的映射,即 points 数组中的每个索引都应在 weights 数组中有相应的索引。
@params
rect: region frame
boost: heat boost value
points: array of NSValue CGPoint objects representing the data points
weights: array of NSNumber integer objects representing the weight of each point
@returns
UIImage object representing the heatmap for the specified region.
+ (UIImage *)heatMapWithRect:(CGRect)rect
boost:(float)boost
points:(NSArray *)points
weights:(NSArray *)weights
与基本热力图大致相同,但可以调整两个额外的参数来控制热力渲染的“染色”效果。
@params
rect: region frame
boost: heat boost value
points: array of NSValue CGPoint objects representing the data points
weights: array of NSNumber integer objects representing the weight of each point
weightsAdjustmentEnabled: set YES for weight balancing and normalization
groupingEnabled: set YES for tighter visual grouping of dense areas
@returns
UIImage object representing the heat map for the specified region.
+ (UIImage *)heatMapWithRect:(CGRect)rect
boost:(float)boost
points:(NSArray *)points
weights:(NSArray *)weights
weightsAdjustmentEnabled:(BOOL)weightsAdjustmentEnabled
groupingEnabled:(BOOL)groupingEnabled
与基本热力图功能相同,但允许您提供特定于地图的参数。传递一个 MKMapView
对象(通常是您想要覆盖的目标),以及对应于指定 MKMapView
对象上坐标的 CLLocation
对象数组的集合。
函数将根据需要将它们转换为所需的 CGRect/CGPoint 值。
@params
mapView: Map view representing the heat map area.
boost: heat boost value
locations: array of CLLocation objects representing the data points
weights: array of NSNumber integer objects representing the weight of each point
@returns
UIImage object representing the heatmap for the map region.
+ (UIImage *)heatMapForMapView:(MKMapView *)mapView
boost:(float)boost
locations:(NSArray *)locations
weights:(NSArray *)weights
LFHeatMap 基于 MIT 许可可用。有关更多信息,请参阅 LICENSE 文件。
LFHeatMap 来源于我在 Skyhook Wireless(现已关闭)开发的 LocalFaves 框架上的工作。该组件已开源,并成为《地理定位 iOS》一书中章节的基础。