Commit 059ce10b authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS circle 接口

parent fc80b021
...@@ -16,7 +16,7 @@ internal class AMapCircleManager : ViewGroupManager<AMapCircle>() { ...@@ -16,7 +16,7 @@ internal class AMapCircleManager : ViewGroupManager<AMapCircle>() {
return AMapCircle(reactContext) return AMapCircle(reactContext)
} }
@ReactProp(name = "center") @ReactProp(name = "coordinate")
fun setCoordinate(circle: AMapCircle, coordinate: ReadableMap) { fun setCoordinate(circle: AMapCircle, coordinate: ReadableMap) {
circle.center = LatLng( circle.center = LatLng(
coordinate.getDouble("latitude"), coordinate.getDouble("latitude"),
......
import React, {PropTypes, Component} from 'react' import React, {PropTypes, Component} from 'react'
import {requireNativeComponent, View, PixelRatio} from 'react-native' import {requireNativeComponent, View, PixelRatio, Platform} from 'react-native'
import {LatLng} from './PropTypes' import {LatLng} from './PropTypes'
class Circle extends Component { class Circle extends Component {
...@@ -9,7 +9,7 @@ class Circle extends Component { ...@@ -9,7 +9,7 @@ class Circle extends Component {
/** /**
* 圆点 * 圆点
*/ */
center: LatLng.isRequired, coordinate: LatLng.isRequired,
/** /**
* 半径(米) * 半径(米)
...@@ -25,7 +25,11 @@ class Circle extends Component { ...@@ -25,7 +25,11 @@ class Circle extends Component {
render() { render() {
const props = { const props = {
...this.props, ...this.props,
strokeWidth: PixelRatio.getPixelSizeForLayoutSize(this.props.strokeWidth), ...Platform.select({
android: {
strokeWidth: PixelRatio.getPixelSizeForLayoutSize(this.props.strokeWidth),
},
}),
} }
return <AMapCircle {...props}/> return <AMapCircle {...props}/>
} }
......
#import <MAMapKit/MAMapKit.h>
#import "AMapModel.h"
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
@interface AMapCircle : AMapModel
@property(nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property(nonatomic, readonly) MAMapRect boundingMapRect;
@end
#import "AMapCircle.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapCircle {
MACircle *_circle;
MACircleRenderer *_renderer;
CGFloat _strokeWidth;
UIColor *_strokeColor;
UIColor *_fillColor;
CLLocationCoordinate2D _coordinate;
CLLocationDistance _radius;
}
- (void)setCoordinate:(CLLocationCoordinate2D)coordinate {
_coordinate = coordinate;
_circle.coordinate = coordinate;
}
- (void)setRadius:(CLLocationDistance)radius {
_radius = radius;
_circle.radius = radius;
}
- (void)setStrokeWidth:(CGFloat)strokeWidth {
_strokeWidth = strokeWidth;
_renderer.lineWidth = strokeWidth;
}
- (void)setStrokeColor:(UIColor *)strokeColor {
_strokeColor = strokeColor;
_renderer.strokeColor = strokeColor;
}
- (void)setFillColor:(UIColor *)fillColor {
_fillColor = fillColor;
_renderer.fillColor = fillColor;
}
- (CLLocationCoordinate2D)coordinate {
return _circle.coordinate;
}
- (MAMapRect)boundingMapRect {
return _circle.boundingMapRect;
}
- (MAOverlayRenderer *)renderer {
if (_strokeColor == nil) {
_strokeColor = UIColor.blackColor;
}
_circle = [MACircle circleWithCenterCoordinate:_coordinate radius:_radius];
_renderer = [[MACircleRenderer alloc] initWithCircle:_circle];
_renderer.lineWidth = _strokeWidth;
_renderer.strokeColor = _strokeColor;
_renderer.fillColor = _fillColor;
return _renderer;
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapCircle.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapCircleManager : RCTViewManager <MAMapViewDelegate>
@end
@implementation AMapCircleManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapCircle new];
}
RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D)
RCT_EXPORT_VIEW_PROPERTY(radius, CLLocationDistance)
RCT_EXPORT_VIEW_PROPERTY(strokeWidth, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(strokeColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(fillColor, UIColor)
@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