expo-gaode-map 2.2.6-next.1 → 2.2.8-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
- android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
36
- android.util.Log.i("ExpoGaodeMap", "🚀 自动启动地图预加载")
37
- MapPreloadManager.startPreload(context, poolSize = 1)
38
- }, 2000)
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 : 200)
22
- : (iconWidth && iconWidth > 0 ? iconWidth : 40);
21
+ ? (customViewWidth && customViewWidth > 0 ? customViewWidth : 0)
22
+ : (iconWidth && iconWidth > 0 ? iconWidth : 0);
23
23
  const finalIconHeight = hasChildren
24
- ? (customViewHeight && customViewHeight > 0 ? customViewHeight : 40)
25
- : (iconHeight && iconHeight > 0 ? iconHeight : 40);
24
+ ? (customViewHeight && customViewHeight > 0 ? customViewHeight : 0)
25
+ : (iconHeight && iconHeight > 0 ? iconHeight : 0);
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,GAAG,CAAC;QAClE,CAAC,CAAC,CAAC,SAAS,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,eAAe,GAAG,WAAW;QACjC,CAAC,CAAC,CAAC,gBAAgB,IAAI,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,CAAC,CAAC,CAAC,UAAU,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAErD,OAAO,CACL,CAAC,gBAAgB,CACf,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAC5B,SAAS,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC9B,SAAS,CAAC,CAAC,cAAc,CAAC,CAC1B,UAAU,CAAC,CAAC,eAAe,CAAC,CAC5B,eAAe,CAAC,CAAC,cAAc,CAAC,CAChC,gBAAgB,CAAC,CAAC,eAAe,CAAC,CAClC,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);"]}
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,E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C,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 : 0)\n : (iconWidth && iconWidth > 0 ? iconWidth : 0);\n const finalIconHeight = hasChildren\n ? (customViewHeight && customViewHeight > 0 ? customViewHeight : 0)\n : (iconHeight && iconHeight > 0 ? iconHeight : 0);\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);"]}
@@ -37,10 +37,26 @@ public class ExpoGaodeMapModule: Module {
37
37
  MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
38
38
  print("🔁 ExpoGaodeMap: 已从缓存恢复隐私同意状态: true")
39
39
 
40
+ // 尝试从 Info.plist 读取并设置 API Key
41
+ if AMapServices.shared().apiKey == nil || AMapServices.shared().apiKey?.isEmpty == true {
42
+ if let plistKey = Bundle.main.infoDictionary?["AMapApiKey"] as? String, !plistKey.isEmpty {
43
+ AMapServices.shared().apiKey = plistKey
44
+ AMapServices.shared().enableHTTPS = true
45
+ print("✅ ExpoGaodeMap: OnCreate 从 Info.plist 读取并设置 AMapApiKey 成功")
46
+ } else {
47
+ print("⚠️ ExpoGaodeMap: Info.plist 未找到 AMapApiKey,跳过自动预加载")
48
+ }
49
+ }
50
+
40
51
  // 🚀 自动启动预加载(延迟2秒,避免影响启动速度)
41
- DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
42
- print("🚀 ExpoGaodeMap: 自动启动地图预加载")
43
- MapPreloadManager.shared.startPreload(poolSize: 1)
52
+ // 只有在 API Key 已设置的情况下才启动预加载
53
+ if let apiKey = AMapServices.shared().apiKey, !apiKey.isEmpty {
54
+ DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
55
+ print("🚀 ExpoGaodeMap: 自动启动地图预加载")
56
+ MapPreloadManager.shared.startPreload(poolSize: 1)
57
+ }
58
+ } else {
59
+ print("⚠️ ExpoGaodeMap: API Key 未设置,跳过自动预加载")
44
60
  }
45
61
  } else {
46
62
  print("ℹ️ ExpoGaodeMap: 未发现已同意记录,等待用户同意后再使用 SDK")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "2.2.6-next.1",
3
+ "version": "2.2.8-next.0",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",