expo-gaode-map 2.0.0-alpha.1 → 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.md +1 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +61 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -1
- package/ios/ExpoGaodeMapModule.swift +4 -0
- package/ios/ExpoGaodeMapView.swift +48 -0
- package/ios/ExpoGaodeMapViewModule.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,8 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
59
59
|
private val onMapLongPress by EventDispatcher()
|
|
60
60
|
private val onLoad by EventDispatcher()
|
|
61
61
|
private val onLocation by EventDispatcher()
|
|
62
|
+
private val onCameraMove by EventDispatcher()
|
|
63
|
+
private val onCameraIdle by EventDispatcher()
|
|
62
64
|
|
|
63
65
|
// 高德地图视图
|
|
64
66
|
private lateinit var mapView: MapView
|
|
@@ -129,6 +131,65 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
129
131
|
* 设置地图事件监听
|
|
130
132
|
*/
|
|
131
133
|
private fun setupMapListeners() {
|
|
134
|
+
// 设置相机移动监听器
|
|
135
|
+
aMap.setOnCameraChangeListener(object : AMap.OnCameraChangeListener {
|
|
136
|
+
override fun onCameraChange(cameraPosition: com.amap.api.maps.model.CameraPosition?) {
|
|
137
|
+
// 相机移动中
|
|
138
|
+
cameraPosition?.let {
|
|
139
|
+
val visibleRegion = aMap.projection.visibleRegion
|
|
140
|
+
onCameraMove(mapOf(
|
|
141
|
+
"cameraPosition" to mapOf(
|
|
142
|
+
"target" to mapOf(
|
|
143
|
+
"latitude" to it.target.latitude,
|
|
144
|
+
"longitude" to it.target.longitude
|
|
145
|
+
),
|
|
146
|
+
"zoom" to it.zoom,
|
|
147
|
+
"tilt" to it.tilt,
|
|
148
|
+
"bearing" to it.bearing
|
|
149
|
+
),
|
|
150
|
+
"latLngBounds" to mapOf(
|
|
151
|
+
"northeast" to mapOf(
|
|
152
|
+
"latitude" to visibleRegion.farRight.latitude,
|
|
153
|
+
"longitude" to visibleRegion.farRight.longitude
|
|
154
|
+
),
|
|
155
|
+
"southwest" to mapOf(
|
|
156
|
+
"latitude" to visibleRegion.nearLeft.latitude,
|
|
157
|
+
"longitude" to visibleRegion.nearLeft.longitude
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
))
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
override fun onCameraChangeFinish(cameraPosition: com.amap.api.maps.model.CameraPosition?) {
|
|
165
|
+
// 相机移动完成
|
|
166
|
+
cameraPosition?.let {
|
|
167
|
+
val visibleRegion = aMap.projection.visibleRegion
|
|
168
|
+
onCameraIdle(mapOf(
|
|
169
|
+
"cameraPosition" to mapOf(
|
|
170
|
+
"target" to mapOf(
|
|
171
|
+
"latitude" to it.target.latitude,
|
|
172
|
+
"longitude" to it.target.longitude
|
|
173
|
+
),
|
|
174
|
+
"zoom" to it.zoom,
|
|
175
|
+
"tilt" to it.tilt,
|
|
176
|
+
"bearing" to it.bearing
|
|
177
|
+
),
|
|
178
|
+
"latLngBounds" to mapOf(
|
|
179
|
+
"northeast" to mapOf(
|
|
180
|
+
"latitude" to visibleRegion.farRight.latitude,
|
|
181
|
+
"longitude" to visibleRegion.farRight.longitude
|
|
182
|
+
),
|
|
183
|
+
"southwest" to mapOf(
|
|
184
|
+
"latitude" to visibleRegion.nearLeft.latitude,
|
|
185
|
+
"longitude" to visibleRegion.nearLeft.longitude
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
))
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
132
193
|
// 设置全局 Marker 点击监听器
|
|
133
194
|
aMap.setOnMarkerClickListener { marker ->
|
|
134
195
|
MarkerView.handleMarkerClick(marker)
|
|
@@ -11,7 +11,7 @@ class ExpoGaodeMapViewModule : Module() {
|
|
|
11
11
|
Name("ExpoGaodeMapView")
|
|
12
12
|
|
|
13
13
|
View(ExpoGaodeMapView::class) {
|
|
14
|
-
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation")
|
|
14
|
+
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle")
|
|
15
15
|
|
|
16
16
|
// ✅ 关键修复:拦截 React Native 的视图操作异常
|
|
17
17
|
OnViewDestroys { view: ExpoGaodeMapView ->
|
|
@@ -151,6 +151,10 @@ public class ExpoGaodeMapModule: Module {
|
|
|
151
151
|
self.getLocationManager().setDistanceFilter(Double(interval))
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
Function("setDistanceFilter") { (distance: Double) in
|
|
155
|
+
self.getLocationManager().setDistanceFilter(distance)
|
|
156
|
+
}
|
|
157
|
+
|
|
154
158
|
Function("setLocationTimeout") { (timeout: Int) in
|
|
155
159
|
self.getLocationManager().setLocationTimeout(timeout)
|
|
156
160
|
}
|
|
@@ -56,6 +56,8 @@ class ExpoGaodeMapView: ExpoView, MAMapViewDelegate {
|
|
|
56
56
|
let onMapLongPress = EventDispatcher()
|
|
57
57
|
let onLoad = EventDispatcher()
|
|
58
58
|
let onLocation = EventDispatcher()
|
|
59
|
+
let onCameraMove = EventDispatcher()
|
|
60
|
+
let onCameraIdle = EventDispatcher()
|
|
59
61
|
|
|
60
62
|
// MARK: - 私有属性
|
|
61
63
|
|
|
@@ -530,6 +532,52 @@ extension ExpoGaodeMapView {
|
|
|
530
532
|
onLoad(["loaded": true])
|
|
531
533
|
}
|
|
532
534
|
|
|
535
|
+
/**
|
|
536
|
+
* 地图区域即将改变时触发
|
|
537
|
+
*/
|
|
538
|
+
public func mapView(_ mapView: MAMapView, regionWillChangeAnimated animated: Bool) {
|
|
539
|
+
// 相机开始移动
|
|
540
|
+
let cameraPosition = cameraManager.getCameraPosition()
|
|
541
|
+
let visibleRegion = mapView.region
|
|
542
|
+
|
|
543
|
+
onCameraMove([
|
|
544
|
+
"cameraPosition": cameraPosition,
|
|
545
|
+
"latLngBounds": [
|
|
546
|
+
"northeast": [
|
|
547
|
+
"latitude": visibleRegion.center.latitude + visibleRegion.span.latitudeDelta / 2,
|
|
548
|
+
"longitude": visibleRegion.center.longitude + visibleRegion.span.longitudeDelta / 2
|
|
549
|
+
],
|
|
550
|
+
"southwest": [
|
|
551
|
+
"latitude": visibleRegion.center.latitude - visibleRegion.span.latitudeDelta / 2,
|
|
552
|
+
"longitude": visibleRegion.center.longitude - visibleRegion.span.longitudeDelta / 2
|
|
553
|
+
]
|
|
554
|
+
]
|
|
555
|
+
])
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* 地图区域改变完成后触发
|
|
560
|
+
*/
|
|
561
|
+
public func mapView(_ mapView: MAMapView, regionDidChangeAnimated animated: Bool) {
|
|
562
|
+
// 相机移动完成
|
|
563
|
+
let cameraPosition = cameraManager.getCameraPosition()
|
|
564
|
+
let visibleRegion = mapView.region
|
|
565
|
+
|
|
566
|
+
onCameraIdle([
|
|
567
|
+
"cameraPosition": cameraPosition,
|
|
568
|
+
"latLngBounds": [
|
|
569
|
+
"northeast": [
|
|
570
|
+
"latitude": visibleRegion.center.latitude + visibleRegion.span.latitudeDelta / 2,
|
|
571
|
+
"longitude": visibleRegion.center.longitude + visibleRegion.span.longitudeDelta / 2
|
|
572
|
+
],
|
|
573
|
+
"southwest": [
|
|
574
|
+
"latitude": visibleRegion.center.latitude - visibleRegion.span.latitudeDelta / 2,
|
|
575
|
+
"longitude": visibleRegion.center.longitude - visibleRegion.span.longitudeDelta / 2
|
|
576
|
+
]
|
|
577
|
+
]
|
|
578
|
+
])
|
|
579
|
+
}
|
|
580
|
+
|
|
533
581
|
/**
|
|
534
582
|
* 地图单击事件
|
|
535
583
|
*/
|
|
@@ -9,7 +9,7 @@ public class ExpoGaodeMapViewModule: Module {
|
|
|
9
9
|
Name("ExpoGaodeMapView")
|
|
10
10
|
|
|
11
11
|
View(ExpoGaodeMapView.self) {
|
|
12
|
-
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation")
|
|
12
|
+
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle")
|
|
13
13
|
|
|
14
14
|
Prop("mapType") { (view: ExpoGaodeMapView, type: Int) in
|
|
15
15
|
view.mapType = type
|