expo-gaode-map 0.1.0
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/.eslintrc.js +5 -0
- package/PUBLISHING.md +244 -0
- package/README.md +990 -0
- package/android/build.gradle +48 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +455 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +337 -0
- package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +128 -0
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +324 -0
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +122 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +247 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/SDKInitializer.kt +45 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +151 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +127 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +97 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +204 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +103 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +114 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +138 -0
- package/build/ExpoGaodeMap.types.d.ts +24 -0
- package/build/ExpoGaodeMap.types.d.ts.map +1 -0
- package/build/ExpoGaodeMap.types.js +14 -0
- package/build/ExpoGaodeMap.types.js.map +1 -0
- package/build/ExpoGaodeMapModule.d.ts +7 -0
- package/build/ExpoGaodeMapModule.d.ts.map +1 -0
- package/build/ExpoGaodeMapModule.js +14 -0
- package/build/ExpoGaodeMapModule.js.map +1 -0
- package/build/ExpoGaodeMapView.d.ts +31 -0
- package/build/ExpoGaodeMapView.d.ts.map +1 -0
- package/build/ExpoGaodeMapView.js +141 -0
- package/build/ExpoGaodeMapView.js.map +1 -0
- package/build/components/overlays/Circle.d.ts +18 -0
- package/build/components/overlays/Circle.d.ts.map +1 -0
- package/build/components/overlays/Circle.js +63 -0
- package/build/components/overlays/Circle.js.map +1 -0
- package/build/components/overlays/Cluster.d.ts +22 -0
- package/build/components/overlays/Cluster.d.ts.map +1 -0
- package/build/components/overlays/Cluster.js +35 -0
- package/build/components/overlays/Cluster.js.map +1 -0
- package/build/components/overlays/HeatMap.d.ts +21 -0
- package/build/components/overlays/HeatMap.d.ts.map +1 -0
- package/build/components/overlays/HeatMap.js +34 -0
- package/build/components/overlays/HeatMap.js.map +1 -0
- package/build/components/overlays/Marker.d.ts +17 -0
- package/build/components/overlays/Marker.d.ts.map +1 -0
- package/build/components/overlays/Marker.js +57 -0
- package/build/components/overlays/Marker.js.map +1 -0
- package/build/components/overlays/MultiPoint.d.ts +21 -0
- package/build/components/overlays/MultiPoint.d.ts.map +1 -0
- package/build/components/overlays/MultiPoint.js +34 -0
- package/build/components/overlays/MultiPoint.js.map +1 -0
- package/build/components/overlays/Polygon.d.ts +22 -0
- package/build/components/overlays/Polygon.d.ts.map +1 -0
- package/build/components/overlays/Polygon.js +100 -0
- package/build/components/overlays/Polygon.js.map +1 -0
- package/build/components/overlays/Polyline.d.ts +20 -0
- package/build/components/overlays/Polyline.d.ts.map +1 -0
- package/build/components/overlays/Polyline.js +60 -0
- package/build/components/overlays/Polyline.js.map +1 -0
- package/build/components/overlays/index.d.ts +8 -0
- package/build/components/overlays/index.d.ts.map +1 -0
- package/build/components/overlays/index.js +18 -0
- package/build/components/overlays/index.js.map +1 -0
- package/build/index.d.ts +10 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +28 -0
- package/build/index.js.map +1 -0
- package/build/modules/AMapLocation.d.ts +58 -0
- package/build/modules/AMapLocation.d.ts.map +1 -0
- package/build/modules/AMapLocation.js +141 -0
- package/build/modules/AMapLocation.js.map +1 -0
- package/build/modules/AMapSDK.d.ts +27 -0
- package/build/modules/AMapSDK.d.ts.map +1 -0
- package/build/modules/AMapSDK.js +43 -0
- package/build/modules/AMapSDK.js.map +1 -0
- package/build/modules/AMapView.d.ts +39 -0
- package/build/modules/AMapView.d.ts.map +1 -0
- package/build/modules/AMapView.js +61 -0
- package/build/modules/AMapView.js.map +1 -0
- package/build/types/common.types.d.ts +133 -0
- package/build/types/common.types.d.ts.map +1 -0
- package/build/types/common.types.js +31 -0
- package/build/types/common.types.js.map +1 -0
- package/build/types/index.d.ts +12 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +17 -0
- package/build/types/index.js.map +1 -0
- package/build/types/location.types.d.ts +306 -0
- package/build/types/location.types.d.ts.map +1 -0
- package/build/types/location.types.js +93 -0
- package/build/types/location.types.js.map +1 -0
- package/build/types/map-view.types.d.ts +213 -0
- package/build/types/map-view.types.d.ts.map +1 -0
- package/build/types/map-view.types.js +6 -0
- package/build/types/map-view.types.js.map +1 -0
- package/build/types/overlays.types.d.ts +296 -0
- package/build/types/overlays.types.d.ts.map +1 -0
- package/build/types/overlays.types.js +6 -0
- package/build/types/overlays.types.js.map +1 -0
- package/build/types/sdk.types.d.ts +113 -0
- package/build/types/sdk.types.d.ts.map +1 -0
- package/build/types/sdk.types.js +6 -0
- package/build/types/sdk.types.js.map +1 -0
- package/docs/followUserLocation.md +186 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoGaodeMap.podspec +29 -0
- package/ios/ExpoGaodeMapModule.swift +48 -0
- package/ios/ExpoGaodeMapView.swift +38 -0
- package/package.json +45 -0
- package/src/ExpoGaodeMap.types.ts +68 -0
- package/src/ExpoGaodeMapModule.ts +21 -0
- package/src/ExpoGaodeMapView.tsx +151 -0
- package/src/components/overlays/Circle.tsx +73 -0
- package/src/components/overlays/Cluster.tsx +38 -0
- package/src/components/overlays/HeatMap.tsx +37 -0
- package/src/components/overlays/Marker.tsx +66 -0
- package/src/components/overlays/MultiPoint.tsx +37 -0
- package/src/components/overlays/Polygon.tsx +107 -0
- package/src/components/overlays/Polyline.tsx +69 -0
- package/src/components/overlays/index.ts +18 -0
- package/src/index.ts +55 -0
- package/src/modules/AMapLocation.ts +164 -0
- package/src/modules/AMapSDK.ts +48 -0
- package/src/modules/AMapView.ts +68 -0
- package/src/types/README.md +186 -0
- package/src/types/common.types.ts +155 -0
- package/src/types/index.ts +74 -0
- package/src/types/location.types.ts +364 -0
- package/src/types/map-view.types.ts +249 -0
- package/src/types/overlays.types.ts +346 -0
- package/src/types/sdk.types.ts +128 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
package expo.modules.gaodemap
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import com.amap.api.maps.AMap
|
|
7
|
+
import com.amap.api.maps.MapView
|
|
8
|
+
import com.amap.api.maps.MapsInitializer
|
|
9
|
+
import expo.modules.kotlin.AppContext
|
|
10
|
+
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
11
|
+
import expo.modules.kotlin.views.ExpoView
|
|
12
|
+
import expo.modules.gaodemap.managers.CameraManager
|
|
13
|
+
import expo.modules.gaodemap.managers.UIManager
|
|
14
|
+
import expo.modules.gaodemap.managers.OverlayManager
|
|
15
|
+
import expo.modules.gaodemap.overlays.*
|
|
16
|
+
|
|
17
|
+
@Suppress("ViewConstructor")
|
|
18
|
+
class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
private const val TAG = "ExpoGaodeMapView"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Props 存储
|
|
25
|
+
internal var mapType: Int = 0
|
|
26
|
+
internal var initialCameraPosition: Map<String, Any?>? = null
|
|
27
|
+
internal var followUserLocation: Boolean = false
|
|
28
|
+
|
|
29
|
+
// Handler for posting to main thread
|
|
30
|
+
private val mainHandler = android.os.Handler(android.os.Looper.getMainLooper())
|
|
31
|
+
|
|
32
|
+
// 事件派发器
|
|
33
|
+
private val onPress by EventDispatcher()
|
|
34
|
+
private val onLongPress by EventDispatcher()
|
|
35
|
+
private val onLoad by EventDispatcher()
|
|
36
|
+
|
|
37
|
+
// 高德地图视图
|
|
38
|
+
private lateinit var mapView: MapView
|
|
39
|
+
private lateinit var aMap: AMap
|
|
40
|
+
|
|
41
|
+
// 管理器
|
|
42
|
+
private lateinit var cameraManager: CameraManager
|
|
43
|
+
private lateinit var uiManager: UIManager
|
|
44
|
+
private lateinit var overlayManager: OverlayManager
|
|
45
|
+
|
|
46
|
+
// 缓存初始相机位置,等待地图加载完成后设置
|
|
47
|
+
private var pendingCameraPosition: Map<String, Any?>? = null
|
|
48
|
+
private var isMapLoaded = false
|
|
49
|
+
|
|
50
|
+
init {
|
|
51
|
+
Log.d(TAG, "ExpoGaodeMapView 初始化开始")
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// 确保隐私合规已设置
|
|
55
|
+
MapsInitializer.updatePrivacyShow(context, true, true)
|
|
56
|
+
MapsInitializer.updatePrivacyAgree(context, true)
|
|
57
|
+
Log.d(TAG, "地图隐私合规已确认")
|
|
58
|
+
|
|
59
|
+
// 创建地图视图
|
|
60
|
+
mapView = MapView(context)
|
|
61
|
+
mapView.onCreate(null)
|
|
62
|
+
aMap = mapView.map
|
|
63
|
+
Log.d(TAG, "MapView 创建成功")
|
|
64
|
+
|
|
65
|
+
// 初始化管理器
|
|
66
|
+
cameraManager = CameraManager(aMap)
|
|
67
|
+
uiManager = UIManager(aMap)
|
|
68
|
+
overlayManager = OverlayManager(aMap)
|
|
69
|
+
Log.d(TAG, "管理器初始化完成")
|
|
70
|
+
|
|
71
|
+
// 添加地图视图到布局
|
|
72
|
+
addView(mapView, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
|
73
|
+
Log.d(TAG, "MapView 已添加到布局")
|
|
74
|
+
|
|
75
|
+
// 设置地图事件监听
|
|
76
|
+
setupMapListeners()
|
|
77
|
+
Log.d(TAG, "地图事件监听已设置")
|
|
78
|
+
|
|
79
|
+
// 地图加载完成回调
|
|
80
|
+
aMap.setOnMapLoadedListener {
|
|
81
|
+
Log.d(TAG, "🎉 地图加载完成")
|
|
82
|
+
isMapLoaded = true
|
|
83
|
+
|
|
84
|
+
// 应用缓存的 Props
|
|
85
|
+
if (mapType != 0) {
|
|
86
|
+
Log.d(TAG, "应用 mapType: $mapType")
|
|
87
|
+
setMapType(mapType)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
val positionToApply = initialCameraPosition ?: pendingCameraPosition
|
|
91
|
+
positionToApply?.let { position ->
|
|
92
|
+
Log.d(TAG, "应用初始相机位置")
|
|
93
|
+
applyInitialCameraPosition(position)
|
|
94
|
+
pendingCameraPosition = null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onLoad(mapOf("loaded" to true))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Log.d(TAG, "ExpoGaodeMapView 初始化完成")
|
|
101
|
+
} catch (e: Exception) {
|
|
102
|
+
Log.e(TAG, "ExpoGaodeMapView 初始化失败", e)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 设置地图事件监听
|
|
108
|
+
*/
|
|
109
|
+
private fun setupMapListeners() {
|
|
110
|
+
aMap.setOnMapClickListener { latLng ->
|
|
111
|
+
onPress(mapOf(
|
|
112
|
+
"latitude" to latLng.latitude,
|
|
113
|
+
"longitude" to latLng.longitude
|
|
114
|
+
))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
aMap.setOnMapLongClickListener { latLng ->
|
|
118
|
+
onLongPress(mapOf(
|
|
119
|
+
"latitude" to latLng.latitude,
|
|
120
|
+
"longitude" to latLng.longitude
|
|
121
|
+
))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ==================== 地图类型和相机 ====================
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 设置地图类型
|
|
129
|
+
*/
|
|
130
|
+
fun setMapType(type: Int) {
|
|
131
|
+
Log.d(TAG, "🎯 setMapType: $type")
|
|
132
|
+
mainHandler.post {
|
|
133
|
+
uiManager.setMapType(type)
|
|
134
|
+
Log.d(TAG, "✅ setMapType 完成")
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 设置初始相机位置
|
|
140
|
+
*/
|
|
141
|
+
fun setInitialCameraPosition(position: Map<String, Any?>) {
|
|
142
|
+
Log.d(TAG, "🎯 setInitialCameraPosition")
|
|
143
|
+
mainHandler.post {
|
|
144
|
+
applyInitialCameraPosition(position)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 实际应用相机位置
|
|
150
|
+
*/
|
|
151
|
+
private fun applyInitialCameraPosition(position: Map<String, Any?>) {
|
|
152
|
+
cameraManager.setInitialCameraPosition(position)
|
|
153
|
+
Log.d(TAG, "相机位置设置完成")
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ==================== UI 控件和手势 ====================
|
|
157
|
+
|
|
158
|
+
fun setShowsZoomControls(show: Boolean) = uiManager.setShowsZoomControls(show)
|
|
159
|
+
fun setShowsCompass(show: Boolean) = uiManager.setShowsCompass(show)
|
|
160
|
+
fun setShowsScale(show: Boolean) = uiManager.setShowsScale(show)
|
|
161
|
+
|
|
162
|
+
fun setZoomEnabled(enabled: Boolean) = uiManager.setZoomEnabled(enabled)
|
|
163
|
+
fun setScrollEnabled(enabled: Boolean) = uiManager.setScrollEnabled(enabled)
|
|
164
|
+
fun setRotateEnabled(enabled: Boolean) = uiManager.setRotateEnabled(enabled)
|
|
165
|
+
fun setTiltEnabled(enabled: Boolean) = uiManager.setTiltEnabled(enabled)
|
|
166
|
+
|
|
167
|
+
fun setShowsUserLocation(show: Boolean) = uiManager.setShowsUserLocation(show, followUserLocation)
|
|
168
|
+
|
|
169
|
+
fun setFollowUserLocation(follow: Boolean) {
|
|
170
|
+
followUserLocation = follow
|
|
171
|
+
// 如果定位已开启,立即应用新设置
|
|
172
|
+
uiManager.setShowsUserLocation(true, follow)
|
|
173
|
+
}
|
|
174
|
+
fun setShowsTraffic(show: Boolean) = uiManager.setShowsTraffic(show)
|
|
175
|
+
fun setShowsBuildings(show: Boolean) = uiManager.setShowsBuildings(show)
|
|
176
|
+
fun setShowsIndoorMap(show: Boolean) = uiManager.setShowsIndoorMap(show)
|
|
177
|
+
|
|
178
|
+
// ==================== 相机控制方法 ====================
|
|
179
|
+
|
|
180
|
+
fun moveCamera(position: Map<String, Any>, duration: Int) {
|
|
181
|
+
cameraManager.moveCamera(position, duration)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fun getLatLng(point: Map<String, Double>): Map<String, Double> {
|
|
185
|
+
return cameraManager.getLatLng(point)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fun setCenter(center: Map<String, Double>, animated: Boolean) {
|
|
189
|
+
cameraManager.setCenter(center, animated)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
fun setZoomLevel(zoom: Float, animated: Boolean) {
|
|
193
|
+
cameraManager.setZoomLevel(zoom, animated)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fun getCameraPosition(): Map<String, Any> {
|
|
197
|
+
return cameraManager.getCameraPosition()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ==================== 覆盖物管理 ====================
|
|
201
|
+
|
|
202
|
+
fun addCircle(id: String, props: Map<String, Any>) {
|
|
203
|
+
Log.d(TAG, "🔵 addCircle: id=$id")
|
|
204
|
+
mainHandler.post {
|
|
205
|
+
overlayManager.addCircle(id, props)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
fun removeCircle(id: String) {
|
|
210
|
+
Log.d(TAG, "🔴 removeCircle: id=$id")
|
|
211
|
+
mainHandler.post {
|
|
212
|
+
overlayManager.removeCircle(id)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fun updateCircle(id: String, props: Map<String, Any>) {
|
|
217
|
+
Log.d(TAG, "🔄 updateCircle: id=$id")
|
|
218
|
+
mainHandler.post {
|
|
219
|
+
overlayManager.updateCircle(id, props)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
fun addMarker(id: String, props: Map<String, Any>) {
|
|
224
|
+
Log.d(TAG, "📍 addMarker: id=$id")
|
|
225
|
+
mainHandler.post {
|
|
226
|
+
overlayManager.addMarker(id, props)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fun removeMarker(id: String) {
|
|
231
|
+
Log.d(TAG, "🗑️ removeMarker: id=$id")
|
|
232
|
+
mainHandler.post {
|
|
233
|
+
overlayManager.removeMarker(id)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
fun updateMarker(id: String, props: Map<String, Any>) {
|
|
238
|
+
Log.d(TAG, "🔄 updateMarker: id=$id")
|
|
239
|
+
mainHandler.post {
|
|
240
|
+
overlayManager.updateMarker(id, props)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
fun addPolyline(id: String, props: Map<String, Any>) {
|
|
245
|
+
Log.d(TAG, "📏 addPolyline: id=$id")
|
|
246
|
+
mainHandler.post {
|
|
247
|
+
overlayManager.addPolyline(id, props)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fun removePolyline(id: String) {
|
|
252
|
+
Log.d(TAG, "🗑️ removePolyline: id=$id")
|
|
253
|
+
mainHandler.post {
|
|
254
|
+
overlayManager.removePolyline(id)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fun updatePolyline(id: String, props: Map<String, Any>) {
|
|
259
|
+
Log.d(TAG, "🔄 updatePolyline: id=$id")
|
|
260
|
+
mainHandler.post {
|
|
261
|
+
overlayManager.updatePolyline(id, props)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fun addPolygon(id: String, props: Map<String, Any>) {
|
|
266
|
+
Log.d(TAG, "🔷 addPolygon: id=$id")
|
|
267
|
+
mainHandler.post {
|
|
268
|
+
overlayManager.addPolygon(id, props)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
fun removePolygon(id: String) {
|
|
273
|
+
Log.d(TAG, "🗑️ removePolygon: id=$id")
|
|
274
|
+
mainHandler.post {
|
|
275
|
+
overlayManager.removePolygon(id)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fun updatePolygon(id: String, props: Map<String, Any>) {
|
|
280
|
+
Log.d(TAG, "🔄 updatePolygon: id=$id")
|
|
281
|
+
mainHandler.post {
|
|
282
|
+
overlayManager.updatePolygon(id, props)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ==================== 生命周期方法 ====================
|
|
287
|
+
|
|
288
|
+
@Suppress("unused")
|
|
289
|
+
fun onResume() {
|
|
290
|
+
mapView.onResume()
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@Suppress("unused")
|
|
294
|
+
fun onPause() {
|
|
295
|
+
mapView.onPause()
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
@Suppress("unused")
|
|
299
|
+
fun onDestroy() {
|
|
300
|
+
overlayManager.clear()
|
|
301
|
+
mapView.onDestroy()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@Suppress("unused")
|
|
305
|
+
fun onSaveInstanceState(outState: android.os.Bundle) {
|
|
306
|
+
mapView.onSaveInstanceState(outState)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 添加子视图时自动连接到地图
|
|
311
|
+
*/
|
|
312
|
+
override fun addView(child: View?, index: Int) {
|
|
313
|
+
Log.d(TAG, "addView - child: ${child?.javaClass?.simpleName}")
|
|
314
|
+
super.addView(child, index)
|
|
315
|
+
|
|
316
|
+
// 自动将地图实例传递给覆盖物子视图
|
|
317
|
+
child?.let {
|
|
318
|
+
when (it) {
|
|
319
|
+
is MarkerView -> it.setMap(aMap)
|
|
320
|
+
is PolylineView -> it.setMap(aMap)
|
|
321
|
+
is PolygonView -> it.setMap(aMap)
|
|
322
|
+
is CircleView -> it.setMap(aMap)
|
|
323
|
+
is HeatMapView -> it.setMap(aMap)
|
|
324
|
+
is MultiPointView -> it.setMap(aMap)
|
|
325
|
+
is ClusterView -> it.setMap(aMap)
|
|
326
|
+
else -> Log.d(TAG, "未识别的子视图类型: ${it.javaClass.name}")
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
332
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
333
|
+
if (changed) {
|
|
334
|
+
Log.d(TAG, "onLayout - bounds: ($left,$top,$right,$bottom)")
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
package expo.modules.gaodemap.managers
|
|
2
|
+
|
|
3
|
+
import android.graphics.Point
|
|
4
|
+
import com.amap.api.maps.AMap
|
|
5
|
+
import com.amap.api.maps.CameraUpdateFactory
|
|
6
|
+
import com.amap.api.maps.model.CameraPosition
|
|
7
|
+
import com.amap.api.maps.model.LatLng
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 相机控制管理器
|
|
11
|
+
* 负责地图相机位置、缩放、倾斜等操作
|
|
12
|
+
*/
|
|
13
|
+
class CameraManager(private val aMap: AMap) {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 设置初始相机位置
|
|
17
|
+
*/
|
|
18
|
+
fun setInitialCameraPosition(position: Map<String, Any?>) {
|
|
19
|
+
@Suppress("UNCHECKED_CAST")
|
|
20
|
+
val target = position["target"] as? Map<String, Double>
|
|
21
|
+
val zoom = (position["zoom"] as? Number)?.toFloat() ?: 10f
|
|
22
|
+
val tilt = (position["tilt"] as? Number)?.toFloat() ?: 0f
|
|
23
|
+
val bearing = (position["bearing"] as? Number)?.toFloat() ?: 0f
|
|
24
|
+
|
|
25
|
+
if (target != null) {
|
|
26
|
+
val lat = target["latitude"] ?: 0.0
|
|
27
|
+
val lng = target["longitude"] ?: 0.0
|
|
28
|
+
val latLng = LatLng(lat, lng)
|
|
29
|
+
|
|
30
|
+
val cameraPosition = CameraPosition.Builder()
|
|
31
|
+
.target(latLng)
|
|
32
|
+
.zoom(zoom)
|
|
33
|
+
.tilt(tilt)
|
|
34
|
+
.bearing(bearing)
|
|
35
|
+
.build()
|
|
36
|
+
|
|
37
|
+
aMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 移动相机
|
|
43
|
+
*/
|
|
44
|
+
fun moveCamera(position: Map<String, Any>, duration: Int) {
|
|
45
|
+
@Suppress("UNCHECKED_CAST")
|
|
46
|
+
val target = position["target"] as? Map<String, Double>
|
|
47
|
+
val zoom = (position["zoom"] as? Number)?.toFloat()
|
|
48
|
+
val tilt = (position["tilt"] as? Number)?.toFloat()
|
|
49
|
+
val bearing = (position["bearing"] as? Number)?.toFloat()
|
|
50
|
+
|
|
51
|
+
if (target != null) {
|
|
52
|
+
val lat = target["latitude"] ?: 0.0
|
|
53
|
+
val lng = target["longitude"] ?: 0.0
|
|
54
|
+
val latLng = LatLng(lat, lng)
|
|
55
|
+
|
|
56
|
+
val builder = CameraPosition.Builder().target(latLng)
|
|
57
|
+
zoom?.let { builder.zoom(it) }
|
|
58
|
+
tilt?.let { builder.tilt(it) }
|
|
59
|
+
bearing?.let { builder.bearing(it) }
|
|
60
|
+
|
|
61
|
+
val cameraUpdate = CameraUpdateFactory.newCameraPosition(builder.build())
|
|
62
|
+
|
|
63
|
+
if (duration > 0) {
|
|
64
|
+
aMap.animateCamera(cameraUpdate, duration.toLong(), null)
|
|
65
|
+
} else {
|
|
66
|
+
aMap.moveCamera(cameraUpdate)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 设置地图中心点
|
|
73
|
+
*/
|
|
74
|
+
fun setCenter(center: Map<String, Double>, animated: Boolean) {
|
|
75
|
+
val lat = center["latitude"] ?: 0.0
|
|
76
|
+
val lng = center["longitude"] ?: 0.0
|
|
77
|
+
val latLng = LatLng(lat, lng)
|
|
78
|
+
val cameraUpdate = CameraUpdateFactory.newLatLng(latLng)
|
|
79
|
+
|
|
80
|
+
if (animated) {
|
|
81
|
+
aMap.animateCamera(cameraUpdate)
|
|
82
|
+
} else {
|
|
83
|
+
aMap.moveCamera(cameraUpdate)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 设置地图缩放级别
|
|
89
|
+
*/
|
|
90
|
+
fun setZoomLevel(zoom: Float, animated: Boolean) {
|
|
91
|
+
val cameraUpdate = CameraUpdateFactory.zoomTo(zoom)
|
|
92
|
+
|
|
93
|
+
if (animated) {
|
|
94
|
+
aMap.animateCamera(cameraUpdate)
|
|
95
|
+
} else {
|
|
96
|
+
aMap.moveCamera(cameraUpdate)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 获取当前相机位置
|
|
102
|
+
*/
|
|
103
|
+
fun getCameraPosition(): Map<String, Any> {
|
|
104
|
+
val position = aMap.cameraPosition
|
|
105
|
+
return mapOf(
|
|
106
|
+
"target" to mapOf(
|
|
107
|
+
"latitude" to position.target.latitude,
|
|
108
|
+
"longitude" to position.target.longitude
|
|
109
|
+
),
|
|
110
|
+
"zoom" to position.zoom,
|
|
111
|
+
"tilt" to position.tilt,
|
|
112
|
+
"bearing" to position.bearing
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 获取屏幕坐标对应的地理坐标
|
|
118
|
+
*/
|
|
119
|
+
fun getLatLng(point: Map<String, Double>): Map<String, Double> {
|
|
120
|
+
val x = (point["x"] ?: 0.0).toInt()
|
|
121
|
+
val y = (point["y"] ?: 0.0).toInt()
|
|
122
|
+
val latLng = aMap.projection.fromScreenLocation(Point(x, y))
|
|
123
|
+
return mapOf(
|
|
124
|
+
"latitude" to latLng.latitude,
|
|
125
|
+
"longitude" to latLng.longitude
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|