expo-gaode-map 1.0.1 → 1.0.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 (106) hide show
  1. package/README.md +1 -0
  2. package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +17 -1
  3. package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +52 -5
  4. package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +184 -6
  5. package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +24 -51
  6. package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +3 -0
  7. package/build/ExpoGaodeMap.types.d.ts.map +1 -1
  8. package/build/ExpoGaodeMap.types.js +0 -10
  9. package/build/ExpoGaodeMap.types.js.map +1 -1
  10. package/build/ExpoGaodeMapModule.d.ts.map +1 -1
  11. package/build/ExpoGaodeMapModule.js +0 -10
  12. package/build/ExpoGaodeMapModule.js.map +1 -1
  13. package/build/ExpoGaodeMapView.d.ts +39 -20
  14. package/build/ExpoGaodeMapView.d.ts.map +1 -1
  15. package/build/ExpoGaodeMapView.js +215 -31
  16. package/build/ExpoGaodeMapView.js.map +1 -1
  17. package/build/components/overlays/Circle.d.ts +0 -15
  18. package/build/components/overlays/Circle.d.ts.map +1 -1
  19. package/build/components/overlays/Circle.js +28 -46
  20. package/build/components/overlays/Circle.js.map +1 -1
  21. package/build/components/overlays/Cluster.d.ts +3 -15
  22. package/build/components/overlays/Cluster.d.ts.map +1 -1
  23. package/build/components/overlays/Cluster.js +3 -25
  24. package/build/components/overlays/Cluster.js.map +1 -1
  25. package/build/components/overlays/HeatMap.d.ts +3 -14
  26. package/build/components/overlays/HeatMap.d.ts.map +1 -1
  27. package/build/components/overlays/HeatMap.js +3 -24
  28. package/build/components/overlays/HeatMap.js.map +1 -1
  29. package/build/components/overlays/Marker.d.ts +2 -15
  30. package/build/components/overlays/Marker.d.ts.map +1 -1
  31. package/build/components/overlays/Marker.js +60 -46
  32. package/build/components/overlays/Marker.js.map +1 -1
  33. package/build/components/overlays/MultiPoint.d.ts +3 -14
  34. package/build/components/overlays/MultiPoint.d.ts.map +1 -1
  35. package/build/components/overlays/MultiPoint.js +3 -24
  36. package/build/components/overlays/MultiPoint.js.map +1 -1
  37. package/build/components/overlays/Polygon.d.ts +13 -16
  38. package/build/components/overlays/Polygon.d.ts.map +1 -1
  39. package/build/components/overlays/Polygon.js +41 -75
  40. package/build/components/overlays/Polygon.js.map +1 -1
  41. package/build/components/overlays/Polyline.d.ts +12 -14
  42. package/build/components/overlays/Polyline.d.ts.map +1 -1
  43. package/build/components/overlays/Polyline.js +34 -35
  44. package/build/components/overlays/Polyline.js.map +1 -1
  45. package/build/components/overlays/index.d.ts.map +1 -1
  46. package/build/components/overlays/index.js +0 -10
  47. package/build/components/overlays/index.js.map +1 -1
  48. package/build/index.d.ts.map +1 -1
  49. package/build/index.js +0 -10
  50. package/build/index.js.map +1 -1
  51. package/build/modules/AMapLocation.d.ts +47 -10
  52. package/build/modules/AMapLocation.d.ts.map +1 -1
  53. package/build/modules/AMapLocation.js +48 -20
  54. package/build/modules/AMapLocation.js.map +1 -1
  55. package/build/modules/AMapPermissions.d.ts +3 -1
  56. package/build/modules/AMapPermissions.d.ts.map +1 -1
  57. package/build/modules/AMapPermissions.js +3 -11
  58. package/build/modules/AMapPermissions.js.map +1 -1
  59. package/build/modules/AMapSDK.d.ts +5 -4
  60. package/build/modules/AMapSDK.d.ts.map +1 -1
  61. package/build/modules/AMapSDK.js +5 -14
  62. package/build/modules/AMapSDK.js.map +1 -1
  63. package/build/modules/AMapView.d.ts.map +1 -1
  64. package/build/modules/AMapView.js +0 -8
  65. package/build/modules/AMapView.js.map +1 -1
  66. package/build/types/index.d.ts.map +1 -1
  67. package/build/types/index.js +0 -10
  68. package/build/types/index.js.map +1 -1
  69. package/build/types/map-view.types.d.ts +30 -0
  70. package/build/types/map-view.types.d.ts.map +1 -1
  71. package/build/types/map-view.types.js.map +1 -1
  72. package/build/types/overlays.types.d.ts +25 -1
  73. package/build/types/overlays.types.d.ts.map +1 -1
  74. package/build/types/overlays.types.js.map +1 -1
  75. package/docs/API.md +40 -0
  76. package/docs/EXAMPLES.md +86 -2
  77. package/docs/RELEASE_GUIDE.md +178 -0
  78. package/expo-module.config.json +1 -1
  79. package/ios/ExpoGaodeMapModule.swift +42 -14
  80. package/ios/ExpoGaodeMapView.swift +210 -7
  81. package/ios/managers/OverlayManager.swift +78 -10
  82. package/ios/overlays/CircleView.swift +41 -12
  83. package/ios/overlays/MarkerView.swift +55 -3
  84. package/ios/overlays/PolygonView.swift +25 -5
  85. package/ios/overlays/PolylineView.swift +23 -4
  86. package/ios/utils/ColorParser.swift +0 -5
  87. package/package.json +1 -1
  88. package/src/ExpoGaodeMap.types.ts +1 -10
  89. package/src/ExpoGaodeMapModule.ts +1 -10
  90. package/src/ExpoGaodeMapView.tsx +257 -38
  91. package/src/components/overlays/Circle.tsx +32 -50
  92. package/src/components/overlays/Cluster.tsx +4 -26
  93. package/src/components/overlays/HeatMap.tsx +4 -25
  94. package/src/components/overlays/Marker.tsx +69 -52
  95. package/src/components/overlays/MultiPoint.tsx +4 -25
  96. package/src/components/overlays/Polygon.tsx +48 -78
  97. package/src/components/overlays/Polyline.tsx +41 -38
  98. package/src/components/overlays/index.ts +0 -11
  99. package/src/index.ts +0 -11
  100. package/src/modules/AMapLocation.ts +56 -20
  101. package/src/modules/AMapPermissions.ts +4 -11
  102. package/src/modules/AMapSDK.ts +7 -14
  103. package/src/modules/AMapView.ts +0 -8
  104. package/src/types/index.ts +1 -10
  105. package/src/types/map-view.types.ts +25 -0
  106. package/src/types/overlays.types.ts +30 -1
@@ -1,22 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import type { ClusterProps } from '../../types';
3
3
  /**
4
- * 地图点聚合组件
5
- * 将相近的标记点聚合显示,提高大量标记的展示性能
4
+ * 高德地图点聚合组件
6
5
  *
7
- * @example
8
- * ```tsx
9
- * <MapView>
10
- * <Cluster
11
- * points={[
12
- * { latitude: 39.9, longitude: 116.4, id: '1' },
13
- * { latitude: 39.91, longitude: 116.41, id: '2' },
14
- * ]}
15
- * radius={60}
16
- * minClusterSize={2}
17
- * />
18
- * </MapView>
19
- * ```
6
+ * @param props 点聚合组件的属性配置
7
+ * @returns 渲染原生点聚合组件
20
8
  */
21
9
  export default function Cluster(props: ClusterProps): React.JSX.Element;
22
10
  //# sourceMappingURL=Cluster.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cluster.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Cluster.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,qBAElD"}
1
+ {"version":3,"file":"Cluster.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Cluster.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,qBAElD"}
@@ -1,33 +1,11 @@
1
- /*
2
- * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
3
- * @Date : 2025-11-13 15:02:50
4
- * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
5
- * @LastEditTime : 2025-11-13 18:19:20
6
- * @FilePath : /expo-gaode-map/src/components/overlays/Cluster.tsx
7
- * @Description : 地图点聚合组件
8
- *
9
- * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
10
- */
11
1
  import { requireNativeViewManager } from 'expo-modules-core';
12
2
  import * as React from 'react';
13
3
  const NativeCluster = requireNativeViewManager('ExpoGaodeMap_ClusterView');
14
4
  /**
15
- * 地图点聚合组件
16
- * 将相近的标记点聚合显示,提高大量标记的展示性能
5
+ * 高德地图点聚合组件
17
6
  *
18
- * @example
19
- * ```tsx
20
- * <MapView>
21
- * <Cluster
22
- * points={[
23
- * { latitude: 39.9, longitude: 116.4, id: '1' },
24
- * { latitude: 39.91, longitude: 116.41, id: '2' },
25
- * ]}
26
- * radius={60}
27
- * minClusterSize={2}
28
- * />
29
- * </MapView>
30
- * ```
7
+ * @param props 点聚合组件的属性配置
8
+ * @returns 渲染原生点聚合组件
31
9
  */
32
10
  export default function Cluster(props) {
33
11
  return <NativeCluster {...props}/>;
@@ -1 +1 @@
1
- {"version":3,"file":"Cluster.js","sourceRoot":"","sources":["../../../src/components/overlays/Cluster.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,aAAa,GAAG,wBAAwB,CAAC,0BAA0B,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACtC,CAAC","sourcesContent":["/*\n * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @Date : 2025-11-13 15:02:50\n * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @LastEditTime : 2025-11-13 18:19:20\n * @FilePath : /expo-gaode-map/src/components/overlays/Cluster.tsx\n * @Description : 地图点聚合组件\n * \n * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved. \n */\n\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { ClusterProps } from '../../types';\n\nconst NativeCluster = requireNativeViewManager('ExpoGaodeMap_ClusterView');\n\n/**\n * 地图点聚合组件\n * 将相近的标记点聚合显示,提高大量标记的展示性能\n * \n * @example\n * ```tsx\n * <MapView>\n * <Cluster\n * points={[\n * { latitude: 39.9, longitude: 116.4, id: '1' },\n * { latitude: 39.91, longitude: 116.41, id: '2' },\n * ]}\n * radius={60}\n * minClusterSize={2}\n * />\n * </MapView>\n * ```\n */\nexport default function Cluster(props: ClusterProps) {\n return <NativeCluster {...props} />;\n}\n"]}
1
+ {"version":3,"file":"Cluster.js","sourceRoot":"","sources":["../../../src/components/overlays/Cluster.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,aAAa,GAAG,wBAAwB,CAAC,0BAA0B,CAAC,CAAC;AAG3E;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACtC,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { ClusterProps } from '../../types';\n\nconst NativeCluster = requireNativeViewManager('ExpoGaodeMap_ClusterView');\n\n\n/**\n * 高德地图点聚合组件\n * \n * @param props 点聚合组件的属性配置\n * @returns 渲染原生点聚合组件\n */\nexport default function Cluster(props: ClusterProps) {\n return <NativeCluster {...props} />;\n}\n"]}
@@ -1,21 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import type { HeatMapProps } from '../../types';
3
3
  /**
4
- * 地图热力图组件
4
+ * 高德地图热力图组件
5
5
  *
6
- * @example
7
- * ```tsx
8
- * <MapView>
9
- * <HeatMap
10
- * data={[
11
- * { latitude: 39.9, longitude: 116.4, intensity: 100 },
12
- * { latitude: 39.91, longitude: 116.41, intensity: 80 },
13
- * ]}
14
- * radius={50}
15
- * opacity={0.6}
16
- * />
17
- * </MapView>
18
- * ```
6
+ * @param props - 热力图配置属性,继承自NativeHeatMap组件的属性
7
+ * @returns 渲染高德地图原生热力图组件
19
8
  */
20
9
  export default function HeatMap(props: HeatMapProps): React.JSX.Element;
21
10
  //# sourceMappingURL=HeatMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HeatMap.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/HeatMap.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,qBAElD"}
1
+ {"version":3,"file":"HeatMap.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/HeatMap.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,qBAElD"}
@@ -1,32 +1,11 @@
1
- /*
2
- * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
3
- * @Date : 2025-11-13 15:02:15
4
- * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
5
- * @LastEditTime : 2025-11-13 18:12:07
6
- * @FilePath : /expo-gaode-map/src/components/overlays/HeatMap.tsx
7
- * @Description : 地图热力图组件
8
- *
9
- * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
10
- */
11
1
  import { requireNativeViewManager } from 'expo-modules-core';
12
2
  import * as React from 'react';
13
3
  const NativeHeatMap = requireNativeViewManager('ExpoGaodeMap_HeatMapView');
14
4
  /**
15
- * 地图热力图组件
5
+ * 高德地图热力图组件
16
6
  *
17
- * @example
18
- * ```tsx
19
- * <MapView>
20
- * <HeatMap
21
- * data={[
22
- * { latitude: 39.9, longitude: 116.4, intensity: 100 },
23
- * { latitude: 39.91, longitude: 116.41, intensity: 80 },
24
- * ]}
25
- * radius={50}
26
- * opacity={0.6}
27
- * />
28
- * </MapView>
29
- * ```
7
+ * @param props - 热力图配置属性,继承自NativeHeatMap组件的属性
8
+ * @returns 渲染高德地图原生热力图组件
30
9
  */
31
10
  export default function HeatMap(props) {
32
11
  return <NativeHeatMap {...props}/>;
@@ -1 +1 @@
1
- {"version":3,"file":"HeatMap.js","sourceRoot":"","sources":["../../../src/components/overlays/HeatMap.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,aAAa,GAAG,wBAAwB,CAAC,0BAA0B,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACtC,CAAC","sourcesContent":["/*\n * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @Date : 2025-11-13 15:02:15\n * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @LastEditTime : 2025-11-13 18:12:07\n * @FilePath : /expo-gaode-map/src/components/overlays/HeatMap.tsx\n * @Description : 地图热力图组件\n * \n * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved. \n */\n\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { HeatMapProps } from '../../types';\n\nconst NativeHeatMap = requireNativeViewManager('ExpoGaodeMap_HeatMapView');\n\n/**\n * 地图热力图组件\n * \n * @example\n * ```tsx\n * <MapView>\n * <HeatMap\n * data={[\n * { latitude: 39.9, longitude: 116.4, intensity: 100 },\n * { latitude: 39.91, longitude: 116.41, intensity: 80 },\n * ]}\n * radius={50}\n * opacity={0.6}\n * />\n * </MapView>\n * ```\n */\nexport default function HeatMap(props: HeatMapProps) {\n return <NativeHeatMap {...props} />;\n}\n"]}
1
+ {"version":3,"file":"HeatMap.js","sourceRoot":"","sources":["../../../src/components/overlays/HeatMap.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,aAAa,GAAG,wBAAwB,CAAC,0BAA0B,CAAC,CAAC;AAG3E;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACtC,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { HeatMapProps } from '../../types';\n\nconst NativeHeatMap = requireNativeViewManager('ExpoGaodeMap_HeatMapView');\n\n\n/**\n * 高德地图热力图组件\n * \n * @param props - 热力图配置属性,继承自NativeHeatMap组件的属性\n * @returns 渲染高德地图原生热力图组件\n */\nexport default function HeatMap(props: HeatMapProps) {\n return <NativeHeatMap {...props} />;\n}\n"]}
@@ -1,17 +1,4 @@
1
+ import * as React from 'react';
1
2
  import type { MarkerProps } from '../../types';
2
- /**
3
- * 地图标记组件
4
- *
5
- * @example
6
- * ```tsx
7
- * <MapView>
8
- * <Marker
9
- * position={{ latitude: 39.9, longitude: 116.4 }}
10
- * title="标记点"
11
- * onPress={() => console.log('Marker pressed')}
12
- * />
13
- * </MapView>
14
- * ```
15
- */
16
- export default function Marker(props: MarkerProps): null;
3
+ export default function Marker(props: MarkerProps): React.JSX.Element;
17
4
  //# sourceMappingURL=Marker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Marker.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,QAoChD"}
1
+ {"version":3,"file":"Marker.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAK,EAAE,WAAW,qBAEhD"}
@@ -1,57 +1,71 @@
1
- /*
2
- * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
3
- * @Date : 2025-11-13 15:01:10
4
- * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
5
- * @LastEditTime : 2025-11-13 18:55:00
6
- * @FilePath : /expo-gaode-map/src/components/overlays/Marker.tsx
7
- * @Description : 地图标记组件 - 使用命令式 API
8
- *
9
- * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
10
- */
11
1
  import * as React from 'react';
12
- import { MapContext } from '../../ExpoGaodeMapView';
13
- /**
14
- * 地图标记组件
15
- *
16
- * @example
17
- * ```tsx
18
- * <MapView>
19
- * <Marker
20
- * position={{ latitude: 39.9, longitude: 116.4 }}
21
- * title="标记点"
22
- * onPress={() => console.log('Marker pressed')}
23
- * />
24
- * </MapView>
25
- * ```
26
- */
2
+ import { Image } from 'react-native';
3
+ import { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';
27
4
  export default function Marker(props) {
5
+ return <MarkerImperative {...props}/>;
6
+ }
7
+ function MarkerImperative(props) {
28
8
  const mapRef = React.useContext(MapContext);
29
- const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);
30
- console.log('Marker 组件渲染,props:', props);
31
- // 添加标记
9
+ const eventManager = React.useContext(MarkerEventContext);
10
+ const markerIdRef = React.useRef(null);
11
+ const propsRef = React.useRef(props);
12
+ React.useEffect(() => {
13
+ propsRef.current = props;
14
+ }, [props]);
32
15
  React.useEffect(() => {
33
- const markerId = markerIdRef.current;
34
- console.log('Marker useEffect - 添加标记到地图');
35
- mapRef?.current?.addMarker?.(markerId, props).then(() => {
36
- console.log('✅ 标记已添加:', markerId);
37
- }).catch((error) => {
38
- console.error('❌ 添加标记失败:', error);
39
- });
16
+ const checkAndAdd = () => {
17
+ if (!mapRef?.current) {
18
+ setTimeout(checkAndAdd, 50);
19
+ return;
20
+ }
21
+ const markerId = `marker_${Date.now()}_${Math.random()}`;
22
+ markerIdRef.current = markerId;
23
+ if (eventManager) {
24
+ eventManager.register(markerId, {
25
+ onPress: props.onPress,
26
+ onDragStart: props.onDragStart,
27
+ onDrag: props.onDrag,
28
+ onDragEnd: props.onDragEnd,
29
+ });
30
+ }
31
+ const processedProps = { ...propsRef.current };
32
+ if (processedProps.icon && typeof processedProps.icon === 'number') {
33
+ const resolved = Image.resolveAssetSource(processedProps.icon);
34
+ processedProps.icon = resolved;
35
+ }
36
+ mapRef.current.addMarker(markerId, processedProps);
37
+ };
38
+ checkAndAdd();
40
39
  return () => {
41
- console.log('Marker useEffect cleanup - 移除标记');
42
- mapRef?.current?.removeMarker?.(markerId).catch((error) => {
43
- console.error('❌ 移除标记失败:', error);
44
- });
40
+ if (markerIdRef.current) {
41
+ if (eventManager) {
42
+ eventManager.unregister(markerIdRef.current);
43
+ }
44
+ if (mapRef?.current) {
45
+ mapRef.current.removeMarker(markerIdRef.current);
46
+ }
47
+ }
45
48
  };
46
49
  }, []);
47
- // 监听 Props 变化,更新标记
48
50
  React.useEffect(() => {
49
- const markerId = markerIdRef.current;
50
- console.log('Marker props 变化,更新标记:', props);
51
- mapRef?.current?.updateMarker?.(markerId, props).catch((error) => {
52
- console.error('❌ 更新标记失败:', error);
53
- });
54
- }, [props.position, props.title, props.draggable]);
51
+ if (markerIdRef.current && mapRef?.current) {
52
+ const processedProps = { ...props };
53
+ if (processedProps.icon && typeof processedProps.icon === 'number') {
54
+ const resolved = Image.resolveAssetSource(processedProps.icon);
55
+ processedProps.icon = resolved;
56
+ }
57
+ mapRef.current.updateMarker(markerIdRef.current, processedProps);
58
+ }
59
+ }, [
60
+ props.position?.latitude,
61
+ props.position?.longitude,
62
+ props.title,
63
+ props.draggable,
64
+ props.icon,
65
+ props.iconWidth,
66
+ props.iconHeight,
67
+ props.pinColor
68
+ ]);
55
69
  return null;
56
70
  }
57
71
  //# sourceMappingURL=Marker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAkB;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAS,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAElF,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IAEzC,OAAO;IACP,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;QAErC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC1C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACtD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;YACtB,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;YAC/C,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;gBAC7D,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,mBAAmB;IACnB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;QAErC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;YACpE,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAEnD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*\n * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @Date : 2025-11-13 15:01:10\n * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @LastEditTime : 2025-11-13 18:55:00\n * @FilePath : /expo-gaode-map/src/components/overlays/Marker.tsx\n * @Description : 地图标记组件 - 使用命令式 API\n * \n * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved. \n */\n\nimport * as React from 'react';\nimport { MapContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\n/**\n * 地图标记组件\n * \n * @example\n * ```tsx\n * <MapView>\n * <Marker\n * position={{ latitude: 39.9, longitude: 116.4 }}\n * title=\"标记点\"\n * onPress={() => console.log('Marker pressed')}\n * />\n * </MapView>\n * ```\n */\nexport default function Marker(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const markerIdRef = React.useRef<string>(`marker_${Date.now()}_${Math.random()}`);\n\n console.log('Marker 组件渲染,props:', props);\n\n // 添加标记\n React.useEffect(() => {\n const markerId = markerIdRef.current;\n \n console.log('Marker useEffect - 添加标记到地图');\n mapRef?.current?.addMarker?.(markerId, props).then(() => {\n console.log('✅ 标记已添加:', markerId);\n }).catch((error: any) => {\n console.error('❌ 添加标记失败:', error);\n });\n\n return () => {\n console.log('Marker useEffect cleanup - 移除标记');\n mapRef?.current?.removeMarker?.(markerId).catch((error: any) => {\n console.error('❌ 移除标记失败:', error);\n });\n };\n }, []);\n\n // 监听 Props 变化,更新标记\n React.useEffect(() => {\n const markerId = markerIdRef.current;\n \n console.log('Marker props 变化,更新标记:', props);\n mapRef?.current?.updateMarker?.(markerId, props).catch((error: any) => {\n console.error('❌ 更新标记失败:', error);\n });\n }, [props.position, props.title, props.draggable]);\n\n return null;\n}\n"]}
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,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGxE,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAkB;IAC/C,OAAO,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACzC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAkB;IAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,kBAA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-native';\nimport { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\nexport default function Marker(props: MarkerProps) {\n return <MarkerImperative {...props} />;\n}\n\nfunction MarkerImperative(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef<string | null>(null);\n const propsRef = React.useRef(props);\n \n React.useEffect(() => {\n propsRef.current = props;\n }, [props]);\n \n React.useEffect(() => {\n const checkAndAdd = () => {\n if (!mapRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const markerId = `marker_${Date.now()}_${Math.random()}`;\n markerIdRef.current = markerId;\n \n if (eventManager) {\n eventManager.register(markerId, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n \n const processedProps = { ...propsRef.current };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n \n mapRef.current.addMarker(markerId, processedProps);\n };\n \n checkAndAdd();\n \n return () => {\n if (markerIdRef.current) {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n if (mapRef?.current) {\n mapRef.current.removeMarker(markerIdRef.current);\n }\n }\n };\n }, []);\n\n React.useEffect(() => {\n if (markerIdRef.current && mapRef?.current) {\n const processedProps = { ...props };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n mapRef.current.updateMarker(markerIdRef.current, processedProps);\n }\n }, [\n props.position?.latitude,\n props.position?.longitude,\n props.title,\n props.draggable,\n props.icon,\n props.iconWidth,\n props.iconHeight,\n props.pinColor\n ]);\n \n return null;\n}\n"]}
@@ -1,21 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import type { MultiPointProps } from '../../types';
3
3
  /**
4
- * 地图海量点组件
5
- * 用于展示大量标记点,性能优于普通 Marker
4
+ * 高德地图多点标记组件
6
5
  *
7
- * @example
8
- * ```tsx
9
- * <MapView>
10
- * <MultiPoint
11
- * points={[
12
- * { latitude: 39.9, longitude: 116.4, id: '1' },
13
- * { latitude: 39.91, longitude: 116.41, id: '2' },
14
- * ]}
15
- * icon={require('./marker.png')}
16
- * />
17
- * </MapView>
18
- * ```
6
+ * @param props 多点标记的配置属性,继承自MultiPointProps接口
7
+ * @returns 渲染原生高德地图多点标记组件
19
8
  */
20
9
  export default function MultiPoint(props: MultiPointProps): React.JSX.Element;
21
10
  //# sourceMappingURL=MultiPoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MultiPoint.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/MultiPoint.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,EAAE,eAAe,qBAExD"}
1
+ {"version":3,"file":"MultiPoint.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/MultiPoint.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAKnD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAK,EAAE,eAAe,qBAExD"}
@@ -1,32 +1,11 @@
1
- /*
2
- * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
3
- * @Date : 2025-11-13 15:02:35
4
- * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
5
- * @LastEditTime : 2025-11-13 18:19:09
6
- * @FilePath : /expo-gaode-map/src/components/overlays/MultiPoint.tsx
7
- * @Description : 地图海量点组件
8
- *
9
- * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
10
- */
11
1
  import { requireNativeViewManager } from 'expo-modules-core';
12
2
  import * as React from 'react';
13
3
  const NativeMultiPoint = requireNativeViewManager('ExpoGaodeMap_MultiPointView');
14
4
  /**
15
- * 地图海量点组件
16
- * 用于展示大量标记点,性能优于普通 Marker
5
+ * 高德地图多点标记组件
17
6
  *
18
- * @example
19
- * ```tsx
20
- * <MapView>
21
- * <MultiPoint
22
- * points={[
23
- * { latitude: 39.9, longitude: 116.4, id: '1' },
24
- * { latitude: 39.91, longitude: 116.41, id: '2' },
25
- * ]}
26
- * icon={require('./marker.png')}
27
- * />
28
- * </MapView>
29
- * ```
7
+ * @param props 多点标记的配置属性,继承自MultiPointProps接口
8
+ * @returns 渲染原生高德地图多点标记组件
30
9
  */
31
10
  export default function MultiPoint(props) {
32
11
  return <NativeMultiPoint {...props}/>;
@@ -1 +1 @@
1
- {"version":3,"file":"MultiPoint.js","sourceRoot":"","sources":["../../../src/components/overlays/MultiPoint.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,6BAA6B,CAAC,CAAC;AAEjF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAsB;IACvD,OAAO,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACzC,CAAC","sourcesContent":["/*\n * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @Date : 2025-11-13 15:02:35\n * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @LastEditTime : 2025-11-13 18:19:09\n * @FilePath : /expo-gaode-map/src/components/overlays/MultiPoint.tsx\n * @Description : 地图海量点组件\n * \n * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved. \n */\n\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { MultiPointProps } from '../../types';\n\nconst NativeMultiPoint = requireNativeViewManager('ExpoGaodeMap_MultiPointView');\n\n/**\n * 地图海量点组件\n * 用于展示大量标记点,性能优于普通 Marker\n * \n * @example\n * ```tsx\n * <MapView>\n * <MultiPoint\n * points={[\n * { latitude: 39.9, longitude: 116.4, id: '1' },\n * { latitude: 39.91, longitude: 116.41, id: '2' },\n * ]}\n * icon={require('./marker.png')}\n * />\n * </MapView>\n * ```\n */\nexport default function MultiPoint(props: MultiPointProps) {\n return <NativeMultiPoint {...props} />;\n}\n"]}
1
+ {"version":3,"file":"MultiPoint.js","sourceRoot":"","sources":["../../../src/components/overlays/MultiPoint.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,6BAA6B,CAAC,CAAC;AAGjF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,KAAsB;IACvD,OAAO,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { requireNativeViewManager } from 'expo-modules-core';\nimport * as React from 'react';\nimport type { MultiPointProps } from '../../types';\n\nconst NativeMultiPoint = requireNativeViewManager('ExpoGaodeMap_MultiPointView');\n\n\n/**\n * 高德地图多点标记组件\n * \n * @param props 多点标记的配置属性,继承自MultiPointProps接口\n * @returns 渲染原生高德地图多点标记组件\n */\nexport default function MultiPoint(props: MultiPointProps) {\n return <NativeMultiPoint {...props} />;\n}\n"]}
@@ -1,22 +1,19 @@
1
1
  import type { PolygonProps } from '../../types';
2
2
  /**
3
- * 地图多边形组件 - 命令式 API
3
+ * 高德地图多边形覆盖物组件
4
4
  *
5
- * @example
6
- * ```tsx
7
- * <MapView>
8
- * <Polygon
9
- * points={[
10
- * { latitude: 39.9, longitude: 116.4 },
11
- * { latitude: 39.91, longitude: 116.41 },
12
- * { latitude: 39.92, longitude: 116.40 },
13
- * ]}
14
- * fillColor={0x44FF0000}
15
- * strokeColor={-65536}
16
- * strokeWidth={5}
17
- * />
18
- * </MapView>
19
- * ```
5
+ * @param props - 多边形配置属性
6
+ * @param props.points - 多边形顶点坐标数组,至少需要3个点
7
+ * @param props.fillColor - 多边形填充颜色,十六进制格式,默认0x440000FF
8
+ * @param props.strokeColor - 多边形边框颜色,默认-16776961
9
+ * @param props.strokeWidth - 多边形边框宽度,默认10
10
+ * @param props.zIndex - 多边形层级,默认0
11
+ *
12
+ * @remarks
13
+ * 组件内部会自动生成唯一ID用于标识多边形,并在组件挂载时添加到地图,
14
+ * 更新时同步修改多边形属性,卸载时自动移除多边形。
15
+ *
16
+ * 注意:points数组长度必须大于等于3才能有效绘制多边形。
20
17
  */
21
18
  export default function Polygon(props: PolygonProps): null;
22
19
  //# sourceMappingURL=Polygon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Polygon.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Polygon.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,QAuElD"}
1
+ {"version":3,"file":"Polygon.d.ts","sourceRoot":"","sources":["../../../src/components/overlays/Polygon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,QAuDlD"}
@@ -1,98 +1,64 @@
1
- /*
2
- * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com
3
- * @Date : 2025-11-13 15:01:45
4
- * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com
5
- * @LastEditTime : 2025-11-13 19:24:22
6
- * @FilePath : /expo-gaode-map/src/components/overlays/Polygon.tsx
7
- * @Description : 地图多边形组件 - 命令式 API
8
- *
9
- * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved.
10
- */
11
1
  import { useContext, useEffect, useRef } from 'react';
12
2
  import { MapContext } from '../../ExpoGaodeMapView';
13
3
  /**
14
- * 地图多边形组件 - 命令式 API
4
+ * 高德地图多边形覆盖物组件
5
+ *
6
+ * @param props - 多边形配置属性
7
+ * @param props.points - 多边形顶点坐标数组,至少需要3个点
8
+ * @param props.fillColor - 多边形填充颜色,十六进制格式,默认0x440000FF
9
+ * @param props.strokeColor - 多边形边框颜色,默认-16776961
10
+ * @param props.strokeWidth - 多边形边框宽度,默认10
11
+ * @param props.zIndex - 多边形层级,默认0
15
12
  *
16
- * @example
17
- * ```tsx
18
- * <MapView>
19
- * <Polygon
20
- * points={[
21
- * { latitude: 39.9, longitude: 116.4 },
22
- * { latitude: 39.91, longitude: 116.41 },
23
- * { latitude: 39.92, longitude: 116.40 },
24
- * ]}
25
- * fillColor={0x44FF0000}
26
- * strokeColor={-65536}
27
- * strokeWidth={5}
28
- * />
29
- * </MapView>
30
- * ```
13
+ * @remarks
14
+ * 组件内部会自动生成唯一ID用于标识多边形,并在组件挂载时添加到地图,
15
+ * 更新时同步修改多边形属性,卸载时自动移除多边形。
16
+ *
17
+ * 注意:points数组长度必须大于等于3才能有效绘制多边形。
31
18
  */
32
19
  export default function Polygon(props) {
33
20
  const { points, fillColor, strokeColor, strokeWidth, zIndex } = props;
34
21
  const nativeRef = useContext(MapContext);
35
- const polygonIdRef = useRef(`polygon_${Date.now()}_${Math.random()}`);
22
+ const polygonIdRef = useRef(null);
23
+ const propsRef = useRef(props);
36
24
  useEffect(() => {
37
- const polygonId = polygonIdRef.current;
38
- // 添加多边形
39
- if (nativeRef?.current && points && points.length >= 3) {
40
- try {
41
- console.log('🟦 Polygon 组件调用 addPolygon:', polygonId, {
42
- points,
43
- fillColor: fillColor ?? 0x440000FF,
44
- strokeColor: strokeColor ?? -16776961,
45
- strokeWidth: strokeWidth ?? 10,
46
- zIndex: zIndex ?? 0,
47
- });
25
+ propsRef.current = props;
26
+ }, [props]);
27
+ useEffect(() => {
28
+ const checkAndAdd = () => {
29
+ if (!nativeRef?.current) {
30
+ setTimeout(checkAndAdd, 50);
31
+ return;
32
+ }
33
+ const polygonId = `polygon_${Date.now()}_${Math.random()}`;
34
+ polygonIdRef.current = polygonId;
35
+ const { points, fillColor, strokeColor, strokeWidth, zIndex } = propsRef.current;
36
+ if (points && points.length >= 3) {
48
37
  nativeRef.current.addPolygon(polygonId, {
49
38
  points,
50
- fillColor: fillColor ?? 0x440000FF,
51
- strokeColor: strokeColor ?? -16776961,
39
+ fillColor: fillColor ?? '#880000FF',
40
+ strokeColor: strokeColor ?? '#FFFF0000',
52
41
  strokeWidth: strokeWidth ?? 10,
53
42
  zIndex: zIndex ?? 0,
54
43
  });
55
- console.log('✅ Polygon addPolygon 调用完成');
56
44
  }
57
- catch (error) {
58
- console.error('❌ 添加多边形失败:', error);
59
- }
60
- }
61
- else {
62
- console.warn('⚠️ Polygon 组件条件不满足:', {
63
- hasNativeRef: !!nativeRef?.current,
64
- hasPoints: !!points,
65
- pointsLength: points?.length,
66
- });
67
- }
68
- // 清理函数
45
+ };
46
+ checkAndAdd();
69
47
  return () => {
70
- if (nativeRef?.current) {
71
- try {
72
- nativeRef.current.removePolygon(polygonId);
73
- }
74
- catch (error) {
75
- console.error('移除多边形失败:', error);
76
- }
48
+ if (polygonIdRef.current && nativeRef?.current) {
49
+ nativeRef.current.removePolygon(polygonIdRef.current);
77
50
  }
78
51
  };
79
52
  }, []);
80
- // 更新多边形属性
81
53
  useEffect(() => {
82
- const polygonId = polygonIdRef.current;
83
- if (nativeRef?.current) {
84
- try {
85
- nativeRef.current.updatePolygon(polygonId, {
86
- points,
87
- fillColor,
88
- strokeColor,
89
- strokeWidth,
90
- zIndex,
91
- });
92
- }
93
- catch (error) {
94
- console.error('更新多边形失败:', error);
95
- }
54
+ if (polygonIdRef.current && nativeRef?.current) {
55
+ nativeRef.current.updatePolygon(polygonIdRef.current, {
56
+ points,
57
+ fillColor,
58
+ strokeColor,
59
+ strokeWidth,
60
+ zIndex,
61
+ });
96
62
  }
97
63
  }, [points, fillColor, strokeColor, strokeWidth, zIndex]);
98
64
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"Polygon.js","sourceRoot":"","sources":["../../../src/components/overlays/Polygon.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACtE,MAAM,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,MAAM,CAAS,WAAW,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAE9E,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QAEvC,QAAQ;QACR,IAAI,SAAS,EAAE,OAAO,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACvD,IAAI,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,SAAS,EAAE;oBACpD,MAAM;oBACN,SAAS,EAAE,SAAS,IAAI,UAAU;oBAClC,WAAW,EAAE,WAAW,IAAI,CAAC,QAAQ;oBACrC,WAAW,EAAE,WAAW,IAAI,EAAE;oBAC9B,MAAM,E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,SAAS;oBACT,WAAW;oBACX,WAAW;oBACX,MAAM;iBACP,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1D,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*\n * @Author : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @Date : 2025-11-13 15:01:45\n * @LastEditors : 尚博信_王强 wangqiang03@sunboxsoft.com\n * @LastEditTime : 2025-11-13 19:24:22\n * @FilePath : /expo-gaode-map/src/components/overlays/Polygon.tsx\n * @Description : 地图多边形组件 - 命令式 API\n * \n * Copyright (c) 2025 by 尚博信_王强, All Rights Reserved. \n */\n\n\nimport { useContext, useEffect, useRef } from 'react';\nimport type { PolygonProps } from '../../types';\nimport { MapContext } from '../../ExpoGaodeMapView';\n\n/**\n * 地图多边形组件 - 命令式 API\n * \n * @example\n * ```tsx\n * <MapView>\n * <Polygon\n * points={[\n * { latitude: 39.9, longitude: 116.4 },\n * { latitude: 39.91, longitude: 116.41 },\n * { latitude: 39.92, longitude: 116.40 },\n * ]}\n * fillColor={0x44FF0000}\n * strokeColor={-65536}\n * strokeWidth={5}\n * />\n * </MapView>\n * ```\n */\nexport default function Polygon(props: PolygonProps) {\n const { points, fillColor, strokeColor, strokeWidth, zIndex } = props;\n const nativeRef = useContext(MapContext);\n const polygonIdRef = useRef<string>(`polygon_${Date.now()}_${Math.random()}`);\n\n useEffect(() => {\n const polygonId = polygonIdRef.current;\n\n // 添加多边形\n if (nativeRef?.current && points && points.length >= 3) {\n try {\n console.log('🟦 Polygon 组件调用 addPolygon:', polygonId, {\n points,\n fillColor: fillColor ?? 0x440000FF,\n strokeColor: strokeColor ?? -16776961,\n strokeWidth: strokeWidth ?? 10,\n zIndex: zIndex ?? 0,\n });\n \n nativeRef.current.addPolygon(polygonId, {\n points,\n fillColor: fillColor ?? 0x440000FF,\n strokeColor: strokeColor ?? -16776961,\n strokeWidth: strokeWidth ?? 10,\n zIndex: zIndex ?? 0,\n });\n \n console.log('✅ Polygon addPolygon 调用完成');\n } catch (error) {\n console.error('❌ 添加多边形失败:', error);\n }\n } else {\n console.warn('⚠️ Polygon 组件条件不满足:', {\n hasNativeRef: !!nativeRef?.current,\n hasPoints: !!points,\n pointsLength: points?.length,\n });\n }\n\n // 清理函数\n return () => {\n if (nativeRef?.current) {\n try {\n nativeRef.current.removePolygon(polygonId);\n } catch (error) {\n console.error('移除多边形失败:', error);\n }\n }\n };\n }, []);\n\n // 更新多边形属性\n useEffect(() => {\n const polygonId = polygonIdRef.current;\n\n if (nativeRef?.current) {\n try {\n nativeRef.current.updatePolygon(polygonId, {\n points,\n fillColor,\n strokeColor,\n strokeWidth,\n zIndex,\n });\n } catch (error) {\n console.error('更新多边形失败:', error);\n }\n }\n }, [points, fillColor, strokeColor, strokeWidth, zIndex]);\n\n return null;\n}\n"]}
1
+ {"version":3,"file":"Polygon.js","sourceRoot":"","sources":["../../../src/components/overlays/Polygon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAmB;IACjD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACtE,MAAM,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CA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OAAO,EAAE,CAAC;YAC/C,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE;gBACpD,MAAM;gBACN,SAAS;gBACT,WAAW;gBACX,WAAW;gBACX,MAAM;aACP,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1D,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { useContext, useEffect, useRef } from 'react';\nimport type { PolygonProps } from '../../types';\nimport { MapContext } from '../../ExpoGaodeMapView';\n\n\n/**\n * 高德地图多边形覆盖物组件\n * \n * @param props - 多边形配置属性\n * @param props.points - 多边形顶点坐标数组,至少需要3个点\n * @param props.fillColor - 多边形填充颜色,十六进制格式,默认0x440000FF\n * @param props.strokeColor - 多边形边框颜色,默认-16776961\n * @param props.strokeWidth - 多边形边框宽度,默认10\n * @param props.zIndex - 多边形层级,默认0\n * \n * @remarks\n * 组件内部会自动生成唯一ID用于标识多边形,并在组件挂载时添加到地图,\n * 更新时同步修改多边形属性,卸载时自动移除多边形。\n * \n * 注意:points数组长度必须大于等于3才能有效绘制多边形。\n */\nexport default function Polygon(props: PolygonProps) {\n const { points, fillColor, strokeColor, strokeWidth, zIndex } = props;\n const nativeRef = useContext(MapContext);\n const polygonIdRef = useRef<string | null>(null);\n const propsRef = useRef(props);\n \n useEffect(() => {\n propsRef.current = props;\n }, [props]);\n\n useEffect(() => {\n const checkAndAdd = () => {\n if (!nativeRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const polygonId = `polygon_${Date.now()}_${Math.random()}`;\n polygonIdRef.current = polygonId;\n \n const { points, fillColor, strokeColor, strokeWidth, zIndex } = propsRef.current;\n \n if (points && points.length >= 3) {\n nativeRef.current.addPolygon(polygonId, {\n points,\n fillColor: fillColor ?? '#880000FF',\n strokeColor: strokeColor ?? '#FFFF0000',\n strokeWidth: strokeWidth ?? 10,\n zIndex: zIndex ?? 0,\n });\n }\n };\n \n checkAndAdd();\n \n return () => {\n if (polygonIdRef.current && nativeRef?.current) {\n nativeRef.current.removePolygon(polygonIdRef.current);\n }\n };\n }, []);\n\n useEffect(() => {\n if (polygonIdRef.current && nativeRef?.current) {\n nativeRef.current.updatePolygon(polygonIdRef.current, {\n points,\n fillColor,\n strokeColor,\n strokeWidth,\n zIndex,\n });\n }\n }, [points, fillColor, strokeColor, strokeWidth, zIndex]);\n\n return null;\n}\n"]}