expo-gaode-map 2.2.7-next.0 → 2.2.9-next.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.
|
@@ -32,10 +32,28 @@ class ExpoGaodeMapModule : Module() {
|
|
|
32
32
|
|
|
33
33
|
// 🚀 如果用户已同意隐私协议,自动启动预加载(延迟2秒)
|
|
34
34
|
if (SDKInitializer.isPrivacyAgreed()) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// 尝试从 AndroidManifest.xml 读取并设置 API Key
|
|
36
|
+
val apiKey = context.packageManager
|
|
37
|
+
.getApplicationInfo(context.packageName, android.content.pm.PackageManager.GET_META_DATA)
|
|
38
|
+
.metaData?.getString("com.amap.api.v2.apikey")
|
|
39
|
+
|
|
40
|
+
if (!apiKey.isNullOrEmpty()) {
|
|
41
|
+
try {
|
|
42
|
+
com.amap.api.maps.MapsInitializer.setApiKey(apiKey)
|
|
43
|
+
com.amap.api.location.AMapLocationClient.setApiKey(apiKey)
|
|
44
|
+
android.util.Log.d("ExpoGaodeMap", "✅ 从 AndroidManifest.xml 读取并设置 API Key 成功")
|
|
45
|
+
|
|
46
|
+
// 只有在 API Key 已设置的情况下才启动预加载
|
|
47
|
+
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
|
48
|
+
android.util.Log.i("ExpoGaodeMap", "🚀 自动启动地图预加载")
|
|
49
|
+
MapPreloadManager.startPreload(context, poolSize = 1)
|
|
50
|
+
}, 2000)
|
|
51
|
+
} catch (e: Exception) {
|
|
52
|
+
android.util.Log.w("ExpoGaodeMap", "设置 API Key 失败: ${e.message}")
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
android.util.Log.w("ExpoGaodeMap", "⚠️ AndroidManifest.xml 未找到 API Key,跳过自动预加载")
|
|
56
|
+
}
|
|
39
57
|
}
|
|
40
58
|
} catch (e: Exception) {
|
|
41
59
|
android.util.Log.w("ExpoGaodeMap", "恢复隐私状态时出现问题: ${e.message}")
|
|
@@ -54,6 +72,24 @@ class ExpoGaodeMapModule : Module() {
|
|
|
54
72
|
|
|
55
73
|
// 🚀 用户首次同意隐私协议后,自动启动预加载
|
|
56
74
|
if (hasAgreed) {
|
|
75
|
+
// 在用户同意后,如果尚未设置 API Key,则尝试从 AndroidManifest.xml 读取并设置
|
|
76
|
+
try {
|
|
77
|
+
val apiKey = context.packageManager
|
|
78
|
+
.getApplicationInfo(context.packageName, android.content.pm.PackageManager.GET_META_DATA)
|
|
79
|
+
.metaData?.getString("com.amap.api.v2.apikey")
|
|
80
|
+
|
|
81
|
+
if (!apiKey.isNullOrEmpty()) {
|
|
82
|
+
com.amap.api.maps.MapsInitializer.setApiKey(apiKey)
|
|
83
|
+
com.amap.api.location.AMapLocationClient.setApiKey(apiKey)
|
|
84
|
+
android.util.Log.d("ExpoGaodeMap", "✅ 从 AndroidManifest.xml 读取并设置 API Key 成功")
|
|
85
|
+
} else {
|
|
86
|
+
android.util.Log.w("ExpoGaodeMap", "⚠️ AndroidManifest.xml 未找到 API Key,后续需通过 initSDK 提供 androidKey")
|
|
87
|
+
}
|
|
88
|
+
} catch (e: Exception) {
|
|
89
|
+
android.util.Log.w("ExpoGaodeMap", "读取 API Key 失败: ${e.message}")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 延迟启动预加载
|
|
57
93
|
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
|
58
94
|
if (!MapPreloadManager.hasPreloadedMapView() &&
|
|
59
95
|
!(MapPreloadManager.getStatus()["isPreloading"] as Boolean)) {
|
|
@@ -18,11 +18,11 @@ function Marker(props) {
|
|
|
18
18
|
// 根据是否有 children 来决定使用哪个尺寸属性
|
|
19
19
|
const hasChildren = !!children;
|
|
20
20
|
const finalIconWidth = hasChildren
|
|
21
|
-
? (customViewWidth && customViewWidth > 0 ? customViewWidth :
|
|
22
|
-
: (iconWidth && iconWidth > 0 ? iconWidth :
|
|
21
|
+
? (customViewWidth && customViewWidth > 0 ? customViewWidth : 200)
|
|
22
|
+
: (iconWidth && iconWidth > 0 ? iconWidth : 40);
|
|
23
23
|
const finalIconHeight = hasChildren
|
|
24
|
-
? (customViewHeight && customViewHeight > 0 ? customViewHeight :
|
|
25
|
-
: (iconHeight && iconHeight > 0 ? iconHeight :
|
|
24
|
+
? (customViewHeight && customViewHeight > 0 ? customViewHeight : 40)
|
|
25
|
+
: (iconHeight && iconHeight > 0 ? iconHeight : 40);
|
|
26
26
|
return (<NativeMarkerView latitude={position.latitude} longitude={position.longitude} iconWidth={finalIconWidth} iconHeight={finalIconHeight} customViewWidth={finalIconWidth} customViewHeight={finalIconHeight} {...restProps}>
|
|
27
27
|
{children}
|
|
28
28
|
</NativeMarkerView>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,YAAY,CAAC,CAAC;AAEhE;;;;;;;;;GASG;AACH,SAAS,MAAM,CAAC,KAAkB;IAChC,mCAAmC;IACnC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAE7G,qBAAqB;IACrB,6BAA6B;IAC7B,MAAM,WAAW,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC/B,MAAM,cAAc,GAAG,WAAW;QAChC,CAAC,CAAC,CAAC,eAAe,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"A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ClC,IAAI,SAAS,CAAC,CAEd;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,gBAAgB,CAAC,CACpB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,SAAsB,EAAE,SAAsB;IACnE,0BAA0B;IAC1B,IACE,SAAS,CAAC,QAAQ,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CAAC,QAAQ;QAC3D,SAAS,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC,QAAQ,CAAC,SAAS,EAC7D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,0CAA0C;IAC1C,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6BAA6B;IAC7B,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,eAAe;IACf,OAAO,IAAI,CAAC;AACd,CAAC;AAED,WAAW;AACX,eAAe,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport type { MarkerProps } from '../../types';\n\nconst NativeMarkerView = requireNativeViewManager('MarkerView');\n\n/**\n * Marker 组件 - 完全声明式 API\n *\n * 支持:\n * - 自定义图标(icon)\n * - 自定义内容(children)\n * - 大头针样式(pinColor)\n * - 拖拽功能\n * - 所有事件回调\n */\nfunction Marker(props: MarkerProps) {\n // 从 props 中排除 position 属性,避免传递到原生层\n const { position, customViewWidth, customViewHeight, iconWidth, iconHeight, children, ...restProps } = props;\n \n // 🔑 性能优化:使用常量避免重复计算\n // 根据是否有 children 来决定使用哪个尺寸属性\n const hasChildren = !!children;\n const finalIconWidth = hasChildren\n ? (customViewWidth && customViewWidth > 0 ? customViewWidth : 200)\n : (iconWidth && iconWidth > 0 ? iconWidth : 40);\n const finalIconHeight = hasChildren\n ? (customViewHeight && customViewHeight > 0 ? customViewHeight : 40)\n : (iconHeight && iconHeight > 0 ? iconHeight : 40);\n \n return (\n <NativeMarkerView\n latitude={position.latitude}\n longitude={position.longitude}\n iconWidth={finalIconWidth}\n iconHeight={finalIconHeight}\n customViewWidth={finalIconWidth}\n customViewHeight={finalIconHeight}\n {...restProps}\n >\n {children}\n </NativeMarkerView>\n );\n}\n\n/**\n * 🔑 性能优化:极简比较函数\n * 只检查最常变化的关键属性,减少 JS 线程开销\n */\nfunction arePropsEqual(prevProps: MarkerProps, nextProps: MarkerProps): boolean {\n // 快速路径:比较 position (最常变化)\n if (\n prevProps.position.latitude !== nextProps.position.latitude ||\n prevProps.position.longitude !== nextProps.position.longitude\n ) {\n return false;\n }\n \n // 比较 cacheKey (如果提供了 cacheKey,其他属性理论上不会变)\n if (prevProps.cacheKey !== nextProps.cacheKey) {\n return false;\n }\n \n // 比较 children (如果有 children)\n if (prevProps.children !== nextProps.children) {\n return false;\n }\n \n // 其他属性相同,不重新渲染\n return true;\n}\n\n// 导出优化后的组件\nexport default React.memo(Marker, arePropsEqual);"]}
|
|
@@ -21,6 +21,48 @@ public class ExpoGaodeMapModule: Module {
|
|
|
21
21
|
/// 隐私同意持久化 Key
|
|
22
22
|
private static let privacyDefaultsKey = "expo_gaode_map_privacy_agreed"
|
|
23
23
|
|
|
24
|
+
// MARK: - 私有辅助方法
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 尝试从 Info.plist 读取并设置 API Key
|
|
28
|
+
* @return 是否成功设置 API Key
|
|
29
|
+
*/
|
|
30
|
+
private func trySetupApiKeyFromPlist() -> Bool {
|
|
31
|
+
if AMapServices.shared().apiKey == nil || AMapServices.shared().apiKey?.isEmpty == true {
|
|
32
|
+
if let plistKey = Bundle.main.infoDictionary?["AMapApiKey"] as? String, !plistKey.isEmpty {
|
|
33
|
+
AMapServices.shared().apiKey = plistKey
|
|
34
|
+
AMapServices.shared().enableHTTPS = true
|
|
35
|
+
print("✅ ExpoGaodeMap: 从 Info.plist 读取并设置 AMapApiKey 成功")
|
|
36
|
+
return true
|
|
37
|
+
} else {
|
|
38
|
+
print("⚠️ ExpoGaodeMap: Info.plist 未找到 AMapApiKey")
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true // 已经设置过了
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 尝试启动预加载(检查 API Key 后)
|
|
47
|
+
* @param delay 延迟时间(秒)
|
|
48
|
+
* @param poolSize 预加载池大小
|
|
49
|
+
*/
|
|
50
|
+
private func tryStartPreload(delay: Double = 1.0, poolSize: Int = 1) {
|
|
51
|
+
if let apiKey = AMapServices.shared().apiKey, !apiKey.isEmpty {
|
|
52
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
|
|
53
|
+
let status = MapPreloadManager.shared.getStatus()
|
|
54
|
+
let isPreloading = (status["isPreloading"] as? Bool) ?? false
|
|
55
|
+
|
|
56
|
+
if !MapPreloadManager.shared.hasPreloadedMapView() && !isPreloading {
|
|
57
|
+
print("🚀 ExpoGaodeMap: 自动启动地图预加载")
|
|
58
|
+
MapPreloadManager.shared.startPreload(poolSize: poolSize)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
print("⚠️ ExpoGaodeMap: API Key 未设置,跳过自动预加载")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
24
66
|
public func definition() -> ModuleDefinition {
|
|
25
67
|
Name("ExpoGaodeMap")
|
|
26
68
|
|
|
@@ -37,11 +79,9 @@ public class ExpoGaodeMapModule: Module {
|
|
|
37
79
|
MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
|
|
38
80
|
print("🔁 ExpoGaodeMap: 已从缓存恢复隐私同意状态: true")
|
|
39
81
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
MapPreloadManager.shared.startPreload(poolSize: 1)
|
|
44
|
-
}
|
|
82
|
+
// 尝试设置 API Key 并启动预加载(延迟2秒)
|
|
83
|
+
self.trySetupApiKeyFromPlist()
|
|
84
|
+
self.tryStartPreload(delay: 2.0, poolSize: 1)
|
|
45
85
|
} else {
|
|
46
86
|
print("ℹ️ ExpoGaodeMap: 未发现已同意记录,等待用户同意后再使用 SDK")
|
|
47
87
|
}
|
|
@@ -64,33 +104,14 @@ public class ExpoGaodeMapModule: Module {
|
|
|
64
104
|
MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
|
|
65
105
|
print("✅ ExpoGaodeMap: 用户已同意隐私协议,可以使用 SDK(状态已持久化)")
|
|
66
106
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
AMapServices.shared().apiKey = plistKey
|
|
71
|
-
AMapServices.shared().enableHTTPS = true
|
|
72
|
-
print("✅ ExpoGaodeMap: 从 Info.plist 读取并设置 AMapApiKey 成功")
|
|
73
|
-
} else {
|
|
74
|
-
print("⚠️ ExpoGaodeMap: Info.plist 未找到 AMapApiKey,后续需通过 initSDK 提供 iosKey")
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 🚀 用户首次同意后,立即启动预加载
|
|
79
|
-
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
|
80
|
-
let status = MapPreloadManager.shared.getStatus()
|
|
81
|
-
let isPreloading = (status["isPreloading"] as? Bool) ?? false
|
|
82
|
-
|
|
83
|
-
if !MapPreloadManager.shared.hasPreloadedMapView() && !isPreloading {
|
|
84
|
-
print("🚀 ExpoGaodeMap: 用户同意隐私协议,自动启动预加载")
|
|
85
|
-
MapPreloadManager.shared.startPreload(poolSize: 1)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
107
|
+
// 尝试设置 API Key 并启动预加载(延迟1秒)
|
|
108
|
+
self.trySetupApiKeyFromPlist()
|
|
109
|
+
self.tryStartPreload(delay: 1.0, poolSize: 1)
|
|
88
110
|
} else {
|
|
89
111
|
MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.notAgree)
|
|
90
112
|
print("⚠️ ExpoGaodeMap: 用户未同意隐私协议,SDK 功能将受限(状态已持久化)")
|
|
91
113
|
}
|
|
92
114
|
}
|
|
93
|
-
|
|
94
115
|
// ==================== SDK 初始化 ====================
|
|
95
116
|
|
|
96
117
|
/**
|
|
@@ -446,7 +467,7 @@ public class ExpoGaodeMapModule: Module {
|
|
|
446
467
|
}
|
|
447
468
|
}
|
|
448
469
|
|
|
449
|
-
// MARK: -
|
|
470
|
+
// MARK: - 定位管理器
|
|
450
471
|
|
|
451
472
|
/**
|
|
452
473
|
* 获取或创建定位管理器实例
|