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

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 (122) hide show
  1. package/README.md +43 -29
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/v2/App.js +5 -3
  5. package/dist/v2/Demo/DemoBusinessQuoting.js +3 -2
  6. package/dist/v2/Demo/DemoBusinessRecomendPlace.js +1 -1
  7. package/dist/v2/api/cdn.d.ts +1 -0
  8. package/dist/v2/api/cdn.js +2 -0
  9. package/dist/v2/api/googleSnapRoad.js +7 -2
  10. package/dist/v2/api/pingConnection.d.ts +9 -0
  11. package/dist/v2/api/pingConnection.js +111 -0
  12. package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
  13. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -2
  14. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +4 -3
  15. package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +3 -3
  16. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +2 -2
  17. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +22 -13
  18. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
  19. package/dist/v2/chunks/{BusinessRecomendPlaceMap.5be4fdcf.js → BusinessRecomendPlaceMap.b4d45108.js} +30 -18
  20. package/dist/v2/chunks/{Loading.fc6e75d0.js → Loading.492acbc2.js} +30 -2
  21. package/dist/v2/components/Loading/Loading.css.d.ts +5 -0
  22. package/dist/v2/components/Loading/Loading.d.ts +6 -0
  23. package/dist/v2/components/Loading/Loading.js +4 -2
  24. package/dist/v2/components/Loading/index.js +3 -2
  25. package/dist/v2/components/MapProvider/MapProvider.d.ts +2 -2
  26. package/dist/v2/components/MapProvider/MapProvider.js +23 -13
  27. package/dist/v2/css/Loading-49e58ced.css +46 -0
  28. package/dist/v2/hooks/useDrivingRoute.js +4 -0
  29. package/dist/v2/hooks/useMapGCJ02.js +4 -37
  30. package/dist/v2/hooks/useMapGeometry.d.ts +1 -3
  31. package/dist/v2/hooks/useMapGeometry.js +4 -4
  32. package/dist/v2/hooks/useMapGraspRoad.js +1 -2
  33. package/dist/v2/hooks/useMapInChina.d.ts +3 -15
  34. package/dist/v2/hooks/useMapInChina.js +11 -16
  35. package/dist/v2/hooks/useMapLoader.d.ts +13 -7
  36. package/dist/v2/hooks/useMapLoader.js +144 -82
  37. package/dist/v2/hooks/useMapPlace.d.ts +1 -0
  38. package/dist/v2/hooks/useMapPlace.js +52 -44
  39. package/dist/v2/hooks/useMapRecomendPlace.d.ts +1 -0
  40. package/dist/v2/hooks/useMapRecomendPlace.js +75 -67
  41. package/dist/v2/hooks/useMapSupplier.d.ts +8 -0
  42. package/dist/v2/hooks/useMapSupplier.js +17 -0
  43. package/dist/v2/hooks/usePingConnection.d.ts +10 -0
  44. package/dist/v2/hooks/usePingConnection.js +26 -0
  45. package/dist/v2/hooks-business/useBusinessQuotingMap.d.ts +2 -0
  46. package/dist/v2/hooks-business/useBusinessQuotingMap.js +7 -2
  47. package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  48. package/dist/v2/index.js +1 -1
  49. package/dist/v2/types/global.d.ts +3 -0
  50. package/dist/v2/types/interface.d.ts +1 -1
  51. package/dist/v2/utils/ManualAbortError.d.ts +3 -0
  52. package/dist/v2/utils/ManualAbortError.js +14 -0
  53. package/dist/v2/utils/helper.d.ts +2 -0
  54. package/dist/v2/utils/helper.js +29 -0
  55. package/dist/v2/utils/log.js +1 -1
  56. package/dist/v2/utils/patchGoogleMapLoader.d.ts +2 -0
  57. package/dist/v2/utils/patchGoogleMapLoader.js +64 -0
  58. package/dist/v3/App.js +5 -3
  59. package/dist/v3/Demo/DemoBusinessQuoting.js +4 -3
  60. package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
  61. package/dist/v3/api/cdn.d.ts +1 -0
  62. package/dist/v3/api/cdn.js +2 -0
  63. package/dist/v3/api/googleSnapRoad.js +7 -2
  64. package/dist/v3/api/pingConnection.d.ts +9 -0
  65. package/dist/v3/api/pingConnection.js +111 -0
  66. package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
  67. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -2
  68. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +4 -3
  69. package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +3 -3
  70. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +2 -2
  71. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +22 -13
  72. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
  73. package/dist/v3/chunks/{BusinessRecomendPlaceMap.39888296.js → BusinessRecomendPlaceMap.6ba5dbb1.js} +30 -18
  74. package/dist/v3/chunks/{Loading.a8e2f26a.js → Loading.21d8e759.js} +26 -2
  75. package/dist/v3/components/Loading/Loading.css.d.ts +5 -0
  76. package/dist/v3/components/Loading/Loading.d.ts +8 -0
  77. package/dist/v3/components/Loading/Loading.js +4 -2
  78. package/dist/v3/components/Loading/index.js +3 -2
  79. package/dist/v3/components/MapProvider/MapProvider.d.ts +6 -3
  80. package/dist/v3/components/MapProvider/MapProvider.js +21 -13
  81. package/dist/v3/css/Loading-49e58ced.css +46 -0
  82. package/dist/v3/hooks/useDrivingRoute.js +4 -0
  83. package/dist/v3/hooks/useMapGCJ02.js +4 -37
  84. package/dist/v3/hooks/useMapGeometry.d.ts +1 -3
  85. package/dist/v3/hooks/useMapGeometry.js +4 -4
  86. package/dist/v3/hooks/useMapGraspRoad.js +1 -2
  87. package/dist/v3/hooks/useMapInChina.d.ts +3 -15
  88. package/dist/v3/hooks/useMapInChina.js +11 -16
  89. package/dist/v3/hooks/useMapLoader.d.ts +13 -7
  90. package/dist/v3/hooks/useMapLoader.js +144 -82
  91. package/dist/v3/hooks/useMapPlace.d.ts +1 -0
  92. package/dist/v3/hooks/useMapPlace.js +52 -44
  93. package/dist/v3/hooks/useMapRecomendPlace.d.ts +1 -0
  94. package/dist/v3/hooks/useMapRecomendPlace.js +75 -67
  95. package/dist/v3/hooks/useMapSupplier.d.ts +8 -0
  96. package/dist/v3/hooks/useMapSupplier.js +17 -0
  97. package/dist/v3/hooks/usePingConnection.d.ts +10 -0
  98. package/dist/v3/hooks/usePingConnection.js +26 -0
  99. package/dist/v3/hooks-business/useBusinessQuotingMap.d.ts +2 -0
  100. package/dist/v3/hooks-business/useBusinessQuotingMap.js +7 -2
  101. package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  102. package/dist/v3/index.js +1 -1
  103. package/dist/v3/types/global.d.ts +3 -0
  104. package/dist/v3/types/interface.d.ts +1 -1
  105. package/dist/v3/utils/ManualAbortError.d.ts +3 -0
  106. package/dist/v3/utils/ManualAbortError.js +14 -0
  107. package/dist/v3/utils/helper.d.ts +2 -0
  108. package/dist/v3/utils/helper.js +29 -0
  109. package/dist/v3/utils/log.js +1 -1
  110. package/dist/v3/utils/patchGoogleMapLoader.d.ts +2 -0
  111. package/dist/v3/utils/patchGoogleMapLoader.js +64 -0
  112. package/package.json +2 -2
  113. package/dist/v2/api/googleConnection.d.ts +0 -5
  114. package/dist/v2/api/googleConnection.js +0 -51
  115. package/dist/v2/css/Loading-523061b9.css +0 -9
  116. package/dist/v2/hooks/useGoogleConnection.d.ts +0 -7
  117. package/dist/v2/hooks/useGoogleConnection.js +0 -15
  118. package/dist/v3/api/googleConnection.d.ts +0 -5
  119. package/dist/v3/api/googleConnection.js +0 -51
  120. package/dist/v3/css/Loading-523061b9.css +0 -9
  121. package/dist/v3/hooks/useGoogleConnection.d.ts +0 -7
  122. package/dist/v3/hooks/useGoogleConnection.js +0 -15
@@ -1,8 +1,9 @@
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
- import { useMapGeometry } from "./useMapGeometry.js";
6
+ import { useMapGeometry, apiLocalIsPointInRing } from "./useMapGeometry.js";
6
7
  import { useMapPlace } from "./useMapPlace.js";
7
8
  function mergeGetRecommendPlaceAndGetAvailable(getRecomendPlace, getAvailable, timeout) {
8
9
  return function mergedGetRecommendPlace(place, context) {
@@ -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();
53
- const { apiMapIsPointInRing, apiMapDistance } = useMapGeometry();
55
+ const abortable = createAbortable(signal);
56
+ const { 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,41 +94,43 @@ 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 || !apiLocalIsPointInRing(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
- if (zone && apiMapIsPointInRing(point, zone.path))
133
+ if (zone && apiLocalIsPointInRing(point, zone.path))
128
134
  return;
129
135
  const [lng, lat] = point;
130
136
  const intermediateQueryingPlace = {
@@ -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,17 @@
1
+ import type { AnyFn } from "@vueuse/core";
2
+ import type { ConnectionStatus } from "../types/interface";
1
3
  import type { Status, UseMapLoaderOutput, UseMapLoaderProps } from "./useMapLoader";
2
4
  export interface MapSupplierPayolad extends UseMapLoaderProps {
3
5
  gmapRasterId: string;
4
6
  gmapId: string;
5
7
  readyPromise: UseMapLoaderOutput["readyPromise"];
6
8
  status: Status;
9
+ pingStatus: ConnectionStatus;
10
+ renderLoadFailedTitle?: (status: Status) => string | undefined;
11
+ renderLoadFailedDescription?: (status: Status) => string | undefined;
7
12
  }
8
13
  export declare const useMapSupplier: () => MapSupplierPayolad;
9
14
  export declare const provideMapSupplier: (payload: MapSupplierPayolad) => void;
15
+ export declare const useMapAssertSupplier: () => {
16
+ assertSupplier: <T extends AnyFn>(fn: T) => T;
17
+ };
@@ -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
  };
@@ -0,0 +1,10 @@
1
+ import { type PingConnectionOnChangeHandler } from "../api/pingConnection";
2
+ export interface UsePingConnectionProps {
3
+ onChange?: PingConnectionOnChangeHandler;
4
+ }
5
+ export declare const usePingAmapConnection: (props?: UsePingConnectionProps) => {
6
+ connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
7
+ };
8
+ export declare const usePingGmapConnection: (props?: UsePingConnectionProps) => {
9
+ connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
10
+ };
@@ -0,0 +1,26 @@
1
+ import { ref, onUnmounted, readonly } from "vue-demi";
2
+ import { apiGetPingAmapStatus, apiSubscribePingAmapChange, apiGetPingGmapStatus, apiSubscribePingGmapChange } from "../api/pingConnection.js";
3
+ const usePingAmapConnection = (props) => {
4
+ const statusRef = ref(apiGetPingAmapStatus());
5
+ const unsubscribe = apiSubscribePingAmapChange((status) => {
6
+ var _a;
7
+ statusRef.value = status;
8
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
9
+ });
10
+ onUnmounted(unsubscribe);
11
+ return { connectionStatus: readonly(statusRef) };
12
+ };
13
+ const usePingGmapConnection = (props) => {
14
+ const statusRef = ref(apiGetPingGmapStatus());
15
+ const unsubscribe = apiSubscribePingGmapChange((status) => {
16
+ var _a;
17
+ statusRef.value = status;
18
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
19
+ });
20
+ onUnmounted(unsubscribe);
21
+ return { connectionStatus: readonly(statusRef) };
22
+ };
23
+ export {
24
+ usePingAmapConnection,
25
+ usePingGmapConnection
26
+ };
@@ -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.5be4fdcf.js";
2
+ import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.b4d45108.js";
3
3
  import { CenterPlaceStatus } from "../types/interface.js";
4
4
  import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
5
5
  const useBusinessRecomendPlaceMap = () => {
package/dist/v2/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.5be4fdcf.js";
5
+ import { B } from "./chunks/BusinessRecomendPlaceMap.b4d45108.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";
@@ -20,3 +20,6 @@ declare global {
20
20
  deviceorientationabsolute: DeviceOrientationEvent;
21
21
  }
22
22
  }
23
+ declare module "@amap/amap-jsapi-loader" {
24
+ const reset: () => void;
25
+ }
@@ -93,7 +93,7 @@ export declare enum CenterPlaceStatus {
93
93
  SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
94
94
  OK = "OK"
95
95
  }
96
- export type GoogleConnectionStatus = "pending" | "connected" | "unconnected";
96
+ export type ConnectionStatus = "pending" | "connected" | "unconnected";
97
97
  export interface BusinessGeolocationPositionError extends GeolocationPositionError {
98
98
  isBusinessTimeout: boolean;
99
99
  }
@@ -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;
@@ -0,0 +1,14 @@
1
+ const MANUAL_ABORT_MESSAGE = "MANUAL_ABORT_MESSAGE";
2
+ const throwNoneManualAbortError = (e) => {
3
+ if (e !== MANUAL_ABORT_MESSAGE)
4
+ throw e;
5
+ };
6
+ const logNoneManualAbortError = (e) => {
7
+ if (e !== MANUAL_ABORT_MESSAGE)
8
+ console.error(e);
9
+ };
10
+ export {
11
+ MANUAL_ABORT_MESSAGE,
12
+ logNoneManualAbortError,
13
+ throwNoneManualAbortError
14
+ };
@@ -22,6 +22,7 @@ export declare const pausableSleep: (milliSeconds: number) => {
22
22
  restart: () => void;
23
23
  };
24
24
  export declare const createRunOnce: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => R;
25
+ export declare const createOneConcurrent: <P extends any[], R>(fn: (...args: P) => Promise<R>) => (...args: P) => Promise<R> | undefined;
25
26
  export declare const createReadOnce: <T>(value: T) => () => T | undefined;
26
27
  export declare const createAsyncNoFailNonNullable: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: NonNullable<R>) => (...args: P) => Promise<NonNullable<R>>;
27
28
  export declare const pipeTimeout: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: R, timeout: number) => (...args: P) => Promise<R>;
@@ -33,4 +34,5 @@ export declare const assertAssingedBeforeUsed: () => never;
33
34
  type PickFunctionalPropertyName<T, K extends keyof T = keyof T> = K extends any ? T[K] extends (...args: any) => any ? K : never : never;
34
35
  type PickFunctionalProperty<T> = Pick<T, PickFunctionalPropertyName<T>>;
35
36
  export declare const proxyFunctionalProperty: <T extends object>(target: T) => PickFunctionalProperty<T>;
37
+ export declare const createAbortable: (signal?: AbortSignal) => <F extends ((...args: any) => Promise<any>) | undefined>(fn: F) => F;
36
38
  export {};
@@ -93,6 +93,17 @@ const createRunOnce = (fn) => {
93
93
  return result;
94
94
  };
95
95
  };
96
+ const createOneConcurrent = (fn) => {
97
+ let isRunning = false;
98
+ return function runOneConcurrent(...args) {
99
+ if (isRunning)
100
+ return;
101
+ isRunning = true;
102
+ const result = fn(...args);
103
+ result.finally(() => isRunning = false);
104
+ return result;
105
+ };
106
+ };
96
107
  const createReadOnce = (value) => {
97
108
  let isRead = false;
98
109
  return function read() {
@@ -147,13 +158,31 @@ const proxyFunctionalProperty = (target) => {
147
158
  }
148
159
  return result;
149
160
  };
161
+ const createAbortable = (signal) => {
162
+ return function abortable(fn) {
163
+ if (!fn || !signal)
164
+ return fn;
165
+ return function abrotableFn(...args) {
166
+ return new Promise((resolve, reject) => {
167
+ if (signal.aborted)
168
+ return reject(signal.reason);
169
+ signal.addEventListener("abort", () => reject(signal.reason));
170
+ fn(...args).then((result) => {
171
+ signal.aborted ? reject(signal.reason) : resolve(result);
172
+ }, reject);
173
+ });
174
+ };
175
+ };
176
+ };
150
177
  export {
151
178
  assertAngle,
152
179
  assertAssingedBeforeUsed,
153
180
  assertNotEmptyArray,
154
181
  assertPoint,
155
182
  assertZone,
183
+ createAbortable,
156
184
  createAsyncNoFailNonNullable,
185
+ createOneConcurrent,
157
186
  createReadOnce,
158
187
  createRunOnce,
159
188
  defered,
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap1";
3
+ const pkgVersion = "2.0.0-switchMap10";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -0,0 +1,2 @@
1
+ import { Loader } from "@googlemaps/js-api-loader";
2
+ export declare const patchGoogleMapLoader: (loader: Loader) => void;
@@ -0,0 +1,64 @@
1
+ const patchGoogleMapLoader = (loader) => {
2
+ loader.setScript = setScript;
3
+ };
4
+ function setScript() {
5
+ var _a, _b;
6
+ if (document.getElementById(this.id)) {
7
+ this.callback();
8
+ return;
9
+ }
10
+ const params = {
11
+ key: this.apiKey,
12
+ channel: this.channel,
13
+ client: this.client,
14
+ libraries: this.libraries.length && this.libraries,
15
+ v: this.version,
16
+ mapIds: this.mapIds,
17
+ language: this.language,
18
+ region: this.region,
19
+ authReferrerPolicy: this.authReferrerPolicy
20
+ };
21
+ Object.keys(params).forEach((key) => !params[key] && delete params[key]);
22
+ if (!((_b = (_a = window == null ? void 0 : window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.importLibrary)) {
23
+ ((g) => {
24
+ let h, a, k, p = "The Google Maps JavaScript API", c = "google", l = "importLibrary", q = "__ib__", m = document, b = window;
25
+ b = b[c] || (b[c] = {});
26
+ const d = b.maps || (b.maps = {}), r = /* @__PURE__ */ new Set(), e = new URLSearchParams(), u = () => (
27
+ // @ts-ignore
28
+ h || (h = new Promise(async (f, n) => {
29
+ var _a2;
30
+ await (a = m.createElement("script"));
31
+ a.id = this.id;
32
+ e.set("libraries", [...r] + "");
33
+ for (k in g)
34
+ e.set(
35
+ k.replace(/[A-Z]/g, (t) => "_" + t[0].toLowerCase()),
36
+ g[k]
37
+ );
38
+ e.set("callback", c + ".maps." + q);
39
+ e.set("t", Date.now().toString());
40
+ a.src = this.url + `?` + e;
41
+ d[q] = f;
42
+ a.onerror = () => h = n(Error(p + " could not load."));
43
+ a.nonce = this.nonce || ((_a2 = m.querySelector("script[nonce]")) == null ? void 0 : _a2.nonce) || "";
44
+ m.head.append(a);
45
+ }))
46
+ );
47
+ d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n));
48
+ })(params);
49
+ }
50
+ const libraryPromises = this.libraries.map((library) => this.importLibrary(library));
51
+ if (!libraryPromises.length) {
52
+ libraryPromises.push(this.importLibrary("core"));
53
+ }
54
+ Promise.all(libraryPromises).then(
55
+ () => this.callback(),
56
+ (error) => {
57
+ const event = new ErrorEvent("error", { error });
58
+ this.loadErrorCallback(event);
59
+ }
60
+ );
61
+ }
62
+ export {
63
+ patchGoogleMapLoader
64
+ };
package/dist/v3/App.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createVNode } from "vue";
2
2
  import { defineComponent, ref } from "vue-demi";
3
- import { DemoBusinessTaxiService } from "./Demo/DemoBusinessTaxiService.js";
3
+ import { DemoBusinessQuoting } from "./Demo/DemoBusinessQuoting.js";
4
4
  import { MapProvider } from "./components/MapProvider/MapProvider.js";
5
5
  const gmapApiKey = "AIzaSyCRtkaNSWMOhOXDOUpJK4OVbm5RIstYj-I";
6
6
  const gmapId = "d0af0c05331af64a";
@@ -18,9 +18,11 @@ const App = /* @__PURE__ */ defineComponent({
18
18
  "gmapRasterId": gmapRasterId,
19
19
  "gmapKey": gmapApiKey,
20
20
  "language": "en",
21
- "supplier": supplierRef.value
21
+ "supplier": supplierRef.value,
22
+ "renderLoadFailedTitle": () => supplierRef.value === "gmap" ? "未能成功访问谷歌地图" : "高德地图加载失败",
23
+ "renderLoadFailedDescription": () => supplierRef.value === "gmap" ? "请确认您的网络能正常访问谷歌地图, \n或切回高德地图" : void 0
22
24
  }, {
23
- default: () => [createVNode(DemoBusinessTaxiService, null, null)]
25
+ default: () => [createVNode(DemoBusinessQuoting, null, null)]
24
26
  });
25
27
  }
26
28
  });
@@ -1,11 +1,12 @@
1
- import { createVNode } from "vue";
1
+ import { createVNode, createTextVNode } from "vue";
2
2
  import { BusinessQuotingMap } from "../business-components/BusinessQuotingMap/BusinessQuotingMap.js";
3
3
  import { useBusinessQuotingMap } from "../hooks-business/useBusinessQuotingMap.js";
4
4
  import { defineSetup } from "../types/helper.js";
5
5
  import { d as demo } from "../chunks/Demo.css.e921a2f6.js";
6
6
  const DemoBusinessQuoting = defineSetup("DemoBusinessQuoting", function() {
7
7
  const {
8
- mapContext
8
+ mapContext,
9
+ toAmapCoordinateType
9
10
  } = useBusinessQuotingMap();
10
11
  return () => createVNode("div", null, [createVNode(BusinessQuotingMap, {
11
12
  "class": demo,
@@ -32,7 +33,7 @@ const DemoBusinessQuoting = defineSetup("DemoBusinessQuoting", function() {
32
33
  "mapContext": mapContext,
33
34
  "onClickStartPoint": (place) => console.log("点击起点时触发 palce = ", place),
34
35
  "onClickEndPoint": (place) => console.log("点击终点时触发 palce = ", place)
35
- }, null)]);
36
+ }, null), createVNode("div", null, [createTextVNode("经度 103.841974, 纬度 1.311295 在高德地图上的坐标类型是:"), toAmapCoordinateType([103.841974, 1.311295])])]);
36
37
  });
37
38
  export {
38
39
  DemoBusinessQuoting
@@ -1,5 +1,5 @@
1
1
  import { createVNode } from "vue";
2
- import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.39888296.js";
2
+ import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.6ba5dbb1.js";
3
3
  import { useBusinessRecomendPlaceMap } from "../hooks-business/useBusinessRecomendPlaceMap.js";
4
4
  import { defineSetup } from "../types/helper.js";
5
5
  import { d as demo } from "../chunks/Demo.css.e921a2f6.js";
@@ -5,3 +5,4 @@ export declare const ICON_END_POINT_EN_URL = "https://overseas-oss.heycars.cn/he
5
5
  export declare const ICON_END_POINT_ZH_TW_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/end-point-zh-TW.svg";
6
6
  export declare const ICON_TAXI_CAR_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/taxi-car.svg";
7
7
  export declare const ICON_DOT_LOADING_URL = "https://overseas-oss.heycars.cn/heycar-map/gif/dot-loading.gif";
8
+ export declare const ICON_LOAD_FAILED_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/load-failed.svg";
@@ -5,12 +5,14 @@ const ICON_END_POINT_EN_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/en
5
5
  const ICON_END_POINT_ZH_TW_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/end-point-zh-TW.svg";
6
6
  const ICON_TAXI_CAR_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/taxi-car.svg";
7
7
  const ICON_DOT_LOADING_URL = "https://overseas-oss.heycars.cn/heycar-map/gif/dot-loading.gif";
8
+ const ICON_LOAD_FAILED_URL = "https://overseas-oss.heycars.cn/heycar-map/svg/load-failed.svg";
8
9
  export {
9
10
  AMAP_DEFAULT_MARKER_ICON_URL,
10
11
  ICON_DOT_LOADING_URL,
11
12
  ICON_END_POINT_EN_URL,
12
13
  ICON_END_POINT_ZH_TW_URL,
13
14
  ICON_FULL_SCREEN_URL,
15
+ ICON_LOAD_FAILED_URL,
14
16
  ICON_START_POINT_EN_URL,
15
17
  ICON_TAXI_CAR_URL
16
18
  };
@@ -13,9 +13,14 @@ function assertLatitudeLongitudeLiteral(value) {
13
13
  throw Error(`MyError: expect type LatitudeLongitudeLiteral, actual is: ${JSON.stringify(value)}`);
14
14
  }
15
15
  function assertSnappedPoint(value) {
16
- if (value)
16
+ const error = Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
17
+ if (!value)
18
+ throw error;
19
+ try {
17
20
  assertLatitudeLongitudeLiteral(value.location);
18
- throw Error(`MyError: expect type SnappedPoint, actual is: ${JSON.stringify(value)}`);
21
+ } catch {
22
+ throw error;
23
+ }
19
24
  }
20
25
  function assertSnapToRoadsResponse(value) {
21
26
  const error = Error(
@@ -0,0 +1,9 @@
1
+ import type { ConnectionStatus } from "../types/interface";
2
+ export type PingConnectionOnChangeHandler = (status: ConnectionStatus) => void;
3
+ export type PingConnectionOnChangeCleanup = () => void;
4
+ export declare const apiGetPingAmapStatus: () => ConnectionStatus;
5
+ export declare const apiGetPingGmapStatus: () => ConnectionStatus;
6
+ export declare const apiPingAmap: () => Promise<ConnectionStatus>;
7
+ export declare const apiPingGmap: () => Promise<ConnectionStatus>;
8
+ export declare const apiSubscribePingAmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;
9
+ export declare const apiSubscribePingGmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;