expo-gaode-map 2.0.0-alpha.2 → 2.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +6 -11
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -1
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +6 -62
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +1 -3
- package/android/src/main/java/expo/modules/gaodemap/modules/SDKInitializer.kt +1 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +10 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +7 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +7 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +86 -122
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +10 -5
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointViewModule.kt +8 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +7 -2
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +7 -2
- package/android/src/main/java/expo/modules/gaodemap/services/LocationForegroundService.kt +1 -2
- package/android/src/main/java/expo/modules/gaodemap/utils/ColorParser.kt +3 -2
- package/build/ExpoGaodeMap.types.d.ts +3 -6
- package/build/ExpoGaodeMap.types.d.ts.map +1 -1
- package/build/ExpoGaodeMap.types.js +4 -2
- package/build/ExpoGaodeMap.types.js.map +1 -1
- package/build/ExpoGaodeMapModule.d.ts +10 -1
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +20 -1
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/types/common.types.d.ts +0 -25
- package/build/types/common.types.d.ts.map +1 -1
- package/build/types/common.types.js.map +1 -1
- package/build/types/index.d.ts +2 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js.map +1 -1
- package/build/types/map-view.types.d.ts +17 -0
- package/build/types/map-view.types.d.ts.map +1 -1
- package/build/types/map-view.types.js.map +1 -1
- package/docs/API.md +2 -2
- package/docs/EXAMPLES.md +2 -2
- package/docs/MIGRATION.md +3 -3
- package/ios/overlays/MarkerView.swift +3 -1
- package/package.json +1 -1
- package/src/ExpoGaodeMap.types.ts +4 -42
- package/src/ExpoGaodeMapModule.ts +34 -1
- package/src/ExpoGaodeMapView.tsx +0 -1
- package/src/types/common.types.ts +0 -30
- package/src/types/index.ts +1 -11
- package/src/types/map-view.types.ts +22 -0
- package/build/types/sdk.types.d.ts +0 -113
- package/build/types/sdk.types.d.ts.map +0 -1
- package/build/types/sdk.types.js +0 -6
- package/build/types/sdk.types.js.map +0 -1
- package/src/types/sdk.types.ts +0 -128
package/README.md
CHANGED
|
@@ -372,7 +372,7 @@ export default function LocationApp() {
|
|
|
372
372
|
ExpoGaodeMapModule.setInterval(2000); // 2秒更新一次
|
|
373
373
|
|
|
374
374
|
// 监听位置更新
|
|
375
|
-
const subscription = ExpoGaodeMapModule.
|
|
375
|
+
const subscription = ExpoGaodeMapModule.addLocationListener('onLocationUpdate', (loc) => {
|
|
376
376
|
console.log('位置更新:', loc);
|
|
377
377
|
setLocation(loc);
|
|
378
378
|
});
|
|
@@ -2,7 +2,6 @@ package expo.modules.gaodemap
|
|
|
2
2
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
5
|
-
import android.util.Log
|
|
6
5
|
import android.view.View
|
|
7
6
|
import com.amap.api.maps.AMap
|
|
8
7
|
import com.amap.api.maps.MapView
|
|
@@ -34,15 +33,11 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
34
33
|
override fun requestLayout() {
|
|
35
34
|
try {
|
|
36
35
|
super.requestLayout()
|
|
37
|
-
} catch (
|
|
36
|
+
} catch (_: Exception) {
|
|
38
37
|
// 忽略异常
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
companion object {
|
|
43
|
-
private const val TAG = "ExpoGaodeMapView"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
41
|
// Props 存储
|
|
47
42
|
/** 地图类型 */
|
|
48
43
|
internal var mapType: Int = 0
|
|
@@ -122,7 +117,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
122
117
|
|
|
123
118
|
onLoad(mapOf("loaded" to true))
|
|
124
119
|
}
|
|
125
|
-
} catch (
|
|
120
|
+
} catch (_: Exception) {
|
|
126
121
|
// 初始化失败,静默处理
|
|
127
122
|
}
|
|
128
123
|
}
|
|
@@ -438,7 +433,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
438
433
|
return
|
|
439
434
|
}
|
|
440
435
|
|
|
441
|
-
if (child is
|
|
436
|
+
if (child is MapView) {
|
|
442
437
|
super.addView(child, index)
|
|
443
438
|
return
|
|
444
439
|
}
|
|
@@ -469,7 +464,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
469
464
|
|
|
470
465
|
try {
|
|
471
466
|
super.removeView(child)
|
|
472
|
-
} catch (
|
|
467
|
+
} catch (_: Exception) {
|
|
473
468
|
// 忽略异常
|
|
474
469
|
}
|
|
475
470
|
}
|
|
@@ -481,7 +476,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
481
476
|
try {
|
|
482
477
|
val child = super.getChildAt(index)
|
|
483
478
|
|
|
484
|
-
if (child is
|
|
479
|
+
if (child is MapView) {
|
|
485
480
|
return
|
|
486
481
|
}
|
|
487
482
|
|
|
@@ -491,7 +486,7 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
|
|
|
491
486
|
|
|
492
487
|
super.removeViewAt(index)
|
|
493
488
|
|
|
494
|
-
} catch (
|
|
489
|
+
} catch (_: Exception) {
|
|
495
490
|
// 忽略异常
|
|
496
491
|
}
|
|
497
492
|
}
|
|
@@ -14,7 +14,7 @@ class ExpoGaodeMapViewModule : Module() {
|
|
|
14
14
|
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle")
|
|
15
15
|
|
|
16
16
|
// ✅ 关键修复:拦截 React Native 的视图操作异常
|
|
17
|
-
OnViewDestroys {
|
|
17
|
+
OnViewDestroys { _: ExpoGaodeMapView ->
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
Prop<Int>("mapType") { view, type ->
|
|
@@ -4,15 +4,14 @@ import android.content.Context
|
|
|
4
4
|
import android.graphics.BitmapFactory
|
|
5
5
|
import android.location.Location
|
|
6
6
|
import android.location.LocationListener
|
|
7
|
-
import android.location.LocationManager as AndroidLocationManager
|
|
8
7
|
import android.os.Bundle
|
|
9
8
|
import com.amap.api.maps.AMap
|
|
10
9
|
import com.amap.api.maps.LocationSource
|
|
11
10
|
import com.amap.api.maps.model.BitmapDescriptorFactory
|
|
12
11
|
import com.amap.api.maps.model.MyLocationStyle
|
|
13
12
|
import expo.modules.gaodemap.utils.ColorParser
|
|
14
|
-
import java.io.File
|
|
15
13
|
import java.net.URL
|
|
14
|
+
import androidx.core.graphics.scale
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* UI 和手势管理器
|
|
@@ -22,7 +21,6 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
22
21
|
|
|
23
22
|
var onLocationChanged: ((latitude: Double, longitude: Double, accuracy: Float) -> Unit)? = null
|
|
24
23
|
|
|
25
|
-
private var locationManager: AndroidLocationManager? = null
|
|
26
24
|
private var locationChangedListener: LocationSource.OnLocationChangedListener? = null
|
|
27
25
|
|
|
28
26
|
// ==================== 控件显示 ====================
|
|
@@ -134,61 +132,7 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
134
|
|
|
137
|
-
|
|
138
|
-
* 启动真实的系统定位
|
|
139
|
-
*/
|
|
140
|
-
private fun startRealLocation() {
|
|
141
|
-
try {
|
|
142
|
-
if (locationManager == null) {
|
|
143
|
-
locationManager = context.getSystemService(Context.LOCATION_SERVICE) as AndroidLocationManager
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
val providers = locationManager?.getProviders(true) ?: emptyList()
|
|
147
|
-
|
|
148
|
-
val provider = when {
|
|
149
|
-
providers.contains(AndroidLocationManager.GPS_PROVIDER) -> {
|
|
150
|
-
AndroidLocationManager.GPS_PROVIDER
|
|
151
|
-
}
|
|
152
|
-
providers.contains(AndroidLocationManager.NETWORK_PROVIDER) -> {
|
|
153
|
-
AndroidLocationManager.NETWORK_PROVIDER
|
|
154
|
-
}
|
|
155
|
-
else -> {
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 请求位置更新
|
|
161
|
-
locationManager?.requestLocationUpdates(
|
|
162
|
-
provider,
|
|
163
|
-
2000L, // 最小时间间隔 2秒
|
|
164
|
-
10f, // 最小距离变化 10米
|
|
165
|
-
this
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
// 立即获取最后已知位置
|
|
169
|
-
val lastLocation = locationManager?.getLastKnownLocation(provider)
|
|
170
|
-
if (lastLocation != null) {
|
|
171
|
-
onLocationChanged(lastLocation)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
} catch (e: SecurityException) {
|
|
175
|
-
// 忽略异常
|
|
176
|
-
} catch (e: Exception) {
|
|
177
|
-
// 忽略异常
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 停止系统定位
|
|
183
|
-
*/
|
|
184
|
-
private fun stopRealLocation() {
|
|
185
|
-
try {
|
|
186
|
-
locationManager?.removeUpdates(this)
|
|
187
|
-
} catch (e: Exception) {
|
|
188
|
-
// 忽略异常
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
135
|
+
|
|
192
136
|
/**
|
|
193
137
|
* 位置变化回调
|
|
194
138
|
*/
|
|
@@ -268,7 +212,7 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
268
212
|
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
|
269
213
|
if (originalBitmap != null) {
|
|
270
214
|
val scaledBitmap = if (imageWidth != null && imageHeight != null) {
|
|
271
|
-
|
|
215
|
+
originalBitmap.scale(imageWidth, imageHeight)
|
|
272
216
|
} else originalBitmap
|
|
273
217
|
|
|
274
218
|
style.myLocationIcon(BitmapDescriptorFactory.fromBitmap(scaledBitmap))
|
|
@@ -282,7 +226,7 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
282
226
|
}
|
|
283
227
|
}
|
|
284
228
|
}
|
|
285
|
-
} catch (
|
|
229
|
+
} catch (_: Exception) {
|
|
286
230
|
// 忽略异常
|
|
287
231
|
}
|
|
288
232
|
}.start()
|
|
@@ -313,7 +257,7 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
313
257
|
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
|
314
258
|
if (originalBitmap != null) {
|
|
315
259
|
val scaledBitmap = if (imageWidth != null && imageHeight != null) {
|
|
316
|
-
|
|
260
|
+
originalBitmap.scale(imageWidth, imageHeight)
|
|
317
261
|
} else originalBitmap
|
|
318
262
|
|
|
319
263
|
style.myLocationIcon(BitmapDescriptorFactory.fromBitmap(scaledBitmap))
|
|
@@ -327,7 +271,7 @@ class UIManager(private val aMap: AMap, private val context: Context) : Location
|
|
|
327
271
|
}
|
|
328
272
|
}
|
|
329
273
|
}
|
|
330
|
-
} catch (
|
|
274
|
+
} catch (_: Exception) {
|
|
331
275
|
// 忽略异常
|
|
332
276
|
}
|
|
333
277
|
}.start()
|
|
@@ -18,9 +18,7 @@ import expo.modules.gaodemap.services.LocationForegroundService
|
|
|
18
18
|
* - 定位结果回调
|
|
19
19
|
*/
|
|
20
20
|
class LocationManager(context: Context) {
|
|
21
|
-
|
|
22
|
-
private const val TAG = "LocationManager"
|
|
23
|
-
}
|
|
21
|
+
|
|
24
22
|
|
|
25
23
|
/** 应用上下文(避免 Activity 泄露) */
|
|
26
24
|
private val appContext: Context = context.applicationContext
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package expo.modules.gaodemap.modules
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import android.util.Log
|
|
5
4
|
import com.amap.api.location.AMapLocationClient
|
|
6
5
|
import com.amap.api.maps.MapsInitializer
|
|
7
6
|
|
|
@@ -15,7 +14,7 @@ import com.amap.api.maps.MapsInitializer
|
|
|
15
14
|
* - 获取 SDK 版本信息
|
|
16
15
|
*/
|
|
17
16
|
object SDKInitializer {
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* 初始化高德地图和定位 SDK
|
|
@@ -154,8 +154,16 @@ class CircleView(context: Context, appContext: AppContext) : ExpoView(context, a
|
|
|
154
154
|
|
|
155
155
|
override fun onDetachedFromWindow() {
|
|
156
156
|
super.onDetachedFromWindow()
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
// 🔑 关键修复:使用 post 延迟检查,避免 TabView 切换时误删
|
|
158
|
+
// 如果是真正的移除,parent 会保持为 null
|
|
159
|
+
// 如果只是 TabView 切换,parent 会在短时间内恢复
|
|
160
|
+
post {
|
|
161
|
+
// 延迟后再次检查 parent,如果仍然为 null,说明是真正的移除
|
|
162
|
+
if (parent == null) {
|
|
163
|
+
removeCircle()
|
|
164
|
+
aMap = null
|
|
165
|
+
}
|
|
166
|
+
}
|
|
159
167
|
}
|
|
160
168
|
|
|
161
169
|
}
|
|
@@ -128,7 +128,12 @@ class ClusterView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
128
128
|
|
|
129
129
|
override fun onDetachedFromWindow() {
|
|
130
130
|
super.onDetachedFromWindow()
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
// 🔑 关键修复:使用 post 延迟检查
|
|
132
|
+
post {
|
|
133
|
+
if (parent == null) {
|
|
134
|
+
removeCluster()
|
|
135
|
+
aMap = null
|
|
136
|
+
}
|
|
137
|
+
}
|
|
133
138
|
}
|
|
134
139
|
}
|
|
@@ -94,7 +94,12 @@ class HeatMapView(context: Context, appContext: AppContext) : ExpoView(context,
|
|
|
94
94
|
|
|
95
95
|
override fun onDetachedFromWindow() {
|
|
96
96
|
super.onDetachedFromWindow()
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
// 🔑 关键修复:使用 post 延迟检查
|
|
98
|
+
post {
|
|
99
|
+
if (parent == null) {
|
|
100
|
+
removeHeatMap()
|
|
101
|
+
aMap = null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
99
104
|
}
|
|
100
105
|
}
|