@heycar/heycars-map 2.0.0-switchMap1 → 2.0.0-switchMap3

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 (96) hide show
  1. package/README.md +43 -29
  2. package/dist/v2/App.js +5 -3
  3. package/dist/v2/Demo/DemoBusinessQuoting.js +3 -2
  4. package/dist/v2/Demo/DemoBusinessRecomendPlace.js +1 -1
  5. package/dist/v2/api/cdn.d.ts +1 -0
  6. package/dist/v2/api/cdn.js +2 -0
  7. package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
  8. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -2
  9. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +2 -1
  10. package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  11. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +2 -2
  12. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +18 -11
  13. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
  14. package/dist/v2/chunks/{BusinessRecomendPlaceMap.5be4fdcf.js → BusinessRecomendPlaceMap.f589ebf7.js} +17 -10
  15. package/dist/v2/chunks/{Loading.fc6e75d0.js → Loading.da68a2a6.js} +31 -1
  16. package/dist/v2/chunks/throttle.8bdd8d3b.js +20 -0
  17. package/dist/v2/components/Loading/Loading.css.d.ts +5 -0
  18. package/dist/v2/components/Loading/Loading.d.ts +6 -0
  19. package/dist/v2/components/Loading/Loading.js +3 -1
  20. package/dist/v2/components/Loading/index.js +2 -1
  21. package/dist/v2/components/MapProvider/MapProvider.d.ts +2 -2
  22. package/dist/v2/components/MapProvider/MapProvider.js +16 -9
  23. package/dist/v2/css/Loading-0e058b68.css +51 -0
  24. package/dist/v2/hooks/useDeviceOrientation.js +1 -17
  25. package/dist/v2/hooks/useMapGCJ02.js +1 -3
  26. package/dist/v2/hooks/useMapGraspRoad.js +1 -2
  27. package/dist/v2/hooks/useMapInChina.d.ts +3 -15
  28. package/dist/v2/hooks/useMapInChina.js +11 -16
  29. package/dist/v2/hooks/useMapLoader.d.ts +10 -6
  30. package/dist/v2/hooks/useMapLoader.js +88 -59
  31. package/dist/v2/hooks/useMapPlace.d.ts +1 -0
  32. package/dist/v2/hooks/useMapPlace.js +10 -9
  33. package/dist/v2/hooks/useMapRecomendPlace.d.ts +1 -0
  34. package/dist/v2/hooks/useMapRecomendPlace.js +72 -64
  35. package/dist/v2/hooks/useMapSupplier.d.ts +6 -0
  36. package/dist/v2/hooks/useMapSupplier.js +17 -0
  37. package/dist/v2/hooks-business/useBusinessQuotingMap.d.ts +2 -0
  38. package/dist/v2/hooks-business/useBusinessQuotingMap.js +7 -2
  39. package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  40. package/dist/v2/index.js +1 -1
  41. package/dist/v2/utils/ManualAbortError.d.ts +3 -0
  42. package/dist/v2/utils/ManualAbortError.js +14 -0
  43. package/dist/v2/utils/helper.d.ts +1 -0
  44. package/dist/v2/utils/helper.js +17 -0
  45. package/dist/v2/utils/log.js +1 -1
  46. package/dist/v2/utils/patchGoogleMapLoader.d.ts +2 -0
  47. package/dist/v2/utils/patchGoogleMapLoader.js +64 -0
  48. package/dist/v3/App.js +5 -3
  49. package/dist/v3/Demo/DemoBusinessQuoting.js +4 -3
  50. package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
  51. package/dist/v3/api/cdn.d.ts +1 -0
  52. package/dist/v3/api/cdn.js +2 -0
  53. package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
  54. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -2
  55. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +2 -1
  56. package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  57. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +2 -2
  58. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +18 -11
  59. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
  60. package/dist/v3/chunks/{BusinessRecomendPlaceMap.39888296.js → BusinessRecomendPlaceMap.86e9c287.js} +17 -10
  61. package/dist/v3/chunks/{Loading.a8e2f26a.js → Loading.98d687c0.js} +27 -1
  62. package/dist/v3/chunks/throttle.8bdd8d3b.js +20 -0
  63. package/dist/v3/components/Loading/Loading.css.d.ts +5 -0
  64. package/dist/v3/components/Loading/Loading.d.ts +8 -0
  65. package/dist/v3/components/Loading/Loading.js +3 -1
  66. package/dist/v3/components/Loading/index.js +2 -1
  67. package/dist/v3/components/MapProvider/MapProvider.d.ts +6 -3
  68. package/dist/v3/components/MapProvider/MapProvider.js +14 -9
  69. package/dist/v3/css/Loading-0e058b68.css +51 -0
  70. package/dist/v3/hooks/useDeviceOrientation.js +1 -17
  71. package/dist/v3/hooks/useMapGCJ02.js +1 -3
  72. package/dist/v3/hooks/useMapGraspRoad.js +1 -2
  73. package/dist/v3/hooks/useMapInChina.d.ts +3 -15
  74. package/dist/v3/hooks/useMapInChina.js +11 -16
  75. package/dist/v3/hooks/useMapLoader.d.ts +10 -6
  76. package/dist/v3/hooks/useMapLoader.js +88 -59
  77. package/dist/v3/hooks/useMapPlace.d.ts +1 -0
  78. package/dist/v3/hooks/useMapPlace.js +10 -9
  79. package/dist/v3/hooks/useMapRecomendPlace.d.ts +1 -0
  80. package/dist/v3/hooks/useMapRecomendPlace.js +72 -64
  81. package/dist/v3/hooks/useMapSupplier.d.ts +6 -0
  82. package/dist/v3/hooks/useMapSupplier.js +17 -0
  83. package/dist/v3/hooks-business/useBusinessQuotingMap.d.ts +2 -0
  84. package/dist/v3/hooks-business/useBusinessQuotingMap.js +7 -2
  85. package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  86. package/dist/v3/index.js +1 -1
  87. package/dist/v3/utils/ManualAbortError.d.ts +3 -0
  88. package/dist/v3/utils/ManualAbortError.js +14 -0
  89. package/dist/v3/utils/helper.d.ts +1 -0
  90. package/dist/v3/utils/helper.js +17 -0
  91. package/dist/v3/utils/log.js +1 -1
  92. package/dist/v3/utils/patchGoogleMapLoader.d.ts +2 -0
  93. package/dist/v3/utils/patchGoogleMapLoader.js +64 -0
  94. package/package.json +2 -2
  95. package/dist/v2/css/Loading-523061b9.css +0 -9
  96. package/dist/v3/css/Loading-523061b9.css +0 -9
@@ -5,8 +5,8 @@ import { type GmapLoaderProps, type UseMapLoaderProps } from "../../hooks/useMap
5
5
  import { type MapSupplierPayolad } from "../../hooks/useMapSupplier";
6
6
  import type { AmapMap } from "../../types/interface";
7
7
  import { type AmapProps } from "../Amap";
8
- export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId">;
9
- export declare const MapProvider: import("vue").DefineComponent<import("vue3").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "change", MapProviderProps>;
8
+ export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "renderLoadFailedTitle" | "renderLoadFailedDescription">;
9
+ export declare const MapProvider: import("vue").DefineComponent<import("vue3").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "success" | "fail", MapProviderProps>;
10
10
  export interface HeycarMapProps extends Pick<GmapLoaderProps, "fallback" | "loading">, Pick<AmapProps, "center" | "zoom"> {
11
11
  mapRef?: SetMap<AmapMap> | SetMap<google.maps.Map>;
12
12
  outerArea?: () => VueNode;
@@ -1,6 +1,6 @@
1
1
  import "../../css/MapProvider-156bfd53.css";
2
2
  import { h } from "vue";
3
- import { L as Loading, i as imgGrid } from "../../chunks/Loading.fc6e75d0.js";
3
+ import { L as Loading, a as LoadFailed, i as imgGrid } from "../../chunks/Loading.da68a2a6.js";
4
4
  import { useMapLoader, Status } from "../../hooks/useMapLoader.js";
5
5
  import { provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier.js";
6
6
  import { defineLagecySetup } from "../../types/helper.js";
@@ -36,7 +36,7 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
36
36
  var _a;
37
37
  return h("div", [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
38
38
  };
39
- }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language"]);
39
+ }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "renderLoadFailedTitle", "renderLoadFailedDescription"]);
40
40
  const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
41
41
  slots,
42
42
  emit,
@@ -64,7 +64,7 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
64
64
  const handleResize = () => emit("resize");
65
65
  loadTraditionalChineseConvertOnce(payload.language === "zh-TW");
66
66
  return () => {
67
- var _a, _b, _c, _d, _e, _f;
67
+ var _a, _b, _c, _d, _e, _f, _g, _h;
68
68
  const {
69
69
  supplier,
70
70
  gmapId,
@@ -83,12 +83,19 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
83
83
  const node = (_a = slots.loading) == null ? void 0 : _a.call(slots);
84
84
  return node ? h("div", [node]) : h(Loading);
85
85
  }
86
- if (status === Status.FAILURE) {
86
+ if (status === Status.FAILURE || status === Status.TIMEOUT) {
87
87
  const node = (_b = slots.fallback) == null ? void 0 : _b.call(slots);
88
- return node ? h("div", [node]) : h(Loading);
88
+ const title = (_c = payload.renderLoadFailedTitle) == null ? void 0 : _c.call(payload, status);
89
+ const description = (_d = payload.renderLoadFailedDescription) == null ? void 0 : _d.call(payload, status);
90
+ return node ? h("div", [node]) : h(LoadFailed, {
91
+ "attrs": {
92
+ "title": title,
93
+ "description": description
94
+ }
95
+ });
89
96
  }
90
- const children = (_c = slots.default) == null ? void 0 : _c.call(slots);
91
- const outArea = (_d = slots.outerArea) == null ? void 0 : _d.call(slots);
97
+ const children = (_e = slots.default) == null ? void 0 : _e.call(slots);
98
+ const outArea = (_f = slots.outerArea) == null ? void 0 : _f.call(slots);
92
99
  const mapId = patchGmapIdForAlipayCompatible({
93
100
  gmapId,
94
101
  gmapRasterId,
@@ -98,7 +105,7 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
98
105
  switch (supplier) {
99
106
  case "gmap":
100
107
  return h("div", {
101
- "class": `${heycarMap} ${(_e = attrs.class) != null ? _e : ""}`,
108
+ "class": `${heycarMap} ${(_g = attrs.class) != null ? _g : ""}`,
102
109
  "attrs": {
103
110
  "lang": language
104
111
  },
@@ -129,7 +136,7 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
129
136
  }), outArea]);
130
137
  default:
131
138
  return h("div", {
132
- "class": `${heycarMap} ${(_f = attrs.class) != null ? _f : ""}`,
139
+ "class": `${heycarMap} ${(_h = attrs.class) != null ? _h : ""}`,
133
140
  "attrs": {
134
141
  "lang": language
135
142
  },
@@ -0,0 +1,51 @@
1
+ ._17ify490 {
2
+ position: relative;
3
+ background-color: #EDF1F5;
4
+ }
5
+ ._17ify491 {
6
+ width: 100%;
7
+ height: 100%;
8
+ object-fit: cover;
9
+ }
10
+ ._17ify492 {
11
+ position: absolute;
12
+ margin: auto;
13
+ top: 0;
14
+ left: 0;
15
+ right: 0;
16
+ bottom: 0;
17
+ width: fit-content;
18
+ height: fit-content;
19
+ }
20
+ ._17ify493 {
21
+ width: 40.8vw;
22
+ height: 24.53vw;
23
+ }
24
+ ._17ify494 {
25
+ position: absolute;
26
+ top: 100%;
27
+ display: flex;
28
+ flex-direction: column;
29
+ align-items: center;
30
+ width: max-content;
31
+ left: 50%;
32
+ transform: translate(-50%, 0);
33
+ }
34
+ ._17ify495 {
35
+ margin-top: 1.6vw;
36
+ font-family: var(--HEYCAR_MAP_CSS_VAR_FONT_REGULAR);
37
+ font-weight: 500;
38
+ font-size: 4vw;
39
+ color: #1E1E1E;
40
+ line-height: 6.4vw;
41
+ }
42
+ ._17ify496 {
43
+ margin-top: 1.6vw;
44
+ font-family: var(--HEYCAR_MAP_CSS_VAR_FONT_REGULAR);
45
+ font-weight: 400;
46
+ font-size: 3.73vw;
47
+ color: #999BA1;
48
+ line-height: 6.4vw;
49
+ white-space: pre-line;
50
+ text-align: center;
51
+ }
@@ -1,23 +1,7 @@
1
1
  import { reactive, watch } from "vue-demi";
2
2
  import { MINI_PROGRAM_WEB_VIEW_CLOSE_EVENT } from "../utils/patchMiniprogram.js";
3
3
  import { OS_PLATFORM, detectOSPlatform } from "../utils/platform.js";
4
- import { i as isObject, d as debounce } from "../chunks/debounce.5afe7867.js";
5
- var FUNC_ERROR_TEXT = "Expected a function";
6
- function throttle(func, wait, options) {
7
- var leading = true, trailing = true;
8
- if (typeof func != "function") {
9
- throw new TypeError(FUNC_ERROR_TEXT);
10
- }
11
- if (isObject(options)) {
12
- leading = "leading" in options ? !!options.leading : leading;
13
- trailing = "trailing" in options ? !!options.trailing : trailing;
14
- }
15
- return debounce(func, wait, {
16
- "leading": leading,
17
- "maxWait": wait,
18
- "trailing": trailing
19
- });
20
- }
4
+ import { t as throttle } from "../chunks/throttle.8bdd8d3b.js";
21
5
  const DEVICE_ORIENTATION_INTERVAL = 200;
22
6
  const CSS_DEVICE_ORIENTATION_VAR_PREFIX = "--CSS_DEVICE_ORIENTATION_VAR_ROTATION_DEGREE_";
23
7
  const useDeviceOrientation = (props) => {
@@ -1,6 +1,6 @@
1
1
  import { AMAP_TO_GCJ02_TIMEOUT } from "../api/contants.js";
2
2
  import { lnglat2point } from "../utils/transform.js";
3
- import { useMapInChina } from "./useMapInChina.js";
3
+ import { inChina, inHongkong, inMacau } from "./useMapInChina.js";
4
4
  import { useMapSupplier } from "./useMapSupplier.js";
5
5
  /**
6
6
  * @preserve
@@ -515,7 +515,6 @@ const exported = Object.assign(Object.assign({}, CRSTypes), {
515
515
  });
516
516
  const useAmapGCJ02 = () => {
517
517
  const { readyPromise } = useMapSupplier();
518
- const { inChina } = useMapInChina();
519
518
  const toCoordinateType = (p) => {
520
519
  return inChina(p) ? "gcj02" : "wgs84";
521
520
  };
@@ -567,7 +566,6 @@ const useAmapGCJ02 = () => {
567
566
  };
568
567
  const useGmapGCJ02 = () => {
569
568
  const { readyPromise } = useMapSupplier();
570
- const { inChina, inHongkong, inMacau } = useMapInChina();
571
569
  const toCoordinateType = (p) => {
572
570
  return inChina(p) && !inHongkong(p) && !inMacau(p) ? "gcj02" : "wgs84";
573
571
  };
@@ -3,7 +3,7 @@ import { apiGoogleSnapRoad } from "../api/googleSnapRoad.js";
3
3
  import { watchEffectForDeepOption } from "../utils/compare.js";
4
4
  import { lnglat2point, trackPoints2amapGraspRoadPoints } from "../utils/transform.js";
5
5
  import { useMapAngle } from "./useMapAngle.js";
6
- import { useMapInChina } from "./useMapInChina.js";
6
+ import { inChina } from "./useMapInChina.js";
7
7
  import { useMapSupplier } from "./useMapSupplier.js";
8
8
  const GRASP_ROAD_INPUT_MIN_AMOUNT = 2;
9
9
  const GRASP_ROAD_INPUT_MAX_AMOUNT = 500;
@@ -12,7 +12,6 @@ const useAmapGraspRoad = (props) => {
12
12
  const pathRef = ref([]);
13
13
  const angleRef = ref(0);
14
14
  const { apiMapComputeHeading } = useMapAngle();
15
- const { inChina } = useMapInChina();
16
15
  const apiMapToGraspRoadPath = (tracks) => {
17
16
  return new Promise((resolve) => {
18
17
  var _a, _b, _c;
@@ -1,16 +1,4 @@
1
1
  import { type Point } from "../types/interface";
2
- export declare const useMapInChina: () => {
3
- inChina: (point: Point) => boolean;
4
- inHongkong: (point: Point) => boolean;
5
- inMacau: (point: Point) => boolean;
6
- };
7
- export declare const useAmapInChina: () => {
8
- inChina: (point: Point) => boolean;
9
- inHongkong: (point: Point) => boolean;
10
- inMacau: (point: Point) => boolean;
11
- };
12
- export declare const useGmapInChina: () => {
13
- inChina: (point: Point) => boolean;
14
- inHongkong: (point: Point) => boolean;
15
- inMacau: (point: Point) => boolean;
16
- };
2
+ export declare const inChina: (point: Point) => boolean;
3
+ export declare const inHongkong: (point: Point) => boolean;
4
+ export declare const inMacau: (point: Point) => boolean;
@@ -2593,22 +2593,17 @@ const macauBounds = [
2593
2593
  22.19885
2594
2594
  ]
2595
2595
  ];
2596
- const useMapInChina = () => {
2597
- const inChina = (point) => {
2598
- return pointInPolygon(point, chinaBounds) >= 0;
2599
- };
2600
- const inHongkong = (point) => {
2601
- return pointInPolygon(point, hongkongBounds) >= 0;
2602
- };
2603
- const inMacau = (point) => {
2604
- return pointInPolygon(point, macauBounds) >= 0;
2605
- };
2606
- return { inChina, inHongkong, inMacau };
2596
+ const inChina = (point) => {
2597
+ return pointInPolygon(point, chinaBounds) >= 0;
2598
+ };
2599
+ const inHongkong = (point) => {
2600
+ return pointInPolygon(point, hongkongBounds) >= 0;
2601
+ };
2602
+ const inMacau = (point) => {
2603
+ return pointInPolygon(point, macauBounds) >= 0;
2607
2604
  };
2608
- const useAmapInChina = useMapInChina;
2609
- const useGmapInChina = useMapInChina;
2610
2605
  export {
2611
- useAmapInChina,
2612
- useGmapInChina,
2613
- useMapInChina
2606
+ inChina,
2607
+ inHongkong,
2608
+ inMacau
2614
2609
  };
@@ -7,6 +7,7 @@ export declare const DEFAULT_AMAP_PLUGINS: AmapLoaderProps["plugins"];
7
7
  export declare const DEFAULT_GMAP_LIBRARIES: LoaderOptions["libraries"];
8
8
  export declare enum Status {
9
9
  LOADING = "LOADING",
10
+ TIMEOUT = "TIMEOUT",
10
11
  FAILURE = "FAILURE",
11
12
  SUCCESS = "SUCCESS"
12
13
  }
@@ -19,7 +20,7 @@ declare global {
19
20
  };
20
21
  }
21
22
  }
22
- export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loading" | "onChange">, Omit<AMapLoaderOptions, "key" | "version" | "plugins"> {
23
+ export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loading" | "onSuccess" | "onFail">, Omit<AMapLoaderOptions, "key" | "version" | "plugins"> {
23
24
  apiKey: string;
24
25
  apiSecret?: string;
25
26
  apiServiceHost?: string;
@@ -42,11 +43,13 @@ export interface GmapLoaderProps extends LoaderOptions {
42
43
  */
43
44
  fallback?: () => VNodeChild;
44
45
  /**
45
- * Callback prop used to access `@googlemaps/js-api-loader` and `Status`.
46
- *
47
- * Note: The callback be executed multiple times in the lifecycle of the component.
46
+ * 成功回调只会触发一次
48
47
  */
49
- onChange?: (status: Status) => void;
48
+ onSuccess?: () => void;
49
+ /**
50
+ * 失败回调可能会触发多次
51
+ */
52
+ onFail?: () => void;
50
53
  }
51
54
  export declare const useGmapLoader: (props: GmapLoaderProps) => {
52
55
  statusRef: import("vue-demi").ShallowRef<Status>;
@@ -64,7 +67,8 @@ export interface UseMapLoaderProps {
64
67
  amapServiceHost?: string;
65
68
  supplier: MapSupplier;
66
69
  language: Language;
67
- onChange?: (status: Status) => any;
70
+ onSuccess?: () => void;
71
+ onFail?: () => void;
68
72
  }
69
73
  export declare const useMapLoader: (props: UseMapLoaderProps) => UseMapLoaderOutput;
70
74
  export {};
@@ -1,6 +1,8 @@
1
- import { shallowRef, computed } from "vue-demi";
1
+ import { shallowRef, computed, ref } from "vue-demi";
2
2
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
3
  import { createRunOnce } from "../utils/helper.js";
4
+ import { patchGoogleMapLoader } from "../utils/patchGoogleMapLoader.js";
5
+ import { t as throttle } from "../chunks/throttle.8bdd8d3b.js";
4
6
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
5
7
  var distExports = {};
6
8
  var dist = {
@@ -537,6 +539,8 @@ class Loader {
537
539
  }
538
540
  }
539
541
  }
542
+ const MIN_MAP_RELOAD_INTERVAL = 5e3;
543
+ const GMAP_LOAD_TIMEOUT = 1e4;
540
544
  const DEFAULT_AMAP_PLUGINS = [
541
545
  "AMap.Geocoder",
542
546
  "AMap.Driving",
@@ -546,12 +550,13 @@ const DEFAULT_AMAP_PLUGINS = [
546
550
  const DEFAULT_GMAP_LIBRARIES = ["marker", "geometry"];
547
551
  var Status = /* @__PURE__ */ ((Status2) => {
548
552
  Status2["LOADING"] = "LOADING";
553
+ Status2["TIMEOUT"] = "TIMEOUT";
549
554
  Status2["FAILURE"] = "FAILURE";
550
555
  Status2["SUCCESS"] = "SUCCESS";
551
556
  return Status2;
552
557
  })(Status || {});
553
558
  const useAmapLoader = (props) => {
554
- const { disableRef, onChange } = props;
559
+ const { disableRef, onSuccess, onFail } = props;
555
560
  let resolveLoader;
556
561
  let rejectLoader;
557
562
  const readyPromise = new Promise((resolve, reject) => {
@@ -563,49 +568,58 @@ const useAmapLoader = (props) => {
563
568
  /* LOADING */
564
569
  );
565
570
  const optionsRef = computed(() => {
566
- const { onChange: onChange2, loading, fallback, apiKey, apiSecret, apiServiceHost, version, ...options } = props;
571
+ const {
572
+ onSuccess: onSuccess2,
573
+ onFail: onFail2,
574
+ loading,
575
+ fallback,
576
+ apiKey,
577
+ apiSecret,
578
+ apiServiceHost,
579
+ version,
580
+ ...options
581
+ } = props;
567
582
  return { ...options, key: apiKey, version: version != null ? version : "2.0" };
568
583
  });
584
+ const defineSecurityOnce = createRunOnce(() => {
585
+ window._AMapSecurityConfig = props.apiServiceHost ? {
586
+ serviceHost: props.apiServiceHost
587
+ } : { securityJsCode: props.apiSecret };
588
+ });
589
+ const reload = throttle(
590
+ (options) => {
591
+ if (statusRef.value === "SUCCESS")
592
+ return;
593
+ statusRef.value = "LOADING";
594
+ defineSecurityOnce();
595
+ return distExports.load(options).then(
596
+ () => {
597
+ statusRef.value = "SUCCESS";
598
+ resolveLoader();
599
+ onSuccess == null ? void 0 : onSuccess();
600
+ },
601
+ () => {
602
+ statusRef.value = "FAILURE";
603
+ rejectLoader();
604
+ onFail == null ? void 0 : onFail();
605
+ }
606
+ );
607
+ },
608
+ MIN_MAP_RELOAD_INTERVAL,
609
+ { trailing: false }
610
+ );
569
611
  watchPostEffectForDeepOption(
570
612
  () => [optionsRef.value, disableRef == null ? void 0 : disableRef.value],
571
613
  ([options, disable]) => {
572
614
  if (disable)
573
615
  return;
574
- const setStatusAndExecuteCallback = (status) => {
575
- statusRef.value = status;
576
- if (status === "SUCCESS")
577
- resolveLoader();
578
- if (status === "FAILURE")
579
- rejectLoader();
580
- onChange == null ? void 0 : onChange(statusRef.value);
581
- };
582
- setStatusAndExecuteCallback(
583
- "LOADING"
584
- /* LOADING */
585
- );
586
- window._AMapSecurityConfig = props.apiServiceHost ? {
587
- serviceHost: props.apiServiceHost
588
- } : { securityJsCode: props.apiSecret };
589
- distExports.load(options).then(
590
- () => setStatusAndExecuteCallback(
591
- "SUCCESS"
592
- /* SUCCESS */
593
- ),
594
- () => setStatusAndExecuteCallback(
595
- "FAILURE"
596
- /* FAILURE */
597
- )
598
- );
616
+ reload(options);
599
617
  }
600
618
  );
601
619
  return { statusRef, readyPromise };
602
620
  };
603
- const loadGmapOnce = createRunOnce((opts) => {
604
- const loader = new Loader(opts);
605
- return loader.load();
606
- });
607
621
  const useGmapLoader = (props) => {
608
- const { disableRef, onChange } = props;
622
+ const { disableRef, onSuccess, onFail } = props;
609
623
  let resolveLoader;
610
624
  let rejectLoader;
611
625
  const readyPromise = new Promise((resolve, reject) => {
@@ -617,50 +631,64 @@ const useGmapLoader = (props) => {
617
631
  /* LOADING */
618
632
  );
619
633
  const optionsRef = computed(() => {
620
- const { onChange: onChange2, fallback, loading, language, ...options } = props;
634
+ const { onSuccess: onSuccess2, onFail: onFail2, fallback, loading, language, ...options } = props;
621
635
  return options;
622
636
  });
637
+ const timerRef = ref();
638
+ const reload = throttle(
639
+ (options) => {
640
+ if (statusRef.value === "SUCCESS")
641
+ return;
642
+ const loader = new Loader(options);
643
+ patchGoogleMapLoader(loader);
644
+ clearTimeout(timerRef.value);
645
+ timerRef.value = window.setTimeout(() => {
646
+ statusRef.value = "TIMEOUT";
647
+ }, GMAP_LOAD_TIMEOUT);
648
+ if (loader.status !== LoaderStatus.INITIALIZED) {
649
+ window.google = void 0;
650
+ loader.reset();
651
+ }
652
+ statusRef.value = "LOADING";
653
+ return loader.load().then(
654
+ () => {
655
+ clearTimeout(timerRef.value);
656
+ statusRef.value = "SUCCESS";
657
+ resolveLoader();
658
+ onSuccess == null ? void 0 : onSuccess();
659
+ },
660
+ () => {
661
+ clearTimeout(timerRef.value);
662
+ statusRef.value = "FAILURE";
663
+ rejectLoader();
664
+ onFail == null ? void 0 : onFail();
665
+ }
666
+ );
667
+ },
668
+ MIN_MAP_RELOAD_INTERVAL,
669
+ { trailing: false }
670
+ );
623
671
  watchPostEffectForDeepOption(
624
672
  () => [optionsRef.value, disableRef == null ? void 0 : disableRef.value],
625
673
  ([options, disable]) => {
626
674
  if (disable)
627
675
  return;
628
676
  const language = navigator.language;
629
- const setStatusAndExecuteCallback = (status) => {
630
- statusRef.value = status;
631
- if (status === "SUCCESS")
632
- resolveLoader();
633
- if (status === "FAILURE")
634
- rejectLoader();
635
- onChange == null ? void 0 : onChange(statusRef.value);
636
- };
637
- setStatusAndExecuteCallback(
638
- "LOADING"
639
- /* LOADING */
640
- );
641
- loadGmapOnce({ ...options, language }).then(
642
- () => setStatusAndExecuteCallback(
643
- "SUCCESS"
644
- /* SUCCESS */
645
- ),
646
- () => setStatusAndExecuteCallback(
647
- "FAILURE"
648
- /* FAILURE */
649
- )
650
- );
677
+ reload({ ...options, language });
651
678
  }
652
679
  );
653
680
  return { statusRef, readyPromise };
654
681
  };
655
682
  const useMapLoader = (props) => {
656
- const { gmapKey, amapKey, amapSecret, amapServiceHost, language, onChange } = props;
683
+ const { gmapKey, amapKey, amapSecret, amapServiceHost, language, onSuccess, onFail } = props;
657
684
  const { statusRef: amapStatusRef, readyPromise: amapReadyPromise } = useAmapLoader({
658
685
  apiKey: amapKey,
659
686
  apiSecret: amapSecret,
660
687
  apiServiceHost: amapServiceHost,
661
688
  plugins: DEFAULT_AMAP_PLUGINS,
662
689
  disableRef: computed(() => props.supplier !== "amap"),
663
- onChange
690
+ onSuccess,
691
+ onFail
664
692
  });
665
693
  const { statusRef: gmapStatusRef, readyPromise: gmapReadyPromise } = useGmapLoader({
666
694
  apiKey: gmapKey,
@@ -670,7 +698,8 @@ const useMapLoader = (props) => {
670
698
  // region: "CN",
671
699
  libraries: DEFAULT_GMAP_LIBRARIES,
672
700
  disableRef: computed(() => props.supplier !== "gmap"),
673
- onChange
701
+ onSuccess,
702
+ onFail
674
703
  });
675
704
  return {
676
705
  get statusRef() {
@@ -3,6 +3,7 @@ import type { Place, Point } from "../types/interface";
3
3
  export interface UseMapPlaceProps {
4
4
  pointRef: Ref<Point>;
5
5
  emptyPlaceName: string;
6
+ signal?: AbortSignal;
6
7
  onChange?: (value: Place) => any;
7
8
  }
8
9
  export declare const useAmapPlace: (props: UseMapPlaceProps) => {
@@ -1,23 +1,23 @@
1
1
  import { ref, reactive, watch } from "vue-demi";
2
2
  import { REGEO_TIMEOUT } from "../api/contants.js";
3
3
  import { createPipeTw } from "../utils/cn2tw.js";
4
- import { equalAssign } from "../utils/helper.js";
4
+ import { equalAssign, createAbortable } from "../utils/helper.js";
5
5
  import { amapPlaceName2DisplayName, gmapPlaceName2DisplayName } from "../utils/transform.js";
6
- import { useAmapInChina } from "./useMapInChina.js";
6
+ import { inChina } from "./useMapInChina.js";
7
7
  import { useMapSupplier } from "./useMapSupplier.js";
8
8
  import { useUpdate } from "./useUdate.js";
9
9
  const useAmapPlace = (props) => {
10
- const { onChange, emptyPlaceName } = props;
10
+ const { signal, onChange, emptyPlaceName } = props;
11
11
  const defaultPoint = [...props.pointRef.value];
12
12
  const pointRef = ref(defaultPoint);
13
13
  const { readyPromise, language } = useMapSupplier();
14
- const { inChina } = useAmapInChina();
15
14
  const place = reactive({
16
15
  lng: pointRef.value[0],
17
16
  lat: pointRef.value[1],
18
17
  name: "",
19
18
  displayName: ""
20
19
  });
20
+ const abortable = createAbortable(signal);
21
21
  const { idx: placeKey, update } = useUpdate();
22
22
  const updatePlace = (value) => {
23
23
  pointRef.value = value;
@@ -29,7 +29,7 @@ const useAmapPlace = (props) => {
29
29
  place.name = value.name;
30
30
  place.displayName = value.displayName;
31
31
  };
32
- const getPlaceByRegeo = ([lng, lat]) => {
32
+ const getPlaceByRegeo = abortable(([lng, lat]) => {
33
33
  return new Promise((resolve) => {
34
34
  const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
35
35
  const pipeTw = createPipeTw(language === "zh-TW");
@@ -59,7 +59,7 @@ const useAmapPlace = (props) => {
59
59
  resolve({ lng, lat, name, displayName });
60
60
  }, REGEO_TIMEOUT);
61
61
  });
62
- };
62
+ });
63
63
  watch(
64
64
  () => [placeKey.value],
65
65
  async () => {
@@ -72,7 +72,7 @@ const useAmapPlace = (props) => {
72
72
  return { place, updatePlace, setPlace, getPlaceByRegeo };
73
73
  };
74
74
  const useGmapPlace = (props) => {
75
- const { onChange, emptyPlaceName } = props;
75
+ const { signal, onChange, emptyPlaceName } = props;
76
76
  const defaultPoint = [...props.pointRef.value];
77
77
  const pointRef = ref(defaultPoint);
78
78
  const { readyPromise, language } = useMapSupplier();
@@ -83,6 +83,7 @@ const useGmapPlace = (props) => {
83
83
  name: "",
84
84
  displayName: ""
85
85
  });
86
+ const abortable = createAbortable(signal);
86
87
  const updatePlace = (value) => {
87
88
  pointRef.value = value;
88
89
  update();
@@ -93,7 +94,7 @@ const useGmapPlace = (props) => {
93
94
  place.name = value.name;
94
95
  place.displayName = value.displayName;
95
96
  };
96
- const getPlaceByRegeo = ([lng, lat]) => {
97
+ const getPlaceByRegeo = abortable(([lng, lat]) => {
97
98
  return new Promise((resolve) => {
98
99
  const geocoder = new google.maps.Geocoder();
99
100
  const pipeTw = createPipeTw(language === "zh-TW");
@@ -114,7 +115,7 @@ const useGmapPlace = (props) => {
114
115
  resolve({ lng, lat, name, displayName });
115
116
  }, REGEO_TIMEOUT);
116
117
  });
117
- };
118
+ });
118
119
  watch(
119
120
  () => placeKey.value,
120
121
  async () => {
@@ -5,6 +5,7 @@ export interface UseMapRecomendPlaceProps<C = Record<string, any>> {
5
5
  context?: C;
6
6
  emptyPlaceName: string;
7
7
  queryingPlaceName: string;
8
+ signal?: AbortSignal;
8
9
  getLimit: (context?: C) => number;
9
10
  getAvailable?: (place: Place) => Promise<boolean>;
10
11
  getRecomendPlace: (place: Place, context?: C) => Promise<RecommendZonePlaces | undefined>;