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
|
@@ -19,6 +19,9 @@ class CircleView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
19
19
|
private var aMap: AMap? = null
|
|
20
20
|
private var center: LatLng? = null
|
|
21
21
|
private var radius: Double = 1000.0
|
|
22
|
+
private var fillColor: Int = Color.argb(50, 0, 0, 255)
|
|
23
|
+
private var strokeColor: Int = Color.BLUE
|
|
24
|
+
private var strokeWidth: Float = 10f
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* 设置地图实例
|
|
@@ -26,28 +29,19 @@ class CircleView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
26
29
|
@Suppress("unused")
|
|
27
30
|
fun setMap(map: AMap) {
|
|
28
31
|
aMap = map
|
|
29
|
-
//
|
|
32
|
+
// 延迟创建圆形,确保所有 props 都已设置
|
|
33
|
+
post { createOrUpdateCircle() }
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
/**
|
|
33
37
|
* 设置圆心
|
|
34
38
|
*/
|
|
35
39
|
fun setCenter(centerMap: Map<String, Double>) {
|
|
36
|
-
android.util.Log.d("CircleView", "setCenter 被调用: $centerMap")
|
|
37
40
|
val lat = centerMap["latitude"]
|
|
38
41
|
val lng = centerMap["longitude"]
|
|
39
42
|
if (lat != null && lng != null) {
|
|
40
43
|
center = LatLng(lat, lng)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// 如果圆形已存在,更新它;否则创建新圆形
|
|
44
|
-
circle?.let {
|
|
45
|
-
android.util.Log.d("CircleView", "更新现有圆形的圆心")
|
|
46
|
-
it.center = center
|
|
47
|
-
} ?: run {
|
|
48
|
-
android.util.Log.d("CircleView", "圆形不存在,尝试创建")
|
|
49
|
-
createOrUpdateCircle()
|
|
50
|
-
}
|
|
44
|
+
circle?.center = center
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
|
|
@@ -56,78 +50,73 @@ class CircleView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
56
50
|
*/
|
|
57
51
|
fun setRadius(radiusValue: Double) {
|
|
58
52
|
radius = radiusValue
|
|
59
|
-
circle?.
|
|
60
|
-
it.radius = radius
|
|
61
|
-
}
|
|
62
|
-
// 半径可以后续更新,不需要在这里创建圆形
|
|
53
|
+
circle?.radius = radius
|
|
63
54
|
}
|
|
64
55
|
|
|
65
56
|
/**
|
|
66
57
|
* 设置填充颜色
|
|
67
58
|
*/
|
|
68
59
|
fun setFillColor(color: Int) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
60
|
+
fillColor = color
|
|
61
|
+
circle?.fillColor = color
|
|
72
62
|
}
|
|
73
63
|
|
|
74
64
|
/**
|
|
75
65
|
* 设置边框颜色
|
|
76
66
|
*/
|
|
77
67
|
fun setStrokeColor(color: Int) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
68
|
+
strokeColor = color
|
|
69
|
+
circle?.strokeColor = color
|
|
81
70
|
}
|
|
82
71
|
|
|
83
72
|
/**
|
|
84
73
|
* 设置边框宽度
|
|
85
74
|
*/
|
|
86
75
|
fun setStrokeWidth(width: Float) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
76
|
+
strokeWidth = width
|
|
77
|
+
circle?.strokeWidth = width
|
|
90
78
|
}
|
|
91
79
|
|
|
92
80
|
/**
|
|
93
81
|
* 设置 z-index
|
|
94
82
|
*/
|
|
95
83
|
fun setZIndex(zIndex: Float) {
|
|
96
|
-
circle?.
|
|
97
|
-
it.zIndex = zIndex
|
|
98
|
-
} ?: createOrUpdateCircle()
|
|
84
|
+
circle?.zIndex = zIndex
|
|
99
85
|
}
|
|
100
86
|
|
|
101
87
|
/**
|
|
102
88
|
* 创建或更新圆形
|
|
103
89
|
*/
|
|
104
90
|
private fun createOrUpdateCircle() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// 必须同时有地图实例和圆心才能创建
|
|
109
|
-
val map = aMap ?: run {
|
|
110
|
-
android.util.Log.w("CircleView", "⚠️ aMap 为 null,无法创建圆形")
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
val centerPoint = center ?: run {
|
|
115
|
-
android.util.Log.w("CircleView", "⚠️ center 为 null,无法创建圆形")
|
|
116
|
-
return
|
|
117
|
-
}
|
|
91
|
+
val map = aMap ?: return
|
|
92
|
+
val centerPoint = center ?: return
|
|
118
93
|
|
|
119
94
|
if (circle == null) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
95
|
+
circle = map.addCircle(
|
|
96
|
+
CircleOptions()
|
|
97
|
+
.center(centerPoint)
|
|
98
|
+
.radius(radius)
|
|
99
|
+
.fillColor(fillColor)
|
|
100
|
+
.strokeColor(strokeColor)
|
|
101
|
+
.strokeWidth(strokeWidth)
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 检查点击位置是否在圆形内
|
|
108
|
+
*/
|
|
109
|
+
fun checkPress(latLng: LatLng): Boolean {
|
|
110
|
+
circle?.let { c ->
|
|
111
|
+
if (c.contains(latLng)) {
|
|
112
|
+
onPress(mapOf(
|
|
113
|
+
"latitude" to latLng.latitude,
|
|
114
|
+
"longitude" to latLng.longitude
|
|
115
|
+
))
|
|
116
|
+
return true
|
|
117
|
+
}
|
|
130
118
|
}
|
|
119
|
+
return false
|
|
131
120
|
}
|
|
132
121
|
|
|
133
122
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package expo.modules.gaodemap.overlays
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
+
import android.graphics.Bitmap
|
|
5
|
+
import android.graphics.Canvas
|
|
6
|
+
import android.view.View
|
|
4
7
|
import com.amap.api.maps.AMap
|
|
5
8
|
import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
6
9
|
import com.amap.api.maps.model.LatLng
|
|
@@ -17,6 +17,7 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
17
17
|
private var polygon: Polygon? = null
|
|
18
18
|
private var aMap: AMap? = null
|
|
19
19
|
private var points: List<LatLng> = emptyList()
|
|
20
|
+
private var strokeWidth: Float = 10f
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* 设置地图实例
|
|
@@ -65,8 +66,11 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
65
66
|
* 设置边框宽度
|
|
66
67
|
*/
|
|
67
68
|
fun setStrokeWidth(width: Float) {
|
|
69
|
+
// Android 需要乘以屏幕密度以匹配 iOS 的视觉效果
|
|
70
|
+
val density = context.resources.displayMetrics.density
|
|
71
|
+
strokeWidth = width * density
|
|
68
72
|
polygon?.let {
|
|
69
|
-
it.strokeWidth =
|
|
73
|
+
it.strokeWidth = strokeWidth
|
|
70
74
|
} ?: createOrUpdatePolygon()
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -89,7 +93,7 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
89
93
|
.addAll(points)
|
|
90
94
|
.fillColor(Color.argb(50, 0, 0, 255))
|
|
91
95
|
.strokeColor(Color.BLUE)
|
|
92
|
-
.strokeWidth(
|
|
96
|
+
.strokeWidth(strokeWidth)
|
|
93
97
|
|
|
94
98
|
polygon = map.addPolygon(options)
|
|
95
99
|
|
|
@@ -99,6 +103,22 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
/**
|
|
107
|
+
* 检查点击位置是否在多边形内
|
|
108
|
+
*/
|
|
109
|
+
fun checkPress(latLng: LatLng): Boolean {
|
|
110
|
+
polygon?.let { poly ->
|
|
111
|
+
if (poly.contains(latLng)) {
|
|
112
|
+
onPress(mapOf(
|
|
113
|
+
"latitude" to latLng.latitude,
|
|
114
|
+
"longitude" to latLng.longitude
|
|
115
|
+
))
|
|
116
|
+
return true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
|
|
102
122
|
/**
|
|
103
123
|
* 移除多边形
|
|
104
124
|
*/
|
|
@@ -7,6 +7,8 @@ import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
|
7
7
|
import com.amap.api.maps.model.LatLng
|
|
8
8
|
import com.amap.api.maps.model.Polyline
|
|
9
9
|
import com.amap.api.maps.model.PolylineOptions
|
|
10
|
+
import com.amap.api.maps.model.PolylineOptions.LineCapType
|
|
11
|
+
import com.amap.api.maps.model.PolylineOptions.LineJoinType
|
|
10
12
|
import expo.modules.kotlin.AppContext
|
|
11
13
|
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
12
14
|
import expo.modules.kotlin.views.ExpoView
|
|
@@ -19,6 +21,10 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
19
21
|
private var polyline: Polyline? = null
|
|
20
22
|
private var aMap: AMap? = null
|
|
21
23
|
private var points: List<LatLng> = emptyList()
|
|
24
|
+
private var strokeWidth: Float = 10f
|
|
25
|
+
private var strokeColor: Int = Color.BLUE
|
|
26
|
+
private var isDotted: Boolean = false
|
|
27
|
+
private var isGeodesic: Boolean = false
|
|
22
28
|
private var textureUrl: String? = null
|
|
23
29
|
|
|
24
30
|
/**
|
|
@@ -50,8 +56,11 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
50
56
|
* 设置线宽
|
|
51
57
|
*/
|
|
52
58
|
fun setStrokeWidth(width: Float) {
|
|
59
|
+
// Android 需要乘以屏幕密度以匹配 iOS 的视觉效果
|
|
60
|
+
val density = context.resources.displayMetrics.density
|
|
61
|
+
strokeWidth = width * density
|
|
53
62
|
polyline?.let {
|
|
54
|
-
it.width =
|
|
63
|
+
it.width = strokeWidth
|
|
55
64
|
} ?: createOrUpdatePolyline()
|
|
56
65
|
}
|
|
57
66
|
|
|
@@ -59,6 +68,7 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
59
68
|
* 设置线条颜色
|
|
60
69
|
*/
|
|
61
70
|
fun setStrokeColor(color: Int) {
|
|
71
|
+
strokeColor = color
|
|
62
72
|
polyline?.let {
|
|
63
73
|
it.color = color
|
|
64
74
|
} ?: createOrUpdatePolyline()
|
|
@@ -67,19 +77,17 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
67
77
|
/**
|
|
68
78
|
* 设置是否虚线
|
|
69
79
|
*/
|
|
70
|
-
fun
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} ?: createOrUpdatePolyline()
|
|
80
|
+
fun setDotted(dotted: Boolean) {
|
|
81
|
+
isDotted = dotted
|
|
82
|
+
createOrUpdatePolyline()
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
/**
|
|
77
|
-
*
|
|
86
|
+
* 设置是否绘制大地线
|
|
78
87
|
*/
|
|
79
|
-
fun
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} ?: createOrUpdatePolyline()
|
|
88
|
+
fun setGeodesic(geodesic: Boolean) {
|
|
89
|
+
isGeodesic = geodesic
|
|
90
|
+
createOrUpdatePolyline()
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
/**
|
|
@@ -122,8 +130,14 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
122
130
|
if (points.isNotEmpty()) {
|
|
123
131
|
val options = PolylineOptions()
|
|
124
132
|
.addAll(points)
|
|
125
|
-
.width(
|
|
126
|
-
.color(
|
|
133
|
+
.width(strokeWidth)
|
|
134
|
+
.color(strokeColor)
|
|
135
|
+
.geodesic(isGeodesic)
|
|
136
|
+
|
|
137
|
+
// 设置虚线样式
|
|
138
|
+
if (isDotted) {
|
|
139
|
+
options.dottedLineType = PolylineOptions.DOTTEDLINE_TYPE_SQUARE
|
|
140
|
+
}
|
|
127
141
|
|
|
128
142
|
// 设置纹理
|
|
129
143
|
textureUrl?.let { url ->
|
|
@@ -164,14 +178,66 @@ class PolylineView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
polyline = map.addPolyline(options)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 检查点击位置是否在折线附近
|
|
187
|
+
*/
|
|
188
|
+
fun checkPress(latLng: LatLng): Boolean {
|
|
189
|
+
polyline?.let { line ->
|
|
190
|
+
val threshold = 20.0 // 20米容差
|
|
191
|
+
val linePoints = line.points
|
|
192
|
+
if (linePoints.size < 2) return false
|
|
193
|
+
|
|
194
|
+
for (i in 0 until linePoints.size - 1) {
|
|
195
|
+
val distance = distanceToSegment(latLng, linePoints[i], linePoints[i + 1])
|
|
196
|
+
if (distance <= threshold) {
|
|
197
|
+
onPress(mapOf(
|
|
198
|
+
"latitude" to latLng.latitude,
|
|
199
|
+
"longitude" to latLng.longitude
|
|
200
|
+
))
|
|
201
|
+
return true
|
|
172
202
|
}
|
|
173
203
|
}
|
|
174
204
|
}
|
|
205
|
+
return false
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private fun distanceToSegment(point: LatLng, start: LatLng, end: LatLng): Double {
|
|
209
|
+
val p = android.location.Location("").apply {
|
|
210
|
+
latitude = point.latitude
|
|
211
|
+
longitude = point.longitude
|
|
212
|
+
}
|
|
213
|
+
val a = android.location.Location("").apply {
|
|
214
|
+
latitude = start.latitude
|
|
215
|
+
longitude = start.longitude
|
|
216
|
+
}
|
|
217
|
+
val b = android.location.Location("").apply {
|
|
218
|
+
latitude = end.latitude
|
|
219
|
+
longitude = end.longitude
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
val ab = a.distanceTo(b).toDouble()
|
|
223
|
+
if (ab == 0.0) return a.distanceTo(p).toDouble()
|
|
224
|
+
|
|
225
|
+
val t = maxOf(0.0, minOf(1.0,
|
|
226
|
+
((point.latitude - start.latitude) * (end.latitude - start.latitude) +
|
|
227
|
+
(point.longitude - start.longitude) * (end.longitude - start.longitude)) / (ab * ab)
|
|
228
|
+
))
|
|
229
|
+
|
|
230
|
+
val projection = LatLng(
|
|
231
|
+
start.latitude + t * (end.latitude - start.latitude),
|
|
232
|
+
start.longitude + t * (end.longitude - start.longitude)
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
val proj = android.location.Location("").apply {
|
|
236
|
+
latitude = projection.latitude
|
|
237
|
+
longitude = projection.longitude
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return p.distanceTo(proj).toDouble()
|
|
175
241
|
}
|
|
176
242
|
|
|
177
243
|
/**
|
|
@@ -1,7 +1,52 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { MapViewProps, MapViewRef } from './types';
|
|
2
|
+
import type { MapViewProps, MapViewRef, LatLng } from './types';
|
|
3
3
|
export type { MapViewRef } from './types';
|
|
4
4
|
export declare const MapContext: React.Context<React.RefObject<MapViewRef | null> | null>;
|
|
5
|
+
type MarkerEventCallbacks = {
|
|
6
|
+
onPress?: () => void;
|
|
7
|
+
onDragStart?: () => void;
|
|
8
|
+
onDrag?: () => void;
|
|
9
|
+
onDragEnd?: (event: {
|
|
10
|
+
nativeEvent: LatLng;
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
|
13
|
+
declare class MarkerEventManager {
|
|
14
|
+
private callbacks;
|
|
15
|
+
register(markerId: string, callbacks: MarkerEventCallbacks): void;
|
|
16
|
+
unregister(markerId: string): void;
|
|
17
|
+
trigger(markerId: string, eventType: keyof MarkerEventCallbacks, data?: any): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const MarkerEventContext: React.Context<MarkerEventManager | null>;
|
|
20
|
+
type CircleEventCallbacks = {
|
|
21
|
+
onPress?: () => void;
|
|
22
|
+
};
|
|
23
|
+
declare class CircleEventManager {
|
|
24
|
+
private callbacks;
|
|
25
|
+
register(circleId: string, callbacks: CircleEventCallbacks): void;
|
|
26
|
+
unregister(circleId: string): void;
|
|
27
|
+
trigger(circleId: string, eventType: keyof CircleEventCallbacks): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const CircleEventContext: React.Context<CircleEventManager | null>;
|
|
30
|
+
type PolygonEventCallbacks = {
|
|
31
|
+
onPress?: () => void;
|
|
32
|
+
};
|
|
33
|
+
declare class PolygonEventManager {
|
|
34
|
+
private callbacks;
|
|
35
|
+
register(polygonId: string, callbacks: PolygonEventCallbacks): void;
|
|
36
|
+
unregister(polygonId: string): void;
|
|
37
|
+
trigger(polygonId: string, eventType: keyof PolygonEventCallbacks): void;
|
|
38
|
+
}
|
|
39
|
+
export declare const PolygonEventContext: React.Context<PolygonEventManager | null>;
|
|
40
|
+
type PolylineEventCallbacks = {
|
|
41
|
+
onPress?: () => void;
|
|
42
|
+
};
|
|
43
|
+
declare class PolylineEventManager {
|
|
44
|
+
private callbacks;
|
|
45
|
+
register(polylineId: string, callbacks: PolylineEventCallbacks): void;
|
|
46
|
+
unregister(polylineId: string): void;
|
|
47
|
+
trigger(polylineId: string, eventType: keyof PolylineEventCallbacks): void;
|
|
48
|
+
}
|
|
49
|
+
export declare const PolylineEventContext: React.Context<PolylineEventManager | null>;
|
|
5
50
|
/**
|
|
6
51
|
* 高德地图视图组件,提供地图操作API和覆盖物管理功能
|
|
7
52
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoGaodeMapView.d.ts","sourceRoot":"","sources":["../src/ExpoGaodeMapView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,
|
|
1
|
+
{"version":3,"file":"ExpoGaodeMapView.d.ts","sourceRoot":"","sources":["../src/ExpoGaodeMapView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EAGV,MAAM,EAMP,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAK1C,eAAO,MAAM,UAAU,0DAAuE,CAAC;AAG/F,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,cAAM,kBAAkB;IACtB,OAAO,CAAC,SAAS,CAA2C;IAE5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB;IAI1D,UAAU,CAAC,QAAQ,EAAE,MAAM;IAI3B,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,oBAAoB,EAAE,IAAI,CAAC,EAAE,GAAG;CAM5E;AAED,eAAO,MAAM,kBAAkB,0CAAuD,CAAC;AAGvF,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,cAAM,kBAAkB;IACtB,OAAO,CAAC,SAAS,CAA2C;IAE5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB;IAI1D,UAAU,CAAC,QAAQ,EAAE,MAAM;IAI3B,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,oBAAoB;CAMhE;AAED,eAAO,MAAM,kBAAkB,0CAAuD,CAAC;AAGvF,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,cAAM,mBAAmB;IACvB,OAAO,CAAC,SAAS,CAA4C;IAE7D,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,qBAAqB;IAI5D,UAAU,CAAC,SAAS,EAAE,MAAM;IAI5B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB;CAMlE;AAED,eAAO,MAAM,mBAAmB,2CAAwD,CAAC;AAGzF,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,cAAM,oBAAoB;IACxB,OAAO,CAAC,SAAS,CAA6C;IAE9D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,sBAAsB;IAI9D,UAAU,CAAC,UAAU,EAAE,MAAM;IAI7B,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,sBAAsB;CAMpE;AAED,eAAO,MAAM,oBAAoB,4CAAyD,CAAC;AAE3F;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,gBAAgB,iFAoSpB,CAAC;AAIH,eAAe,gBAAgB,CAAC"}
|
|
@@ -3,6 +3,70 @@ import * as React from 'react';
|
|
|
3
3
|
const NativeView = requireNativeViewManager('ExpoGaodeMap');
|
|
4
4
|
// 创建 Context 用于子组件访问 MapRef
|
|
5
5
|
export const MapContext = React.createContext(null);
|
|
6
|
+
class MarkerEventManager {
|
|
7
|
+
callbacks = new Map();
|
|
8
|
+
register(markerId, callbacks) {
|
|
9
|
+
this.callbacks.set(markerId, callbacks);
|
|
10
|
+
}
|
|
11
|
+
unregister(markerId) {
|
|
12
|
+
this.callbacks.delete(markerId);
|
|
13
|
+
}
|
|
14
|
+
trigger(markerId, eventType, data) {
|
|
15
|
+
const callbacks = this.callbacks.get(markerId);
|
|
16
|
+
if (callbacks && callbacks[eventType]) {
|
|
17
|
+
callbacks[eventType](data);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const MarkerEventContext = React.createContext(null);
|
|
22
|
+
class CircleEventManager {
|
|
23
|
+
callbacks = new Map();
|
|
24
|
+
register(circleId, callbacks) {
|
|
25
|
+
this.callbacks.set(circleId, callbacks);
|
|
26
|
+
}
|
|
27
|
+
unregister(circleId) {
|
|
28
|
+
this.callbacks.delete(circleId);
|
|
29
|
+
}
|
|
30
|
+
trigger(circleId, eventType) {
|
|
31
|
+
const callbacks = this.callbacks.get(circleId);
|
|
32
|
+
if (callbacks && callbacks[eventType]) {
|
|
33
|
+
callbacks[eventType]();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export const CircleEventContext = React.createContext(null);
|
|
38
|
+
class PolygonEventManager {
|
|
39
|
+
callbacks = new Map();
|
|
40
|
+
register(polygonId, callbacks) {
|
|
41
|
+
this.callbacks.set(polygonId, callbacks);
|
|
42
|
+
}
|
|
43
|
+
unregister(polygonId) {
|
|
44
|
+
this.callbacks.delete(polygonId);
|
|
45
|
+
}
|
|
46
|
+
trigger(polygonId, eventType) {
|
|
47
|
+
const callbacks = this.callbacks.get(polygonId);
|
|
48
|
+
if (callbacks && callbacks[eventType]) {
|
|
49
|
+
callbacks[eventType]();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export const PolygonEventContext = React.createContext(null);
|
|
54
|
+
class PolylineEventManager {
|
|
55
|
+
callbacks = new Map();
|
|
56
|
+
register(polylineId, callbacks) {
|
|
57
|
+
this.callbacks.set(polylineId, callbacks);
|
|
58
|
+
}
|
|
59
|
+
unregister(polylineId) {
|
|
60
|
+
this.callbacks.delete(polylineId);
|
|
61
|
+
}
|
|
62
|
+
trigger(polylineId, eventType) {
|
|
63
|
+
const callbacks = this.callbacks.get(polylineId);
|
|
64
|
+
if (callbacks && callbacks[eventType]) {
|
|
65
|
+
callbacks[eventType]();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export const PolylineEventContext = React.createContext(null);
|
|
6
70
|
/**
|
|
7
71
|
* 高德地图视图组件,提供地图操作API和覆盖物管理功能
|
|
8
72
|
*
|
|
@@ -24,6 +88,65 @@ export const MapContext = React.createContext(null);
|
|
|
24
88
|
const ExpoGaodeMapView = React.forwardRef((props, ref) => {
|
|
25
89
|
const nativeRef = React.useRef(null);
|
|
26
90
|
const internalRef = React.useRef(null);
|
|
91
|
+
const markerEventManager = React.useRef(new MarkerEventManager()).current;
|
|
92
|
+
const circleEventManager = React.useRef(new CircleEventManager()).current;
|
|
93
|
+
const polygonEventManager = React.useRef(new PolygonEventManager()).current;
|
|
94
|
+
const polylineEventManager = React.useRef(new PolylineEventManager()).current;
|
|
95
|
+
// 处理 Marker 事件
|
|
96
|
+
const handleMarkerPress = React.useCallback((event) => {
|
|
97
|
+
const markerId = event.nativeEvent?.markerId;
|
|
98
|
+
if (markerId) {
|
|
99
|
+
markerEventManager.trigger(markerId, 'onPress');
|
|
100
|
+
}
|
|
101
|
+
props.onMarkerPress?.(event);
|
|
102
|
+
}, [props.onMarkerPress]);
|
|
103
|
+
const handleMarkerDragStart = React.useCallback((event) => {
|
|
104
|
+
const markerId = event.nativeEvent?.markerId;
|
|
105
|
+
if (markerId) {
|
|
106
|
+
markerEventManager.trigger(markerId, 'onDragStart');
|
|
107
|
+
}
|
|
108
|
+
props.onMarkerDragStart?.(event);
|
|
109
|
+
}, [props.onMarkerDragStart]);
|
|
110
|
+
const handleMarkerDrag = React.useCallback((event) => {
|
|
111
|
+
const markerId = event.nativeEvent?.markerId;
|
|
112
|
+
if (markerId) {
|
|
113
|
+
markerEventManager.trigger(markerId, 'onDrag');
|
|
114
|
+
}
|
|
115
|
+
props.onMarkerDrag?.(event);
|
|
116
|
+
}, [props.onMarkerDrag]);
|
|
117
|
+
const handleMarkerDragEnd = React.useCallback((event) => {
|
|
118
|
+
const markerId = event.nativeEvent?.markerId;
|
|
119
|
+
if (markerId) {
|
|
120
|
+
markerEventManager.trigger(markerId, 'onDragEnd', {
|
|
121
|
+
nativeEvent: {
|
|
122
|
+
latitude: event.nativeEvent.latitude,
|
|
123
|
+
longitude: event.nativeEvent.longitude
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
props.onMarkerDragEnd?.(event);
|
|
128
|
+
}, [props.onMarkerDragEnd]);
|
|
129
|
+
const handleCirclePress = React.useCallback((event) => {
|
|
130
|
+
const circleId = event.nativeEvent?.circleId;
|
|
131
|
+
if (circleId) {
|
|
132
|
+
circleEventManager.trigger(circleId, 'onPress');
|
|
133
|
+
}
|
|
134
|
+
props.onCirclePress?.(event);
|
|
135
|
+
}, [props.onCirclePress]);
|
|
136
|
+
const handlePolygonPress = React.useCallback((event) => {
|
|
137
|
+
const polygonId = event.nativeEvent?.polygonId;
|
|
138
|
+
if (polygonId) {
|
|
139
|
+
polygonEventManager.trigger(polygonId, 'onPress');
|
|
140
|
+
}
|
|
141
|
+
props.onPolygonPress?.(event);
|
|
142
|
+
}, [props.onPolygonPress]);
|
|
143
|
+
const handlePolylinePress = React.useCallback((event) => {
|
|
144
|
+
const polylineId = event.nativeEvent?.polylineId;
|
|
145
|
+
if (polylineId) {
|
|
146
|
+
polylineEventManager.trigger(polylineId, 'onPress');
|
|
147
|
+
}
|
|
148
|
+
props.onPolylinePress?.(event);
|
|
149
|
+
}, [props.onPolylinePress]);
|
|
27
150
|
const apiRef = React.useMemo(() => ({
|
|
28
151
|
/**
|
|
29
152
|
* 移动地图相机到指定位置
|
|
@@ -236,7 +359,17 @@ const ExpoGaodeMapView = React.forwardRef((props, ref) => {
|
|
|
236
359
|
*/
|
|
237
360
|
React.useImperativeHandle(ref, () => apiRef, [apiRef]);
|
|
238
361
|
return (<MapContext.Provider value={internalRef}>
|
|
239
|
-
<
|
|
362
|
+
<MarkerEventContext.Provider value={markerEventManager}>
|
|
363
|
+
<CircleEventContext.Provider value={circleEventManager}>
|
|
364
|
+
<PolygonEventContext.Provider value={polygonEventManager}>
|
|
365
|
+
<PolylineEventContext.Provider value={polylineEventManager}>
|
|
366
|
+
<NativeView ref={nativeRef} {...props} onMarkerPress={handleMarkerPress} onMarkerDragStart={handleMarkerDragStart} onMarkerDrag={handleMarkerDrag} onMarkerDragEnd={handleMarkerDragEnd} onCirclePress={handleCirclePress} onPolygonPress={handlePolygonPress} onPolylinePress={handlePolylinePress}>
|
|
367
|
+
{props.children}
|
|
368
|
+
</NativeView>
|
|
369
|
+
</PolylineEventContext.Provider>
|
|
370
|
+
</PolygonEventContext.Provider>
|
|
371
|
+
</CircleEventContext.Provider>
|
|
372
|
+
</MarkerEventContext.Provider>
|
|
240
373
|
</MapContext.Provider>);
|
|
241
374
|
});
|
|
242
375
|
ExpoGaodeMapView.displayName = 'ExpoGaodeMapView';
|