expo-gaode-map 1.1.8 → 2.0.0-alpha.1
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.en.md +32 -46
- package/README.md +50 -70
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +37 -268
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -49
- package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +30 -7
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +1 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +10 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +38 -14
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +8 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +322 -93
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +25 -11
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +20 -10
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +6 -2
- package/build/ExpoGaodeMap.types.d.ts +27 -6
- package/build/ExpoGaodeMap.types.d.ts.map +1 -1
- package/build/ExpoGaodeMap.types.js +3 -0
- package/build/ExpoGaodeMap.types.js.map +1 -1
- package/build/ExpoGaodeMapModule.d.ts +157 -10
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +4 -0
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts +1 -17
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +4 -221
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts +11 -1
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +12 -58
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Cluster.d.ts.map +1 -1
- package/build/components/overlays/Cluster.js.map +1 -1
- package/build/components/overlays/Marker.d.ts +13 -1
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +51 -115
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts +7 -15
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +10 -80
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts +7 -14
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +9 -66
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -10
- package/build/index.js.map +1 -1
- package/build/types/map-view.types.d.ts +0 -90
- 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 +9 -9
- package/build/types/overlays.types.d.ts.map +1 -1
- package/build/types/overlays.types.js.map +1 -1
- package/docs/API.en.md +1 -21
- package/docs/API.md +84 -56
- package/docs/EXAMPLES.en.md +0 -48
- package/docs/EXAMPLES.md +49 -102
- package/docs/INITIALIZATION.md +59 -71
- package/docs/MIGRATION.md +423 -0
- package/ios/ExpoGaodeMapView.swift +317 -258
- package/ios/ExpoGaodeMapViewModule.swift +3 -50
- package/ios/managers/CameraManager.swift +23 -2
- package/ios/managers/UIManager.swift +10 -5
- package/ios/modules/LocationManager.swift +10 -0
- package/ios/overlays/CircleView.swift +98 -19
- package/ios/overlays/CircleViewModule.swift +21 -0
- package/ios/overlays/ClusterView.swift +33 -4
- package/ios/overlays/HeatMapView.swift +16 -4
- package/ios/overlays/MarkerView.swift +235 -146
- package/ios/overlays/MarkerViewModule.swift +7 -3
- package/ios/overlays/MultiPointView.swift +30 -1
- package/ios/overlays/PolygonView.swift +63 -12
- package/ios/overlays/PolygonViewModule.swift +17 -0
- package/ios/overlays/PolylineView.swift +95 -25
- package/ios/overlays/PolylineViewModule.swift +17 -8
- package/ios/utils/PermissionManager.swift +9 -14
- package/package.json +4 -3
- package/src/ExpoGaodeMap.types.ts +28 -3
- package/src/ExpoGaodeMapModule.ts +201 -12
- package/src/ExpoGaodeMapView.tsx +9 -234
- package/src/components/overlays/Circle.tsx +14 -70
- package/src/components/overlays/Cluster.tsx +0 -1
- package/src/components/overlays/Marker.tsx +63 -138
- package/src/components/overlays/Polygon.tsx +12 -92
- package/src/components/overlays/Polyline.tsx +11 -77
- package/src/index.ts +4 -29
- package/src/types/map-view.types.ts +1 -85
- package/src/types/overlays.types.ts +9 -9
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +0 -574
- package/build/modules/AMapLocation.d.ts +0 -78
- package/build/modules/AMapLocation.d.ts.map +0 -1
- package/build/modules/AMapLocation.js +0 -132
- package/build/modules/AMapLocation.js.map +0 -1
- package/build/modules/AMapPermissions.d.ts +0 -29
- package/build/modules/AMapPermissions.d.ts.map +0 -1
- package/build/modules/AMapPermissions.js +0 -23
- package/build/modules/AMapPermissions.js.map +0 -1
- package/build/modules/AMapSDK.d.ts +0 -22
- package/build/modules/AMapSDK.d.ts.map +0 -1
- package/build/modules/AMapSDK.js +0 -25
- package/build/modules/AMapSDK.js.map +0 -1
- package/build/modules/AMapView.d.ts +0 -44
- package/build/modules/AMapView.d.ts.map +0 -1
- package/build/modules/AMapView.js +0 -65
- package/build/modules/AMapView.js.map +0 -1
- package/ios/managers/OverlayManager.swift +0 -522
- package/src/modules/AMapLocation.ts +0 -165
- package/src/modules/AMapPermissions.ts +0 -41
- package/src/modules/AMapSDK.ts +0 -31
- package/src/modules/AMapView.ts +0 -72
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
package expo.modules.gaodemap.managers
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.util.Log
|
|
5
|
-
import android.graphics.Bitmap
|
|
6
|
-
import android.graphics.BitmapFactory
|
|
7
|
-
import com.amap.api.maps.AMap
|
|
8
|
-
import com.amap.api.maps.model.LatLng
|
|
9
|
-
import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
10
|
-
import expo.modules.gaodemap.utils.ColorParser
|
|
11
|
-
import java.net.URL
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 覆盖物管理器
|
|
15
|
-
* 负责地图上所有覆盖物的添加、删除、更新
|
|
16
|
-
*/
|
|
17
|
-
class OverlayManager(private val aMap: AMap, private val context: Context) {
|
|
18
|
-
|
|
19
|
-
companion object {
|
|
20
|
-
private const val TAG = "OverlayManager"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 覆盖物存储
|
|
24
|
-
private val circles = mutableMapOf<String, com.amap.api.maps.model.Circle>()
|
|
25
|
-
private val markers = mutableMapOf<String, com.amap.api.maps.model.Marker>()
|
|
26
|
-
private val polylines = mutableMapOf<String, com.amap.api.maps.model.Polyline>()
|
|
27
|
-
private val polygons = mutableMapOf<String, com.amap.api.maps.model.Polygon>()
|
|
28
|
-
|
|
29
|
-
// Marker ID 映射
|
|
30
|
-
private val markerIdMap = mutableMapOf<com.amap.api.maps.model.Marker, String>()
|
|
31
|
-
|
|
32
|
-
// Circle ID 映射
|
|
33
|
-
private val circleIdMap = mutableMapOf<com.amap.api.maps.model.Circle, String>()
|
|
34
|
-
|
|
35
|
-
// Polygon ID 映射
|
|
36
|
-
private val polygonIdMap = mutableMapOf<com.amap.api.maps.model.Polygon, String>()
|
|
37
|
-
|
|
38
|
-
// Polyline ID 映射
|
|
39
|
-
private val polylineIdMap = mutableMapOf<com.amap.api.maps.model.Polyline, String>()
|
|
40
|
-
|
|
41
|
-
// 事件回调
|
|
42
|
-
var onMarkerPress: ((String, Double, Double) -> Unit)? = null
|
|
43
|
-
var onMarkerDragStart: ((String, Double, Double) -> Unit)? = null
|
|
44
|
-
var onMarkerDrag: ((String, Double, Double) -> Unit)? = null
|
|
45
|
-
var onMarkerDragEnd: ((String, Double, Double) -> Unit)? = null
|
|
46
|
-
var onCirclePress: ((String, Double, Double) -> Unit)? = null
|
|
47
|
-
var onPolygonPress: ((String, Double, Double) -> Unit)? = null
|
|
48
|
-
var onPolylinePress: ((String, Double, Double) -> Unit)? = null
|
|
49
|
-
|
|
50
|
-
private val mainHandler = android.os.Handler(android.os.Looper.getMainLooper())
|
|
51
|
-
|
|
52
|
-
// ==================== 圆形覆盖物 ====================
|
|
53
|
-
|
|
54
|
-
fun addCircle(id: String, props: Map<String, Any>) {
|
|
55
|
-
|
|
56
|
-
@Suppress("UNCHECKED_CAST")
|
|
57
|
-
val center = props["center"] as? Map<String, Double>
|
|
58
|
-
val radius = (props["radius"] as? Number)?.toDouble() ?: 1000.0
|
|
59
|
-
val fillColor = ColorParser.parseColor(props["fillColor"])
|
|
60
|
-
val strokeColor = ColorParser.parseColor(props["strokeColor"])
|
|
61
|
-
val strokeWidth = (props["strokeWidth"] as? Number)?.toFloat() ?: 10f
|
|
62
|
-
|
|
63
|
-
if (center != null) {
|
|
64
|
-
val lat = center["latitude"] ?: 0.0
|
|
65
|
-
val lng = center["longitude"] ?: 0.0
|
|
66
|
-
val latLng = LatLng(lat, lng)
|
|
67
|
-
|
|
68
|
-
// 将 dp 转换为 px,与 iOS 的 points 对应
|
|
69
|
-
val density = context.resources.displayMetrics.density
|
|
70
|
-
|
|
71
|
-
val options = com.amap.api.maps.model.CircleOptions()
|
|
72
|
-
.center(latLng)
|
|
73
|
-
.radius(radius)
|
|
74
|
-
.fillColor(fillColor)
|
|
75
|
-
.strokeColor(strokeColor)
|
|
76
|
-
.strokeWidth(strokeWidth * density)
|
|
77
|
-
|
|
78
|
-
val circle = aMap.addCircle(options)
|
|
79
|
-
circles[id] = circle
|
|
80
|
-
circleIdMap[circle] = id
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
fun removeCircle(id: String) {
|
|
85
|
-
circles[id]?.let { circle ->
|
|
86
|
-
circleIdMap.remove(circle)
|
|
87
|
-
circle.remove()
|
|
88
|
-
circles.remove(id)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
fun updateCircle(id: String, props: Map<String, Any>) {
|
|
93
|
-
circles[id]?.let { circle ->
|
|
94
|
-
@Suppress("UNCHECKED_CAST")
|
|
95
|
-
val center = props["center"] as? Map<String, Double>
|
|
96
|
-
val radius = (props["radius"] as? Number)?.toDouble()
|
|
97
|
-
val fillColor = props["fillColor"]?.let { ColorParser.parseColor(it) }
|
|
98
|
-
val strokeColor = props["strokeColor"]?.let { ColorParser.parseColor(it) }
|
|
99
|
-
val strokeWidth = (props["strokeWidth"] as? Number)?.toFloat()
|
|
100
|
-
|
|
101
|
-
center?.let {
|
|
102
|
-
val lat = it["latitude"] ?: 0.0
|
|
103
|
-
val lng = it["longitude"] ?: 0.0
|
|
104
|
-
circle.center = LatLng(lat, lng)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
radius?.let { circle.radius = it }
|
|
108
|
-
fillColor?.let { circle.fillColor = it }
|
|
109
|
-
strokeColor?.let { circle.strokeColor = it }
|
|
110
|
-
strokeWidth?.let {
|
|
111
|
-
val density = context.resources.displayMetrics.density
|
|
112
|
-
circle.strokeWidth = it * density
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// ==================== 标记点 ====================
|
|
118
|
-
|
|
119
|
-
fun addMarker(id: String, props: Map<String, Any>) {
|
|
120
|
-
@Suppress("UNCHECKED_CAST")
|
|
121
|
-
val position = props["position"] as? Map<String, Double>
|
|
122
|
-
val title = props["title"] as? String
|
|
123
|
-
val snippet = props["snippet"] as? String
|
|
124
|
-
val draggable = props["draggable"] as? Boolean ?: false
|
|
125
|
-
val icon = props["icon"]
|
|
126
|
-
// 将 RN 的点(points)转换为 Android 的 dp
|
|
127
|
-
val iconWidth = dpToPx((props["iconWidth"] as? Number)?.toFloat() ?: 40f)
|
|
128
|
-
val iconHeight = dpToPx((props["iconHeight"] as? Number)?.toFloat() ?: 40f)
|
|
129
|
-
val opacity = (props["opacity"] as? Number)?.toFloat() ?: 1.0f
|
|
130
|
-
val flat = props["flat"] as? Boolean ?: false
|
|
131
|
-
val zIndex = (props["zIndex"] as? Number)?.toFloat() ?: 0f
|
|
132
|
-
val anchor = props["anchor"] as? Map<String, Double>
|
|
133
|
-
|
|
134
|
-
if (position != null) {
|
|
135
|
-
val lat = position["latitude"] ?: 0.0
|
|
136
|
-
val lng = position["longitude"] ?: 0.0
|
|
137
|
-
val latLng = LatLng(lat, lng)
|
|
138
|
-
|
|
139
|
-
val options = com.amap.api.maps.model.MarkerOptions()
|
|
140
|
-
.position(latLng)
|
|
141
|
-
.draggable(draggable)
|
|
142
|
-
.setFlat(flat)
|
|
143
|
-
.zIndex(zIndex)
|
|
144
|
-
|
|
145
|
-
title?.let { options.title(it) }
|
|
146
|
-
snippet?.let { options.snippet(it) }
|
|
147
|
-
|
|
148
|
-
anchor?.let {
|
|
149
|
-
val x = (it["x"] as? Number)?.toFloat() ?: 0.5f
|
|
150
|
-
val y = (it["y"] as? Number)?.toFloat() ?: 1.0f
|
|
151
|
-
options.anchor(x, y)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
val marker = aMap.addMarker(options)
|
|
155
|
-
marker?.alpha = opacity
|
|
156
|
-
|
|
157
|
-
markers[id] = marker
|
|
158
|
-
marker?.let { markerIdMap[it] = id }
|
|
159
|
-
|
|
160
|
-
// 加载自定义图标
|
|
161
|
-
icon?.let {
|
|
162
|
-
val uri = when (it) {
|
|
163
|
-
is String -> it
|
|
164
|
-
is Map<*, *> -> it["uri"] as? String
|
|
165
|
-
else -> null
|
|
166
|
-
}
|
|
167
|
-
uri?.let { iconUri ->
|
|
168
|
-
loadMarkerIcon(iconUri, iconWidth, iconHeight) { bitmap ->
|
|
169
|
-
mainHandler.post {
|
|
170
|
-
marker?.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap))
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// 设置事件监听器(只设置一次)
|
|
177
|
-
setupMarkerListeners()
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private fun setupMarkerListeners() {
|
|
182
|
-
aMap.setOnMarkerClickListener { marker ->
|
|
183
|
-
markerIdMap[marker]?.let { id ->
|
|
184
|
-
onMarkerPress?.invoke(id, marker.position.latitude, marker.position.longitude)
|
|
185
|
-
}
|
|
186
|
-
false // 返回 false 允许显示 InfoWindow
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
aMap.setOnMarkerDragListener(object : AMap.OnMarkerDragListener {
|
|
190
|
-
override fun onMarkerDragStart(marker: com.amap.api.maps.model.Marker?) {
|
|
191
|
-
marker?.let { m ->
|
|
192
|
-
markerIdMap[m]?.let { id ->
|
|
193
|
-
onMarkerDragStart?.invoke(id, m.position.latitude, m.position.longitude)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
override fun onMarkerDrag(marker: com.amap.api.maps.model.Marker?) {
|
|
199
|
-
marker?.let { m ->
|
|
200
|
-
markerIdMap[m]?.let { id ->
|
|
201
|
-
onMarkerDrag?.invoke(id, m.position.latitude, m.position.longitude)
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
override fun onMarkerDragEnd(marker: com.amap.api.maps.model.Marker?) {
|
|
207
|
-
marker?.let { m ->
|
|
208
|
-
markerIdMap[m]?.let { id ->
|
|
209
|
-
onMarkerDragEnd?.invoke(id, m.position.latitude, m.position.longitude)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private fun loadMarkerIcon(uri: String, width: Int, height: Int, callback: (Bitmap) -> Unit) {
|
|
217
|
-
Thread {
|
|
218
|
-
try {
|
|
219
|
-
val bitmap = when {
|
|
220
|
-
uri.startsWith("http://") || uri.startsWith("https://") -> {
|
|
221
|
-
BitmapFactory.decodeStream(URL(uri).openStream())
|
|
222
|
-
}
|
|
223
|
-
uri.startsWith("file://") -> {
|
|
224
|
-
BitmapFactory.decodeFile(uri.substring(7))
|
|
225
|
-
}
|
|
226
|
-
else -> {
|
|
227
|
-
null
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (bitmap != null) {
|
|
232
|
-
val resized = Bitmap.createScaledBitmap(bitmap, width, height, true)
|
|
233
|
-
callback(resized)
|
|
234
|
-
}
|
|
235
|
-
} catch (e: Exception) {
|
|
236
|
-
// 忽略异常
|
|
237
|
-
}
|
|
238
|
-
}.start()
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
fun removeMarker(id: String) {
|
|
242
|
-
markers[id]?.let { marker ->
|
|
243
|
-
markerIdMap.remove(marker)
|
|
244
|
-
marker.remove()
|
|
245
|
-
markers.remove(id)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
fun updateMarker(id: String, props: Map<String, Any>) {
|
|
250
|
-
markers[id]?.let { marker ->
|
|
251
|
-
@Suppress("UNCHECKED_CAST")
|
|
252
|
-
val position = props["position"] as? Map<String, Double>
|
|
253
|
-
val title = props["title"] as? String
|
|
254
|
-
val snippet = props["snippet"] as? String
|
|
255
|
-
val draggable = props["draggable"] as? Boolean
|
|
256
|
-
val icon = props["icon"]
|
|
257
|
-
val iconWidth = dpToPx((props["iconWidth"] as? Number)?.toFloat() ?: 40f)
|
|
258
|
-
val iconHeight = dpToPx((props["iconHeight"] as? Number)?.toFloat() ?: 40f)
|
|
259
|
-
val opacity = props["opacity"] as? Number
|
|
260
|
-
val flat = props["flat"] as? Boolean
|
|
261
|
-
val zIndex = props["zIndex"] as? Number
|
|
262
|
-
val anchor = props["anchor"] as? Map<String, Double>
|
|
263
|
-
|
|
264
|
-
position?.let {
|
|
265
|
-
val lat = it["latitude"] ?: 0.0
|
|
266
|
-
val lng = it["longitude"] ?: 0.0
|
|
267
|
-
marker.position = LatLng(lat, lng)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
title?.let { marker.title = it }
|
|
271
|
-
snippet?.let { marker.snippet = it }
|
|
272
|
-
draggable?.let { marker.isDraggable = it }
|
|
273
|
-
opacity?.let { marker.alpha = it.toFloat() }
|
|
274
|
-
flat?.let { marker.isFlat = it }
|
|
275
|
-
zIndex?.let { marker.zIndex = it.toFloat() }
|
|
276
|
-
|
|
277
|
-
anchor?.let {
|
|
278
|
-
val x = (it["x"] as? Number)?.toFloat() ?: 0.5f
|
|
279
|
-
val y = (it["y"] as? Number)?.toFloat() ?: 1.0f
|
|
280
|
-
marker.setAnchor(x, y)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
icon?.let {
|
|
284
|
-
val uri = when (it) {
|
|
285
|
-
is String -> it
|
|
286
|
-
is Map<*, *> -> it["uri"] as? String
|
|
287
|
-
else -> null
|
|
288
|
-
}
|
|
289
|
-
uri?.let { iconUri ->
|
|
290
|
-
loadMarkerIcon(iconUri, iconWidth, iconHeight) { bitmap ->
|
|
291
|
-
mainHandler.post {
|
|
292
|
-
marker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap))
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// ==================== 折线 ====================
|
|
301
|
-
|
|
302
|
-
fun addPolyline(id: String, props: Map<String, Any>) {
|
|
303
|
-
|
|
304
|
-
@Suppress("UNCHECKED_CAST")
|
|
305
|
-
val points = props["points"] as? List<Map<String, Double>>
|
|
306
|
-
val width = (props["width"] as? Number)?.toFloat() ?: (props["strokeWidth"] as? Number)?.toFloat() ?: 10f
|
|
307
|
-
val texture = props["texture"] as? String
|
|
308
|
-
val color = if (!texture.isNullOrEmpty()) {
|
|
309
|
-
android.graphics.Color.TRANSPARENT
|
|
310
|
-
} else {
|
|
311
|
-
ColorParser.parseColor(props["color"] ?: props["strokeColor"])
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (points != null && points.size >= 2) {
|
|
315
|
-
val latLngs = points.map { point ->
|
|
316
|
-
val lat = point["latitude"] ?: 0.0
|
|
317
|
-
val lng = point["longitude"] ?: 0.0
|
|
318
|
-
LatLng(lat, lng)
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// 将 dp 转换为 px,与 iOS 的 points 对应
|
|
322
|
-
val density = context.resources.displayMetrics.density
|
|
323
|
-
|
|
324
|
-
val options = com.amap.api.maps.model.PolylineOptions()
|
|
325
|
-
.addAll(latLngs)
|
|
326
|
-
.width(width * density)
|
|
327
|
-
.color(color)
|
|
328
|
-
|
|
329
|
-
val polyline = aMap.addPolyline(options)
|
|
330
|
-
|
|
331
|
-
// 处理纹理
|
|
332
|
-
if (!texture.isNullOrEmpty()) {
|
|
333
|
-
Thread {
|
|
334
|
-
try {
|
|
335
|
-
val bitmap = if (texture.startsWith("http://") || texture.startsWith("https://")) {
|
|
336
|
-
BitmapFactory.decodeStream(URL(texture).openStream())
|
|
337
|
-
} else if (texture.startsWith("file://")) {
|
|
338
|
-
BitmapFactory.decodeFile(texture.substring(7))
|
|
339
|
-
} else {
|
|
340
|
-
null
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
bitmap?.let {
|
|
344
|
-
val descriptor = BitmapDescriptorFactory.fromBitmap(it)
|
|
345
|
-
polyline.setCustomTexture(descriptor)
|
|
346
|
-
}
|
|
347
|
-
} catch (e: Exception) {
|
|
348
|
-
// 忽略异常
|
|
349
|
-
}
|
|
350
|
-
}.start()
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
polylines[id] = polyline
|
|
354
|
-
polylineIdMap[polyline] = id
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
fun removePolyline(id: String) {
|
|
359
|
-
polylines[id]?.let { polyline ->
|
|
360
|
-
polylineIdMap.remove(polyline)
|
|
361
|
-
polyline.remove()
|
|
362
|
-
polylines.remove(id)
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
fun updatePolyline(id: String, props: Map<String, Any>) {
|
|
367
|
-
polylines[id]?.let { polyline ->
|
|
368
|
-
@Suppress("UNCHECKED_CAST")
|
|
369
|
-
val points = props["points"] as? List<Map<String, Double>>
|
|
370
|
-
val width = (props["strokeWidth"] as? Number)?.toFloat()
|
|
371
|
-
val color = props["strokeColor"]?.let { ColorParser.parseColor(it) }
|
|
372
|
-
|
|
373
|
-
points?.let {
|
|
374
|
-
val latLngs = it.map { point ->
|
|
375
|
-
val lat = point["latitude"] ?: 0.0
|
|
376
|
-
val lng = point["longitude"] ?: 0.0
|
|
377
|
-
LatLng(lat, lng)
|
|
378
|
-
}
|
|
379
|
-
polyline.points = latLngs
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
width?.let {
|
|
383
|
-
val density = context.resources.displayMetrics.density
|
|
384
|
-
polyline.width = it * density
|
|
385
|
-
}
|
|
386
|
-
color?.let { polyline.color = it }
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// ==================== 多边形 ====================
|
|
391
|
-
|
|
392
|
-
fun addPolygon(id: String, props: Map<String, Any>) {
|
|
393
|
-
|
|
394
|
-
@Suppress("UNCHECKED_CAST")
|
|
395
|
-
val points = props["points"] as? List<Map<String, Double>>
|
|
396
|
-
val fillColor = ColorParser.parseColor(props["fillColor"])
|
|
397
|
-
val strokeColor = ColorParser.parseColor(props["strokeColor"])
|
|
398
|
-
|
|
399
|
-
val strokeWidth = (props["strokeWidth"] as? Number)?.toFloat() ?: 10f
|
|
400
|
-
val zIndex = (props["zIndex"] as? Number)?.toFloat() ?: 0f
|
|
401
|
-
|
|
402
|
-
if (points != null && points.size >= 3) {
|
|
403
|
-
val latLngs = points.map { point ->
|
|
404
|
-
val lat = point["latitude"] ?: 0.0
|
|
405
|
-
val lng = point["longitude"] ?: 0.0
|
|
406
|
-
LatLng(lat, lng)
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// 将 dp 转换为 px,与 iOS 的 points 对应
|
|
410
|
-
val density = context.resources.displayMetrics.density
|
|
411
|
-
|
|
412
|
-
val options = com.amap.api.maps.model.PolygonOptions()
|
|
413
|
-
.addAll(latLngs)
|
|
414
|
-
.fillColor(fillColor)
|
|
415
|
-
.strokeColor(strokeColor)
|
|
416
|
-
.strokeWidth(strokeWidth * density)
|
|
417
|
-
.zIndex(zIndex)
|
|
418
|
-
|
|
419
|
-
val polygon = aMap.addPolygon(options)
|
|
420
|
-
polygons[id] = polygon
|
|
421
|
-
polygonIdMap[polygon] = id
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
fun removePolygon(id: String) {
|
|
426
|
-
polygons[id]?.let { polygon ->
|
|
427
|
-
polygonIdMap.remove(polygon)
|
|
428
|
-
polygon.remove()
|
|
429
|
-
polygons.remove(id)
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
fun updatePolygon(id: String, props: Map<String, Any>) {
|
|
434
|
-
polygons[id]?.let { polygon ->
|
|
435
|
-
@Suppress("UNCHECKED_CAST")
|
|
436
|
-
val points = props["points"] as? List<Map<String, Double>>
|
|
437
|
-
val fillColor = props["fillColor"]?.let { ColorParser.parseColor(it) }
|
|
438
|
-
val strokeColor = props["strokeColor"]?.let { ColorParser.parseColor(it) }
|
|
439
|
-
|
|
440
|
-
val strokeWidth = (props["strokeWidth"] as? Number)?.toFloat()
|
|
441
|
-
val zIndex = (props["zIndex"] as? Number)?.toFloat()
|
|
442
|
-
|
|
443
|
-
points?.let {
|
|
444
|
-
val latLngs = it.map { point ->
|
|
445
|
-
val lat = point["latitude"] ?: 0.0
|
|
446
|
-
val lng = point["longitude"] ?: 0.0
|
|
447
|
-
LatLng(lat, lng)
|
|
448
|
-
}
|
|
449
|
-
polygon.points = latLngs
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
fillColor?.let { polygon.fillColor = it }
|
|
453
|
-
strokeColor?.let { polygon.strokeColor = it }
|
|
454
|
-
strokeWidth?.let {
|
|
455
|
-
val density = context.resources.displayMetrics.density
|
|
456
|
-
polygon.strokeWidth = it * density
|
|
457
|
-
}
|
|
458
|
-
zIndex?.let { polygon.zIndex = it }
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* 清理所有覆盖物
|
|
464
|
-
*/
|
|
465
|
-
/**
|
|
466
|
-
* 检查点击位置是否在某个圆形内
|
|
467
|
-
*/
|
|
468
|
-
fun checkCirclePress(latLng: LatLng): String? {
|
|
469
|
-
for ((circle, id) in circleIdMap) {
|
|
470
|
-
if (circle.contains(latLng)) {
|
|
471
|
-
return id
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return null
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* 检查点击位置是否在某个多边形内
|
|
479
|
-
*/
|
|
480
|
-
fun checkPolygonPress(latLng: LatLng): String? {
|
|
481
|
-
for ((polygon, id) in polygonIdMap) {
|
|
482
|
-
if (polygon.contains(latLng)) {
|
|
483
|
-
return id
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return null
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* 检查点击位置是否在某条折线附近
|
|
491
|
-
*/
|
|
492
|
-
fun checkPolylinePress(latLng: LatLng): String? {
|
|
493
|
-
val threshold = 20.0 // 20米容差
|
|
494
|
-
for ((polyline, id) in polylineIdMap) {
|
|
495
|
-
val points = polyline.points
|
|
496
|
-
if (points.size < 2) continue
|
|
497
|
-
|
|
498
|
-
for (i in 0 until points.size - 1) {
|
|
499
|
-
val distance = distanceToSegment(latLng, points[i], points[i + 1])
|
|
500
|
-
if (distance <= threshold) {
|
|
501
|
-
return id
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
return null
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* 计算点到线段的距离(米)
|
|
510
|
-
*/
|
|
511
|
-
private fun distanceToSegment(point: LatLng, start: LatLng, end: LatLng): Double {
|
|
512
|
-
val p = android.location.Location("").apply {
|
|
513
|
-
latitude = point.latitude
|
|
514
|
-
longitude = point.longitude
|
|
515
|
-
}
|
|
516
|
-
val a = android.location.Location("").apply {
|
|
517
|
-
latitude = start.latitude
|
|
518
|
-
longitude = start.longitude
|
|
519
|
-
}
|
|
520
|
-
val b = android.location.Location("").apply {
|
|
521
|
-
latitude = end.latitude
|
|
522
|
-
longitude = end.longitude
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
val ab = a.distanceTo(b).toDouble()
|
|
526
|
-
if (ab == 0.0) return a.distanceTo(p).toDouble()
|
|
527
|
-
|
|
528
|
-
val ap = a.distanceTo(p).toDouble()
|
|
529
|
-
val bp = b.distanceTo(p).toDouble()
|
|
530
|
-
|
|
531
|
-
val t = maxOf(0.0, minOf(1.0,
|
|
532
|
-
((point.latitude - start.latitude) * (end.latitude - start.latitude) +
|
|
533
|
-
(point.longitude - start.longitude) * (end.longitude - start.longitude)) / (ab * ab)
|
|
534
|
-
))
|
|
535
|
-
|
|
536
|
-
val projection = LatLng(
|
|
537
|
-
start.latitude + t * (end.latitude - start.latitude),
|
|
538
|
-
start.longitude + t * (end.longitude - start.longitude)
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
val proj = android.location.Location("").apply {
|
|
542
|
-
latitude = projection.latitude
|
|
543
|
-
longitude = projection.longitude
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return p.distanceTo(proj).toDouble()
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
fun clear() {
|
|
550
|
-
circles.values.forEach { it.remove() }
|
|
551
|
-
circles.clear()
|
|
552
|
-
circleIdMap.clear()
|
|
553
|
-
|
|
554
|
-
markers.values.forEach { it.remove() }
|
|
555
|
-
markers.clear()
|
|
556
|
-
|
|
557
|
-
polylines.values.forEach { it.remove() }
|
|
558
|
-
polylines.clear()
|
|
559
|
-
|
|
560
|
-
polygons.values.forEach { it.remove() }
|
|
561
|
-
polygons.clear()
|
|
562
|
-
polygonIdMap.clear()
|
|
563
|
-
|
|
564
|
-
polylineIdMap.clear()
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* 将 dp 转换为 px
|
|
569
|
-
*/
|
|
570
|
-
private fun dpToPx(dp: Float): Int {
|
|
571
|
-
val density = context.resources.displayMetrics.density
|
|
572
|
-
return (dp * density + 0.5f).toInt()
|
|
573
|
-
}
|
|
574
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { EventSubscription } from 'expo-modules-core';
|
|
2
|
-
import type { Coordinates, ReGeocode, LocationOptions, LocationListener, LatLng, CoordinateType } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* 配置高德地图定位选项
|
|
5
|
-
* @param {LocationOptions} options - 定位配置选项对象
|
|
6
|
-
* @throws {Error} 当传入的配置方法不存在或不可调用时抛出错误
|
|
7
|
-
*/
|
|
8
|
-
export declare function configure(options: LocationOptions): void;
|
|
9
|
-
/**
|
|
10
|
-
* 启动高德地图模块,开始连续定位
|
|
11
|
-
* @throws 如果模块未初始化或启动失败时抛出异常
|
|
12
|
-
*/
|
|
13
|
-
export declare function start(): void;
|
|
14
|
-
/**
|
|
15
|
-
* 停止高德地图相关功能,停止定位
|
|
16
|
-
* @returns {void} 无返回值
|
|
17
|
-
*/
|
|
18
|
-
export declare function stop(): void;
|
|
19
|
-
/**
|
|
20
|
-
* 检查高德地图模块是否已启动,是否正在定位
|
|
21
|
-
* @returns {Promise<boolean>} 返回一个Promise,解析为布尔值表示模块是否已启动
|
|
22
|
-
*/
|
|
23
|
-
export declare function isStarted(): Promise<boolean>;
|
|
24
|
-
/**
|
|
25
|
-
* 获取设备当前位置信息,单次定位
|
|
26
|
-
* @returns {Promise<Coordinates | ReGeocode>} 返回包含坐标或逆地理编码信息的Promise
|
|
27
|
-
* @throws 如果定位服务不可用或权限被拒绝时抛出错误
|
|
28
|
-
*/
|
|
29
|
-
export declare function getCurrentLocation(): Promise<Coordinates | ReGeocode>;
|
|
30
|
-
/**
|
|
31
|
-
* 添加位置更新监听器
|
|
32
|
-
* @param {LocationListener} listener - 位置更新时的回调函数
|
|
33
|
-
* @returns {EventSubscription} 事件订阅对象,包含移除监听器的方法
|
|
34
|
-
* @throws 如果底层模块不可用,返回一个空操作的订阅对象
|
|
35
|
-
*/
|
|
36
|
-
export declare function addLocationListener(listener: LocationListener): EventSubscription;
|
|
37
|
-
/**
|
|
38
|
-
* 将坐标点转换为指定坐标系下的坐标
|
|
39
|
-
* @param {LatLng} coordinate - 需要转换的原始坐标点
|
|
40
|
-
* @param {CoordinateType} type - 目标坐标系类型
|
|
41
|
-
* @returns {Promise<LatLng>} 转换后的坐标点Promise
|
|
42
|
-
* @throws 如果底层模块不可用,则返回原始坐标
|
|
43
|
-
*/
|
|
44
|
-
export declare function coordinateConvert(coordinate: LatLng, type: CoordinateType): Promise<LatLng>;
|
|
45
|
-
/**
|
|
46
|
-
* 开始更新设备方向(罗盘朝向)
|
|
47
|
-
* 调用原生模块方法启动方向更新功能
|
|
48
|
-
* @throws 如果原生模块未实现此方法会抛出异常
|
|
49
|
-
* @platform ios
|
|
50
|
-
*/
|
|
51
|
-
export declare function startUpdatingHeading(): void;
|
|
52
|
-
/**
|
|
53
|
-
* 停止更新设备方向(罗盘朝向)
|
|
54
|
-
* 调用原生模块方法停止监听设备方向变化
|
|
55
|
-
* @throws 如果原生模块未实现此方法会抛出异常
|
|
56
|
-
* @platform ios
|
|
57
|
-
*/
|
|
58
|
-
export declare function stopUpdatingHeading(): void;
|
|
59
|
-
/**
|
|
60
|
-
* 设置高德地图的API密钥
|
|
61
|
-
* @param {string} key - 高德地图的API密钥
|
|
62
|
-
* @returns {void}
|
|
63
|
-
*/
|
|
64
|
-
export declare function setApiKey(key: string): void;
|
|
65
|
-
declare const _default: {
|
|
66
|
-
configure: typeof configure;
|
|
67
|
-
start: typeof start;
|
|
68
|
-
stop: typeof stop;
|
|
69
|
-
isStarted: typeof isStarted;
|
|
70
|
-
getCurrentLocation: typeof getCurrentLocation;
|
|
71
|
-
addLocationListener: typeof addLocationListener;
|
|
72
|
-
coordinateConvert: typeof coordinateConvert;
|
|
73
|
-
startUpdatingHeading: typeof startUpdatingHeading;
|
|
74
|
-
stopUpdatingHeading: typeof stopUpdatingHeading;
|
|
75
|
-
setApiKey: typeof setApiKey;
|
|
76
|
-
};
|
|
77
|
-
export default _default;
|
|
78
|
-
//# sourceMappingURL=AMapLocation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AMapLocation.d.ts","sourceRoot":"","sources":["../../src/modules/AMapLocation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,cAAc,EACf,MAAM,UAAU,CAAC;AA6BlB;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAUxD;AAGD;;;GAGG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAE5B;AAGD;;;GAGG;AACH,wBAAgB,IAAI,IAAI,IAAI,CAE3B;AAGD;;;GAGG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAElD;AAGD;;;;GAIG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAE3E;AAGD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,iBAAiB,CAIjF;AAGD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAGD;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAGD;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C;;;;;;;;;;;;;AAED,wBAWE"}
|