polyline.tsx
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as React from "react";
import { ColorValue, ImageSourcePropType, Platform, processColor, requireNativeComponent } from "react-native";
// @ts-ignore
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
import { LatLng } from "./types";
export interface PolylineProps {
/**
* 节点坐标
*/
points: LatLng[];
/**
* 线段宽度
*/
width?: number;
/**
* 线段的纹理
*/
line?: ImageSourcePropType;
/**
* 线段颜色
*/
color?: ColorValue;
/**
* 层级
*/
zIndex?: number;
/**
* 多段颜色
*/
colors: ColorValue[];
/**
* 是否使用颜色渐变
*/
gradient?: boolean;
/**
* 是否绘制大地线
*/
geodesic?: boolean;
/**
* 是否绘制虚线
*/
dotted?: boolean;
/**
* 点击事件
*/
onPress?: () => void;
}
export default class extends React.PureComponent<PolylineProps> {
static defaultProps = { colors: [], with: 16 };
render() {
const props = {
...this.props,
...Platform.select({ android: { colors: this.props.colors.map(processColor) } }),
};
// @ts-ignore
return <NativePolyline {...props} line={resolveAssetSource(props.line)} />;
}
}
const NativePolyline = requireNativeComponent<PolylineProps>("AMapPolyline");