expo-gaode-map 1.0.2 → 1.0.4
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.md +1 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +87 -5
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +132 -1
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +271 -6
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +40 -51
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +3 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +22 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +83 -17
- package/build/ExpoGaodeMapView.d.ts +46 -1
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +134 -1
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts +0 -20
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +28 -45
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Marker.d.ts +2 -16
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +60 -37
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts +1 -0
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +38 -47
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts +1 -0
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +38 -12
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/types/map-view.types.d.ts +42 -0
- 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 +31 -1
- package/build/types/overlays.types.d.ts.map +1 -1
- package/build/types/overlays.types.js.map +1 -1
- package/docs/API.md +121 -7
- package/docs/EXAMPLES.md +86 -2
- package/docs/INITIALIZATION.md +14 -4
- package/expo-module.config.json +1 -1
- package/ios/ExpoGaodeMapModule.swift +132 -18
- package/ios/ExpoGaodeMapView.swift +361 -12
- package/ios/managers/OverlayManager.swift +188 -12
- package/ios/modules/LocationManager.swift +3 -0
- package/ios/overlays/CircleView.swift +41 -12
- package/ios/overlays/MarkerView.swift +55 -3
- package/ios/overlays/PolygonView.swift +27 -5
- package/ios/overlays/PolylineView.swift +37 -4
- package/ios/utils/ColorParser.swift +0 -5
- package/ios/utils/PermissionManager.swift +62 -7
- package/package.json +1 -1
- package/src/ExpoGaodeMapView.tsx +194 -1
- package/src/components/overlays/Circle.tsx +31 -48
- package/src/components/overlays/Marker.tsx +69 -42
- package/src/components/overlays/Polygon.tsx +46 -49
- package/src/components/overlays/Polyline.tsx +46 -15
- package/src/types/map-view.types.ts +35 -0
- package/src/types/overlays.types.ts +36 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useRef } from 'react';
|
|
2
2
|
import type { PolygonProps } from '../../types';
|
|
3
|
-
import { MapContext } from '../../ExpoGaodeMapView';
|
|
3
|
+
import { MapContext, PolygonEventContext } from '../../ExpoGaodeMapView';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -12,6 +12,7 @@ import { MapContext } from '../../ExpoGaodeMapView';
|
|
|
12
12
|
* @param props.strokeColor - 多边形边框颜色,默认-16776961
|
|
13
13
|
* @param props.strokeWidth - 多边形边框宽度,默认10
|
|
14
14
|
* @param props.zIndex - 多边形层级,默认0
|
|
15
|
+
* @param props.onPress - 多边形点击事件
|
|
15
16
|
*
|
|
16
17
|
* @remarks
|
|
17
18
|
* 组件内部会自动生成唯一ID用于标识多边形,并在组件挂载时添加到地图,
|
|
@@ -22,70 +23,66 @@ import { MapContext } from '../../ExpoGaodeMapView';
|
|
|
22
23
|
export default function Polygon(props: PolygonProps) {
|
|
23
24
|
const { points, fillColor, strokeColor, strokeWidth, zIndex } = props;
|
|
24
25
|
const nativeRef = useContext(MapContext);
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
const eventManager = useContext(PolygonEventContext);
|
|
27
|
+
const polygonIdRef = useRef<string | null>(null);
|
|
28
|
+
const propsRef = useRef(props);
|
|
29
|
+
|
|
27
30
|
useEffect(() => {
|
|
28
|
-
|
|
31
|
+
propsRef.current = props;
|
|
32
|
+
}, [props]);
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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,
|
|
39
47
|
});
|
|
40
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { points, fillColor, strokeColor, strokeWidth, zIndex } = propsRef.current;
|
|
51
|
+
|
|
52
|
+
if (points && points.length >= 3) {
|
|
41
53
|
nativeRef.current.addPolygon(polygonId, {
|
|
42
54
|
points,
|
|
43
|
-
fillColor: fillColor ??
|
|
44
|
-
strokeColor: strokeColor ??
|
|
55
|
+
fillColor: fillColor ?? '#880000FF',
|
|
56
|
+
strokeColor: strokeColor ?? '#FFFF0000',
|
|
45
57
|
strokeWidth: strokeWidth ?? 10,
|
|
46
58
|
zIndex: zIndex ?? 0,
|
|
47
59
|
});
|
|
48
|
-
|
|
49
|
-
console.log('✅ Polygon addPolygon 调用完成');
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error('❌ 添加多边形失败:', error);
|
|
52
60
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
pointsLength: points?.length,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 清理函数
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
checkAndAdd();
|
|
64
|
+
|
|
62
65
|
return () => {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
66
|
+
if (polygonIdRef.current) {
|
|
67
|
+
if (eventManager) {
|
|
68
|
+
eventManager.unregister(polygonIdRef.current);
|
|
69
|
+
}
|
|
70
|
+
if (nativeRef?.current) {
|
|
71
|
+
nativeRef.current.removePolygon(polygonIdRef.current);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
};
|
|
71
75
|
}, []);
|
|
72
76
|
|
|
73
|
-
// 更新多边形属性
|
|
74
77
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
strokeWidth,
|
|
84
|
-
zIndex,
|
|
85
|
-
});
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('更新多边形失败:', error);
|
|
88
|
-
}
|
|
78
|
+
if (polygonIdRef.current && nativeRef?.current) {
|
|
79
|
+
nativeRef.current.updatePolygon(polygonIdRef.current, {
|
|
80
|
+
points,
|
|
81
|
+
fillColor,
|
|
82
|
+
strokeColor,
|
|
83
|
+
strokeWidth,
|
|
84
|
+
zIndex,
|
|
85
|
+
});
|
|
89
86
|
}
|
|
90
87
|
}, [points, fillColor, strokeColor, strokeWidth, zIndex]);
|
|
91
88
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import { MapContext } from '../../ExpoGaodeMapView';
|
|
3
|
+
import { MapContext, PolylineEventContext } from '../../ExpoGaodeMapView';
|
|
3
4
|
import type { PolylineProps } from '../../types';
|
|
4
5
|
|
|
5
6
|
|
|
@@ -10,6 +11,7 @@ import type { PolylineProps } from '../../types';
|
|
|
10
11
|
* @param props.points - 折线的坐标点数组
|
|
11
12
|
* @param props.width - 折线的宽度(像素)
|
|
12
13
|
* @param props.color - 折线的颜色(十六进制或RGBA)
|
|
14
|
+
* @param props.onPress - 折线点击事件回调函数
|
|
13
15
|
* @param [props.texture] - 可选,折线的纹理样式
|
|
14
16
|
*
|
|
15
17
|
* @remarks
|
|
@@ -20,25 +22,54 @@ import type { PolylineProps } from '../../types';
|
|
|
20
22
|
*/
|
|
21
23
|
export default function Polyline(props: PolylineProps) {
|
|
22
24
|
const mapRef = React.useContext(MapContext);
|
|
25
|
+
const eventManager = React.useContext(PolylineEventContext);
|
|
23
26
|
const polylineIdRef = React.useRef<string | null>(null);
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const propsRef = React.useRef(props);
|
|
28
|
+
|
|
26
29
|
React.useEffect(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
36
60
|
};
|
|
37
61
|
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
checkAndAdd();
|
|
63
|
+
|
|
40
64
|
return () => {
|
|
41
|
-
|
|
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
|
+
}
|
|
42
73
|
};
|
|
43
74
|
}, []);
|
|
44
75
|
|
|
@@ -199,6 +199,41 @@ export interface MapViewProps {
|
|
|
199
199
|
*/
|
|
200
200
|
onLocation?: (event: Location) => void;
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Marker 点击事件
|
|
204
|
+
*/
|
|
205
|
+
onMarkerPress?: (event: { markerId: string } & LatLng) => void;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Marker 拖拽开始事件
|
|
209
|
+
*/
|
|
210
|
+
onMarkerDragStart?: (event: { markerId: string } & LatLng) => void;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Marker 拖拽中事件
|
|
214
|
+
*/
|
|
215
|
+
onMarkerDrag?: (event: { markerId: string } & LatLng) => void;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Marker 拖拽结束事件
|
|
219
|
+
*/
|
|
220
|
+
onMarkerDragEnd?: (event: { markerId: string } & LatLng) => void;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Circle 点击事件
|
|
224
|
+
*/
|
|
225
|
+
onCirclePress?: (event: { circleId: string } & LatLng) => void;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Polygon 点击事件
|
|
229
|
+
*/
|
|
230
|
+
onPolygonPress?: (event: { polygonId: string } & LatLng) => void;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Polyline 点击事件
|
|
234
|
+
*/
|
|
235
|
+
onPolylinePress?: (event: { polylineId: string } & LatLng) => void;
|
|
236
|
+
|
|
202
237
|
/**
|
|
203
238
|
* 子组件
|
|
204
239
|
*/
|
|
@@ -18,7 +18,17 @@ export interface MarkerProps {
|
|
|
18
18
|
/**
|
|
19
19
|
* 图标
|
|
20
20
|
*/
|
|
21
|
-
icon?: ImageSourcePropType;
|
|
21
|
+
icon?: string | ImageSourcePropType;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 图标宽度(像素)
|
|
25
|
+
*/
|
|
26
|
+
iconWidth?: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 图标高度(像素)
|
|
30
|
+
*/
|
|
31
|
+
iconHeight?: number;
|
|
22
32
|
|
|
23
33
|
/**
|
|
24
34
|
* 标题
|
|
@@ -33,6 +43,7 @@ export interface MarkerProps {
|
|
|
33
43
|
/**
|
|
34
44
|
* 透明度 [0, 1]
|
|
35
45
|
* @platform android
|
|
46
|
+
* @note iOS 不支持
|
|
36
47
|
*/
|
|
37
48
|
opacity?: number;
|
|
38
49
|
|
|
@@ -44,17 +55,21 @@ export interface MarkerProps {
|
|
|
44
55
|
/**
|
|
45
56
|
* 是否平贴地图
|
|
46
57
|
* @platform android
|
|
58
|
+
* @note iOS 不支持
|
|
47
59
|
*/
|
|
48
60
|
flat?: boolean;
|
|
49
61
|
|
|
50
62
|
/**
|
|
51
63
|
* 层级
|
|
64
|
+
* @platform android
|
|
65
|
+
* @note iOS 不支持 (使用 displayPriority)
|
|
52
66
|
*/
|
|
53
67
|
zIndex?: number;
|
|
54
68
|
|
|
55
69
|
/**
|
|
56
70
|
* 覆盖物锚点比例
|
|
57
71
|
* @platform android
|
|
72
|
+
* @note iOS 使用 centerOffset
|
|
58
73
|
*/
|
|
59
74
|
anchor?: Point;
|
|
60
75
|
|
|
@@ -64,8 +79,21 @@ export interface MarkerProps {
|
|
|
64
79
|
*/
|
|
65
80
|
centerOffset?: Point;
|
|
66
81
|
|
|
82
|
+
/**
|
|
83
|
+
* 是否显示动画
|
|
84
|
+
* @platform ios
|
|
85
|
+
*/
|
|
86
|
+
animatesDrop?: boolean;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 大头针颜色
|
|
90
|
+
* @platform ios
|
|
91
|
+
*/
|
|
92
|
+
pinColor?: 'red' | 'green' | 'purple';
|
|
93
|
+
|
|
67
94
|
/**
|
|
68
95
|
* 自定义视图
|
|
96
|
+
* @note 未实现
|
|
69
97
|
*/
|
|
70
98
|
children?: React.ReactNode;
|
|
71
99
|
|
|
@@ -121,16 +149,22 @@ export interface PolylineProps {
|
|
|
121
149
|
|
|
122
150
|
/**
|
|
123
151
|
* 是否使用渐变色
|
|
152
|
+
* @platform android
|
|
153
|
+
* @note iOS 不支持
|
|
124
154
|
*/
|
|
125
155
|
gradient?: boolean;
|
|
126
156
|
|
|
127
157
|
/**
|
|
128
158
|
* 是否绘制大地线
|
|
159
|
+
* @platform android
|
|
160
|
+
* @note iOS 不支持
|
|
129
161
|
*/
|
|
130
162
|
geodesic?: boolean;
|
|
131
163
|
|
|
132
164
|
/**
|
|
133
165
|
* 是否绘制虚线
|
|
166
|
+
* @platform android
|
|
167
|
+
* @note iOS 不支持
|
|
134
168
|
*/
|
|
135
169
|
dotted?: boolean;
|
|
136
170
|
|
|
@@ -219,6 +253,7 @@ export interface CircleProps {
|
|
|
219
253
|
* 点击事件
|
|
220
254
|
*/
|
|
221
255
|
onPress?: () => void;
|
|
256
|
+
|
|
222
257
|
}
|
|
223
258
|
|
|
224
259
|
/**
|