expo-gaode-map 1.0.7 → 1.0.8
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/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +19 -3
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -1
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +22 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +53 -0
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +29 -0
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/types/map-view.types.d.ts +2 -1
- package/build/types/map-view.types.d.ts.map +1 -1
- package/build/types/map-view.types.js.map +1 -1
- package/ios/ExpoGaodeMapView.swift +19 -5
- package/ios/ExpoGaodeMapViewModule.swift +1 -1
- package/ios/managers/UIManager.swift +32 -4
- package/ios/overlays/MarkerView.swift +50 -2
- package/ios/overlays/MarkerViewModule.swift +0 -2
- package/package.json +1 -1
- package/src/components/overlays/Marker.tsx +47 -0
- package/src/types/map-view.types.ts +2 -1
|
@@ -46,6 +46,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
46
46
|
private val onMapPress by EventDispatcher()
|
|
47
47
|
private val onMapLongPress by EventDispatcher()
|
|
48
48
|
private val onLoad by EventDispatcher()
|
|
49
|
+
private val onLocation by EventDispatcher()
|
|
49
50
|
private val onMarkerPress by EventDispatcher()
|
|
50
51
|
private val onMarkerDragStart by EventDispatcher()
|
|
51
52
|
private val onMarkerDrag by EventDispatcher()
|
|
@@ -80,7 +81,17 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
80
81
|
|
|
81
82
|
// 初始化管理器
|
|
82
83
|
cameraManager = CameraManager(aMap)
|
|
83
|
-
uiManager = UIManager(aMap, context)
|
|
84
|
+
uiManager = UIManager(aMap, context).apply {
|
|
85
|
+
// 设置定位变化回调
|
|
86
|
+
onLocationChanged = { latitude, longitude, accuracy ->
|
|
87
|
+
this@ExpoGaodeMapView.onLocation(mapOf(
|
|
88
|
+
"latitude" to latitude,
|
|
89
|
+
"longitude" to longitude,
|
|
90
|
+
"accuracy" to accuracy.toDouble(),
|
|
91
|
+
"timestamp" to System.currentTimeMillis()
|
|
92
|
+
))
|
|
93
|
+
}
|
|
94
|
+
}
|
|
84
95
|
overlayManager = OverlayManager(aMap, context).apply {
|
|
85
96
|
onMarkerPress = { id, lat, lng ->
|
|
86
97
|
this@ExpoGaodeMapView.onMarkerPress(mapOf(
|
|
@@ -479,12 +490,17 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
479
490
|
* 添加子视图时自动连接到地图
|
|
480
491
|
*/
|
|
481
492
|
override fun addView(child: View?, index: Int) {
|
|
493
|
+
if (child is MarkerView) {
|
|
494
|
+
// 不添加到视图层级,只调用 setMap
|
|
495
|
+
child.setMap(aMap)
|
|
496
|
+
return
|
|
497
|
+
}
|
|
498
|
+
|
|
482
499
|
super.addView(child, index)
|
|
483
500
|
|
|
484
|
-
//
|
|
501
|
+
// 自动将地图实例传递给其他覆盖物子视图
|
|
485
502
|
child?.let {
|
|
486
503
|
when (it) {
|
|
487
|
-
is MarkerView -> it.setMap(aMap)
|
|
488
504
|
is PolylineView -> it.setMap(aMap)
|
|
489
505
|
is PolygonView -> it.setMap(aMap)
|
|
490
506
|
is CircleView -> it.setMap(aMap)
|
|
@@ -11,7 +11,7 @@ class ExpoGaodeMapViewModule : Module() {
|
|
|
11
11
|
Name("ExpoGaodeMapView")
|
|
12
12
|
|
|
13
13
|
View(ExpoGaodeMapView::class) {
|
|
14
|
-
Events("onMapPress", "onMapLongPress", "onLoad", "onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd", "onCirclePress", "onPolygonPress", "onPolylinePress")
|
|
14
|
+
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd", "onCirclePress", "onPolygonPress", "onPolylinePress")
|
|
15
15
|
|
|
16
16
|
Prop<Int>("mapType") { view, type ->
|
|
17
17
|
view.mapType = type
|
|
@@ -3,6 +3,7 @@ package expo.modules.gaodemap.managers
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.BitmapFactory
|
|
5
5
|
import com.amap.api.maps.AMap
|
|
6
|
+
import com.amap.api.maps.LocationSource
|
|
6
7
|
import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
7
8
|
import com.amap.api.maps.model.MyLocationStyle
|
|
8
9
|
import expo.modules.gaodemap.utils.ColorParser
|
|
@@ -15,6 +16,8 @@ import java.net.URL
|
|
|
15
16
|
*/
|
|
16
17
|
class UIManager(private val aMap: AMap, private val context: Context) {
|
|
17
18
|
|
|
19
|
+
var onLocationChanged: ((latitude: Double, longitude: Double, accuracy: Float) -> Unit)? = null
|
|
20
|
+
|
|
18
21
|
// ==================== 控件显示 ====================
|
|
19
22
|
|
|
20
23
|
/**
|
|
@@ -87,8 +90,27 @@ class UIManager(private val aMap: AMap, private val context: Context) {
|
|
|
87
90
|
}
|
|
88
91
|
currentLocationStyle?.myLocationType(locationType)
|
|
89
92
|
aMap.myLocationStyle = currentLocationStyle
|
|
93
|
+
|
|
94
|
+
// 设置定位监听
|
|
95
|
+
aMap.setLocationSource(object : LocationSource {
|
|
96
|
+
override fun activate(listener: LocationSource.OnLocationChangedListener?) {
|
|
97
|
+
// 高德地图会自动处理定位,我们只需要监听位置变化
|
|
98
|
+
}
|
|
99
|
+
override fun deactivate() {}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// 监听定位变化
|
|
103
|
+
aMap.setOnMyLocationChangeListener { location ->
|
|
104
|
+
onLocationChanged?.invoke(
|
|
105
|
+
location.latitude,
|
|
106
|
+
location.longitude,
|
|
107
|
+
location.accuracy
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
90
111
|
aMap.isMyLocationEnabled = true
|
|
91
112
|
} else {
|
|
113
|
+
aMap.setOnMyLocationChangeListener(null)
|
|
92
114
|
aMap.isMyLocationEnabled = false
|
|
93
115
|
}
|
|
94
116
|
}
|
|
@@ -16,6 +16,12 @@ import expo.modules.kotlin.views.ExpoView
|
|
|
16
16
|
|
|
17
17
|
class MarkerView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
|
18
18
|
|
|
19
|
+
init {
|
|
20
|
+
// 不可交互,通过父视图定位到屏幕外
|
|
21
|
+
isClickable = false
|
|
22
|
+
isFocusable = false
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
private val onPress by EventDispatcher()
|
|
20
26
|
private val onDragStart by EventDispatcher()
|
|
21
27
|
private val onDrag by EventDispatcher()
|
|
@@ -142,6 +148,16 @@ class MarkerView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
142
148
|
val options = MarkerOptions()
|
|
143
149
|
marker = map.addMarker(options)
|
|
144
150
|
|
|
151
|
+
// 延迟处理子视图,等待 React Native 添加完成
|
|
152
|
+
postDelayed({
|
|
153
|
+
if (childCount > 0) {
|
|
154
|
+
val bitmap = createBitmapFromView()
|
|
155
|
+
bitmap?.let {
|
|
156
|
+
marker?.setIcon(BitmapDescriptorFactory.fromBitmap(it))
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, 100)
|
|
160
|
+
|
|
145
161
|
// 设置点击监听
|
|
146
162
|
map.setOnMarkerClickListener { clickedMarker ->
|
|
147
163
|
if (clickedMarker == marker) {
|
|
@@ -194,6 +210,43 @@ class MarkerView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
194
210
|
}
|
|
195
211
|
}
|
|
196
212
|
|
|
213
|
+
/**
|
|
214
|
+
* 将视图转换为 Bitmap
|
|
215
|
+
*/
|
|
216
|
+
private fun createBitmapFromView(): Bitmap? {
|
|
217
|
+
if (childCount == 0) return null
|
|
218
|
+
|
|
219
|
+
return try {
|
|
220
|
+
measure(
|
|
221
|
+
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
|
222
|
+
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
|
|
223
|
+
)
|
|
224
|
+
layout(0, 0, measuredWidth, measuredHeight)
|
|
225
|
+
|
|
226
|
+
val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888)
|
|
227
|
+
val canvas = Canvas(bitmap)
|
|
228
|
+
draw(canvas)
|
|
229
|
+
bitmap
|
|
230
|
+
} catch (e: Exception) {
|
|
231
|
+
e.printStackTrace()
|
|
232
|
+
null
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
override fun addView(child: View?, index: Int, params: android.view.ViewGroup.LayoutParams?) {
|
|
237
|
+
super.addView(child, index, params)
|
|
238
|
+
|
|
239
|
+
// 当添加子视图时,手动触发测量和布局
|
|
240
|
+
post {
|
|
241
|
+
if (childCount > 0) {
|
|
242
|
+
val bitmap = createBitmapFromView()
|
|
243
|
+
bitmap?.let {
|
|
244
|
+
marker?.setIcon(BitmapDescriptorFactory.fromBitmap(it))
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
197
250
|
/**
|
|
198
251
|
* 移除标记
|
|
199
252
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Marker.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,qBAOhD"}
|
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
3
4
|
import { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';
|
|
5
|
+
const NativeMarkerView = requireNativeViewManager('MarkerView');
|
|
4
6
|
export default function Marker(props) {
|
|
7
|
+
// 如果有 children,使用声明式 API
|
|
8
|
+
if (props.children) {
|
|
9
|
+
return <MarkerDeclarative {...props}/>;
|
|
10
|
+
}
|
|
11
|
+
// 否则使用命令式 API
|
|
5
12
|
return <MarkerImperative {...props}/>;
|
|
6
13
|
}
|
|
14
|
+
function MarkerDeclarative(props) {
|
|
15
|
+
const eventManager = React.useContext(MarkerEventContext);
|
|
16
|
+
const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);
|
|
17
|
+
React.useEffect(() => {
|
|
18
|
+
if (eventManager) {
|
|
19
|
+
eventManager.register(markerIdRef.current, {
|
|
20
|
+
onPress: props.onPress,
|
|
21
|
+
onDragStart: props.onDragStart,
|
|
22
|
+
onDrag: props.onDrag,
|
|
23
|
+
onDragEnd: props.onDragEnd,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return () => {
|
|
27
|
+
if (eventManager) {
|
|
28
|
+
eventManager.unregister(markerIdRef.current);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
|
|
32
|
+
return (<NativeMarkerView position={props.position} title={props.title} draggable={props.draggable} opacity={props.opacity} anchor={props.anchor} flat={props.flat} zIndex={props.zIndex} onPress={props.onPress} onDragStart={props.onDragStart} onDrag={props.onDrag} onDragEnd={props.onDragEnd}>
|
|
33
|
+
{props.children}
|
|
34
|
+
</NativeMarkerView>);
|
|
35
|
+
}
|
|
7
36
|
function MarkerImperative(props) {
|
|
8
37
|
const mapRef = React.useContext(MapContext);
|
|
9
38
|
const eventManager = React.useContext(MarkerEventContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGxE,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAkB;IAC/C,OAAO,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACzC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAkB;IAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAgB,IAAI,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAErC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;IAC3B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;gBACrB,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBAC5B,OAAO;YACT,CAAC;YAED,MAAM,QAAQ,GAAG,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACzD,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;YAE/B,IAAI,YAAY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C,WAAW;gBAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,KAAK,CAAC,SAAS;aAC3B,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAEtE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,WAAW,CAAC,OAAO,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YAC3C,MAAM,cAAc,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACpC,IAAI,cAAc,CAAC,IAAI,IAAI,OAAO,cAAc,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACnE,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC/D,cAAc,CAAC,IAAI,GAAG,QAAQ,CAAC;YACjC,CAAC;YACD,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACnE,CAAC;IACH,CAAC,EAAE;QACD,KAAK,CAAC,QAAQ,EAAE,QAAQ;QACxB,KAAK,CAAC,QAAQ,EAAE,SAAS;QACzB,KAAK,CAAC,KAAK;QACX,KAAK,CAAC,SAAS;QACf,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,SAAS;QACf,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,QAAQ;KACf,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as React from 'react';\nimport { Image } from 'react-native';\nimport { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\nexport default function Marker(props: MarkerProps) {\n return <MarkerImperative {...props} />;\n}\n\nfunction MarkerImperative(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef<string | null>(null);\n const propsRef = React.useRef(props);\n \n React.useEffect(() => {\n propsRef.current = props;\n }, [props]);\n \n React.useEffect(() => {\n const checkAndAdd = () => {\n if (!mapRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const markerId = `marker_${Date.now()}_${Math.random()}`;\n markerIdRef.current = markerId;\n \n if (eventManager) {\n eventManager.register(markerId, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n \n const processedProps = { ...propsRef.current };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n \n mapRef.current.addMarker(markerId, processedProps);\n };\n \n checkAndAdd();\n \n return () => {\n if (markerIdRef.current) {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n if (mapRef?.current) {\n mapRef.current.removeMarker(markerIdRef.current);\n }\n }\n };\n }, []);\n\n React.useEffect(() => {\n if (markerIdRef.current && eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n }, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n\n React.useEffect(() => {\n if (markerIdRef.current && mapRef?.current) {\n const processedProps = { ...props };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n mapRef.current.updateMarker(markerIdRef.current, processedProps);\n }\n }, [\n props.position?.latitude,\n props.position?.longitude,\n props.title,\n props.draggable,\n props.icon,\n props.iconWidth,\n props.iconHeight,\n props.pinColor\n ]);\n \n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK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CAAC,SAAS;QACf,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,QAAQ;KACf,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as React from 'react';\nimport { Image } from 'react-native';\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\nconst NativeMarkerView = requireNativeViewManager('MarkerView');\n\nexport default function Marker(props: MarkerProps) {\n // 如果有 children,使用声明式 API\n if (props.children) {\n return <MarkerDeclarative {...props} />;\n }\n // 否则使用命令式 API\n return <MarkerImperative {...props} />;\n}\n\nfunction MarkerDeclarative(props: MarkerProps) {\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);\n \n React.useEffect(() => {\n if (eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n return () => {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n };\n }, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n \n return (\n <NativeMarkerView\n position={props.position}\n title={props.title}\n draggable={props.draggable}\n opacity={props.opacity}\n anchor={props.anchor}\n flat={props.flat}\n zIndex={props.zIndex}\n onPress={props.onPress}\n onDragStart={props.onDragStart}\n onDrag={props.onDrag}\n onDragEnd={props.onDragEnd}\n >\n {props.children}\n </NativeMarkerView>\n );\n}\n\nfunction MarkerImperative(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef<string | null>(null);\n const propsRef = React.useRef(props);\n \n React.useEffect(() => {\n propsRef.current = props;\n }, [props]);\n \n React.useEffect(() => {\n const checkAndAdd = () => {\n if (!mapRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const markerId = `marker_${Date.now()}_${Math.random()}`;\n markerIdRef.current = markerId;\n \n if (eventManager) {\n eventManager.register(markerId, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n \n const processedProps = { ...propsRef.current };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n \n mapRef.current.addMarker(markerId, processedProps);\n };\n \n checkAndAdd();\n \n return () => {\n if (markerIdRef.current) {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n if (mapRef?.current) {\n mapRef.current.removeMarker(markerIdRef.current);\n }\n }\n };\n }, []);\n\n React.useEffect(() => {\n if (markerIdRef.current && eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n }, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n\n React.useEffect(() => {\n if (markerIdRef.current && mapRef?.current) {\n const processedProps = { ...props };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n mapRef.current.updateMarker(markerIdRef.current, processedProps);\n }\n }, [\n props.position?.latitude,\n props.position?.longitude,\n props.title,\n props.draggable,\n props.icon,\n props.iconWidth,\n props.iconHeight,\n props.pinColor\n ]);\n \n return null;\n}\n"]}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
6
6
|
import type { CameraPosition, LatLng, LatLngBounds, MapPoi, MapType, Point } from './common.types';
|
|
7
|
+
import type { Coordinates, ReGeocode } from './location.types';
|
|
7
8
|
/**
|
|
8
9
|
* 地图相机事件
|
|
9
10
|
*/
|
|
@@ -165,7 +166,7 @@ export interface MapViewProps {
|
|
|
165
166
|
/**
|
|
166
167
|
* 地图定位更新事件
|
|
167
168
|
*/
|
|
168
|
-
onLocation?: (event:
|
|
169
|
+
onLocation?: (event: Coordinates | ReGeocode) => void;
|
|
169
170
|
/**
|
|
170
171
|
* Marker 点击事件
|
|
171
172
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-view.types.d.ts","sourceRoot":"","sources":["../../src/types/map-view.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"map-view.types.d.ts","sourceRoot":"","sources":["../../src/types/map-view.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,cAAc,EAAE,cAAc,CAAC;IAE/B;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,qBAAqB,CAAC,EAAE,cAAc,CAAC;IAEvC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,0BAA0B,CAAC,EAAE;QAC3B,4BAA4B;QAC5B,iBA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EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxF,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,kBAAkB,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,kBAAkB,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtF,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,kBAAkB,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-view.types.js","sourceRoot":"","sources":["../../src/types/map-view.types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * 高德地图视图相关类型定义\n * 基于 Expo Modules API\n */\n\nimport type { StyleProp, ViewStyle } from 'react-native';\nimport type { CameraPosition, LatLng, LatLngBounds, MapPoi, MapType, Point } from './common.types';\n\n/**\n * 地图相机事件\n */\nexport interface CameraEvent {\n /**\n * 相机位置\n */\n cameraPosition: CameraPosition;\n\n /**\n * 可见区域边界\n */\n latLngBounds: LatLngBounds;\n}\n\n/**\n * 地图视图属性\n */\nexport interface MapViewProps {\n /**\n * 地图类型\n */\n mapType?: MapType;\n\n /**\n * 初始相机位置\n */\n initialCameraPosition?: CameraPosition;\n\n /**\n * 是否显示当前定位\n */\n myLocationEnabled?: boolean;\n\n /**\n * 是否跟随用户位置\n * @default false\n */\n followUserLocation?: boolean;\n\n /**\n * 定位蓝点配置\n */\n userLocationRepresentation?: {\n /** 精度圈是否显示 @default true */\n showsAccuracyRing?: boolean;\n /** 是否显示方向指示 @default true @platform ios */\n showsHeadingIndicator?: boolean;\n /** 精度圈填充颜色 支持 '#RRGGBB'、'red' 或 ARGB 数字 */\n fillColor?: string | number;\n /** 精度圈边线颜色 */\n strokeColor?: string | number;\n /** 精度圈边线宽度 @default 0 */\n lineWidth?: number;\n /** 内部蓝色圆点是否使用律动效果 @default true @platform ios */\n enablePulseAnimation?: boolean;\n /** 定位点背景色 @default 'white' @platform ios */\n locationDotBgColor?: string | number;\n /** 定位点蓝色圆点颜色 @default 'blue' @platform ios */\n locationDotFillColor?: string | number;\n /** 定位图标 支持网络图片(http/https)、本地文件(file://)或资源名称 */\n image?: string;\n /** 定位图标宽度(像素) */\n imageWidth?: number;\n /** 定位图标高度(像素) */\n imageHeight?: number;\n };\n\n /**\n * 是否显示室内地图\n * \n */\n indoorViewEnabled?: boolean;\n\n /**\n * 是否显示3D建筑\n */\n buildingsEnabled?: boolean;\n\n /**\n * 是否显示标注\n */\n labelsEnabled?: boolean;\n\n /**\n * 是否显示指南针\n */\n compassEnabled?: boolean;\n\n /**\n * 是否显示缩放按钮\n * @platform android\n */\n zoomControlsEnabled?: boolean;\n\n /**\n * 是否显示比例尺\n */\n scaleControlsEnabled?: boolean;\n\n /**\n * 是否显示定位按钮\n * @platform android\n */\n myLocationButtonEnabled?: boolean;\n\n /**\n * 是否显示路况\n */\n trafficEnabled?: boolean;\n\n /**\n * 最大缩放级别\n */\n maxZoom?: number;\n\n /**\n * 最小缩放级别\n */\n minZoom?: number;\n\n /**\n * 是否启用缩放手势\n */\n zoomGesturesEnabled?: boolean;\n\n /**\n * 是否启用滑动手势\n */\n scrollGesturesEnabled?: boolean;\n\n /**\n * 是否启用旋转手势\n */\n rotateGesturesEnabled?: boolean;\n\n /**\n * 是否启用倾斜手势\n */\n tiltGesturesEnabled?: boolean;\n\n /**\n * 定位的最小更新距离(米)\n * @platform ios\n */\n distanceFilter?: number;\n\n /**\n * 最小更新角度(度)\n * @platform ios\n */\n headingFilter?: number;\n\n /**\n * 样式\n */\n style?: StyleProp<ViewStyle>;\n\n /**\n * 点击地图事件\n */\n onMapPress?: (event: LatLng) => void;\n\n /**\n * 点击标注点事件\n */\n onPressPoi?: (event: MapPoi) => void;\n\n /**\n * 长按地图事件\n */\n onMapLongPress?: (event: LatLng) => void;\n\n /**\n * 地图状态改变事件(实时触发)\n */\n onCameraMove?: (event: CameraEvent) => void;\n\n /**\n * 地图状态改变完成事件\n */\n onCameraIdle?: (event: CameraEvent) => void;\n\n /**\n * 地图加载完成事件\n */\n onLoad?: (event: {}) => void;\n\n /**\n * 地图定位更新事件\n */\n onLocation?: (event:
|
|
1
|
+
{"version":3,"file":"map-view.types.js","sourceRoot":"","sources":["../../src/types/map-view.types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * 高德地图视图相关类型定义\n * 基于 Expo Modules API\n */\n\nimport type { StyleProp, ViewStyle } from 'react-native';\nimport type { CameraPosition, LatLng, LatLngBounds, MapPoi, MapType, Point } from './common.types';\nimport type { Coordinates, ReGeocode } from './location.types';\n\n/**\n * 地图相机事件\n */\nexport interface CameraEvent {\n /**\n * 相机位置\n */\n cameraPosition: CameraPosition;\n\n /**\n * 可见区域边界\n */\n latLngBounds: LatLngBounds;\n}\n\n/**\n * 地图视图属性\n */\nexport interface MapViewProps {\n /**\n * 地图类型\n */\n mapType?: MapType;\n\n /**\n * 初始相机位置\n */\n initialCameraPosition?: CameraPosition;\n\n /**\n * 是否显示当前定位\n */\n myLocationEnabled?: boolean;\n\n /**\n * 是否跟随用户位置\n * @default false\n */\n followUserLocation?: boolean;\n\n /**\n * 定位蓝点配置\n */\n userLocationRepresentation?: {\n /** 精度圈是否显示 @default true */\n showsAccuracyRing?: boolean;\n /** 是否显示方向指示 @default true @platform ios */\n showsHeadingIndicator?: boolean;\n /** 精度圈填充颜色 支持 '#RRGGBB'、'red' 或 ARGB 数字 */\n fillColor?: string | number;\n /** 精度圈边线颜色 */\n strokeColor?: string | number;\n /** 精度圈边线宽度 @default 0 */\n lineWidth?: number;\n /** 内部蓝色圆点是否使用律动效果 @default true @platform ios */\n enablePulseAnimation?: boolean;\n /** 定位点背景色 @default 'white' @platform ios */\n locationDotBgColor?: string | number;\n /** 定位点蓝色圆点颜色 @default 'blue' @platform ios */\n locationDotFillColor?: string | number;\n /** 定位图标 支持网络图片(http/https)、本地文件(file://)或资源名称 */\n image?: string;\n /** 定位图标宽度(像素) */\n imageWidth?: number;\n /** 定位图标高度(像素) */\n imageHeight?: number;\n };\n\n /**\n * 是否显示室内地图\n * \n */\n indoorViewEnabled?: boolean;\n\n /**\n * 是否显示3D建筑\n */\n buildingsEnabled?: boolean;\n\n /**\n * 是否显示标注\n */\n labelsEnabled?: boolean;\n\n /**\n * 是否显示指南针\n */\n compassEnabled?: boolean;\n\n /**\n * 是否显示缩放按钮\n * @platform android\n */\n zoomControlsEnabled?: boolean;\n\n /**\n * 是否显示比例尺\n */\n scaleControlsEnabled?: boolean;\n\n /**\n * 是否显示定位按钮\n * @platform android\n */\n myLocationButtonEnabled?: boolean;\n\n /**\n * 是否显示路况\n */\n trafficEnabled?: boolean;\n\n /**\n * 最大缩放级别\n */\n maxZoom?: number;\n\n /**\n * 最小缩放级别\n */\n minZoom?: number;\n\n /**\n * 是否启用缩放手势\n */\n zoomGesturesEnabled?: boolean;\n\n /**\n * 是否启用滑动手势\n */\n scrollGesturesEnabled?: boolean;\n\n /**\n * 是否启用旋转手势\n */\n rotateGesturesEnabled?: boolean;\n\n /**\n * 是否启用倾斜手势\n */\n tiltGesturesEnabled?: boolean;\n\n /**\n * 定位的最小更新距离(米)\n * @platform ios\n */\n distanceFilter?: number;\n\n /**\n * 最小更新角度(度)\n * @platform ios\n */\n headingFilter?: number;\n\n /**\n * 样式\n */\n style?: StyleProp<ViewStyle>;\n\n /**\n * 点击地图事件\n */\n onMapPress?: (event: LatLng) => void;\n\n /**\n * 点击标注点事件\n */\n onPressPoi?: (event: MapPoi) => void;\n\n /**\n * 长按地图事件\n */\n onMapLongPress?: (event: LatLng) => void;\n\n /**\n * 地图状态改变事件(实时触发)\n */\n onCameraMove?: (event: CameraEvent) => void;\n\n /**\n * 地图状态改变完成事件\n */\n onCameraIdle?: (event: CameraEvent) => void;\n\n /**\n * 地图加载完成事件\n */\n onLoad?: (event: {}) => void;\n\n /**\n * 地图定位更新事件\n */\n onLocation?: (event: Coordinates | ReGeocode) => void;\n\n /**\n * Marker 点击事件\n */\n onMarkerPress?: (event: { markerId: string } & LatLng) => void;\n\n /**\n * Marker 拖拽开始事件\n */\n onMarkerDragStart?: (event: { markerId: string } & LatLng) => void;\n\n /**\n * Marker 拖拽中事件\n */\n onMarkerDrag?: (event: { markerId: string } & LatLng) => void;\n\n /**\n * Marker 拖拽结束事件\n */\n onMarkerDragEnd?: (event: { markerId: string } & LatLng) => void;\n\n /**\n * Circle 点击事件\n */\n onCirclePress?: (event: { circleId: string } & LatLng) => void;\n\n /**\n * Polygon 点击事件\n */\n onPolygonPress?: (event: { polygonId: string } & LatLng) => void;\n\n /**\n * Polyline 点击事件\n */\n onPolylinePress?: (event: { polylineId: string } & LatLng) => void;\n\n /**\n * 子组件\n */\n children?: React.ReactNode;\n}\n\n/**\n * 地图视图方法\n */\nexport interface MapViewMethods {\n /**\n * 移动相机\n * @param cameraPosition 目标相机位置\n * @param duration 动画时长(毫秒)\n */\n moveCamera(cameraPosition: CameraPosition, duration?: number): void;\n\n /**\n * 将屏幕坐标转换为地理坐标\n * @param point 屏幕坐标\n * @returns 地理坐标\n */\n getLatLng(point: Point): Promise<LatLng>;\n}\n\n/**\n * MapView Ref 公开接口(用户使用)\n */\nexport interface MapViewRef {\n moveCamera(position: CameraPosition, duration?: number): Promise<void>;\n getLatLng(point: Point): Promise<LatLng>;\n setCenter(center: LatLng, animated?: boolean): Promise<void>;\n setZoom(zoom: number, animated?: boolean): Promise<void>;\n getCameraPosition(): Promise<CameraPosition>;\n addCircle(id: string, props: import('./overlays.types').CircleProps): Promise<void>;\n removeCircle(id: string): Promise<void>;\n updateCircle(id: string, props: Partial<import('./overlays.types').CircleProps>): Promise<void>;\n addMarker(id: string, props: import('./overlays.types').MarkerProps): Promise<void>;\n removeMarker(id: string): Promise<void>;\n updateMarker(id: string, props: Partial<import('./overlays.types').MarkerProps>): Promise<void>;\n addPolyline(id: string, props: import('./overlays.types').PolylineProps): Promise<void>;\n removePolyline(id: string): Promise<void>;\n updatePolyline(id: string, props: Partial<import('./overlays.types').PolylineProps>): Promise<void>;\n addPolygon(id: string, props: import('./overlays.types').PolygonProps): Promise<void>;\n removePolygon(id: string): Promise<void>;\n updatePolygon(id: string, props: Partial<import('./overlays.types').PolygonProps>): Promise<void>;\n}\n\n/**\n * 原生 MapView Ref 接口(所有参数必需)\n */\nexport interface NativeMapViewRef {\n moveCamera(position: CameraPosition, duration: number): Promise<void>;\n getLatLng(point: Point): Promise<LatLng>;\n setCenter(center: LatLng, animated: boolean): Promise<void>;\n setZoom(zoom: number, animated: boolean): Promise<void>;\n getCameraPosition(): Promise<CameraPosition>;\n addCircle(id: string, props: import('./overlays.types').CircleProps): Promise<void>;\n removeCircle(id: string): Promise<void>;\n updateCircle(id: string, props: Partial<import('./overlays.types').CircleProps>): Promise<void>;\n addMarker(id: string, props: import('./overlays.types').MarkerProps): Promise<void>;\n removeMarker(id: string): Promise<void>;\n updateMarker(id: string, props: Partial<import('./overlays.types').MarkerProps>): Promise<void>;\n addPolyline(id: string, props: import('./overlays.types').PolylineProps): Promise<void>;\n removePolyline(id: string): Promise<void>;\n updatePolyline(id: string, props: Partial<import('./overlays.types').PolylineProps>): Promise<void>;\n addPolygon(id: string, props: import('./overlays.types').PolygonProps): Promise<void>;\n removePolygon(id: string): Promise<void>;\n updatePolygon(id: string, props: Partial<import('./overlays.types').PolygonProps>): Promise<void>;\n}\n"]}
|
|
@@ -59,6 +59,7 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
|
|
|
59
59
|
let onMapPress = EventDispatcher()
|
|
60
60
|
let onMapLongPress = EventDispatcher()
|
|
61
61
|
let onLoad = EventDispatcher()
|
|
62
|
+
let onLocation = EventDispatcher()
|
|
62
63
|
let onMarkerPress = EventDispatcher()
|
|
63
64
|
let onMarkerDragStart = EventDispatcher()
|
|
64
65
|
let onMarkerDrag = EventDispatcher()
|
|
@@ -99,6 +100,17 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
|
|
|
99
100
|
|
|
100
101
|
cameraManager = CameraManager(mapView: mapView)
|
|
101
102
|
uiManager = UIManager(mapView: mapView)
|
|
103
|
+
|
|
104
|
+
// 设置定位变化回调
|
|
105
|
+
uiManager.onLocationChanged = { [weak self] latitude, longitude, accuracy in
|
|
106
|
+
self?.onLocation([
|
|
107
|
+
"latitude": latitude,
|
|
108
|
+
"longitude": longitude,
|
|
109
|
+
"accuracy": accuracy,
|
|
110
|
+
"timestamp": Date().timeIntervalSince1970 * 1000
|
|
111
|
+
])
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
overlayManager = OverlayManager(mapView: mapView)
|
|
103
115
|
|
|
104
116
|
// 设置覆盖物点击回调
|
|
@@ -125,13 +137,15 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
|
|
|
125
137
|
* 将地图实例传递给覆盖物子视图
|
|
126
138
|
*/
|
|
127
139
|
override func addSubview(_ view: UIView) {
|
|
128
|
-
super.addSubview(view)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
140
|
if let markerView = view as? MarkerView {
|
|
141
|
+
// 不添加到视图层级,只调用 setMap
|
|
133
142
|
markerView.setMap(mapView)
|
|
134
|
-
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
super.addSubview(view)
|
|
147
|
+
|
|
148
|
+
if let circleView = view as? CircleView {
|
|
135
149
|
circleView.setMap(mapView)
|
|
136
150
|
} else if let polylineView = view as? PolylineView {
|
|
137
151
|
polylineView.setMap(mapView)
|
|
@@ -9,7 +9,7 @@ public class ExpoGaodeMapViewModule: Module {
|
|
|
9
9
|
Name("ExpoGaodeMapView")
|
|
10
10
|
|
|
11
11
|
View(ExpoGaodeMapView.self) {
|
|
12
|
-
Events("onMapPress", "onMapLongPress", "onLoad", "onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd", "onCirclePress", "onPolygonPress", "onPolylinePress")
|
|
12
|
+
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd", "onCirclePress", "onPolygonPress", "onPolylinePress")
|
|
13
13
|
|
|
14
14
|
Prop("mapType") { (view: ExpoGaodeMapView, type: Int) in
|
|
15
15
|
view.mapType = type
|
|
@@ -10,12 +10,16 @@ import MAMapKit
|
|
|
10
10
|
* - 图层显示管理
|
|
11
11
|
* - 用户位置样式配置
|
|
12
12
|
*/
|
|
13
|
-
class UIManager {
|
|
13
|
+
class UIManager: NSObject, MAMapViewDelegate {
|
|
14
14
|
/// 弱引用地图视图,避免循环引用
|
|
15
15
|
private weak var mapView: MAMapView?
|
|
16
16
|
|
|
17
|
+
/// 定位变化回调
|
|
18
|
+
var onLocationChanged: ((_ latitude: Double, _ longitude: Double, _ accuracy: Double) -> Void)?
|
|
19
|
+
|
|
17
20
|
init(mapView: MAMapView) {
|
|
18
21
|
self.mapView = mapView
|
|
22
|
+
super.init()
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
// MARK: - 地图类型
|
|
@@ -97,14 +101,38 @@ class UIManager {
|
|
|
97
101
|
*/
|
|
98
102
|
func setShowsUserLocation(_ show: Bool, followUser: Bool) {
|
|
99
103
|
guard let mapView = mapView else { return }
|
|
100
|
-
|
|
101
|
-
if show
|
|
102
|
-
|
|
104
|
+
|
|
105
|
+
if show {
|
|
106
|
+
// 设置代理以监听定位更新
|
|
107
|
+
if mapView.delegate == nil {
|
|
108
|
+
mapView.delegate = self
|
|
109
|
+
}
|
|
110
|
+
mapView.showsUserLocation = true
|
|
111
|
+
if followUser {
|
|
112
|
+
mapView.userTrackingMode = .follow
|
|
113
|
+
} else {
|
|
114
|
+
mapView.userTrackingMode = .none
|
|
115
|
+
}
|
|
103
116
|
} else {
|
|
117
|
+
mapView.showsUserLocation = false
|
|
104
118
|
mapView.userTrackingMode = .none
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
|
|
122
|
+
// MARK: - MAMapViewDelegate
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 定位更新回调
|
|
126
|
+
*/
|
|
127
|
+
public func mapView(_ mapView: MAMapView, didUpdate userLocation: MAUserLocation, updatingLocation: Bool) {
|
|
128
|
+
guard updatingLocation, let location = userLocation.location else { return }
|
|
129
|
+
onLocationChanged?(
|
|
130
|
+
location.coordinate.latitude,
|
|
131
|
+
location.coordinate.longitude,
|
|
132
|
+
location.horizontalAccuracy
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
108
136
|
/**
|
|
109
137
|
* 设置用户位置样式
|
|
110
138
|
* @param config 样式配置字典
|
|
@@ -49,6 +49,8 @@ class MarkerView: ExpoView {
|
|
|
49
49
|
|
|
50
50
|
required init(appContext: AppContext? = nil) {
|
|
51
51
|
super.init(appContext: appContext)
|
|
52
|
+
// 不可交互,通过父视图定位到屏幕外
|
|
53
|
+
isUserInteractionEnabled = false
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
/**
|
|
@@ -84,8 +86,54 @@ class MarkerView: ExpoView {
|
|
|
84
86
|
mapView.addAnnotation(annotation)
|
|
85
87
|
self.annotation = annotation
|
|
86
88
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
+
// 延迟处理子视图,等待 React Native 添加完成
|
|
90
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
|
91
|
+
guard let self = self else { return }
|
|
92
|
+
if let view = mapView.view(for: annotation), self.subviews.count > 0 {
|
|
93
|
+
self.annotationView = view
|
|
94
|
+
if let image = self.createImageFromSubviews() {
|
|
95
|
+
view.image = image
|
|
96
|
+
view.centerOffset = CGPoint(x: 0, y: -image.size.height / 2)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 将子视图转换为图片
|
|
104
|
+
*/
|
|
105
|
+
private func createImageFromSubviews() -> UIImage? {
|
|
106
|
+
guard subviews.count > 0 else { return nil }
|
|
107
|
+
|
|
108
|
+
// 强制布局
|
|
109
|
+
setNeedsLayout()
|
|
110
|
+
layoutIfNeeded()
|
|
111
|
+
|
|
112
|
+
let size = bounds.size
|
|
113
|
+
guard size.width > 0 && size.height > 0 else { return nil }
|
|
114
|
+
|
|
115
|
+
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
|
116
|
+
defer { UIGraphicsEndImageContext() }
|
|
117
|
+
|
|
118
|
+
guard let context = UIGraphicsGetCurrentContext() else { return nil }
|
|
119
|
+
layer.render(in: context)
|
|
120
|
+
|
|
121
|
+
return UIGraphicsGetImageFromCurrentImageContext()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
override func didAddSubview(_ subview: UIView) {
|
|
125
|
+
super.didAddSubview(subview)
|
|
126
|
+
|
|
127
|
+
// 当添加子视图时,更新标记图标
|
|
128
|
+
DispatchQueue.main.async { [weak self] in
|
|
129
|
+
guard let self = self else { return }
|
|
130
|
+
if self.subviews.count > 0, let view = self.annotationView {
|
|
131
|
+
if let image = self.createImageFromSubviews() {
|
|
132
|
+
view.image = image
|
|
133
|
+
view.centerOffset = CGPoint(x: 0, y: -image.size.height / 2)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
89
137
|
}
|
|
90
138
|
|
|
91
139
|
/**
|
package/package.json
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
|
+
import { requireNativeViewManager } from 'expo-modules-core';
|
|
3
4
|
import { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';
|
|
4
5
|
import type { MarkerProps } from '../../types';
|
|
5
6
|
|
|
7
|
+
const NativeMarkerView = requireNativeViewManager('MarkerView');
|
|
8
|
+
|
|
6
9
|
export default function Marker(props: MarkerProps) {
|
|
10
|
+
// 如果有 children,使用声明式 API
|
|
11
|
+
if (props.children) {
|
|
12
|
+
return <MarkerDeclarative {...props} />;
|
|
13
|
+
}
|
|
14
|
+
// 否则使用命令式 API
|
|
7
15
|
return <MarkerImperative {...props} />;
|
|
8
16
|
}
|
|
9
17
|
|
|
18
|
+
function MarkerDeclarative(props: MarkerProps) {
|
|
19
|
+
const eventManager = React.useContext(MarkerEventContext);
|
|
20
|
+
const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
if (eventManager) {
|
|
24
|
+
eventManager.register(markerIdRef.current, {
|
|
25
|
+
onPress: props.onPress,
|
|
26
|
+
onDragStart: props.onDragStart,
|
|
27
|
+
onDrag: props.onDrag,
|
|
28
|
+
onDragEnd: props.onDragEnd,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
if (eventManager) {
|
|
33
|
+
eventManager.unregister(markerIdRef.current);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, [props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<NativeMarkerView
|
|
40
|
+
position={props.position}
|
|
41
|
+
title={props.title}
|
|
42
|
+
draggable={props.draggable}
|
|
43
|
+
opacity={props.opacity}
|
|
44
|
+
anchor={props.anchor}
|
|
45
|
+
flat={props.flat}
|
|
46
|
+
zIndex={props.zIndex}
|
|
47
|
+
onPress={props.onPress}
|
|
48
|
+
onDragStart={props.onDragStart}
|
|
49
|
+
onDrag={props.onDrag}
|
|
50
|
+
onDragEnd={props.onDragEnd}
|
|
51
|
+
>
|
|
52
|
+
{props.children}
|
|
53
|
+
</NativeMarkerView>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
10
57
|
function MarkerImperative(props: MarkerProps) {
|
|
11
58
|
const mapRef = React.useContext(MapContext);
|
|
12
59
|
const eventManager = React.useContext(MarkerEventContext);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
7
7
|
import type { CameraPosition, LatLng, LatLngBounds, MapPoi, MapType, Point } from './common.types';
|
|
8
|
+
import type { Coordinates, ReGeocode } from './location.types';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* 地图相机事件
|
|
@@ -197,7 +198,7 @@ export interface MapViewProps {
|
|
|
197
198
|
/**
|
|
198
199
|
* 地图定位更新事件
|
|
199
200
|
*/
|
|
200
|
-
onLocation?: (event:
|
|
201
|
+
onLocation?: (event: Coordinates | ReGeocode) => void;
|
|
201
202
|
|
|
202
203
|
/**
|
|
203
204
|
* Marker 点击事件
|