Commit 1ce12718 authored by 7c00's avatar 7c00

实现 ios 热力图接口

parent c0ba4855
...@@ -2,6 +2,9 @@ import React, {PropTypes, PureComponent} from 'react' ...@@ -2,6 +2,9 @@ import React, {PropTypes, PureComponent} from 'react'
import {PixelRatio, Platform, requireNativeComponent, ViewPropTypes} from 'react-native' import {PixelRatio, Platform, requireNativeComponent, ViewPropTypes} from 'react-native'
import {LatLng} from '../PropTypes' import {LatLng} from '../PropTypes'
/**
* 注意,热力图组件的 props 设置过一次之后便不能再更改
*/
export default class HeatMap extends PureComponent { export default class HeatMap extends PureComponent {
static propTypes = { static propTypes = {
...ViewPropTypes, ...ViewPropTypes,
......
#import <MAMapKit/MAMapKit.h>
#import "AMapModel.h"
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
@interface AMapHeatMap : AMapModel
@end
#import "AMapHeatMap.h"
#import "Coordinate.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapHeatMap {
NSArray<MAHeatMapNode *> *_data;
MATileOverlayRenderer *_renderer;
MAHeatMapTileOverlay *_heatMap;
NSInteger _radius;
CGFloat _opacity;
}
- (void)setCoordinates:(NSArray<MAHeatMapNode *> *)coordinates {
_data = coordinates;
}
- (void)setRadius:(NSInteger)radius {
_radius = radius;
}
- (void)setOpacity:(CGFloat)opacity {
_opacity = opacity;
}
- (MAOverlayRenderer *)renderer {
if (_renderer == nil) {
if (_opacity == 0) {
_opacity = 0.6;
}
if (_radius == 0) {
_radius = 12;
}
_heatMap = [MAHeatMapTileOverlay new];
_heatMap.data = _data;
_heatMap.opacity = _opacity;
_heatMap.radius = _radius;
_renderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:_heatMap];
}
return _renderer;
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapHeatMap.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapHeatMapManager : RCTViewManager
@end
@implementation AMapHeatMapManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapHeatMap new];
}
RCT_EXPORT_VIEW_PROPERTY(coordinates, MAHeatMapNodeArray)
RCT_EXPORT_VIEW_PROPERTY(radius, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat)
@end
...@@ -24,6 +24,13 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{ ...@@ -24,6 +24,13 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
return [[Coordinate alloc] initWithCoordinate:[self CLLocationCoordinate2D:json]]; return [[Coordinate alloc] initWithCoordinate:[self CLLocationCoordinate2D:json]];
} }
+ (MAHeatMapNode *)MAHeatMapNode:(id)json {
MAHeatMapNode *node = [MAHeatMapNode new];
node.coordinate = [self CLLocationCoordinate2D:json];
node.intensity = 1;
return node;
}
+ (MACoordinateRegion)MACoordinateRegion:(id)json { + (MACoordinateRegion)MACoordinateRegion:(id)json {
return MACoordinateRegionMake( return MACoordinateRegionMake(
[self CLLocationCoordinate2D:json], [self CLLocationCoordinate2D:json],
...@@ -39,6 +46,7 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{ ...@@ -39,6 +46,7 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
} }
RCT_ARRAY_CONVERTER(Coordinate) RCT_ARRAY_CONVERTER(Coordinate)
RCT_ARRAY_CONVERTER(MAHeatMapNode)
RCT_ARRAY_CONVERTER(AMapNaviPoint) RCT_ARRAY_CONVERTER(AMapNaviPoint)
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment