@evnydd0sf/react-native-amap3d-fix 3.2.4-fix.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/lib/android/build.gradle +34 -0
  2. package/lib/android/src/main/AndroidManifest.xml +10 -0
  3. package/lib/android/src/main/java/qiuxiang/amap3d/AMap3DPackage.kt +28 -0
  4. package/lib/android/src/main/java/qiuxiang/amap3d/Utils.kt +114 -0
  5. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Circle.kt +65 -0
  6. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/CircleManager.kt +49 -0
  7. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/HeatMap.kt +32 -0
  8. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/HeatMapManager.kt +33 -0
  9. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MapView.kt +174 -0
  10. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MapViewManager.kt +153 -0
  11. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Marker.kt +102 -0
  12. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MarkerManager.kt +78 -0
  13. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MultiPoint.kt +53 -0
  14. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MultiPointManager.kt +33 -0
  15. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Overlay.kt +8 -0
  16. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Polygon.kt +58 -0
  17. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/PolygonManager.kt +44 -0
  18. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Polyline.kt +69 -0
  19. package/lib/android/src/main/java/qiuxiang/amap3d/map_view/PolylineManager.kt +64 -0
  20. package/lib/android/src/main/java/qiuxiang/amap3d/modules/SdkModule.kt +31 -0
  21. package/lib/ios/.swiftformat +2 -0
  22. package/lib/ios/Bridging-Header.h +4 -0
  23. package/lib/ios/MapView/CircleManager.m +11 -0
  24. package/lib/ios/MapView/CircleManager.swift +30 -0
  25. package/lib/ios/MapView/HeatMapManager.m +9 -0
  26. package/lib/ios/MapView/HeatMapManager.swift +29 -0
  27. package/lib/ios/MapView/MapViewManager.m +35 -0
  28. package/lib/ios/MapView/MapViewManager.swift +159 -0
  29. package/lib/ios/MapView/MarkerManager.m +18 -0
  30. package/lib/ios/MapView/MarkerManager.swift +100 -0
  31. package/lib/ios/MapView/MultiPointManager.m +9 -0
  32. package/lib/ios/MapView/MultiPointManager.swift +47 -0
  33. package/lib/ios/MapView/Overlay.swift +4 -0
  34. package/lib/ios/MapView/PolygonManager.m +10 -0
  35. package/lib/ios/MapView/PolygonManager.swift +30 -0
  36. package/lib/ios/MapView/PolylineManager.m +12 -0
  37. package/lib/ios/MapView/PolylineManager.swift +41 -0
  38. package/lib/ios/Modules/SdkModule.m +8 -0
  39. package/lib/ios/Modules/SdkModule.swift +16 -0
  40. package/lib/ios/Utils.swift +104 -0
  41. package/lib/ios/react-native-amap3d.podspec +20 -0
  42. package/lib/src/circle.tsx +36 -0
  43. package/lib/src/cluster/cluster-view.tsx +47 -0
  44. package/lib/src/cluster/index.tsx +159 -0
  45. package/lib/src/component.ts +31 -0
  46. package/lib/src/heat-map.tsx +21 -0
  47. package/lib/src/index.ts +11 -0
  48. package/lib/src/map-view.tsx +230 -0
  49. package/lib/src/marker.tsx +128 -0
  50. package/lib/src/multi-point.tsx +28 -0
  51. package/lib/src/polygon.tsx +31 -0
  52. package/lib/src/polyline.tsx +65 -0
  53. package/lib/src/sdk.ts +11 -0
  54. package/lib/src/types.ts +137 -0
  55. package/license +21 -0
  56. package/package.json +56 -0
  57. package/react-native-amap3d.podspec +20 -0
  58. package/react-native.config.js +20 -0
  59. package/readme.md +186 -0
@@ -0,0 +1,159 @@
1
+ import * as React from "react";
2
+ import { ViewStyle } from "react-native";
3
+ import Supercluster, { ClusterFeature, ClusterProperties } from "supercluster";
4
+ import { CameraEvent } from "../map-view";
5
+ import { LatLng } from "../types";
6
+ import ClusterView from "./cluster-view";
7
+
8
+ export interface ClusterParams {
9
+ /**
10
+ * 唯一标识
11
+ */
12
+ id: number;
13
+
14
+ /**
15
+ * 包含的 Marker 数量
16
+ */
17
+ count: number;
18
+
19
+ /**
20
+ * 坐标
21
+ */
22
+ position: LatLng;
23
+ }
24
+
25
+ interface ClusterPoint {
26
+ /**
27
+ * 坐标
28
+ */
29
+ position: LatLng;
30
+
31
+ /**
32
+ * 携带的数据,可以是任意类型
33
+ */
34
+ properties?: any;
35
+ }
36
+
37
+ interface Props {
38
+ /**
39
+ * 聚合半径
40
+ */
41
+ radius?: number;
42
+
43
+ /**
44
+ * 聚合点样式
45
+ */
46
+ clusterStyle?: ViewStyle;
47
+
48
+ /**
49
+ * 聚合点文本样式
50
+ */
51
+ clusterTextStyle?: ViewStyle;
52
+
53
+ /**
54
+ * 坐标点列表
55
+ */
56
+ points: ClusterPoint[];
57
+
58
+ /**
59
+ * 渲染 Marker
60
+ */
61
+ renderMarker: (item: ClusterPoint) => React.ReactNode;
62
+
63
+ /**
64
+ * 渲染聚合点
65
+ */
66
+ renderCluster?: (params: ClusterParams) => React.ComponentType<any>;
67
+
68
+ /**
69
+ * 聚合点点击事件
70
+ */
71
+ onPress?: (params: ClusterParams) => void;
72
+ }
73
+
74
+ interface State {
75
+ clusters: ClusterFeature<ClusterProperties>[];
76
+ }
77
+
78
+ export default class Cluster extends React.PureComponent<Props, State> {
79
+ static defaultProps = { radius: 200 };
80
+ state: State = { clusters: [] };
81
+ status?: CameraEvent;
82
+ cluster?: Supercluster<any, ClusterProperties>;
83
+
84
+ componentDidMount() {
85
+ this.init();
86
+ }
87
+
88
+ componentDidUpdate(props: Props) {
89
+ if (props.points != this.props.points) {
90
+ this.init();
91
+ }
92
+ }
93
+
94
+ async init() {
95
+ const { radius, points } = this.props;
96
+ // 如果主线程占用太多计算资源,会导致 ios onLoad 事件无法触发,非常蛋疼
97
+ // 暂时想到的解决办法是等一个事件循环
98
+ await new Promise((resolve) => setTimeout(resolve, 0));
99
+ const options = { radius, minZoom: 3, maxZoom: 21 };
100
+ this.cluster = new Supercluster<any, ClusterProperties>(options).load(
101
+ points.map((marker) => ({
102
+ type: "Feature",
103
+ geometry: {
104
+ type: "Point",
105
+ coordinates: [marker.position.longitude, marker.position.latitude],
106
+ },
107
+ properties: marker.properties,
108
+ }))
109
+ );
110
+ if (this.status) {
111
+ this.update(this.status);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * 需要在 MapView.onCameraIdle({ nativeEvent }) 回调里调用,参数为 nativeEvent
117
+ */
118
+ async update(status: CameraEvent) {
119
+ this.status = status;
120
+ await new Promise((resolve) => setTimeout(resolve, 0));
121
+ const { cameraPosition, latLngBounds } = status;
122
+ const { southwest, northeast } = latLngBounds;
123
+ const clusters = this.cluster!.getClusters(
124
+ [southwest.longitude, southwest.latitude, northeast.longitude, northeast.latitude],
125
+ Math.round(cameraPosition.zoom!)
126
+ );
127
+ this.setState({ clusters });
128
+ }
129
+
130
+ renderCluster = (cluster: ClusterParams) => {
131
+ return (
132
+ <ClusterView
133
+ key={cluster.id}
134
+ cluster={cluster}
135
+ onPress={this.props.onPress}
136
+ style={this.props.clusterStyle}
137
+ textStyle={this.props.clusterTextStyle}
138
+ />
139
+ );
140
+ };
141
+
142
+ render() {
143
+ const { renderCluster, renderMarker } = this.props;
144
+ const render = renderCluster || this.renderCluster;
145
+ return this.state.clusters.map(({ geometry, properties }) => {
146
+ const position = {
147
+ latitude: geometry.coordinates[1],
148
+ longitude: geometry.coordinates[0],
149
+ };
150
+
151
+ if (properties.point_count > 0) {
152
+ const { cluster_id, point_count } = properties;
153
+ return render({ position, id: cluster_id, count: point_count });
154
+ }
155
+
156
+ return renderMarker({ position, properties });
157
+ });
158
+ }
159
+ }
@@ -0,0 +1,31 @@
1
+ import { PureComponent } from "react";
2
+ import { findNodeHandle, UIManager } from "react-native";
3
+
4
+ export default class Component<P, S = {}> extends PureComponent<P, S> {
5
+ /**
6
+ * 原生 View 名称,继承时必须指定
7
+ */
8
+ name = "";
9
+ mounted = false;
10
+
11
+ componentDidMount() {
12
+ this.mounted = true;
13
+ }
14
+
15
+ componentWillUnmount() {
16
+ this.mounted = false;
17
+ }
18
+
19
+ /**
20
+ * 调用原生方法
21
+ */
22
+ invoke(name: string, params?: any[]) {
23
+ if (!this.mounted) return;
24
+
25
+ const handle = findNodeHandle(this);
26
+ if (handle) {
27
+ const command = UIManager.getViewManagerConfig(this.name).Commands[name];
28
+ UIManager.dispatchViewManagerCommand(handle, command, params);
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,21 @@
1
+ import { requireNativeComponent } from "react-native";
2
+ import { LatLng } from "./types";
3
+
4
+ export interface HeatMapProps {
5
+ /**
6
+ * 节点坐标
7
+ */
8
+ data: LatLng[];
9
+
10
+ /**
11
+ * 半径(米)
12
+ */
13
+ radius?: number;
14
+
15
+ /**
16
+ * 透明度
17
+ */
18
+ opacity?: number;
19
+ }
20
+
21
+ export default requireNativeComponent<HeatMapProps>("AMapHeatMap");
@@ -0,0 +1,11 @@
1
+ export { default as Circle } from "./circle";
2
+ export { default as Cluster } from "./cluster";
3
+ export { default as HeatMap } from "./heat-map";
4
+ export { default as MapView } from "./map-view";
5
+ export { default as Marker } from "./marker";
6
+ export { default as MultiPoint } from "./multi-point";
7
+ export { default as Polygon } from "./polygon";
8
+ export { default as Polyline } from "./polyline";
9
+ export * from "./types";
10
+ export { AMapSdk };
11
+ import * as AMapSdk from "./sdk";
@@ -0,0 +1,230 @@
1
+ import * as React from "react";
2
+ import {
3
+ NativeMethods,
4
+ NativeSyntheticEvent,
5
+ requireNativeComponent,
6
+ ViewProps,
7
+ } from "react-native";
8
+ import Component from "./component";
9
+ import { CameraPosition, LatLng, LatLngBounds, MapPoi, MapType, Point } from "./types";
10
+
11
+ export interface CameraEvent {
12
+ cameraPosition: CameraPosition;
13
+ latLngBounds: LatLngBounds;
14
+ }
15
+
16
+ export interface MapViewProps extends ViewProps {
17
+ /**
18
+ * 地图类型
19
+ */
20
+ mapType?: MapType;
21
+
22
+ /**
23
+ * 初始状态
24
+ */
25
+ initialCameraPosition?: CameraPosition;
26
+
27
+ /**
28
+ * 是否显示当前定位
29
+ */
30
+ myLocationEnabled?: boolean;
31
+
32
+ /**
33
+ * 是否显示室内地图
34
+ */
35
+ indoorViewEnabled?: boolean;
36
+
37
+ /**
38
+ * 是否显示3D建筑
39
+ */
40
+ buildingsEnabled?: boolean;
41
+
42
+ /**
43
+ * 是否显示标注
44
+ */
45
+ labelsEnabled?: boolean;
46
+
47
+ /**
48
+ * 是否显示指南针
49
+ */
50
+ compassEnabled?: boolean;
51
+
52
+ /**
53
+ * 是否显示放大缩小按钮
54
+ *
55
+ * @platform android
56
+ */
57
+ zoomControlsEnabled?: boolean;
58
+
59
+ /**
60
+ * 是否显示比例尺
61
+ */
62
+ scaleControlsEnabled?: boolean;
63
+
64
+ /**
65
+ * 是否显示定位按钮
66
+ *
67
+ * @platform android
68
+ */
69
+ myLocationButtonEnabled?: boolean;
70
+
71
+ /**
72
+ * 是否显示路况
73
+ */
74
+ trafficEnabled?: boolean;
75
+
76
+ /**
77
+ * 最大缩放级别
78
+ */
79
+ maxZoom?: number;
80
+
81
+ /**
82
+ * 最小缩放级别
83
+ */
84
+ minZoom?: number;
85
+
86
+ /**
87
+ * 是否启用缩放手势,用于放大缩小
88
+ */
89
+ zoomGesturesEnabled?: boolean;
90
+
91
+ /**
92
+ * 是否启用滑动手势,用于平移
93
+ */
94
+ scrollGesturesEnabled?: boolean;
95
+
96
+ /**
97
+ * 是否启用旋转手势,用于调整方向
98
+ */
99
+ rotateGesturesEnabled?: boolean;
100
+
101
+ /**
102
+ * 是否启用倾斜手势,用于改变视角
103
+ */
104
+ tiltGesturesEnabled?: boolean;
105
+
106
+ /**
107
+ * 设定定位的最小更新距离
108
+ *
109
+ * @platform ios
110
+ */
111
+ distanceFilter?: number;
112
+
113
+ /**
114
+ * 设定最小更新角度,默认为 1 度
115
+ *
116
+ * @platform ios
117
+ */
118
+ headingFilter?: number;
119
+
120
+ /**
121
+ * 点击事件
122
+ */
123
+ onPress?: (event: NativeSyntheticEvent<LatLng>) => void;
124
+
125
+ /**
126
+ * 标注点击事件
127
+ */
128
+ onPressPoi?: (event: NativeSyntheticEvent<MapPoi>) => void;
129
+
130
+ /**
131
+ * 长按事件
132
+ */
133
+ onLongPress?: (event: NativeSyntheticEvent<LatLng>) => void;
134
+
135
+ /**
136
+ * 地图状态改变事件,随地图状态变化不停地触发
137
+ */
138
+ onCameraMove?: (event: NativeSyntheticEvent<CameraEvent>) => void;
139
+
140
+ /**
141
+ * 地图状态改变事件,在停止变化后触发
142
+ */
143
+ onCameraIdle?: (event: NativeSyntheticEvent<CameraEvent>) => void;
144
+
145
+ /**
146
+ * 地图初始化完成事件
147
+ */
148
+ onLoad?: (event: NativeSyntheticEvent<void>) => void;
149
+
150
+ /**
151
+ * 地图定位更新事件
152
+ */
153
+ onLocation?: (event: NativeSyntheticEvent<GeolocationPosition>) => void;
154
+ }
155
+
156
+ const name = "AMapView";
157
+ const NativeMapView = requireNativeComponent<MapViewProps>(name);
158
+
159
+ export default class extends Component<MapViewProps> {
160
+ static defaultProps = {
161
+ style: { flex: 1 },
162
+ compassEnabled: true,
163
+ scaleControlsEnabled: true,
164
+ distanceFilter: 1,
165
+ };
166
+
167
+ name = name;
168
+ ref?: (React.Component<MapViewProps> & NativeMethods) | null;
169
+ state = { loaded: false };
170
+ callbackMap: { [key: number]: (data: any) => void } = {};
171
+
172
+ /**
173
+ * 移动视角
174
+ */
175
+ moveCamera(cameraPosition: CameraPosition, duration = 0) {
176
+ this.invoke("moveCamera", [cameraPosition, duration]);
177
+ }
178
+
179
+ /**
180
+ * 点坐标转地理坐标,主要用于地图选点
181
+ */
182
+ getLatLng(point: Point): Promise<LatLng> {
183
+ return this.call("getLatLng", point);
184
+ }
185
+
186
+ callback = ({ nativeEvent }: NativeSyntheticEvent<{ id: number; data: any }>) => {
187
+ this.callbackMap[nativeEvent.id]?.call(this, nativeEvent.data);
188
+ delete this.callbackMap[nativeEvent.id];
189
+ };
190
+
191
+ call(name: string, args: any): Promise<any> {
192
+ const id = Math.random();
193
+ this.invoke("call", [id, name, args]);
194
+ return new Promise((resolve) => (this.callbackMap[id] = resolve));
195
+ }
196
+
197
+ componentDidMount() {
198
+ super.componentDidMount();
199
+ // 无论如何也要在 1 秒后 setLoaded(true) ,防止 onLoad 事件不触发的情况下显示不正常
200
+ // 目前只在 iOS 上低概率出现
201
+ setTimeout(() => this.setState({ loaded: true }), 1000);
202
+ }
203
+
204
+ render() {
205
+ let { style, onLoad } = this.props;
206
+ if (!this.state.loaded) {
207
+ style = [style, { width: 1, height: 1 }];
208
+ }
209
+ return (
210
+ <NativeMapView
211
+ {...this.props}
212
+ ref={(ref) => (this.ref = ref)}
213
+ style={style}
214
+ // @ts-ignore: 内部接口
215
+ onCallback={this.callback}
216
+ onPress={(event) => {
217
+ if (event.nativeEvent.latitude) {
218
+ this.props.onPress?.call(this, event);
219
+ }
220
+ }}
221
+ onLoad={(event) => {
222
+ // android 地图部分控件不显示的问题在重新 layout 之后会恢复正常。
223
+ // 同时也能修复 ios 地图偶尔出现的 layout 异常
224
+ this.setState({ loaded: true });
225
+ onLoad?.call(this, event);
226
+ }}
227
+ />
228
+ );
229
+ }
230
+ }
@@ -0,0 +1,128 @@
1
+ import * as React from "react";
2
+ import {
3
+ ImageSourcePropType,
4
+ NativeSyntheticEvent,
5
+ requireNativeComponent,
6
+ View,
7
+ ViewStyle,
8
+ } from "react-native";
9
+ // @ts-ignore
10
+ import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
11
+ import Component from "./component";
12
+ import { LatLng, Point } from "./types";
13
+
14
+ export interface MarkerProps {
15
+ /**
16
+ * 坐标
17
+ */ position: LatLng;
18
+
19
+ /**
20
+ * 图标
21
+ */
22
+ icon?: ImageSourcePropType;
23
+
24
+ /**
25
+ * 透明度 [0, 1]
26
+ *
27
+ * @platform android
28
+ */
29
+ opacity?: number;
30
+
31
+ /**
32
+ * 是否可拖拽
33
+ */
34
+ draggable?: boolean;
35
+
36
+ /**
37
+ * 是否平贴地图
38
+ *
39
+ * @platform android
40
+ */
41
+ flat?: boolean;
42
+
43
+ /**
44
+ * 层级
45
+ */
46
+ zIndex?: number;
47
+
48
+ /**
49
+ * 覆盖物锚点比例
50
+ *
51
+ * @link http://a.amap.com/lbs/static/unzip/Android_Map_Doc/3D/com/amap/api/maps/model/Marker.html#setAnchor-float-float-
52
+ * @platform android
53
+ */
54
+ anchor?: Point;
55
+
56
+ /**
57
+ * 覆盖物偏移位置
58
+ *
59
+ * @link http://a.amap.com/lbs/static/unzip/iOS_Map_Doc/AMap_iOS_API_Doc_3D/interface_m_a_annotation_view.html#a78f23c1e6a6d92faf12a00877ac278a7
60
+ * @platform ios
61
+ */
62
+ centerOffset?: Point;
63
+
64
+ /**
65
+ * 自定义 View
66
+ */
67
+ children?: React.ReactNode;
68
+
69
+ /**
70
+ * 点击事件
71
+ */
72
+ onPress?: () => void;
73
+
74
+ /**
75
+ * 拖放开始事件
76
+ */
77
+ onDragStart?: () => void;
78
+
79
+ /**
80
+ * 拖放进行事件,类似于 mousemove,在结束之前会不断调用
81
+ */
82
+ onDrag?: () => void;
83
+
84
+ /**
85
+ * 拖放结束事件
86
+ */
87
+ onDragEnd?: (event: NativeSyntheticEvent<LatLng>) => void;
88
+ }
89
+
90
+ export default class extends Component<MarkerProps> {
91
+ name = name;
92
+
93
+ /**
94
+ * 触发自定义 view 更新
95
+ *
96
+ * 通常来说,不需要主动调用该方法,对于 android,如果自定义 view 存在异步更新,
97
+ * 例如,包含一个引用了网络图片的 <Image />,则需要在 view 更新后主动调用该方法触发
98
+ * icon 更新。
99
+ */
100
+ update = () => {
101
+ setTimeout(() => this.invoke("update"), 0);
102
+ };
103
+
104
+ componentDidUpdate() {
105
+ if (this.props.children) {
106
+ this.update();
107
+ }
108
+ }
109
+
110
+ render() {
111
+ const props = { ...this.props };
112
+ Reflect.set(props, "latLng", props.position);
113
+ // @ts-ignore android 不能用 position 作为属性,会发生冲突,也是个蛋疼的问题
114
+ delete props.position;
115
+ if (props.children) {
116
+ props.children = (
117
+ <View style={style} onLayout={this.update}>
118
+ {props.children}
119
+ </View>
120
+ );
121
+ }
122
+ return <NativeMarker {...props} icon={resolveAssetSource(props.icon)} />;
123
+ }
124
+ }
125
+
126
+ const name = "AMapMarker";
127
+ const style: ViewStyle = { position: "absolute", zIndex: -1 };
128
+ const NativeMarker = requireNativeComponent<MarkerProps>(name);
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ import { ImageSourcePropType, NativeSyntheticEvent, requireNativeComponent } from "react-native";
3
+ // @ts-ignore
4
+ import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
5
+ import { LatLng } from "./types";
6
+
7
+ const NativeMultiPoint = requireNativeComponent<MultiPointProps>("AMapMultiPoint");
8
+
9
+ export interface MultiPointProps {
10
+ /**
11
+ * 坐标点集合
12
+ */
13
+ items?: LatLng[];
14
+
15
+ /**
16
+ * 图标
17
+ */
18
+ icon?: ImageSourcePropType;
19
+
20
+ /**
21
+ * 点击事件
22
+ */
23
+ onPress?: (event: NativeSyntheticEvent<{ index: number }>) => void;
24
+ }
25
+
26
+ export default (props: MultiPointProps) => {
27
+ return <NativeMultiPoint {...props} icon={resolveAssetSource(props.icon)} />;
28
+ };
@@ -0,0 +1,31 @@
1
+ import { requireNativeComponent } from "react-native";
2
+ import { LatLng } from "./types";
3
+
4
+ export interface Polygon {
5
+ /**
6
+ * 节点坐标
7
+ */
8
+ points: LatLng[];
9
+
10
+ /**
11
+ * 边线宽度
12
+ */
13
+ strokeWidth?: number;
14
+
15
+ /**
16
+ * 边线颜色
17
+ */
18
+ strokeColor?: string;
19
+
20
+ /**
21
+ * 填充颜色
22
+ */
23
+ fillColor?: string;
24
+
25
+ /**
26
+ * 层级
27
+ */
28
+ zIndex?: number;
29
+ }
30
+
31
+ export default requireNativeComponent<Polygon>("AMapPolygon");
@@ -0,0 +1,65 @@
1
+ import * as React from "react";
2
+ import { ColorValue, Platform, processColor, requireNativeComponent } from "react-native";
3
+ import { LatLng } from "./types";
4
+
5
+ export interface PolylineProps {
6
+ /**
7
+ * 节点坐标
8
+ */
9
+ points: LatLng[];
10
+
11
+ /**
12
+ * 线段宽度
13
+ */
14
+ width?: number;
15
+
16
+ /**
17
+ * 线段颜色
18
+ */
19
+ color?: ColorValue;
20
+
21
+ /**
22
+ * 层级
23
+ */
24
+ zIndex?: number;
25
+
26
+ /**
27
+ * 多段颜色
28
+ */
29
+ colors: ColorValue[];
30
+
31
+ /**
32
+ * 是否使用颜色渐变
33
+ */
34
+ gradient?: boolean;
35
+
36
+ /**
37
+ * 是否绘制大地线
38
+ */
39
+ geodesic?: boolean;
40
+
41
+ /**
42
+ * 是否绘制虚线
43
+ */
44
+ dotted?: boolean;
45
+
46
+ /**
47
+ * 点击事件
48
+ */
49
+ onPress?: () => void;
50
+ }
51
+
52
+ export default class extends React.PureComponent<PolylineProps> {
53
+ static defaultProps = { colors: [] };
54
+
55
+ render() {
56
+ const props = {
57
+ ...this.props,
58
+ ...Platform.select({ android: { colors: this.props.colors.map(processColor) } }),
59
+ };
60
+ // @ts-ignore
61
+ return <NativePolyline {...props} />;
62
+ }
63
+ }
64
+
65
+ const NativePolyline = requireNativeComponent<PolylineProps>("AMapPolyline");