@heycar/heycars-map 2.0.0-switchMap2 → 2.0.0-switchMap4
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/v2/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +2 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +18 -11
- package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
- package/dist/v2/chunks/{BusinessRecomendPlaceMap.5be4fdcf.js → BusinessRecomendPlaceMap.4b641c71.js} +23 -13
- package/dist/v2/chunks/{Loading.da68a2a6.js → Loading.f2515cd7.js} +8 -10
- package/dist/v2/components/Loading/Loading.css.d.ts +2 -2
- package/dist/v2/components/Loading/Loading.js +1 -1
- package/dist/v2/components/Loading/index.js +1 -1
- package/dist/v2/components/MapProvider/MapProvider.js +1 -1
- package/dist/{v3/css/Loading-0e058b68.css → v2/css/Loading-49e58ced.css} +6 -11
- package/dist/v2/hooks/useMapGCJ02.js +0 -3
- package/dist/v2/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v2/hooks/useMapGeometry.js +4 -4
- package/dist/v2/hooks/useMapLoader.js +3 -0
- package/dist/v2/hooks/useMapPlace.d.ts +1 -0
- package/dist/v2/hooks/useMapPlace.js +51 -42
- package/dist/v2/hooks/useMapRecomendPlace.d.ts +1 -0
- package/dist/v2/hooks/useMapRecomendPlace.js +75 -67
- package/dist/v2/hooks/useMapSupplier.d.ts +4 -0
- package/dist/v2/hooks/useMapSupplier.js +17 -0
- package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- package/dist/v2/index.js +1 -1
- package/dist/v2/utils/ManualAbortError.d.ts +3 -0
- package/dist/v2/utils/ManualAbortError.js +14 -0
- package/dist/v2/utils/helper.d.ts +1 -0
- package/dist/v2/utils/helper.js +17 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v2/utils/patchGoogleMapLoader.d.ts +2 -0
- package/dist/v2/utils/patchGoogleMapLoader.js +64 -0
- package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.js +5 -2
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +2 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +18 -11
- package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +12 -5
- package/dist/v3/chunks/{BusinessRecomendPlaceMap.39888296.js → BusinessRecomendPlaceMap.4befb6c7.js} +23 -13
- package/dist/v3/chunks/{Loading.98d687c0.js → Loading.32ae3c98.js} +8 -10
- package/dist/v3/components/Loading/Loading.css.d.ts +2 -2
- package/dist/v3/components/Loading/Loading.js +1 -1
- package/dist/v3/components/Loading/index.js +1 -1
- package/dist/v3/components/MapProvider/MapProvider.js +1 -1
- package/dist/{v2/css/Loading-0e058b68.css → v3/css/Loading-49e58ced.css} +6 -11
- package/dist/v3/hooks/useMapGCJ02.js +0 -3
- package/dist/v3/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v3/hooks/useMapGeometry.js +4 -4
- package/dist/v3/hooks/useMapLoader.js +3 -0
- package/dist/v3/hooks/useMapPlace.d.ts +1 -0
- package/dist/v3/hooks/useMapPlace.js +51 -42
- package/dist/v3/hooks/useMapRecomendPlace.d.ts +1 -0
- package/dist/v3/hooks/useMapRecomendPlace.js +75 -67
- package/dist/v3/hooks/useMapSupplier.d.ts +4 -0
- package/dist/v3/hooks/useMapSupplier.js +17 -0
- package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- package/dist/v3/index.js +1 -1
- package/dist/v3/utils/ManualAbortError.d.ts +3 -0
- package/dist/v3/utils/ManualAbortError.js +14 -0
- package/dist/v3/utils/helper.d.ts +1 -0
- package/dist/v3/utils/helper.js +17 -0
- package/dist/v3/utils/log.js +1 -1
- package/dist/v3/utils/patchGoogleMapLoader.d.ts +2 -0
- package/dist/v3/utils/patchGoogleMapLoader.js +64 -0
- package/package.json +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
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
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();
|
|
@@ -17,6 +17,7 @@ const useAmapPlace = (props) => {
|
|
|
17
17
|
name: "",
|
|
18
18
|
displayName: ""
|
|
19
19
|
});
|
|
20
|
+
const abortable = createAbortable(signal);
|
|
20
21
|
const { idx: placeKey, update } = useUpdate();
|
|
21
22
|
const updatePlace = (value) => {
|
|
22
23
|
pointRef.value = value;
|
|
@@ -28,37 +29,42 @@ const useAmapPlace = (props) => {
|
|
|
28
29
|
place.name = value.name;
|
|
29
30
|
place.displayName = value.displayName;
|
|
30
31
|
};
|
|
31
|
-
const getPlaceByRegeo = ([lng, lat]) => {
|
|
32
|
+
const getPlaceByRegeo = abortable(([lng, lat]) => {
|
|
32
33
|
return new Promise((resolve) => {
|
|
33
|
-
const
|
|
34
|
-
const pipeTw = createPipeTw(language === "zh-TW");
|
|
35
|
-
const isChina = inChina([lng, lat]);
|
|
36
|
-
geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
|
|
37
|
-
switch (status) {
|
|
38
|
-
case "complete": {
|
|
39
|
-
const { formattedAddress, addressComponent } = result.regeocode;
|
|
40
|
-
const name = formattedAddress ? formattedAddress : emptyPlaceName;
|
|
41
|
-
const displayName = amapPlaceName2DisplayName(name, { isChina, ...addressComponent });
|
|
42
|
-
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
case "no_data":
|
|
46
|
-
case "error": {
|
|
47
|
-
const name = emptyPlaceName;
|
|
48
|
-
const displayName = emptyPlaceName;
|
|
49
|
-
resolve({ lng, lat, name, displayName });
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
setTimeout(() => {
|
|
55
|
-
console.warn("高德逆地理请求超时!");
|
|
34
|
+
const handleFailed = () => {
|
|
56
35
|
const name = emptyPlaceName;
|
|
57
36
|
const displayName = emptyPlaceName;
|
|
58
37
|
resolve({ lng, lat, name, displayName });
|
|
38
|
+
};
|
|
39
|
+
readyPromise.then(() => {
|
|
40
|
+
const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
|
|
41
|
+
const pipeTw = createPipeTw(language === "zh-TW");
|
|
42
|
+
const isChina = inChina([lng, lat]);
|
|
43
|
+
geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
|
|
44
|
+
switch (status) {
|
|
45
|
+
case "complete": {
|
|
46
|
+
const { formattedAddress, addressComponent } = result.regeocode;
|
|
47
|
+
const name = formattedAddress ? formattedAddress : emptyPlaceName;
|
|
48
|
+
const displayName = amapPlaceName2DisplayName(name, {
|
|
49
|
+
isChina,
|
|
50
|
+
...addressComponent
|
|
51
|
+
});
|
|
52
|
+
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
case "no_data":
|
|
56
|
+
case "error": {
|
|
57
|
+
handleFailed();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}, handleFailed);
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
console.warn("高德逆地理请求超时!");
|
|
64
|
+
handleFailed();
|
|
59
65
|
}, REGEO_TIMEOUT);
|
|
60
66
|
});
|
|
61
|
-
};
|
|
67
|
+
});
|
|
62
68
|
watch(
|
|
63
69
|
() => [placeKey.value],
|
|
64
70
|
async () => {
|
|
@@ -71,7 +77,7 @@ const useAmapPlace = (props) => {
|
|
|
71
77
|
return { place, updatePlace, setPlace, getPlaceByRegeo };
|
|
72
78
|
};
|
|
73
79
|
const useGmapPlace = (props) => {
|
|
74
|
-
const { onChange, emptyPlaceName } = props;
|
|
80
|
+
const { signal, onChange, emptyPlaceName } = props;
|
|
75
81
|
const defaultPoint = [...props.pointRef.value];
|
|
76
82
|
const pointRef = ref(defaultPoint);
|
|
77
83
|
const { readyPromise, language } = useMapSupplier();
|
|
@@ -82,6 +88,7 @@ const useGmapPlace = (props) => {
|
|
|
82
88
|
name: "",
|
|
83
89
|
displayName: ""
|
|
84
90
|
});
|
|
91
|
+
const abortable = createAbortable(signal);
|
|
85
92
|
const updatePlace = (value) => {
|
|
86
93
|
pointRef.value = value;
|
|
87
94
|
update();
|
|
@@ -92,28 +99,30 @@ const useGmapPlace = (props) => {
|
|
|
92
99
|
place.name = value.name;
|
|
93
100
|
place.displayName = value.displayName;
|
|
94
101
|
};
|
|
95
|
-
const getPlaceByRegeo = ([lng, lat]) => {
|
|
102
|
+
const getPlaceByRegeo = abortable(([lng, lat]) => {
|
|
96
103
|
return new Promise((resolve) => {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
|
|
101
|
-
const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
|
|
102
|
-
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
103
|
-
}).catch((err) => {
|
|
104
|
-
console.error(err);
|
|
104
|
+
const handleFailed = (err) => {
|
|
105
|
+
if (err)
|
|
106
|
+
console.error(err);
|
|
105
107
|
const name = emptyPlaceName;
|
|
106
108
|
const displayName = emptyPlaceName;
|
|
107
109
|
resolve({ lng, lat, name, displayName });
|
|
108
|
-
}
|
|
110
|
+
};
|
|
111
|
+
readyPromise.then(() => {
|
|
112
|
+
const geocoder = new google.maps.Geocoder();
|
|
113
|
+
const pipeTw = createPipeTw(language === "zh-TW");
|
|
114
|
+
geocoder.geocode({ language, location: { lng, lat } }).then(({ results }) => {
|
|
115
|
+
const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
|
|
116
|
+
const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
|
|
117
|
+
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
118
|
+
}).catch(handleFailed);
|
|
119
|
+
}, handleFailed);
|
|
109
120
|
setTimeout(() => {
|
|
110
121
|
console.warn("谷歌逆地理请求超时!");
|
|
111
|
-
|
|
112
|
-
const displayName = emptyPlaceName;
|
|
113
|
-
resolve({ lng, lat, name, displayName });
|
|
122
|
+
handleFailed();
|
|
114
123
|
}, REGEO_TIMEOUT);
|
|
115
124
|
});
|
|
116
|
-
};
|
|
125
|
+
});
|
|
117
126
|
watch(
|
|
118
127
|
() => placeKey.value,
|
|
119
128
|
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,8 +1,9 @@
|
|
|
1
1
|
import { ref, reactive } from "vue-demi";
|
|
2
2
|
import { GET_RECOMMEND_PLACE_TIMEOUT } from "../api/contants.js";
|
|
3
|
-
import {
|
|
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(
|
|
15
|
+
}).catch(logNoneManualAbortError);
|
|
15
16
|
getRecomendPlace(place, context).then((result) => resolve(result != null ? result : { available })).catch((error) => {
|
|
16
|
-
|
|
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
|
|
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 =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
110
|
-
|
|
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
|
-
|
|
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 &&
|
|
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 =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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,3 +1,4 @@
|
|
|
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;
|
|
@@ -9,3 +10,6 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
|
|
|
9
10
|
}
|
|
10
11
|
export declare const useMapSupplier: () => MapSupplierPayolad;
|
|
11
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,5 +1,5 @@
|
|
|
1
1
|
import { reactive, ref, readonly } from "vue-demi";
|
|
2
|
-
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.
|
|
2
|
+
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.4befb6c7.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.
|
|
5
|
+
import { B } from "./chunks/BusinessRecomendPlaceMap.4befb6c7.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,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
|
+
};
|
|
@@ -33,4 +33,5 @@ export declare const assertAssingedBeforeUsed: () => never;
|
|
|
33
33
|
type PickFunctionalPropertyName<T, K extends keyof T = keyof T> = K extends any ? T[K] extends (...args: any) => any ? K : never : never;
|
|
34
34
|
type PickFunctionalProperty<T> = Pick<T, PickFunctionalPropertyName<T>>;
|
|
35
35
|
export declare const proxyFunctionalProperty: <T extends object>(target: T) => PickFunctionalProperty<T>;
|
|
36
|
+
export declare const createAbortable: (signal?: AbortSignal) => <F extends ((...args: any) => Promise<any>) | undefined>(fn: F) => F;
|
|
36
37
|
export {};
|
package/dist/v3/utils/helper.js
CHANGED
|
@@ -147,12 +147,29 @@ const proxyFunctionalProperty = (target) => {
|
|
|
147
147
|
}
|
|
148
148
|
return result;
|
|
149
149
|
};
|
|
150
|
+
const createAbortable = (signal) => {
|
|
151
|
+
return function abortable(fn) {
|
|
152
|
+
if (!fn || !signal)
|
|
153
|
+
return fn;
|
|
154
|
+
return function abrotableFn(...args) {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
if (signal.aborted)
|
|
157
|
+
return reject(signal.reason);
|
|
158
|
+
signal.addEventListener("abort", () => reject(signal.reason));
|
|
159
|
+
fn(...args).then((result) => {
|
|
160
|
+
signal.aborted ? reject(signal.reason) : resolve(result);
|
|
161
|
+
}, reject);
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
150
166
|
export {
|
|
151
167
|
assertAngle,
|
|
152
168
|
assertAssingedBeforeUsed,
|
|
153
169
|
assertNotEmptyArray,
|
|
154
170
|
assertPoint,
|
|
155
171
|
assertZone,
|
|
172
|
+
createAbortable,
|
|
156
173
|
createAsyncNoFailNonNullable,
|
|
157
174
|
createReadOnce,
|
|
158
175
|
createRunOnce,
|
package/dist/v3/utils/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const availableLogKeys = /* @__PURE__ */ new Set();
|
|
2
2
|
const pkgName = "@heycar/heycars-map";
|
|
3
|
-
const pkgVersion = "2.0.0-
|
|
3
|
+
const pkgVersion = "2.0.0-switchMap4";
|
|
4
4
|
const isEnableLog = (name) => {
|
|
5
5
|
const searchParam = new URLSearchParams(location.search);
|
|
6
6
|
return searchParam.has(`log-${name}`);
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heycar/heycars-map",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-switchMap4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"checkVersion": "./bin/checkVersion.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@amap/amap-jsapi-loader": "^1.0.1",
|
|
39
39
|
"@amap/amap-jsapi-types": "^0.0.13",
|
|
40
|
-
"@googlemaps/js-api-loader": "
|
|
40
|
+
"@googlemaps/js-api-loader": "1.16.6",
|
|
41
41
|
"@googlemaps/typescript-guards": "^2.0.3",
|
|
42
42
|
"@types/google.maps": "^3.54.10",
|
|
43
43
|
"@types/lodash-es": "^4.17.6",
|