@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
@@ -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>;
@@ -1,6 +1,7 @@
1
1
  import { ref, reactive } from "vue-demi";
2
2
  import { GET_RECOMMEND_PLACE_TIMEOUT } from "../api/contants.js";
3
- import { equalAssign, isPlacesInclude } from "../utils/helper.js";
3
+ import { logNoneManualAbortError } from "../utils/ManualAbortError.js";
4
+ import { equalAssign, createAbortable, isPlacesInclude } from "../utils/helper.js";
4
5
  import { isZoneEqual, place2point, isPlaceEqual, businessCandidatesToAdsorptionPlace } from "../utils/transform.js";
5
6
  import { useMapGeometry } from "./useMapGeometry.js";
6
7
  import { useMapPlace } from "./useMapPlace.js";
@@ -11,9 +12,9 @@ function mergeGetRecommendPlaceAndGetAvailable(getRecomendPlace, getAvailable, t
11
12
  getAvailable == null ? void 0 : getAvailable(place).then((value) => {
12
13
  if (!value)
13
14
  resolve({ available: false });
14
- }).catch((error) => console.error(error));
15
+ }).catch(logNoneManualAbortError);
15
16
  getRecomendPlace(place, context).then((result) => resolve(result != null ? result : { available })).catch((error) => {
16
- console.error(error);
17
+ logNoneManualAbortError(error);
17
18
  resolve({ available });
18
19
  });
19
20
  setTimeout(() => resolve({ available }), timeout);
@@ -42,6 +43,7 @@ const useMapRecomendPlace = (props) => {
42
43
  context,
43
44
  emptyPlaceName,
44
45
  queryingPlaceName,
46
+ signal,
45
47
  onChange,
46
48
  onQueryingPlace,
47
49
  onChangePlace
@@ -50,10 +52,12 @@ const useMapRecomendPlace = (props) => {
50
52
  const forceRef = ref(false);
51
53
  const placeCandidatesRef = ref([]);
52
54
  const zoneRef = ref();
55
+ const abortable = createAbortable(signal);
53
56
  const { apiMapIsPointInRing, apiMapDistance } = useMapGeometry();
54
57
  const { getPlaceByRegeo } = useMapPlace({
55
58
  emptyPlaceName,
56
- pointRef: ref([...defaultPoint])
59
+ pointRef: ref([...defaultPoint]),
60
+ signal
57
61
  });
58
62
  const recomendPlace = reactive({
59
63
  lng: defaultPoint[0],
@@ -63,11 +67,11 @@ const useMapRecomendPlace = (props) => {
63
67
  });
64
68
  const isQueryingRef = ref(false);
65
69
  const getRecomendPlaceNoFail = mergeGetRecommendPlaceAndGetAvailable(
66
- getRecomendPlace,
67
- getAvailable,
70
+ abortable(getRecomendPlace),
71
+ abortable(getAvailable),
68
72
  GET_RECOMMEND_PLACE_TIMEOUT
69
73
  );
70
- const findAttachedPlace = async (place) => {
74
+ const findAttachedPlace = abortable(async (place) => {
71
75
  const {
72
76
  places: placeCandidates,
73
77
  zone,
@@ -90,38 +94,40 @@ const useMapRecomendPlace = (props) => {
90
94
  const limit = getLimit(context);
91
95
  const resultPlace = zone || shortestDistance <= limit ? shortestPlace : place;
92
96
  return { place: { ...resultPlace }, zone, candidates: placeCandidates, available, force };
93
- };
94
- const getRecommendPlaceZoneState = async (point, prevState) => {
95
- const [lng, lat] = point;
96
- const zone = zoneRef.value;
97
- if (!zone || !apiMapIsPointInRing(point, zone.path)) {
98
- const reGeoPlacePromise = getPlaceByRegeo(point);
99
- const {
100
- place: closestPlace,
101
- candidates,
102
- available,
103
- force,
104
- zone: zone2
105
- } = await findAttachedPlace({ lng, lat, name: "", displayName: "" });
106
- if (isPlacesInclude(candidates, closestPlace)) {
107
- return { place: { ...closestPlace }, zone: zone2, available, candidates, force };
97
+ });
98
+ const getRecommendPlaceZoneState = abortable(
99
+ async (point, prevState) => {
100
+ const [lng, lat] = point;
101
+ const zone = zoneRef.value;
102
+ if (!zone || !apiMapIsPointInRing(point, zone.path)) {
103
+ const reGeoPlacePromise = getPlaceByRegeo(point);
104
+ const {
105
+ place: closestPlace,
106
+ candidates,
107
+ available,
108
+ force,
109
+ zone: zone2
110
+ } = await findAttachedPlace({ lng, lat, name: "", displayName: "" });
111
+ if (isPlacesInclude(candidates, closestPlace)) {
112
+ return { place: { ...closestPlace }, zone: zone2, available, candidates, force };
113
+ }
114
+ const regeoPlace = await reGeoPlacePromise;
115
+ return { place: { ...regeoPlace }, zone: zone2, available, candidates, force };
108
116
  }
109
- const regeoPlace = await reGeoPlacePromise;
110
- return { place: { ...regeoPlace }, zone: zone2, available, candidates, force };
117
+ const { shortestPlace: resultPlace } = findNearestPlace(
118
+ { lng, lat, name: "", displayName: "" },
119
+ prevState.candidates,
120
+ apiMapDistance
121
+ );
122
+ return {
123
+ place: { ...resultPlace },
124
+ zone,
125
+ available: prevState.available,
126
+ force: prevState.force,
127
+ candidates: prevState.candidates
128
+ };
111
129
  }
112
- const { shortestPlace: resultPlace } = findNearestPlace(
113
- { lng, lat, name: "", displayName: "" },
114
- prevState.candidates,
115
- apiMapDistance
116
- );
117
- return {
118
- place: { ...resultPlace },
119
- zone,
120
- available: prevState.available,
121
- force: prevState.force,
122
- candidates: prevState.candidates
123
- };
124
- };
130
+ );
125
131
  const updateIntermediateQueryingState = (point) => {
126
132
  const zone = zoneRef.value;
127
133
  if (zone && apiMapIsPointInRing(point, zone.path))
@@ -141,7 +147,7 @@ const useMapRecomendPlace = (props) => {
141
147
  equalAssign(recomendPlace, { ...intermediateQueryingPlace });
142
148
  onQueryingPlace == null ? void 0 : onQueryingPlace({ ...intermediateQueryingPlace });
143
149
  };
144
- const updatePlace = async (point) => {
150
+ const updatePlace = abortable(async (point) => {
145
151
  updateIntermediateQueryingState(point);
146
152
  const {
147
153
  place: resultPlace,
@@ -166,29 +172,31 @@ const useMapRecomendPlace = (props) => {
166
172
  onChangePlace == null ? void 0 : onChangePlace({ ...resultPlace });
167
173
  const inputPlace = { name: "", displayName: "", lng: point[0], lat: point[1] };
168
174
  onChange == null ? void 0 : onChange({ place: { ...resultPlace }, inputPlace, isInZone: !!zone, isSameZone });
169
- };
170
- const updatePlaceCandidates = async (place) => {
171
- updateIntermediateQueryingState(place2point(place));
172
- const {
173
- places: placeCandidates,
174
- zone,
175
- available = false,
176
- force = false
177
- } = await getRecomendPlaceNoFail({ ...place }, context);
178
- const isSameZone = !!zone && isZoneEqual(zone, zoneRef.value);
179
- isQueryingRef.value = false;
180
- availableRef.value = !!available;
181
- forceRef.value = !!force;
182
- zoneRef.value = zone;
183
- placeCandidatesRef.value = placeCandidates != null ? placeCandidates : [];
184
- return {
185
- inputPlace: { ...place },
186
- isInZone: !!zone,
187
- place: { ...place },
188
- isSameZone
189
- };
190
- };
191
- const updateRecommendPlace = async (place) => {
175
+ });
176
+ const updatePlaceCandidates = abortable(
177
+ async (place) => {
178
+ updateIntermediateQueryingState(place2point(place));
179
+ const {
180
+ places: placeCandidates,
181
+ zone,
182
+ available = false,
183
+ force = false
184
+ } = await getRecomendPlaceNoFail({ ...place }, context);
185
+ const isSameZone = !!zone && isZoneEqual(zone, zoneRef.value);
186
+ isQueryingRef.value = false;
187
+ availableRef.value = !!available;
188
+ forceRef.value = !!force;
189
+ zoneRef.value = zone;
190
+ placeCandidatesRef.value = placeCandidates != null ? placeCandidates : [];
191
+ return {
192
+ inputPlace: { ...place },
193
+ isInZone: !!zone,
194
+ place: { ...place },
195
+ isSameZone
196
+ };
197
+ }
198
+ );
199
+ const updateRecommendPlace = abortable(async (place) => {
192
200
  updateIntermediateQueryingState(place2point(place));
193
201
  const {
194
202
  place: resultPlace,
@@ -211,8 +219,8 @@ const useMapRecomendPlace = (props) => {
211
219
  isInZone: !!zone,
212
220
  isSameZone
213
221
  });
214
- };
215
- const updateRecommendPlaceOnlyInZone = async (place) => {
222
+ });
223
+ const updateRecommendPlaceOnlyInZone = abortable(async (place) => {
216
224
  var _a;
217
225
  updateIntermediateQueryingState(place2point(place));
218
226
  const {
@@ -237,7 +245,7 @@ const useMapRecomendPlace = (props) => {
237
245
  isInZone: !!zone,
238
246
  isSameZone
239
247
  });
240
- };
248
+ });
241
249
  const setPlaceCandidatesAndZone = ({ zone, places: placeCandidates }) => {
242
250
  availableRef.value = true;
243
251
  forceRef.value = !!zone;
@@ -1,9 +1,15 @@
1
+ import type { AnyFn } from "@vueuse/core";
1
2
  import type { Status, UseMapLoaderOutput, UseMapLoaderProps } from "./useMapLoader";
2
3
  export interface MapSupplierPayolad extends UseMapLoaderProps {
3
4
  gmapRasterId: string;
4
5
  gmapId: string;
5
6
  readyPromise: UseMapLoaderOutput["readyPromise"];
6
7
  status: Status;
8
+ renderLoadFailedTitle?: (status: Status) => string | undefined;
9
+ renderLoadFailedDescription?: (status: Status) => string | undefined;
7
10
  }
8
11
  export declare const useMapSupplier: () => MapSupplierPayolad;
9
12
  export declare const provideMapSupplier: (payload: MapSupplierPayolad) => void;
13
+ export declare const useMapAssertSupplier: () => {
14
+ assertSupplier: <T extends AnyFn>(fn: T) => T;
15
+ };
@@ -7,7 +7,24 @@ const useMapSupplier = () => {
7
7
  return payload;
8
8
  };
9
9
  const provideMapSupplier = (payload) => provide(context, payload);
10
+ const useMapAssertSupplier = () => {
11
+ const payload = useMapSupplier();
12
+ const instanceSupplier = payload.supplier;
13
+ function assertSupplier(fn) {
14
+ return function fnWithAssertSupplier(...args) {
15
+ console.log("instanceSupplier, payload.supplier = ", instanceSupplier, payload.supplier);
16
+ if (instanceSupplier === payload.supplier)
17
+ return fn(...args);
18
+ throw Error(
19
+ `MyError: expect instance supplier ${payload.supplier}, actual is ${instanceSupplier}
20
+ You probably call the api (exposed by useBusinessXXX) before the Element <BusinessXXX /> rendering!`
21
+ );
22
+ };
23
+ }
24
+ return { assertSupplier };
25
+ };
10
26
  export {
11
27
  provideMapSupplier,
28
+ useMapAssertSupplier,
12
29
  useMapSupplier
13
30
  };
@@ -1,7 +1,9 @@
1
+ import type { CoordinateType, Point } from "../types/interface";
1
2
  export type BusinessQuotingContext = {
2
3
  setFitView: () => void;
3
4
  };
4
5
  export declare const useBusinessQuotingMap: () => {
5
6
  setFitView: () => void;
6
7
  mapContext: BusinessQuotingContext;
8
+ toAmapCoordinateType: (point: Point) => CoordinateType;
7
9
  };
@@ -1,9 +1,14 @@
1
- import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
1
+ import { inChina } from "../hooks/useMapInChina.js";
2
+ import { proxyFunctionalProperty, assertAssingedBeforeUsed, assertPoint } from "../utils/helper.js";
2
3
  const useBusinessQuotingMap = () => {
3
4
  const mapContext = {
4
5
  setFitView: assertAssingedBeforeUsed
5
6
  };
6
- return { mapContext, ...proxyFunctionalProperty(mapContext) };
7
+ const toAmapCoordinateType = (point) => {
8
+ assertPoint(point);
9
+ return inChina(point) ? "gcj02" : "wgs84";
10
+ };
11
+ return { mapContext, toAmapCoordinateType, ...proxyFunctionalProperty(mapContext) };
7
12
  };
8
13
  export {
9
14
  useBusinessQuotingMap
@@ -1,5 +1,5 @@
1
1
  import { reactive, ref, readonly } from "vue-demi";
2
- import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.39888296.js";
2
+ import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.86e9c287.js";
3
3
  import { CenterPlaceStatus } from "../types/interface.js";
4
4
  import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
5
5
  const useBusinessRecomendPlaceMap = () => {
package/dist/v3/index.js CHANGED
@@ -2,7 +2,7 @@ import "./utils/alipayPolyfill.js";
2
2
  import { AbsoluteAddressBox } from "./business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
3
3
  import { AddressBox } from "./business-components/AddressBox/AddressBox.js";
4
4
  import { BusinessQuotingMap } from "./business-components/BusinessQuotingMap/BusinessQuotingMap.js";
5
- import { B } from "./chunks/BusinessRecomendPlaceMap.39888296.js";
5
+ import { B } from "./chunks/BusinessRecomendPlaceMap.86e9c287.js";
6
6
  import { BusinessReselectPlaceMap } from "./business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js";
7
7
  import { BusinessTaxiEndMap } from "./business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js";
8
8
  import { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js";
@@ -0,0 +1,3 @@
1
+ export declare const MANUAL_ABORT_MESSAGE = "MANUAL_ABORT_MESSAGE";
2
+ export declare const throwNoneManualAbortError: (e: unknown) => void;
3
+ export declare const logNoneManualAbortError: (e: unknown) => void;