expo-gaode-map 1.1.8 → 2.0.0-alpha.2
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.
- package/README.en.md +32 -46
- package/README.md +51 -70
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +98 -268
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -49
- package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +30 -7
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +1 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +10 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +38 -14
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +8 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +322 -93
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +25 -11
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +20 -10
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +6 -2
- package/build/ExpoGaodeMap.types.d.ts +27 -6
- package/build/ExpoGaodeMap.types.d.ts.map +1 -1
- package/build/ExpoGaodeMap.types.js +3 -0
- package/build/ExpoGaodeMap.types.js.map +1 -1
- package/build/ExpoGaodeMapModule.d.ts +157 -10
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +4 -0
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts +1 -17
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +4 -221
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts +11 -1
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +12 -58
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Cluster.d.ts.map +1 -1
- package/build/components/overlays/Cluster.js.map +1 -1
- package/build/components/overlays/Marker.d.ts +13 -1
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +51 -115
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts +7 -15
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +10 -80
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts +7 -14
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +9 -66
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -10
- package/build/index.js.map +1 -1
- package/build/types/map-view.types.d.ts +0 -90
- package/build/types/map-view.types.d.ts.map +1 -1
- package/build/types/map-view.types.js.map +1 -1
- package/build/types/overlays.types.d.ts +9 -9
- package/build/types/overlays.types.d.ts.map +1 -1
- package/build/types/overlays.types.js.map +1 -1
- package/docs/API.en.md +1 -21
- package/docs/API.md +84 -56
- package/docs/EXAMPLES.en.md +0 -48
- package/docs/EXAMPLES.md +49 -102
- package/docs/INITIALIZATION.md +59 -71
- package/docs/MIGRATION.md +423 -0
- package/ios/ExpoGaodeMapModule.swift +4 -0
- package/ios/ExpoGaodeMapView.swift +365 -258
- package/ios/ExpoGaodeMapViewModule.swift +3 -50
- package/ios/managers/CameraManager.swift +23 -2
- package/ios/managers/UIManager.swift +10 -5
- package/ios/modules/LocationManager.swift +10 -0
- package/ios/overlays/CircleView.swift +98 -19
- package/ios/overlays/CircleViewModule.swift +21 -0
- package/ios/overlays/ClusterView.swift +33 -4
- package/ios/overlays/HeatMapView.swift +16 -4
- package/ios/overlays/MarkerView.swift +235 -146
- package/ios/overlays/MarkerViewModule.swift +7 -3
- package/ios/overlays/MultiPointView.swift +30 -1
- package/ios/overlays/PolygonView.swift +63 -12
- package/ios/overlays/PolygonViewModule.swift +17 -0
- package/ios/overlays/PolylineView.swift +95 -25
- package/ios/overlays/PolylineViewModule.swift +17 -8
- package/ios/utils/PermissionManager.swift +9 -14
- package/package.json +4 -3
- package/src/ExpoGaodeMap.types.ts +28 -3
- package/src/ExpoGaodeMapModule.ts +201 -12
- package/src/ExpoGaodeMapView.tsx +9 -234
- package/src/components/overlays/Circle.tsx +14 -70
- package/src/components/overlays/Cluster.tsx +0 -1
- package/src/components/overlays/Marker.tsx +63 -138
- package/src/components/overlays/Polygon.tsx +12 -92
- package/src/components/overlays/Polyline.tsx +11 -77
- package/src/index.ts +4 -29
- package/src/types/map-view.types.ts +1 -85
- package/src/types/overlays.types.ts +9 -9
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +0 -574
- package/build/modules/AMapLocation.d.ts +0 -78
- package/build/modules/AMapLocation.d.ts.map +0 -1
- package/build/modules/AMapLocation.js +0 -132
- package/build/modules/AMapLocation.js.map +0 -1
- package/build/modules/AMapPermissions.d.ts +0 -29
- package/build/modules/AMapPermissions.d.ts.map +0 -1
- package/build/modules/AMapPermissions.js +0 -23
- package/build/modules/AMapPermissions.js.map +0 -1
- package/build/modules/AMapSDK.d.ts +0 -22
- package/build/modules/AMapSDK.d.ts.map +0 -1
- package/build/modules/AMapSDK.js +0 -25
- package/build/modules/AMapSDK.js.map +0 -1
- package/build/modules/AMapView.d.ts +0 -44
- package/build/modules/AMapView.d.ts.map +0 -1
- package/build/modules/AMapView.js +0 -65
- package/build/modules/AMapView.js.map +0 -1
- package/ios/managers/OverlayManager.swift +0 -522
- package/src/modules/AMapLocation.ts +0 -165
- package/src/modules/AMapPermissions.ts +0 -41
- package/src/modules/AMapSDK.ts +0 -31
- package/src/modules/AMapView.ts +0 -72
|
@@ -1,162 +1,87 @@
|
|
|
1
|
+
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import { Image } from 'react-native';
|
|
3
3
|
import { requireNativeViewManager } from 'expo-modules-core';
|
|
4
|
-
import { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';
|
|
5
4
|
import type { MarkerProps } from '../../types';
|
|
6
5
|
|
|
7
6
|
const NativeMarkerView = requireNativeViewManager('MarkerView');
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);
|
|
21
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Marker 组件 - 完全声明式 API
|
|
10
|
+
*
|
|
11
|
+
* 支持:
|
|
12
|
+
* - 自定义图标(icon)
|
|
13
|
+
* - 自定义内容(children)
|
|
14
|
+
* - 大头针样式(pinColor)
|
|
15
|
+
* - 拖拽功能
|
|
16
|
+
* - 所有事件回调
|
|
17
|
+
*/
|
|
18
|
+
function Marker(props: MarkerProps) {
|
|
22
19
|
// 根据是否有 children 来决定使用哪个尺寸属性
|
|
23
|
-
// 有 children:使用 customViewWidth/customViewHeight(默认
|
|
24
|
-
// 无 children:使用 iconWidth/iconHeight
|
|
20
|
+
// 有 children:使用 customViewWidth/customViewHeight(默认 200x40)
|
|
21
|
+
// 无 children:使用 iconWidth/iconHeight(用于自定义图标,默认 40x40)
|
|
25
22
|
const containerWidth = props.children
|
|
26
|
-
? (props.customViewWidth && props.customViewWidth > 0 ? props.customViewWidth :
|
|
27
|
-
: (props.iconWidth
|
|
23
|
+
? (props.customViewWidth && props.customViewWidth > 0 ? props.customViewWidth : 200)
|
|
24
|
+
: (props.iconWidth && props.iconWidth > 0 ? props.iconWidth : 40);
|
|
28
25
|
const containerHeight = props.children
|
|
29
|
-
? (props.customViewHeight && props.customViewHeight > 0 ? props.customViewHeight :
|
|
30
|
-
: (props.iconHeight
|
|
26
|
+
? (props.customViewHeight && props.customViewHeight > 0 ? props.customViewHeight : 40)
|
|
27
|
+
: (props.iconHeight && props.iconHeight > 0 ? props.iconHeight : 40);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
eventManager.register(markerIdRef.current, {
|
|
35
|
-
onPress: props.onPress,
|
|
36
|
-
onDragStart: props.onDragStart,
|
|
37
|
-
onDrag: props.onDrag,
|
|
38
|
-
onDragEnd: props.onDragEnd,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return () => {
|
|
42
|
-
if (eventManager) {
|
|
43
|
-
eventManager.unregister(markerIdRef.current);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
|
|
29
|
+
// 从 props 中排除 position 属性,避免传递到原生层
|
|
30
|
+
const { position, ...restProps } = props;
|
|
47
31
|
|
|
48
32
|
return (
|
|
49
33
|
<NativeMarkerView
|
|
50
|
-
latitude={
|
|
51
|
-
longitude={
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
iconHeight={props.iconHeight || 0} // 传递原始的 iconHeight(用于自定义图标)
|
|
58
|
-
customViewWidth={containerWidth} // 新增:自定义视图宽度
|
|
59
|
-
customViewHeight={containerHeight} // 新增:自定义视图高度
|
|
60
|
-
pinColor={props.pinColor}
|
|
61
|
-
animatesDrop={props.animatesDrop}
|
|
62
|
-
centerOffset={props.centerOffset}
|
|
63
|
-
opacity={props.opacity}
|
|
64
|
-
flat={props.flat}
|
|
65
|
-
zIndex={props.zIndex}
|
|
66
|
-
anchor={props.anchor}
|
|
67
|
-
style={{ width: containerWidth, height: containerHeight }}
|
|
34
|
+
latitude={position.latitude}
|
|
35
|
+
longitude={position.longitude}
|
|
36
|
+
iconWidth={containerWidth}
|
|
37
|
+
iconHeight={containerHeight}
|
|
38
|
+
customViewWidth={containerWidth}
|
|
39
|
+
customViewHeight={containerHeight}
|
|
40
|
+
{...restProps}
|
|
68
41
|
>
|
|
69
42
|
{props.children}
|
|
70
43
|
</NativeMarkerView>
|
|
71
44
|
);
|
|
72
45
|
}
|
|
73
46
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
47
|
+
/**
|
|
48
|
+
* 自定义比较函数
|
|
49
|
+
* 深度比较 position 和其他关键属性
|
|
50
|
+
*/
|
|
51
|
+
function arePropsEqual(prevProps: MarkerProps, nextProps: MarkerProps): boolean {
|
|
52
|
+
// 比较 position
|
|
53
|
+
if (
|
|
54
|
+
prevProps.position.latitude !== nextProps.position.latitude ||
|
|
55
|
+
prevProps.position.longitude !== nextProps.position.longitude
|
|
56
|
+
) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
79
59
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
// 比较基础属性
|
|
61
|
+
if (
|
|
62
|
+
prevProps.title !== nextProps.title ||
|
|
63
|
+
prevProps.snippet !== nextProps.snippet ||
|
|
64
|
+
prevProps.icon !== nextProps.icon ||
|
|
65
|
+
prevProps.pinColor !== nextProps.pinColor ||
|
|
66
|
+
prevProps.draggable !== nextProps.draggable ||
|
|
67
|
+
prevProps.animatesDrop !== nextProps.animatesDrop ||
|
|
68
|
+
prevProps.iconWidth !== nextProps.iconWidth ||
|
|
69
|
+
prevProps.iconHeight !== nextProps.iconHeight ||
|
|
70
|
+
prevProps.customViewWidth !== nextProps.customViewWidth ||
|
|
71
|
+
prevProps.customViewHeight !== nextProps.customViewHeight
|
|
72
|
+
) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const markerId = `marker_${Date.now()}_${Math.random()}`;
|
|
92
|
-
markerIdRef.current = markerId;
|
|
93
|
-
|
|
94
|
-
if (eventManager) {
|
|
95
|
-
eventManager.register(markerId, {
|
|
96
|
-
onPress: props.onPress,
|
|
97
|
-
onDragStart: props.onDragStart,
|
|
98
|
-
onDrag: props.onDrag,
|
|
99
|
-
onDragEnd: props.onDragEnd,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const processedProps = { ...propsRef.current };
|
|
104
|
-
if (processedProps.icon && typeof processedProps.icon === 'number') {
|
|
105
|
-
const resolved = Image.resolveAssetSource(processedProps.icon);
|
|
106
|
-
processedProps.icon = resolved;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
mapRef.current.addMarker(markerId, processedProps);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
checkAndAdd();
|
|
113
|
-
|
|
114
|
-
return () => {
|
|
115
|
-
if (markerIdRef.current) {
|
|
116
|
-
if (eventManager) {
|
|
117
|
-
eventManager.unregister(markerIdRef.current);
|
|
118
|
-
}
|
|
119
|
-
if (mapRef?.current) {
|
|
120
|
-
mapRef.current.removeMarker(markerIdRef.current);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}, []);
|
|
125
|
-
|
|
126
|
-
React.useEffect(() => {
|
|
127
|
-
if (markerIdRef.current && eventManager) {
|
|
128
|
-
eventManager.register(markerIdRef.current, {
|
|
129
|
-
onPress: props.onPress,
|
|
130
|
-
onDragStart: props.onDragStart,
|
|
131
|
-
onDrag: props.onDrag,
|
|
132
|
-
onDragEnd: props.onDragEnd,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
|
|
136
|
-
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
if (markerIdRef.current && mapRef?.current) {
|
|
139
|
-
const processedProps = { ...props };
|
|
140
|
-
if (processedProps.icon && typeof processedProps.icon === 'number') {
|
|
141
|
-
const resolved = Image.resolveAssetSource(processedProps.icon);
|
|
142
|
-
processedProps.icon = resolved;
|
|
143
|
-
}
|
|
144
|
-
mapRef.current.updateMarker(markerIdRef.current, processedProps);
|
|
145
|
-
}
|
|
146
|
-
}, [
|
|
147
|
-
mapRef,
|
|
148
|
-
props.position?.latitude,
|
|
149
|
-
props.position?.longitude,
|
|
150
|
-
props.title,
|
|
151
|
-
props.draggable,
|
|
152
|
-
props.icon,
|
|
153
|
-
props.iconWidth,
|
|
154
|
-
props.iconHeight,
|
|
155
|
-
props.customViewWidth,
|
|
156
|
-
props.customViewHeight,
|
|
157
|
-
props.pinColor
|
|
158
|
-
]);
|
|
76
|
+
// 比较 children(简单比较,可根据需要深度比较)
|
|
77
|
+
if (prevProps.children !== nextProps.children) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
159
80
|
|
|
160
|
-
|
|
81
|
+
// 其他属性相同,不需要重新渲染
|
|
82
|
+
return true;
|
|
161
83
|
}
|
|
162
84
|
|
|
85
|
+
// 导出优化后的组件
|
|
86
|
+
export default React.memo(Marker, arePropsEqual);
|
|
87
|
+
|
|
@@ -1,98 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import type { PolygonProps } from '../../types';
|
|
3
|
-
import { MapContext, PolygonEventContext } from '../../ExpoGaodeMapView';
|
|
4
3
|
|
|
4
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
5
|
+
const NativePolygonView = requireNativeViewManager<PolygonProps>('PolygonView');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param props -
|
|
10
|
-
* @
|
|
11
|
-
* @param props.fillColor - 多边形填充颜色,十六进制格式,默认0x440000FF
|
|
12
|
-
* @param props.strokeColor - 多边形边框颜色,默认-16776961
|
|
13
|
-
* @param props.strokeWidth - 多边形边框宽度,默认10
|
|
14
|
-
* @param props.zIndex - 多边形层级,默认0
|
|
15
|
-
* @param props.onPress - 多边形点击事件
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* 组件内部会自动生成唯一ID用于标识多边形,并在组件挂载时添加到地图,
|
|
19
|
-
* 更新时同步修改多边形属性,卸载时自动移除多边形。
|
|
20
|
-
*
|
|
21
|
-
* 注意:points数组长度必须大于等于3才能有效绘制多边形。
|
|
8
|
+
* 渲染一个高德地图多边形覆盖物组件
|
|
9
|
+
*
|
|
10
|
+
* @param props - 多边形属性配置,继承自PolygonProps类型
|
|
11
|
+
* @returns 高德地图原生多边形视图组件
|
|
22
12
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const nativeRef = useContext(MapContext);
|
|
26
|
-
const eventManager = useContext(PolygonEventContext);
|
|
27
|
-
const polygonIdRef = useRef<string | null>(null);
|
|
28
|
-
const propsRef = useRef(props);
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
propsRef.current = props;
|
|
32
|
-
}, [props]);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const checkAndAdd = () => {
|
|
36
|
-
if (!nativeRef?.current) {
|
|
37
|
-
setTimeout(checkAndAdd, 50);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const polygonId = `polygon_${Date.now()}_${Math.random()}`;
|
|
42
|
-
polygonIdRef.current = polygonId;
|
|
43
|
-
|
|
44
|
-
if (eventManager && props.onPress) {
|
|
45
|
-
eventManager.register(polygonId, {
|
|
46
|
-
onPress: props.onPress,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { points, fillColor, strokeColor, strokeWidth, zIndex } = propsRef.current;
|
|
51
|
-
|
|
52
|
-
if (points && points.length >= 3) {
|
|
53
|
-
nativeRef.current.addPolygon(polygonId, {
|
|
54
|
-
points,
|
|
55
|
-
fillColor: fillColor ?? '#880000FF',
|
|
56
|
-
strokeColor: strokeColor ?? '#FFFF0000',
|
|
57
|
-
strokeWidth: strokeWidth ?? 10,
|
|
58
|
-
zIndex: zIndex ?? 0,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
checkAndAdd();
|
|
64
|
-
|
|
65
|
-
return () => {
|
|
66
|
-
if (polygonIdRef.current) {
|
|
67
|
-
if (eventManager) {
|
|
68
|
-
eventManager.unregister(polygonIdRef.current);
|
|
69
|
-
}
|
|
70
|
-
if (nativeRef?.current) {
|
|
71
|
-
nativeRef.current.removePolygon(polygonIdRef.current);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}, []);
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (polygonIdRef.current && eventManager) {
|
|
79
|
-
eventManager.register(polygonIdRef.current, {
|
|
80
|
-
onPress: props.onPress,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}, [props.onPress]);
|
|
84
|
-
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (polygonIdRef.current && nativeRef?.current) {
|
|
87
|
-
nativeRef.current.updatePolygon(polygonIdRef.current, {
|
|
88
|
-
points,
|
|
89
|
-
fillColor,
|
|
90
|
-
strokeColor,
|
|
91
|
-
strokeWidth,
|
|
92
|
-
zIndex,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}, [points, fillColor, strokeColor, strokeWidth, zIndex]);
|
|
96
|
-
|
|
97
|
-
return null;
|
|
13
|
+
function Polygon(props: PolygonProps) {
|
|
14
|
+
return <NativePolygonView {...props} />;
|
|
98
15
|
}
|
|
16
|
+
|
|
17
|
+
// 导出优化后的组件
|
|
18
|
+
export default React.memo(Polygon);
|
|
@@ -1,85 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { MapContext, PolylineEventContext } from '../../ExpoGaodeMapView';
|
|
4
3
|
import type { PolylineProps } from '../../types';
|
|
5
4
|
|
|
5
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
6
|
+
const NativePolylineView = requireNativeViewManager<PolylineProps>('PolylineView');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param props -
|
|
11
|
-
* @
|
|
12
|
-
* @param props.width - 折线的宽度(像素)
|
|
13
|
-
* @param props.color - 折线的颜色(十六进制或RGBA)
|
|
14
|
-
* @param props.onPress - 折线点击事件回调函数
|
|
15
|
-
* @param [props.texture] - 可选,折线的纹理样式
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* 组件内部使用 React 的 useEffect 钩子来管理折线的生命周期:
|
|
19
|
-
* 1. 组件挂载时创建折线并添加到地图
|
|
20
|
-
* 2. 组件卸载时自动从地图移除折线
|
|
21
|
-
* 3. 使用 ref 保存折线ID以便清理
|
|
9
|
+
* 渲染高德地图上的折线覆盖物组件
|
|
10
|
+
*
|
|
11
|
+
* @param props - 折线属性配置,继承自PolylineProps类型
|
|
12
|
+
* @returns 高德地图原生折线视图组件
|
|
22
13
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const eventManager = React.useContext(PolylineEventContext);
|
|
26
|
-
const polylineIdRef = React.useRef<string | null>(null);
|
|
27
|
-
const propsRef = React.useRef(props);
|
|
28
|
-
|
|
29
|
-
React.useEffect(() => {
|
|
30
|
-
propsRef.current = props;
|
|
31
|
-
}, [props]);
|
|
32
|
-
|
|
33
|
-
React.useEffect(() => {
|
|
34
|
-
const checkAndAdd = () => {
|
|
35
|
-
if (!mapRef?.current) {
|
|
36
|
-
setTimeout(checkAndAdd, 50);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const polylineId = `polyline_${Date.now()}_${Math.random()}`;
|
|
41
|
-
polylineIdRef.current = polylineId;
|
|
42
|
-
|
|
43
|
-
if (eventManager && props.onPress) {
|
|
44
|
-
eventManager.register(polylineId, {
|
|
45
|
-
onPress: props.onPress,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const polylineProps = {
|
|
50
|
-
points: propsRef.current.points,
|
|
51
|
-
width: propsRef.current.width,
|
|
52
|
-
color: propsRef.current.color,
|
|
53
|
-
...(propsRef.current.texture && { texture: propsRef.current.texture }),
|
|
54
|
-
...(propsRef.current.dotted !== undefined && { dotted: propsRef.current.dotted }),
|
|
55
|
-
...(propsRef.current.geodesic !== undefined && { geodesic: propsRef.current.geodesic }),
|
|
56
|
-
...(propsRef.current.zIndex !== undefined && { zIndex: propsRef.current.zIndex }),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
mapRef.current.addPolyline(polylineId, polylineProps);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
checkAndAdd();
|
|
63
|
-
|
|
64
|
-
return () => {
|
|
65
|
-
if (polylineIdRef.current) {
|
|
66
|
-
if (eventManager) {
|
|
67
|
-
eventManager.unregister(polylineIdRef.current);
|
|
68
|
-
}
|
|
69
|
-
if (mapRef?.current) {
|
|
70
|
-
mapRef.current.removePolyline(polylineIdRef.current);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}, []);
|
|
75
|
-
|
|
76
|
-
React.useEffect(() => {
|
|
77
|
-
if (polylineIdRef.current && eventManager) {
|
|
78
|
-
eventManager.register(polylineIdRef.current, {
|
|
79
|
-
onPress: props.onPress,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}, [props.onPress]);
|
|
83
|
-
|
|
84
|
-
return null;
|
|
14
|
+
function Polyline(props: PolylineProps) {
|
|
15
|
+
return <NativePolylineView {...props} />;
|
|
85
16
|
}
|
|
17
|
+
|
|
18
|
+
// 导出优化后的组件
|
|
19
|
+
export default React.memo(Polyline);
|
package/src/index.ts
CHANGED
|
@@ -2,36 +2,11 @@
|
|
|
2
2
|
export * from './ExpoGaodeMap.types';
|
|
3
3
|
export * from './types';
|
|
4
4
|
|
|
5
|
-
// 导出原生模块
|
|
5
|
+
// 导出原生模块 - 直接使用,无需封装
|
|
6
6
|
export { default as ExpoGaodeMapModule } from './ExpoGaodeMapModule';
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
// 导出定位模块
|
|
12
|
-
export {
|
|
13
|
-
default as AMapLocation,
|
|
14
|
-
configure,
|
|
15
|
-
start,
|
|
16
|
-
stop,
|
|
17
|
-
isStarted,
|
|
18
|
-
getCurrentLocation,
|
|
19
|
-
addLocationListener,
|
|
20
|
-
coordinateConvert,
|
|
21
|
-
startUpdatingHeading,
|
|
22
|
-
stopUpdatingHeading,
|
|
23
|
-
} from './modules/AMapLocation';
|
|
24
|
-
|
|
25
|
-
// 导出权限管理模块
|
|
26
|
-
export {
|
|
27
|
-
default as AMapPermissions,
|
|
28
|
-
checkLocationPermission,
|
|
29
|
-
requestLocationPermission,
|
|
30
|
-
} from './modules/AMapPermissions';
|
|
31
|
-
export type { PermissionStatus } from './modules/AMapPermissions';
|
|
32
|
-
|
|
33
|
-
// 地图视图控制已移至 MapView 的 ref 调用
|
|
34
|
-
// 使用方式: const mapRef = useRef<MapViewRef>(null); mapRef.current.moveCamera() 等
|
|
8
|
+
// 从 ExpoGaodeMapModule 重新导出类型,方便使用
|
|
9
|
+
export type { SDKConfig, PermissionStatus } from './ExpoGaodeMapModule';
|
|
35
10
|
|
|
36
11
|
// 导出地图视图组件
|
|
37
12
|
export { default as MapView } from './ExpoGaodeMapView';
|
|
@@ -48,5 +23,5 @@ export {
|
|
|
48
23
|
Cluster,
|
|
49
24
|
} from './components/overlays';
|
|
50
25
|
|
|
51
|
-
//
|
|
26
|
+
// 默认导出原生模块
|
|
52
27
|
export { default } from './ExpoGaodeMapModule';
|
|
@@ -220,41 +220,6 @@ export interface MapViewProps {
|
|
|
220
220
|
*/
|
|
221
221
|
onLocation?: (event: NativeSyntheticEvent<LocationEvent>) => void;
|
|
222
222
|
|
|
223
|
-
/**
|
|
224
|
-
* Marker 点击事件
|
|
225
|
-
*/
|
|
226
|
-
onMarkerPress?: (event: NativeSyntheticEvent<{ markerId: string } & LatLng>) => void;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Marker 拖拽开始事件
|
|
230
|
-
*/
|
|
231
|
-
onMarkerDragStart?: (event: NativeSyntheticEvent<{ markerId: string } & LatLng>) => void;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Marker 拖拽中事件
|
|
235
|
-
*/
|
|
236
|
-
onMarkerDrag?: (event: NativeSyntheticEvent<{ markerId: string } & LatLng>) => void;
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Marker 拖拽结束事件
|
|
240
|
-
*/
|
|
241
|
-
onMarkerDragEnd?: (event: NativeSyntheticEvent<{ markerId: string } & LatLng>) => void;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Circle 点击事件
|
|
245
|
-
*/
|
|
246
|
-
onCirclePress?: (event: NativeSyntheticEvent<{ circleId: string } & LatLng>) => void;
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Polygon 点击事件
|
|
250
|
-
*/
|
|
251
|
-
onPolygonPress?: (event: NativeSyntheticEvent<{ polygonId: string } & LatLng>) => void;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Polyline 点击事件
|
|
255
|
-
*/
|
|
256
|
-
onPolylinePress?: (event: NativeSyntheticEvent<{ polylineId: string } & LatLng>) => void;
|
|
257
|
-
|
|
258
223
|
/**
|
|
259
224
|
* 子组件
|
|
260
225
|
*/
|
|
@@ -289,55 +254,6 @@ export interface MapViewRef {
|
|
|
289
254
|
setCenter(center: LatLng, animated?: boolean): Promise<void>;
|
|
290
255
|
setZoom(zoom: number, animated?: boolean): Promise<void>;
|
|
291
256
|
getCameraPosition(): Promise<CameraPosition>;
|
|
292
|
-
|
|
293
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
294
|
-
*/
|
|
295
|
-
addCircle(id: string, props: import('./overlays.types').CircleProps): Promise<void>;
|
|
296
|
-
/**
|
|
297
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
298
|
-
*/
|
|
299
|
-
removeCircle(id: string): Promise<void>;
|
|
300
|
-
/**
|
|
301
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
302
|
-
*/
|
|
303
|
-
updateCircle(id: string, props: Partial<import('./overlays.types').CircleProps>): Promise<void>;
|
|
304
|
-
/**
|
|
305
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
306
|
-
*/
|
|
307
|
-
addMarker(id: string, props: import('./overlays.types').MarkerProps): Promise<void>;
|
|
308
|
-
/**
|
|
309
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
310
|
-
*/
|
|
311
|
-
removeMarker(id: string): Promise<void>;
|
|
312
|
-
/**
|
|
313
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
314
|
-
*/
|
|
315
|
-
updateMarker(id: string, props: Partial<import('./overlays.types').MarkerProps>): Promise<void>;
|
|
316
|
-
/**
|
|
317
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
318
|
-
*/
|
|
319
|
-
addPolyline(id: string, props: import('./overlays.types').PolylineProps): Promise<void>;
|
|
320
|
-
/**
|
|
321
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
322
|
-
*/
|
|
323
|
-
removePolyline(id: string): Promise<void>;
|
|
324
|
-
/**
|
|
325
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
326
|
-
*/
|
|
327
|
-
updatePolyline(id: string, props: Partial<import('./overlays.types').PolylineProps>): Promise<void>;
|
|
328
|
-
/**
|
|
329
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
330
|
-
*/
|
|
331
|
-
addPolygon(id: string, props: import('./overlays.types').PolygonProps): Promise<void>;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
335
|
-
*/
|
|
336
|
-
removePolygon(id: string): Promise<void>;
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* @@deprecated 不推荐使用,请使用声明式添加
|
|
340
|
-
*/
|
|
341
|
-
updatePolygon(id: string, props: Partial<import('./overlays.types').PolygonProps>): Promise<void>;
|
|
257
|
+
|
|
342
258
|
}
|
|
343
259
|
|
|
@@ -116,22 +116,22 @@ export interface MarkerProps {
|
|
|
116
116
|
/**
|
|
117
117
|
* 点击事件
|
|
118
118
|
*/
|
|
119
|
-
|
|
119
|
+
onMarkerPress?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* 拖拽开始事件
|
|
123
123
|
*/
|
|
124
|
-
|
|
124
|
+
onMarkerDragStart?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* 拖拽中事件
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
onMarkerDrag?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* 拖拽结束事件
|
|
133
133
|
*/
|
|
134
|
-
|
|
134
|
+
onMarkerDragEnd?: (event: NativeSyntheticEvent<LatLng>) => void;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
@@ -146,12 +146,12 @@ export interface PolylineProps {
|
|
|
146
146
|
/**
|
|
147
147
|
* 线宽
|
|
148
148
|
*/
|
|
149
|
-
|
|
149
|
+
strokeWidth?: number;
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* 线条颜色
|
|
153
153
|
*/
|
|
154
|
-
|
|
154
|
+
strokeColor?: ColorValue;
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
157
|
* 层级
|
|
@@ -193,7 +193,7 @@ export interface PolylineProps {
|
|
|
193
193
|
/**
|
|
194
194
|
* 点击事件
|
|
195
195
|
*/
|
|
196
|
-
|
|
196
|
+
onPolylinePress?: (event: NativeSyntheticEvent<{}>) => void;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -228,7 +228,7 @@ export interface PolygonProps {
|
|
|
228
228
|
/**
|
|
229
229
|
* 点击事件
|
|
230
230
|
*/
|
|
231
|
-
|
|
231
|
+
onPolygonPress?: (event: NativeSyntheticEvent<{}>) => void;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
/**
|
|
@@ -268,7 +268,7 @@ export interface CircleProps {
|
|
|
268
268
|
/**
|
|
269
269
|
* 点击事件
|
|
270
270
|
*/
|
|
271
|
-
|
|
271
|
+
onCirclePress?: (event: NativeSyntheticEvent<{}>) => void;
|
|
272
272
|
|
|
273
273
|
|
|
274
274
|
}
|