expo-gaode-map-navigation 1.1.5-next.1 → 1.1.5-next.3

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.
Files changed (136) hide show
  1. package/android/build.gradle +10 -0
  2. package/android/src/main/cpp/CMakeLists.txt +24 -0
  3. package/android/src/main/cpp/cluster_jni.cpp +848 -0
  4. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapModule.kt +616 -92
  5. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapOfflineModule.kt +493 -0
  6. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapView.kt +230 -14
  7. package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapViewModule.kt +37 -27
  8. package/android/src/main/java/expo/modules/gaodemap/map/MapPreloadManager.kt +494 -0
  9. package/android/src/main/java/expo/modules/gaodemap/map/companion/BitmapDescriptorCache.kt +30 -0
  10. package/android/src/main/java/expo/modules/gaodemap/map/companion/IconBitmapCache.kt +37 -0
  11. package/android/src/main/java/expo/modules/gaodemap/map/managers/UIManager.kt +76 -0
  12. package/android/src/main/java/expo/modules/gaodemap/map/modules/LocationManager.kt +15 -3
  13. package/android/src/main/java/expo/modules/gaodemap/map/modules/SDKInitializer.kt +4 -59
  14. package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleView.kt +9 -12
  15. package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleViewModule.kt +5 -6
  16. package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterView.kt +539 -66
  17. package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterViewModule.kt +17 -1
  18. package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapView.kt +165 -33
  19. package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapViewModule.kt +15 -3
  20. package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerView.kt +1249 -672
  21. package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerViewModule.kt +40 -17
  22. package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointView.kt +177 -22
  23. package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointViewModule.kt +11 -3
  24. package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonView.kt +57 -14
  25. package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonViewModule.kt +9 -5
  26. package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineView.kt +90 -63
  27. package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineViewModule.kt +7 -3
  28. package/android/src/main/java/expo/modules/gaodemap/map/services/LocationForegroundService.kt +3 -2
  29. package/android/src/main/java/expo/modules/gaodemap/map/utils/BitmapDescriptorCache.kt +20 -0
  30. package/android/src/main/java/expo/modules/gaodemap/map/utils/ClusterNative.kt +13 -0
  31. package/android/src/main/java/expo/modules/gaodemap/map/utils/ColorParser.kt +20 -0
  32. package/android/src/main/java/expo/modules/gaodemap/map/utils/GeometryUtils.kt +515 -0
  33. package/android/src/main/java/expo/modules/gaodemap/map/utils/LatLngParser.kt +91 -0
  34. package/android/src/main/java/expo/modules/gaodemap/map/utils/PermissionHelper.kt +248 -0
  35. package/build/ExpoGaodeMapNaviView.d.ts +7 -7
  36. package/build/ExpoGaodeMapNaviView.js +8 -8
  37. package/build/ExpoGaodeMapNavigationModule.d.ts +2 -1
  38. package/build/index.d.ts +35 -33
  39. package/build/index.js +70 -106
  40. package/build/map/ExpoGaodeMapModule.d.ts +2 -201
  41. package/build/map/ExpoGaodeMapModule.js +584 -14
  42. package/build/map/ExpoGaodeMapOfflineModule.d.ts +139 -0
  43. package/build/map/ExpoGaodeMapOfflineModule.js +8 -0
  44. package/build/map/ExpoGaodeMapView.js +66 -58
  45. package/build/map/components/FoldableMapView.d.ts +38 -0
  46. package/build/map/components/FoldableMapView.js +209 -0
  47. package/build/map/components/MapContext.d.ts +12 -0
  48. package/build/map/components/MapContext.js +54 -0
  49. package/build/map/components/MapUI.d.ts +18 -0
  50. package/build/map/components/MapUI.js +29 -0
  51. package/build/map/components/overlays/Circle.js +34 -3
  52. package/build/map/components/overlays/Cluster.d.ts +3 -1
  53. package/build/map/components/overlays/Cluster.js +31 -2
  54. package/build/map/components/overlays/HeatMap.d.ts +3 -1
  55. package/build/map/components/overlays/HeatMap.js +33 -3
  56. package/build/map/components/overlays/Marker.d.ts +1 -1
  57. package/build/map/components/overlays/Marker.js +37 -32
  58. package/build/map/components/overlays/MultiPoint.js +1 -1
  59. package/build/map/components/overlays/Polygon.js +30 -3
  60. package/build/map/components/overlays/Polyline.js +36 -3
  61. package/build/map/index.d.ts +25 -5
  62. package/build/map/index.js +59 -18
  63. package/build/map/types/common.types.d.ts +40 -0
  64. package/build/map/types/common.types.js +0 -4
  65. package/build/map/types/index.d.ts +3 -2
  66. package/build/map/types/map-view.types.d.ts +108 -3
  67. package/build/map/types/native-module.types.d.ts +363 -0
  68. package/build/map/types/native-module.types.js +5 -0
  69. package/build/map/types/offline.types.d.ts +132 -0
  70. package/build/map/types/offline.types.js +5 -0
  71. package/build/map/types/overlays.types.d.ts +137 -24
  72. package/build/map/utils/ErrorHandler.d.ts +110 -0
  73. package/build/map/utils/ErrorHandler.js +421 -0
  74. package/build/map/utils/GeoUtils.d.ts +20 -0
  75. package/build/map/utils/GeoUtils.js +76 -0
  76. package/build/map/utils/OfflineMapManager.d.ts +148 -0
  77. package/build/map/utils/OfflineMapManager.js +217 -0
  78. package/build/map/utils/PermissionUtils.d.ts +91 -0
  79. package/build/map/utils/PermissionUtils.js +255 -0
  80. package/build/map/utils/PlatformDetector.d.ts +102 -0
  81. package/build/map/utils/PlatformDetector.js +186 -0
  82. package/build/types/index.d.ts +1 -0
  83. package/build/types/index.js +1 -0
  84. package/build/types/native-module.types.d.ts +69 -0
  85. package/build/types/native-module.types.js +2 -0
  86. package/build/types/naviview.types.d.ts +1 -1
  87. package/expo-module.config.json +12 -10
  88. package/ios/ExpoGaodeMapNavigation.podspec +9 -0
  89. package/ios/map/ExpoGaodeMapModule.swift +485 -75
  90. package/ios/map/ExpoGaodeMapOfflineModule.swift +479 -0
  91. package/ios/map/ExpoGaodeMapView.swift +611 -62
  92. package/ios/map/ExpoGaodeMapViewModule.swift +48 -26
  93. package/ios/map/MapPreloadManager.swift +348 -0
  94. package/ios/map/cpp/ClusterEngine.cpp +110 -0
  95. package/ios/map/cpp/ClusterEngine.hpp +20 -0
  96. package/ios/map/cpp/ColorParser.cpp +135 -0
  97. package/ios/map/cpp/ColorParser.hpp +14 -0
  98. package/ios/map/cpp/GeometryEngine.cpp +574 -0
  99. package/ios/map/cpp/GeometryEngine.hpp +159 -0
  100. package/ios/map/cpp/QuadTree.cpp +92 -0
  101. package/ios/map/cpp/QuadTree.hpp +42 -0
  102. package/ios/map/cpp/README.md +55 -0
  103. package/ios/map/cpp/tests/benchmark_js.js +41 -0
  104. package/ios/map/cpp/tests/run.sh +17 -0
  105. package/ios/map/cpp/tests/test_main.cpp +276 -0
  106. package/ios/map/managers/UIManager.swift +72 -1
  107. package/ios/map/modules/LocationManager.swift +114 -165
  108. package/ios/map/overlays/CircleView.swift +16 -32
  109. package/ios/map/overlays/CircleViewModule.swift +12 -12
  110. package/ios/map/overlays/ClusterAnnotation.swift +32 -0
  111. package/ios/map/overlays/ClusterView.swift +331 -45
  112. package/ios/map/overlays/ClusterViewModule.swift +20 -6
  113. package/ios/map/overlays/HeatMapView.swift +135 -32
  114. package/ios/map/overlays/HeatMapViewModule.swift +20 -8
  115. package/ios/map/overlays/MarkerView.swift +613 -130
  116. package/ios/map/overlays/MarkerViewModule.swift +38 -18
  117. package/ios/map/overlays/MultiPointView.swift +168 -10
  118. package/ios/map/overlays/MultiPointViewModule.swift +27 -5
  119. package/ios/map/overlays/PolygonView.swift +62 -23
  120. package/ios/map/overlays/PolygonViewModule.swift +18 -12
  121. package/ios/map/overlays/PolylineView.swift +21 -13
  122. package/ios/map/overlays/PolylineViewModule.swift +18 -12
  123. package/ios/map/utils/ClusterNative.h +96 -0
  124. package/ios/map/utils/ClusterNative.mm +377 -0
  125. package/ios/map/utils/ColorParser.swift +12 -1
  126. package/ios/map/utils/CppBridging.mm +13 -0
  127. package/ios/map/utils/GeometryUtils.swift +34 -0
  128. package/ios/map/utils/LatLngParser.swift +87 -0
  129. package/ios/map/utils/PermissionManager.swift +135 -6
  130. package/package.json +1 -1
  131. package/build/map/ExpoGaodeMap.types.d.ts +0 -41
  132. package/build/map/ExpoGaodeMap.types.js +0 -24
  133. package/build/map/utils/EventManager.d.ts +0 -10
  134. package/build/map/utils/EventManager.js +0 -26
  135. package/build/map/utils/ModuleLoader.d.ts +0 -73
  136. package/build/map/utils/ModuleLoader.js +0 -112
@@ -8,71 +8,94 @@ import expo.modules.kotlin.modules.ModuleDefinition
8
8
  */
9
9
  class MarkerViewModule : Module() {
10
10
  override fun definition() = ModuleDefinition {
11
- Name("NaviMarkerView")
11
+ Name("MarkerView")
12
12
 
13
13
  View(MarkerView::class) {
14
14
  Events("onMarkerPress", "onMarkerDragStart", "onMarkerDrag", "onMarkerDragEnd")
15
15
 
16
- // 拆分 position 为两个独立属性以兼容 React Native 旧架构
16
+ // 纬度
17
17
  Prop<Double>("latitude") { view, lat ->
18
18
  view.setLatitude(lat)
19
19
  }
20
-
20
+ // 经度
21
21
  Prop<Double>("longitude") { view, lng ->
22
22
  view.setLongitude(lng)
23
23
  }
24
-
24
+ // 位置
25
+ Prop<Map<String, Any>?>("position") { view, position ->
26
+ view.setPosition(position)
27
+ }
28
+ // 标题
25
29
  Prop<String>("title") { view, title ->
26
30
  view.setTitle(title)
27
31
  }
28
-
32
+ // 副标题
29
33
  Prop<String>("snippet") { view, snippet ->
30
34
  view.setDescription(snippet)
31
35
  }
32
-
36
+ // 是否可拖拽
33
37
  Prop<Boolean>("draggable") { view, draggable ->
34
38
  view.setDraggable(draggable)
35
39
  }
36
-
40
+ // 图标
37
41
  Prop<String>("icon") { view, icon ->
38
42
  view.setMarkerIcon(icon)
39
43
  }
40
-
44
+ // 图标颜色
41
45
  Prop<String>("pinColor") { view, color ->
42
46
  view.setPinColor(color)
43
47
  }
44
-
48
+ // 透明度
45
49
  Prop<Float>("opacity") { view, opacity ->
46
50
  view.setOpacity(opacity)
47
51
  }
48
-
52
+ // 是否平铺
49
53
  Prop<Boolean>("flat") { view, flat ->
50
54
  view.setFlat(flat)
51
55
  }
52
-
56
+ // 层级
53
57
  Prop<Float>("zIndex") { view, zIndex ->
54
58
  view.setZIndex(zIndex)
55
59
  }
56
-
60
+ // 锚点
57
61
  Prop<Map<String, Float>>("anchor") { view, anchor ->
58
62
  view.setAnchor(anchor)
59
63
  }
60
-
64
+ // 图标宽度
61
65
  Prop<Int>("iconWidth") { view, width ->
62
66
  view.setIconWidth(width)
63
67
  }
64
-
68
+ // 图标高度
65
69
  Prop<Int>("iconHeight") { view, height ->
66
70
  view.setIconHeight(height)
67
71
  }
68
-
72
+ // 自定义视图宽度
69
73
  Prop<Int>("customViewWidth") { view, width ->
70
74
  view.setCustomViewWidth(width)
71
75
  }
72
-
76
+ // 自定义视图高度
73
77
  Prop<Int>("customViewHeight") { view, height ->
74
78
  view.setCustomViewHeight(height)
75
79
  }
80
+ // 缓存key
81
+ Prop<String>("cacheKey") { view, key ->
82
+ view.setCacheKey(key)
83
+ }
84
+
85
+ // 平滑移动路径
86
+ Prop<List<Any>?>("smoothMovePath") { view: MarkerView, path ->
87
+ view.setSmoothMovePath(path)
88
+ }
89
+
90
+ // 平滑移动时长(秒)
91
+ Prop<Double>("smoothMoveDuration") { view, duration ->
92
+ view.setSmoothMoveDuration(duration)
93
+ }
94
+
95
+ // 生长动画
96
+ Prop<Boolean>("growAnimation") { view, enable ->
97
+ view.setGrowAnimation(enable)
98
+ }
76
99
  }
77
100
  }
78
- }
101
+ }
@@ -1,24 +1,48 @@
1
1
  package expo.modules.gaodemap.map.overlays
2
2
 
3
3
  import android.content.Context
4
+ import android.graphics.Bitmap
5
+ import android.graphics.BitmapFactory
6
+ import android.os.Handler
7
+ import android.os.Looper
4
8
 
9
+ import expo.modules.gaodemap.map.utils.LatLngParser
5
10
  import com.amap.api.maps.AMap
11
+ import com.amap.api.maps.model.BitmapDescriptor
6
12
  import com.amap.api.maps.model.BitmapDescriptorFactory
7
13
  import com.amap.api.maps.model.LatLng
8
14
  import com.amap.api.maps.model.MultiPointItem
9
15
  import com.amap.api.maps.model.MultiPointOverlay
10
16
  import com.amap.api.maps.model.MultiPointOverlayOptions
17
+ import expo.modules.gaodemap.map.companion.BitmapDescriptorCache
18
+
11
19
  import expo.modules.kotlin.AppContext
20
+ import expo.modules.kotlin.viewevent.EventDispatcher
12
21
 
13
22
  import expo.modules.kotlin.views.ExpoView
23
+ import java.io.InputStream
24
+ import java.net.HttpURLConnection
25
+ import java.net.URL
26
+ import kotlin.concurrent.thread
27
+ import androidx.core.graphics.scale
14
28
 
15
29
  class MultiPointView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
16
30
 
17
-
31
+ private val onMultiPointPress by EventDispatcher()
18
32
  private var multiPointOverlay: MultiPointOverlay? = null
19
33
  private var aMap: AMap? = null
20
34
  private var points: MutableList<MultiPointItem> = mutableListOf()
21
35
 
36
+ private var pendingIconUri: String? = null
37
+ private var currentIconDescriptor: BitmapDescriptor? = null
38
+ private val mainHandler = Handler(Looper.getMainLooper())
39
+
40
+ private var anchorX: Float = 0.5f
41
+ private var anchorY: Float = 0.5f
42
+
43
+ private var iconWidth: Int? = null
44
+ private var iconHeight: Int? = null
45
+
22
46
  /**
23
47
  * 设置地图实例
24
48
  */
@@ -27,20 +51,22 @@ class MultiPointView(context: Context, appContext: AppContext) : ExpoView(contex
27
51
  createOrUpdateMultiPoint()
28
52
  }
29
53
 
54
+
55
+
30
56
  /**
31
57
  * 设置海量点数据
32
58
  */
33
- fun setPoints(pointsList: List<Map<String, Any>>) {
59
+ fun setPoints(pointsList: List<Any>) {
34
60
  points.clear()
35
- pointsList.forEach { point ->
36
- val lat = (point["latitude"] as? Number)?.toDouble()
37
- val lng = (point["longitude"] as? Number)?.toDouble()
38
- val id = point["id"] as? String ?: ""
39
-
40
- // 坐标验证
41
- if (lat != null && lng != null && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180) {
42
- val multiPointItem = MultiPointItem(LatLng(lat, lng))
43
- multiPointItem.customerId = id
61
+ pointsList.forEach { pointData ->
62
+ val latLng = LatLngParser.parseLatLng(pointData)
63
+ if (latLng != null) {
64
+ val multiPointItem = MultiPointItem(latLng)
65
+ // 如果是 Map,尝试获取 ID
66
+ if (pointData is Map<*, *>) {
67
+ val id = pointData["customerId"] as? String ?: pointData["id"] as? String ?: ""
68
+ multiPointItem.customerId = id
69
+ }
44
70
  points.add(multiPointItem)
45
71
  }
46
72
  }
@@ -51,18 +77,32 @@ class MultiPointView(context: Context, appContext: AppContext) : ExpoView(contex
51
77
  * 设置图标
52
78
  */
53
79
  fun setIcon(iconUri: String?) {
80
+ pendingIconUri = iconUri
81
+ if (iconUri != null) {
82
+ loadAndSetIcon(iconUri)
83
+ } else {
84
+ currentIconDescriptor = null
85
+ createOrUpdateMultiPoint()
86
+ }
87
+ }
54
88
 
55
- // 简化处理,实际需要实现图片加载
56
- createOrUpdateMultiPoint()
89
+ fun setIconWidth(width: Int?) {
90
+ iconWidth = width
91
+ pendingIconUri?.let { loadAndSetIcon(it) }
92
+ }
93
+
94
+ fun setIconHeight(height: Int?) {
95
+ iconHeight = height
96
+ pendingIconUri?.let { loadAndSetIcon(it) }
57
97
  }
58
98
 
59
99
  /**
60
100
  * 设置锚点
61
101
  */
62
102
  fun setAnchor(anchor: Map<String, Float>) {
63
- val x = anchor["x"] ?: 0.5f
64
- val y = anchor["y"] ?: 0.5f
65
- multiPointOverlay?.setAnchor(x, y)
103
+ anchorX = anchor["x"] ?: 0.5f
104
+ anchorY = anchor["y"] ?: 0.5f
105
+ multiPointOverlay?.setAnchor(anchorX, anchorY)
66
106
  }
67
107
 
68
108
  /**
@@ -76,18 +116,133 @@ class MultiPointView(context: Context, appContext: AppContext) : ExpoView(contex
76
116
 
77
117
  // 创建海量点选项
78
118
  val overlayOptions = MultiPointOverlayOptions()
79
- overlayOptions.icon(BitmapDescriptorFactory.defaultMarker())
80
- overlayOptions.anchor(0.5f, 0.5f)
119
+ // 使用加载的图标或默认图标
120
+ val icon = currentIconDescriptor ?: BitmapDescriptorFactory.defaultMarker()
121
+ overlayOptions.icon(icon)
122
+ overlayOptions.anchor(anchorX, anchorY)
81
123
 
82
124
  // 创建海量点覆盖物
83
125
  multiPointOverlay = map.addMultiPointOverlay(overlayOptions)
84
- multiPointOverlay?.items = points
85
-
86
- // 注意:MultiPointOverlay 在高德地图 Android SDK 中不直接支持点击事件
87
- // 如果需要点击事件,需要使用 Marker 或其他方式实现
126
+ multiPointOverlay?.items = points
88
127
  }
89
128
  }
90
129
  }
130
+
131
+ fun handleMultiPointClick(item: MultiPointItem): Boolean {
132
+ val index = points.indexOfFirst { it.customerId == item.customerId }
133
+ if (index != -1) {
134
+ onMultiPointPress(mapOf(
135
+ "id" to item.customerId, // 兼容旧版
136
+ "customerId" to item.customerId,
137
+ "index" to index, // 添加 index 字段
138
+ "latitude" to item.latLng.latitude,
139
+ "longitude" to item.latLng.longitude
140
+ ))
141
+ return true
142
+ }
143
+ return false
144
+ }
145
+
146
+ private fun loadAndSetIcon(iconUri: String) {
147
+ val w = iconWidth ?: 0
148
+ val h = iconHeight ?: 0
149
+ val cacheKey = "multipoint|$iconUri|$w|$h"
150
+
151
+ // 尝试从缓存获取
152
+ BitmapDescriptorCache.get(cacheKey)?.let {
153
+ currentIconDescriptor = it
154
+ createOrUpdateMultiPoint()
155
+ return
156
+ }
157
+
158
+ when {
159
+ iconUri.startsWith("http") -> {
160
+ loadImageFromUrl(iconUri) { bitmap ->
161
+ processBitmap(bitmap, cacheKey)
162
+ }
163
+ }
164
+ iconUri.startsWith("file://") -> {
165
+ val path = iconUri.substring(7)
166
+ val bitmap = BitmapFactory.decodeFile(path)
167
+ processBitmap(bitmap, cacheKey)
168
+ }
169
+ else -> {
170
+ val resId = context.resources.getIdentifier(iconUri, "drawable", context.packageName)
171
+ if (resId != 0) {
172
+ val bitmap = BitmapFactory.decodeResource(context.resources, resId)
173
+ processBitmap(bitmap, cacheKey)
174
+ } else {
175
+ currentIconDescriptor = null
176
+ mainHandler.post { createOrUpdateMultiPoint() }
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ private fun processBitmap(bitmap: Bitmap?, cacheKey: String) {
183
+ if (bitmap != null) {
184
+ var finalBitmap = bitmap
185
+ if (iconWidth != null || iconHeight != null) {
186
+ var w = iconWidth?.let { dpToPx(it) } ?: 0
187
+ var h = iconHeight?.let { dpToPx(it) } ?: 0
188
+
189
+ if (w > 0 && h == 0) {
190
+ h = (bitmap.height * (w.toFloat() / bitmap.width)).toInt()
191
+ } else if (h > 0 && w == 0) {
192
+ w = (bitmap.width * (h.toFloat() / bitmap.height)).toInt()
193
+ } else if (w == 0 && h == 0) {
194
+ w = bitmap.width
195
+ h = bitmap.height
196
+ }
197
+
198
+ try {
199
+ finalBitmap = bitmap.scale(w, h)
200
+ } catch (e: Exception) {
201
+ e.printStackTrace()
202
+ }
203
+ }
204
+
205
+ val descriptor = BitmapDescriptorFactory.fromBitmap(finalBitmap)
206
+ BitmapDescriptorCache.putDescriptor(cacheKey, descriptor)
207
+ currentIconDescriptor = descriptor
208
+ } else {
209
+ currentIconDescriptor = null
210
+ }
211
+ mainHandler.post { createOrUpdateMultiPoint() }
212
+ }
213
+
214
+ private fun dpToPx(dp: Int): Int {
215
+ val density = context.resources.displayMetrics.density
216
+ return (dp * density).toInt()
217
+ }
218
+
219
+ private fun loadImageFromUrl(url: String, callback: (Bitmap?) -> Unit) {
220
+ thread {
221
+ var connection: HttpURLConnection? = null
222
+ var inputStream: InputStream? = null
223
+ try {
224
+ val urlConnection = URL(url)
225
+ connection = urlConnection.openConnection() as HttpURLConnection
226
+ connection.connectTimeout = 10000
227
+ connection.readTimeout = 10000
228
+ connection.doInput = true
229
+ connection.connect()
230
+
231
+ if (connection.responseCode == HttpURLConnection.HTTP_OK) {
232
+ inputStream = connection.inputStream
233
+ val bitmap = BitmapFactory.decodeStream(inputStream)
234
+ callback(bitmap)
235
+ } else {
236
+ callback(null)
237
+ }
238
+ } catch (_: Exception) {
239
+ callback(null)
240
+ } finally {
241
+ inputStream?.close()
242
+ connection?.disconnect()
243
+ }
244
+ }
245
+ }
91
246
 
92
247
  /**
93
248
  * 移除海量点
@@ -8,12 +8,12 @@ import expo.modules.kotlin.modules.ModuleDefinition
8
8
  */
9
9
  class MultiPointViewModule : Module() {
10
10
  override fun definition() = ModuleDefinition {
11
- Name("NaviMultiPointView")
11
+ Name("MultiPointView")
12
12
 
13
13
  View(MultiPointView::class) {
14
- Events("onPress")
14
+ Events("onMultiPointPress")
15
15
 
16
- Prop<List<Map<String, Any>>>("points") { view: MultiPointView, points ->
16
+ Prop<List<Any>>("points") { view: MultiPointView, points ->
17
17
  view.setPoints(points)
18
18
  }
19
19
 
@@ -21,6 +21,14 @@ class MultiPointViewModule : Module() {
21
21
  view.setIcon(icon)
22
22
  }
23
23
 
24
+ Prop<Int?>("iconWidth") { view: MultiPointView, width: Int? ->
25
+ view.setIconWidth(width)
26
+ }
27
+
28
+ Prop<Int?>("iconHeight") { view: MultiPointView, height: Int? ->
29
+ view.setIconHeight(height)
30
+ }
31
+
24
32
  Prop<Map<String, Float>>("anchor"){ view: MultiPointView, anchor ->
25
33
  view.setAnchor(anchor)
26
34
  }
@@ -5,8 +5,12 @@ import android.graphics.Color
5
5
  import com.amap.api.maps.AMap
6
6
  import com.amap.api.maps.model.LatLng
7
7
  import com.amap.api.maps.model.Polygon
8
+ import com.amap.api.maps.model.PolygonHoleOptions
8
9
  import com.amap.api.maps.model.PolygonOptions
10
+ import com.amap.api.maps.model.BaseHoleOptions
9
11
  import expo.modules.gaodemap.map.utils.ColorParser
12
+ import expo.modules.gaodemap.map.utils.GeometryUtils
13
+ import expo.modules.gaodemap.map.utils.LatLngParser
10
14
  import expo.modules.kotlin.AppContext
11
15
  import expo.modules.kotlin.viewevent.EventDispatcher
12
16
  import expo.modules.kotlin.views.ExpoView
@@ -14,11 +18,14 @@ import expo.modules.kotlin.views.ExpoView
14
18
  class PolygonView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
15
19
 
16
20
  private val onPolygonPress by EventDispatcher()
21
+ private val onPolygonSimplified by EventDispatcher()
17
22
 
18
23
  private var polygon: Polygon? = null
19
24
  private var aMap: AMap? = null
20
25
  private var points: List<LatLng> = emptyList()
26
+ private var holes: List<List<LatLng>> = emptyList()
21
27
  private var strokeWidth: Float = 10f
28
+ private var simplificationTolerance: Double = 0.0
22
29
 
23
30
  private var fillColor: Int = Color.argb(50, 0, 0, 255)
24
31
 
@@ -39,24 +46,28 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
39
46
  /**
40
47
  * 设置多边形点集合
41
48
  */
42
- fun setPoints(pointsList: List<Map<String, Double>>) {
43
- points = pointsList.mapNotNull { point ->
44
- val lat = point["latitude"]
45
- val lng = point["longitude"]
46
- // 坐标验证
47
- if (lat != null && lng != null && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180) {
48
- LatLng(lat, lng)
49
- } else null
49
+ fun setPoints(pointsList: List<Any>?) {
50
+ val nestedPoints = LatLngParser.parseLatLngListList(pointsList)
51
+ if (nestedPoints.isNotEmpty()) {
52
+ points = nestedPoints[0]
53
+ holes = if (nestedPoints.size > 1) nestedPoints.subList(1, nestedPoints.size) else emptyList()
54
+ } else {
55
+ points = emptyList()
56
+ holes = emptyList()
50
57
  }
58
+
51
59
  polygon?.let {
52
60
  it.points = points
61
+ it.holeOptions = holes.map { holePoints ->
62
+ PolygonHoleOptions().addAll(holePoints)
63
+ }
53
64
  } ?: createOrUpdatePolygon()
54
65
  }
55
66
 
56
67
  /**
57
68
  * 设置填充颜色
58
69
  */
59
- fun setFillColor(color: Any) {
70
+ fun setFillColor(color: String?) {
60
71
  fillColor = ColorParser.parseColor(color)
61
72
  polygon?.let {
62
73
  it.fillColor = fillColor
@@ -66,7 +77,7 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
66
77
  /**
67
78
  * 设置边框颜色
68
79
  */
69
- fun setStrokeColor(color: Any) {
80
+ fun setStrokeColor(color: String?) {
70
81
  strokeColor = ColorParser.parseColor(color)
71
82
  polygon?.let {
72
83
  it.strokeColor = strokeColor
@@ -94,24 +105,56 @@ class PolygonView(context: Context, appContext: AppContext) : ExpoView(context,
94
105
  it.zIndex = _zIndex
95
106
  } ?: createOrUpdatePolygon()
96
107
  }
108
+
109
+ /**
110
+ * 设置简化容差
111
+ */
112
+ fun setSimplificationTolerance(tolerance: Double) {
113
+ simplificationTolerance = tolerance
114
+ if (points.isNotEmpty()) {
115
+ createOrUpdatePolygon()
116
+ }
117
+ }
97
118
 
98
119
  /**
99
120
  * 创建或更新多边形
100
121
  */
101
122
  private fun createOrUpdatePolygon() {
102
123
  aMap?.let { map ->
103
- if (polygon == null && points.isNotEmpty()) {
124
+ // 移除旧的多边形
125
+ polygon?.remove()
126
+ polygon = null
127
+
128
+ if (points.isNotEmpty()) {
129
+ val displayPoints = if (simplificationTolerance > 0) {
130
+ GeometryUtils.simplifyPolyline(points, simplificationTolerance)
131
+ } else {
132
+ points
133
+ }
134
+
135
+ // 至少3个点
136
+ if (displayPoints.size < 3) return
137
+
104
138
  val options = PolygonOptions()
105
- .addAll(points)
139
+ .addAll(displayPoints)
106
140
  .fillColor(fillColor)
107
141
  .strokeColor(strokeColor)
108
142
  .strokeWidth(strokeWidth)
109
143
  .zIndex(_zIndex)
110
144
 
145
+ if (holes.isNotEmpty()) {
146
+ holes.forEach { holePoints ->
147
+ options.addHoles(PolygonHoleOptions().addAll(holePoints))
148
+ }
149
+ }
150
+
111
151
  polygon = map.addPolygon(options)
112
152
 
113
- // 注意:高德地图 Android SDK 不直接支持 Polygon 点击事件
114
- // 如果需要点击事件,需要通过其他方式实现
153
+ // 派发简化事件
154
+ onPolygonSimplified(mapOf(
155
+ "originalCount" to points.size,
156
+ "simplifiedCount" to displayPoints.size
157
+ ))
115
158
  }
116
159
  }
117
160
  }
@@ -8,20 +8,20 @@ import expo.modules.kotlin.modules.ModuleDefinition
8
8
  */
9
9
  class PolygonViewModule : Module() {
10
10
  override fun definition() = ModuleDefinition {
11
- Name("NaviPolygonView")
11
+ Name("PolygonView")
12
12
 
13
13
  View(PolygonView::class) {
14
- Events("onPolygonPress")
14
+ Events("onPolygonPress", "onPolygonSimplified")
15
15
 
16
- Prop<List<Map<String, Double>>>("points") { view: PolygonView, points ->
16
+ Prop<List<Any>?>("points") { view: PolygonView, points ->
17
17
  view.setPoints(points)
18
18
  }
19
19
 
20
- Prop<Any>("fillColor") { view: PolygonView, color ->
20
+ Prop<String?>("fillColor") { view: PolygonView, color ->
21
21
  view.setFillColor(color)
22
22
  }
23
23
 
24
- Prop<Any>("strokeColor") { view: PolygonView, color ->
24
+ Prop<String?>("strokeColor") { view: PolygonView, color ->
25
25
  view.setStrokeColor(color)
26
26
  }
27
27
 
@@ -32,6 +32,10 @@ class PolygonViewModule : Module() {
32
32
  Prop<Float>("zIndex") { view: PolygonView, zIndex ->
33
33
  view.setZIndex(zIndex)
34
34
  }
35
+
36
+ Prop<Double>("simplificationTolerance") { view: PolygonView, tolerance ->
37
+ view.setSimplificationTolerance(tolerance)
38
+ }
35
39
  }
36
40
  }
37
41
  }