@heycar/heycars-map 2.20.0-pointSource6 → 2.21.0-gmapCost2
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/v2/App.js +1 -0
- package/dist/v2/api/apiGoogleRegeo.d.ts +7 -0
- package/dist/v2/api/apiGoogleRegeo.js +28 -0
- package/dist/v2/api/googleRoutes.js +2 -0
- package/dist/v2/components/MapProvider/MapProvider.d.ts +1 -1
- package/dist/v2/components/MapProvider/MapProvider.js +1 -1
- package/dist/v2/hooks/useDrivingRoute.js +2 -2
- package/dist/v2/hooks/useMapPlace.d.ts +1 -0
- package/dist/v2/hooks/useMapPlace.js +90 -61
- package/dist/v2/hooks/useMapRecomendPlace.js +27 -17
- package/dist/v2/hooks/useMapSupplier.d.ts +1 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v2/utils/transform.js +2 -0
- package/dist/v3/App.js +1 -0
- package/dist/v3/api/apiGoogleRegeo.d.ts +7 -0
- package/dist/v3/api/apiGoogleRegeo.js +28 -0
- package/dist/v3/api/googleRoutes.js +2 -0
- package/dist/v3/components/MapProvider/MapProvider.d.ts +1 -1
- package/dist/v3/components/MapProvider/MapProvider.js +1 -1
- package/dist/v3/hooks/useDrivingRoute.js +2 -2
- package/dist/v3/hooks/useMapPlace.d.ts +1 -0
- package/dist/v3/hooks/useMapPlace.js +90 -61
- package/dist/v3/hooks/useMapRecomendPlace.js +27 -17
- package/dist/v3/hooks/useMapSupplier.d.ts +1 -0
- package/dist/v3/utils/log.js +1 -1
- package/dist/v3/utils/transform.js +2 -0
- package/package.json +1 -1
package/dist/v2/App.js
CHANGED
|
@@ -19,6 +19,7 @@ const App = defineComponent({
|
|
|
19
19
|
"language": "en",
|
|
20
20
|
"supplier": supplierRef.value,
|
|
21
21
|
"gaodeRegeoProxyUrl": "/overseas/amap/regeo",
|
|
22
|
+
"googleRegeoProxyUrl": "/overseas/maps/regeo",
|
|
22
23
|
"hkGovernRegeoProxyUrl": "/overseas/gov/hk/identify",
|
|
23
24
|
"googleSnapRoadProxyUrl": "/overseas/maps/snapToRoads",
|
|
24
25
|
"googleRoutesProxyUrl": "/overseas/maps/routes/directions/v2",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isProxyServiceError } from "../utils/typeChecking.js";
|
|
2
|
+
import { guid } from "../utils/helper.js";
|
|
3
|
+
import { createUrlObject } from "../utils/url.js";
|
|
4
|
+
const apiGoogleRegeo = async (props) => {
|
|
5
|
+
const { proxyUrl, lng, lat, language } = props;
|
|
6
|
+
const url = createUrlObject(proxyUrl);
|
|
7
|
+
url.searchParams.set("lang", language);
|
|
8
|
+
url.searchParams.set("lng", lng.toString());
|
|
9
|
+
url.searchParams.set("lat", lat.toString());
|
|
10
|
+
url.searchParams.set("reqSid", guid());
|
|
11
|
+
const response = await fetch(url);
|
|
12
|
+
if (response.ok) {
|
|
13
|
+
const result = await response.json();
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
const error = await response.json();
|
|
17
|
+
if (isProxyServiceError(error)) {
|
|
18
|
+
const { code, msg } = error;
|
|
19
|
+
throw new Error(`apiGaodeRegeo proxy failed code: ${code}, msg:
|
|
20
|
+
${msg}`);
|
|
21
|
+
}
|
|
22
|
+
throw new Error(
|
|
23
|
+
`apiGaodeRegeo failed with unrecognized server response: ${JSON.stringify(error)}`
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
apiGoogleRegeo
|
|
28
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
|
|
2
2
|
import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
|
|
3
3
|
import { createUrlObject } from "../utils/url.js";
|
|
4
|
+
import { guid } from "../utils/helper.js";
|
|
4
5
|
const DEFAULT_GOOGLE_ROUTES_FIELDS = ["routes.polyline", "routes.legs"];
|
|
5
6
|
const ALL_ROUTES_STATUS = [
|
|
6
7
|
"OK",
|
|
@@ -109,6 +110,7 @@ async function apiGoogleRoutes(props) {
|
|
|
109
110
|
}
|
|
110
111
|
const url = createUrlObject(proxyUrl);
|
|
111
112
|
url.searchParams.set("fields", DEFAULT_GOOGLE_ROUTES_FIELDS.join(","));
|
|
113
|
+
url.searchParams.set("reqSid", guid());
|
|
112
114
|
const response = await fetch(url, {
|
|
113
115
|
method: "POST",
|
|
114
116
|
headers: { "Content-Type": "application/json" },
|
|
@@ -5,7 +5,7 @@ import { type GmapLoaderProps, type UseMapLoaderProps } from "../../hooks/useMap
|
|
|
5
5
|
import { type MapSupplierPayolad } from "../../hooks/useMapSupplier";
|
|
6
6
|
import type { AmapMap } from "../../types/interface";
|
|
7
7
|
import { type AmapProps } from "../Amap";
|
|
8
|
-
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl">;
|
|
8
|
+
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl" | "googleRegeoProxyUrl">;
|
|
9
9
|
export declare const MapProvider: import("vue-demi").DefineComponent<import("vue3").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "success" | "fail" | "downloadOptimizeEnd", MapProviderProps>;
|
|
10
10
|
export interface HeycarMapProps extends Pick<GmapLoaderProps, "fallback" | "loading">, Pick<AmapProps, "center" | "zoom"> {
|
|
11
11
|
mapRef?: SetMap<AmapMap> | SetMap<google.maps.Map>;
|
|
@@ -50,7 +50,7 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
|
|
|
50
50
|
var _a;
|
|
51
51
|
return h("div", [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
|
|
52
52
|
};
|
|
53
|
-
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl"]);
|
|
53
|
+
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl", "googleRegeoProxyUrl"]);
|
|
54
54
|
const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
|
|
55
55
|
slots,
|
|
56
56
|
emit,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { reactive } from "vue-demi";
|
|
2
2
|
import { watchPostEffectForDeepOption } from "../utils/compare.js";
|
|
3
3
|
import { googleServiceApiDrivingRoute, gaodeServiceApiDrivingRoute, amapJsApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
|
|
4
|
-
import { inTaiwan
|
|
4
|
+
import { inTaiwan } from "./useMapInChina.js";
|
|
5
5
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
6
6
|
const useADrivingRoute = (props) => {
|
|
7
7
|
const { googleRoutesProxyUrl, gaodeDirectionDrivingProxyUrl } = useMapSupplier();
|
|
@@ -48,7 +48,7 @@ const useGDrivingRoute = (props) => {
|
|
|
48
48
|
});
|
|
49
49
|
const gmapDirectionsService = new google.maps.DirectionsService();
|
|
50
50
|
const apiMapDrivingRoute = (from, to, waypoints = []) => {
|
|
51
|
-
return gaodeDirectionDrivingProxyUrl &&
|
|
51
|
+
return gaodeDirectionDrivingProxyUrl && !inTaiwan(from) ? gaodeServiceApiDrivingRoute(from, to, waypoints, gaodeDirectionDrivingProxyUrl) : googleRoutesProxyUrl ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : gmapJsApiDrivingRoute(from, to, waypoints, gmapDirectionsService);
|
|
52
52
|
};
|
|
53
53
|
watchPostEffectForDeepOption(
|
|
54
54
|
() => {
|
|
@@ -5,18 +5,18 @@ import { PointSource } from "../types/interface.js";
|
|
|
5
5
|
import { createPipeTw } from "../utils/cn2tw.js";
|
|
6
6
|
import { equalAssign, AbortSignalAny, sleep } from "../utils/helper.js";
|
|
7
7
|
import { getHKGovernResult } from "../utils/hongkongGovernGeoCoder.js";
|
|
8
|
-
import {
|
|
9
|
-
import { inChina, inTaiwan
|
|
8
|
+
import { amapPlaceName2DisplayName, signal2promise, toLocalWgs84Force, gmapPlaceName2DisplayName } from "../utils/transform.js";
|
|
9
|
+
import { inHongkong, inChina, inTaiwan } from "./useMapInChina.js";
|
|
10
10
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
11
11
|
import { useUpdate } from "./useUdate.js";
|
|
12
12
|
import { useMapGCJ02 } from "./useMapGCJ02.js";
|
|
13
13
|
import { apiGaodeRegeo } from "../api/gaodeRegeo.js";
|
|
14
|
+
import { apiGoogleRegeo } from "../api/apiGoogleRegeo.js";
|
|
14
15
|
const useAmapPlace = (props) => {
|
|
15
16
|
const { signal: inputSignal, onChange, emptyPlaceName } = props;
|
|
16
17
|
const defaultPoint = [...props.pointRef.value];
|
|
17
18
|
const pointRef = ref(defaultPoint);
|
|
18
19
|
const { readyPromise, language, hkGovernRegeoProxyUrl, gaodeRegeoProxyUrl } = useMapSupplier();
|
|
19
|
-
const { toCoordinateType } = useMapGCJ02();
|
|
20
20
|
const place = reactive({
|
|
21
21
|
lng: pointRef.value[0],
|
|
22
22
|
lat: pointRef.value[1],
|
|
@@ -34,6 +34,7 @@ const useAmapPlace = (props) => {
|
|
|
34
34
|
place.name = value.name;
|
|
35
35
|
place.displayName = value.displayName;
|
|
36
36
|
};
|
|
37
|
+
const { getPlaceByRegeo: getPlaceByGmapRegeo } = useGmapPlace(props);
|
|
37
38
|
const getPlaceByRegeo = ([lng, lat], opt) => {
|
|
38
39
|
const signal = AbortSignalAny([opt == null ? void 0 : opt.signal, inputSignal]);
|
|
39
40
|
const regeoPromise = new Promise((resolve) => {
|
|
@@ -42,37 +43,13 @@ const useAmapPlace = (props) => {
|
|
|
42
43
|
const displayName = emptyPlaceName;
|
|
43
44
|
resolve({ lng, lat, name, displayName, pointSource: PointSource.OTHERS });
|
|
44
45
|
};
|
|
46
|
+
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
47
|
+
if (isUseHKGovern) {
|
|
48
|
+
return getPlaceByGmapRegeo([lng, lat], opt).then((res) => resolve(res));
|
|
49
|
+
}
|
|
45
50
|
readyPromise.then(() => {
|
|
46
51
|
const pipeTw = createPipeTw(language === "zh-TW");
|
|
47
52
|
const isChinese = inChina([lng, lat]) || inTaiwan([lng, lat]);
|
|
48
|
-
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
49
|
-
const startTime = Date.now();
|
|
50
|
-
let hkReturned = !isUseHKGovern;
|
|
51
|
-
let amapReturned = false;
|
|
52
|
-
if (isUseHKGovern) {
|
|
53
|
-
const [finalLng, finalLat] = toLocalWgs84Force([lng, lat], toCoordinateType([lng, lat]));
|
|
54
|
-
console.log("lng:", lng, finalLng, "lat:", lat, finalLat);
|
|
55
|
-
apiHongKongGovernDriving({
|
|
56
|
-
proxyUrl: hkGovernRegeoProxyUrl,
|
|
57
|
-
lng: finalLng,
|
|
58
|
-
lat: finalLat,
|
|
59
|
-
language: language === "zh-TW" ? "zh" : language
|
|
60
|
-
}).then(({ result, origin }) => {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
const hkGovernRes = getHKGovernResult((_b = (_a = result == null ? void 0 : result.data) == null ? void 0 : _a.rawResponse) == null ? void 0 : _b.results, origin);
|
|
63
|
-
if (!amapReturned && hkGovernRes) {
|
|
64
|
-
const name = language === "en" ? hkGovernRes.ename : hkGovernRes.cname;
|
|
65
|
-
hkReturned = true;
|
|
66
|
-
resolve({
|
|
67
|
-
lng,
|
|
68
|
-
lat,
|
|
69
|
-
name,
|
|
70
|
-
displayName: name,
|
|
71
|
-
pointSource: PointSource.HKGOV
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
53
|
if (gaodeRegeoProxyUrl) {
|
|
77
54
|
apiGaodeRegeo({
|
|
78
55
|
proxyUrl: gaodeRegeoProxyUrl,
|
|
@@ -81,16 +58,6 @@ const useAmapPlace = (props) => {
|
|
|
81
58
|
language: language === "en" ? "en" : "zh_cn"
|
|
82
59
|
}).then(async (result) => {
|
|
83
60
|
clearTimeout(timer);
|
|
84
|
-
if (isUseHKGovern) {
|
|
85
|
-
const diff = Date.now() - startTime;
|
|
86
|
-
console.log("==time of AmapReGeo==", diff);
|
|
87
|
-
const rest = HK_GOVERN_API_TIMEOUT - diff;
|
|
88
|
-
if (rest >= 0)
|
|
89
|
-
await sleep(rest);
|
|
90
|
-
console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
|
|
91
|
-
if (hkReturned)
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
61
|
const { formatted_address, addressComponent } = result.regeocode;
|
|
95
62
|
const _formmatted_address = typeof formatted_address === "string" ? formatted_address : "";
|
|
96
63
|
const name = _formmatted_address || emptyPlaceName;
|
|
@@ -98,7 +65,6 @@ const useAmapPlace = (props) => {
|
|
|
98
65
|
isChinese,
|
|
99
66
|
...addressComponent
|
|
100
67
|
});
|
|
101
|
-
amapReturned = true;
|
|
102
68
|
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName), pointSource: PointSource.GAODE });
|
|
103
69
|
}).catch(() => {
|
|
104
70
|
handleFailed();
|
|
@@ -107,16 +73,6 @@ const useAmapPlace = (props) => {
|
|
|
107
73
|
const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
|
|
108
74
|
geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
|
|
109
75
|
clearTimeout(timer);
|
|
110
|
-
if (isUseHKGovern) {
|
|
111
|
-
const diff = Date.now() - startTime;
|
|
112
|
-
console.log("==time of AmapReGeo==", diff);
|
|
113
|
-
const rest = HK_GOVERN_API_TIMEOUT - diff;
|
|
114
|
-
if (rest >= 0)
|
|
115
|
-
await sleep(rest);
|
|
116
|
-
console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
|
|
117
|
-
if (hkReturned)
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
76
|
switch (status) {
|
|
121
77
|
case "complete": {
|
|
122
78
|
const { formattedAddress, addressComponent } = result.regeocode;
|
|
@@ -125,7 +81,6 @@ const useAmapPlace = (props) => {
|
|
|
125
81
|
isChinese,
|
|
126
82
|
...addressComponent
|
|
127
83
|
});
|
|
128
|
-
amapReturned = true;
|
|
129
84
|
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName), pointSource: PointSource.GAODE });
|
|
130
85
|
return;
|
|
131
86
|
}
|
|
@@ -159,7 +114,8 @@ const useGmapPlace = (props) => {
|
|
|
159
114
|
const { signal: inputSignal, onChange, emptyPlaceName } = props;
|
|
160
115
|
const defaultPoint = [...props.pointRef.value];
|
|
161
116
|
const pointRef = ref(defaultPoint);
|
|
162
|
-
const { readyPromise, language } = useMapSupplier();
|
|
117
|
+
const { readyPromise, language, googleRegeoProxyUrl, hkGovernRegeoProxyUrl } = useMapSupplier();
|
|
118
|
+
const { toCoordinateType } = useMapGCJ02();
|
|
163
119
|
const { idx: placeKey, update } = useUpdate();
|
|
164
120
|
const place = reactive({
|
|
165
121
|
lng: pointRef.value[0],
|
|
@@ -178,6 +134,7 @@ const useGmapPlace = (props) => {
|
|
|
178
134
|
place.displayName = value.displayName;
|
|
179
135
|
};
|
|
180
136
|
const getPlaceByRegeo = ([lng, lat], opt) => {
|
|
137
|
+
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
181
138
|
const signal = AbortSignalAny([opt == null ? void 0 : opt.signal, inputSignal]);
|
|
182
139
|
const regeoPromise = new Promise((resolve) => {
|
|
183
140
|
const handleFailed = (err) => {
|
|
@@ -187,14 +144,86 @@ const useGmapPlace = (props) => {
|
|
|
187
144
|
const displayName = emptyPlaceName;
|
|
188
145
|
resolve({ lng, lat, name, displayName, pointSource: PointSource.OTHERS });
|
|
189
146
|
};
|
|
190
|
-
readyPromise.then(() => {
|
|
191
|
-
|
|
147
|
+
readyPromise.then(async () => {
|
|
148
|
+
var _a;
|
|
192
149
|
const pipeTw = createPipeTw(language === "zh-TW");
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
150
|
+
let hkReturned = false;
|
|
151
|
+
let mapReturned = false;
|
|
152
|
+
if (isUseHKGovern) {
|
|
153
|
+
const [finalLng, finalLat] = toLocalWgs84Force([lng, lat], toCoordinateType([lng, lat]));
|
|
154
|
+
console.log("lng:", lng, finalLng, "lat:", lat, finalLat);
|
|
155
|
+
apiHongKongGovernDriving({
|
|
156
|
+
proxyUrl: hkGovernRegeoProxyUrl,
|
|
157
|
+
lng: finalLng,
|
|
158
|
+
lat: finalLat,
|
|
159
|
+
language: language === "zh-TW" ? "zh" : language
|
|
160
|
+
}).then(({ result, origin }) => {
|
|
161
|
+
var _a2, _b;
|
|
162
|
+
const hkGovernRes = getHKGovernResult((_b = (_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.rawResponse) == null ? void 0 : _b.results, origin);
|
|
163
|
+
if (mapReturned || !hkGovernRes)
|
|
164
|
+
return;
|
|
165
|
+
const name = language === "en" ? hkGovernRes.ename : hkGovernRes.cname;
|
|
166
|
+
hkReturned = true;
|
|
167
|
+
const addressInfo = {
|
|
168
|
+
lng,
|
|
169
|
+
lat,
|
|
170
|
+
name,
|
|
171
|
+
displayName: name,
|
|
172
|
+
pointSource: PointSource.HKGOV
|
|
173
|
+
};
|
|
174
|
+
console.log("==港府接口返回结果==", JSON.stringify(addressInfo));
|
|
175
|
+
resolve(addressInfo);
|
|
176
|
+
});
|
|
177
|
+
await sleep(HK_GOVERN_API_TIMEOUT);
|
|
178
|
+
if ((_a = props.findAttachedPlaceDone) == null ? void 0 : _a.value)
|
|
179
|
+
return;
|
|
180
|
+
if (hkReturned)
|
|
181
|
+
return;
|
|
182
|
+
console.log("==1s后推荐点和港府均未返回,开始请求谷歌逆地理==");
|
|
183
|
+
}
|
|
184
|
+
if (googleRegeoProxyUrl) {
|
|
185
|
+
apiGoogleRegeo({
|
|
186
|
+
proxyUrl: googleRegeoProxyUrl,
|
|
187
|
+
lng,
|
|
188
|
+
lat,
|
|
189
|
+
language
|
|
190
|
+
}).then(({ results }) => {
|
|
191
|
+
var _a2, _b;
|
|
192
|
+
const name = ((_a2 = results[0]) == null ? void 0 : _a2.formatted_address) || emptyPlaceName;
|
|
193
|
+
const displayName = gmapPlaceName2DisplayName(name, (_b = results[0]) == null ? void 0 : _b.address_components);
|
|
194
|
+
if (hkReturned)
|
|
195
|
+
return;
|
|
196
|
+
mapReturned = true;
|
|
197
|
+
const addressInfo = {
|
|
198
|
+
lng,
|
|
199
|
+
lat,
|
|
200
|
+
name: pipeTw(name),
|
|
201
|
+
displayName: pipeTw(displayName),
|
|
202
|
+
pointSource: PointSource.GOOGLE
|
|
203
|
+
};
|
|
204
|
+
console.log("==谷歌逆地理返回结果==", JSON.stringify(addressInfo));
|
|
205
|
+
resolve(addressInfo);
|
|
206
|
+
}).catch(handleFailed);
|
|
207
|
+
} else {
|
|
208
|
+
const geocoder = new google.maps.Geocoder();
|
|
209
|
+
geocoder.geocode({ language, location: { lng, lat } }).finally(() => clearTimeout(timer)).then(({ results }) => {
|
|
210
|
+
var _a2, _b;
|
|
211
|
+
const name = ((_a2 = results[0]) == null ? void 0 : _a2.formatted_address) || emptyPlaceName;
|
|
212
|
+
const displayName = gmapPlaceName2DisplayName(name, (_b = results[0]) == null ? void 0 : _b.address_components);
|
|
213
|
+
if (hkReturned)
|
|
214
|
+
return;
|
|
215
|
+
mapReturned = true;
|
|
216
|
+
const addressInfo = {
|
|
217
|
+
lng,
|
|
218
|
+
lat,
|
|
219
|
+
name: pipeTw(name),
|
|
220
|
+
displayName: pipeTw(displayName),
|
|
221
|
+
pointSource: PointSource.GOOGLE
|
|
222
|
+
};
|
|
223
|
+
console.log("==谷歌逆地理返回结果==", JSON.stringify(addressInfo));
|
|
224
|
+
resolve(addressInfo);
|
|
225
|
+
}).catch(handleFailed);
|
|
226
|
+
}
|
|
198
227
|
}, handleFailed);
|
|
199
228
|
const timer = setTimeout(() => {
|
|
200
229
|
console.warn("谷歌逆地理请求超时!");
|
|
@@ -52,6 +52,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
52
52
|
onChangePlace
|
|
53
53
|
} = props;
|
|
54
54
|
const availableRef = ref(true);
|
|
55
|
+
const findAttachedPlaceDone = ref(false);
|
|
55
56
|
const recommendTypeRef = ref(DEFAULT_RECOMMEND_TYPE);
|
|
56
57
|
const placeCandidatesRef = ref([]);
|
|
57
58
|
const zoneRef = ref();
|
|
@@ -60,7 +61,8 @@ const useMapRecomendPlace = (props) => {
|
|
|
60
61
|
const { getPlaceByRegeo } = useMapPlace({
|
|
61
62
|
emptyPlaceName,
|
|
62
63
|
pointRef: ref([...defaultPoint]),
|
|
63
|
-
signal: inputSignal
|
|
64
|
+
signal: inputSignal,
|
|
65
|
+
findAttachedPlaceDone
|
|
64
66
|
});
|
|
65
67
|
const recomendPlace = reactive({
|
|
66
68
|
lng: defaultPoint[0],
|
|
@@ -104,22 +106,30 @@ const useMapRecomendPlace = (props) => {
|
|
|
104
106
|
const [lng, lat] = point;
|
|
105
107
|
const { type, zone, available, candidates } = prevState;
|
|
106
108
|
if (!zone || !apiLocalIsPointInRing(point, zone.path)) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
findAttachedPlaceDone.value = false;
|
|
111
|
+
const reGeoPlacePromiseIgnored = recoverablyIgnoreManualAbortReject(
|
|
112
|
+
getPlaceByRegeo(point, opt)
|
|
113
|
+
);
|
|
114
|
+
findAttachedPlace({ lng, lat, name: "", displayName: "" }, opt).then(async ({
|
|
115
|
+
place: closestPlace,
|
|
116
|
+
candidates: candidates2,
|
|
117
|
+
available: available2,
|
|
118
|
+
type: type2,
|
|
119
|
+
zone: zone2
|
|
120
|
+
}) => {
|
|
121
|
+
findAttachedPlaceDone.value = true;
|
|
122
|
+
const adsorbed = isPlacesInclude(candidates2, closestPlace);
|
|
123
|
+
console.log("==推荐点接口==", `是否吸附:${adsorbed}`, `地址:${JSON.stringify(closestPlace)}`);
|
|
124
|
+
if (adsorbed) {
|
|
125
|
+
resolve({ place: { ...closestPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 });
|
|
126
|
+
} else {
|
|
127
|
+
const regeoPlace = await reGeoPlacePromiseIgnored.recover();
|
|
128
|
+
console.log("==RegeoPlace==", regeoPlace);
|
|
129
|
+
resolve({ place: { ...regeoPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
123
133
|
}
|
|
124
134
|
if (type === "Forbidden") {
|
|
125
135
|
const regeoPlace = await getPlaceByRegeo(point, opt);
|
|
@@ -14,6 +14,7 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
|
|
|
14
14
|
googleSnapRoadProxyUrl?: string;
|
|
15
15
|
hkGovernRegeoProxyUrl?: string;
|
|
16
16
|
gaodeRegeoProxyUrl?: string;
|
|
17
|
+
googleRegeoProxyUrl?: string;
|
|
17
18
|
themeVariables?: MapThemeVariables;
|
|
18
19
|
renderLoadFailedTitle?: (status: Status) => string | undefined;
|
|
19
20
|
renderLoadFailedDescription?: (status: Status) => string | undefined;
|
package/dist/v2/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.
|
|
3
|
+
const pkgVersion = "2.21.0-gmapCost2";
|
|
4
4
|
const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
|
|
5
5
|
const enableSessionLogKey = (key) => {
|
|
6
6
|
const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
|
|
@@ -191,6 +191,8 @@ const EMPTY_REGEX = /^$/;
|
|
|
191
191
|
const POSTAL_CODE_ZH_DESC = "邮政编码:";
|
|
192
192
|
function gmapPlaceName2DisplayName(name, addressComponents) {
|
|
193
193
|
var _a, _b;
|
|
194
|
+
if (!addressComponents)
|
|
195
|
+
return name;
|
|
194
196
|
const addressComponentMap = gmapAddressComponentList2AddressComponentMap(addressComponents);
|
|
195
197
|
const streetNumberComponent = addressComponentMap["street_number"];
|
|
196
198
|
const routeComponent = addressComponentMap["route"];
|
package/dist/v3/App.js
CHANGED
|
@@ -18,6 +18,7 @@ const App = /* @__PURE__ */ defineComponent({
|
|
|
18
18
|
"language": "en",
|
|
19
19
|
"supplier": supplierRef.value,
|
|
20
20
|
"gaodeRegeoProxyUrl": "/overseas/amap/regeo",
|
|
21
|
+
"googleRegeoProxyUrl": "/overseas/maps/regeo",
|
|
21
22
|
"hkGovernRegeoProxyUrl": "/overseas/gov/hk/identify",
|
|
22
23
|
"googleSnapRoadProxyUrl": "/overseas/maps/snapToRoads",
|
|
23
24
|
"googleRoutesProxyUrl": "/overseas/maps/routes/directions/v2",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isProxyServiceError } from "../utils/typeChecking.js";
|
|
2
|
+
import { guid } from "../utils/helper.js";
|
|
3
|
+
import { createUrlObject } from "../utils/url.js";
|
|
4
|
+
const apiGoogleRegeo = async (props) => {
|
|
5
|
+
const { proxyUrl, lng, lat, language } = props;
|
|
6
|
+
const url = createUrlObject(proxyUrl);
|
|
7
|
+
url.searchParams.set("lang", language);
|
|
8
|
+
url.searchParams.set("lng", lng.toString());
|
|
9
|
+
url.searchParams.set("lat", lat.toString());
|
|
10
|
+
url.searchParams.set("reqSid", guid());
|
|
11
|
+
const response = await fetch(url);
|
|
12
|
+
if (response.ok) {
|
|
13
|
+
const result = await response.json();
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
const error = await response.json();
|
|
17
|
+
if (isProxyServiceError(error)) {
|
|
18
|
+
const { code, msg } = error;
|
|
19
|
+
throw new Error(`apiGaodeRegeo proxy failed code: ${code}, msg:
|
|
20
|
+
${msg}`);
|
|
21
|
+
}
|
|
22
|
+
throw new Error(
|
|
23
|
+
`apiGaodeRegeo failed with unrecognized server response: ${JSON.stringify(error)}`
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
apiGoogleRegeo
|
|
28
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
|
|
2
2
|
import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
|
|
3
3
|
import { createUrlObject } from "../utils/url.js";
|
|
4
|
+
import { guid } from "../utils/helper.js";
|
|
4
5
|
const DEFAULT_GOOGLE_ROUTES_FIELDS = ["routes.polyline", "routes.legs"];
|
|
5
6
|
const ALL_ROUTES_STATUS = [
|
|
6
7
|
"OK",
|
|
@@ -109,6 +110,7 @@ async function apiGoogleRoutes(props) {
|
|
|
109
110
|
}
|
|
110
111
|
const url = createUrlObject(proxyUrl);
|
|
111
112
|
url.searchParams.set("fields", DEFAULT_GOOGLE_ROUTES_FIELDS.join(","));
|
|
113
|
+
url.searchParams.set("reqSid", guid());
|
|
112
114
|
const response = await fetch(url, {
|
|
113
115
|
method: "POST",
|
|
114
116
|
headers: { "Content-Type": "application/json" },
|
|
@@ -5,7 +5,7 @@ import { Status, type GmapLoaderProps, type UseMapLoaderProps } from "../../hook
|
|
|
5
5
|
import { type MapSupplierPayolad } from "../../hooks/useMapSupplier";
|
|
6
6
|
import type { AmapMap } from "../../types/interface";
|
|
7
7
|
import { type AmapProps } from "../Amap";
|
|
8
|
-
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl">;
|
|
8
|
+
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl" | "googleRegeoProxyUrl">;
|
|
9
9
|
export declare const MapProvider: import("vue-demi").DefineComponent<import("vue-demi").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "success" | "fail" | "downloadOptimizeEnd", import("vue-demi").PublicProps, MapProviderProps, MapProviderProps, import("vue-demi").SlotsType<{
|
|
10
10
|
renderLoadFailedTitle?: ((status: Status) => string | undefined) | undefined;
|
|
11
11
|
renderLoadFailedDescription?: ((status: Status) => string | undefined) | undefined;
|
|
@@ -53,7 +53,7 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
|
|
|
53
53
|
var _a;
|
|
54
54
|
return createVNode("div", null, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
|
|
55
55
|
};
|
|
56
|
-
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl"]);
|
|
56
|
+
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl", "googleRegeoProxyUrl"]);
|
|
57
57
|
const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
|
|
58
58
|
slots,
|
|
59
59
|
emit,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { reactive } from "vue-demi";
|
|
2
2
|
import { watchPostEffectForDeepOption } from "../utils/compare.js";
|
|
3
3
|
import { googleServiceApiDrivingRoute, gaodeServiceApiDrivingRoute, amapJsApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
|
|
4
|
-
import { inTaiwan
|
|
4
|
+
import { inTaiwan } from "./useMapInChina.js";
|
|
5
5
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
6
6
|
const useADrivingRoute = (props) => {
|
|
7
7
|
const { googleRoutesProxyUrl, gaodeDirectionDrivingProxyUrl } = useMapSupplier();
|
|
@@ -48,7 +48,7 @@ const useGDrivingRoute = (props) => {
|
|
|
48
48
|
});
|
|
49
49
|
const gmapDirectionsService = new google.maps.DirectionsService();
|
|
50
50
|
const apiMapDrivingRoute = (from, to, waypoints = []) => {
|
|
51
|
-
return gaodeDirectionDrivingProxyUrl &&
|
|
51
|
+
return gaodeDirectionDrivingProxyUrl && !inTaiwan(from) ? gaodeServiceApiDrivingRoute(from, to, waypoints, gaodeDirectionDrivingProxyUrl) : googleRoutesProxyUrl ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : gmapJsApiDrivingRoute(from, to, waypoints, gmapDirectionsService);
|
|
52
52
|
};
|
|
53
53
|
watchPostEffectForDeepOption(
|
|
54
54
|
() => {
|
|
@@ -5,18 +5,18 @@ import { PointSource } from "../types/interface.js";
|
|
|
5
5
|
import { createPipeTw } from "../utils/cn2tw.js";
|
|
6
6
|
import { equalAssign, AbortSignalAny, sleep } from "../utils/helper.js";
|
|
7
7
|
import { getHKGovernResult } from "../utils/hongkongGovernGeoCoder.js";
|
|
8
|
-
import {
|
|
9
|
-
import { inChina, inTaiwan
|
|
8
|
+
import { amapPlaceName2DisplayName, signal2promise, toLocalWgs84Force, gmapPlaceName2DisplayName } from "../utils/transform.js";
|
|
9
|
+
import { inHongkong, inChina, inTaiwan } from "./useMapInChina.js";
|
|
10
10
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
11
11
|
import { useUpdate } from "./useUdate.js";
|
|
12
12
|
import { useMapGCJ02 } from "./useMapGCJ02.js";
|
|
13
13
|
import { apiGaodeRegeo } from "../api/gaodeRegeo.js";
|
|
14
|
+
import { apiGoogleRegeo } from "../api/apiGoogleRegeo.js";
|
|
14
15
|
const useAmapPlace = (props) => {
|
|
15
16
|
const { signal: inputSignal, onChange, emptyPlaceName } = props;
|
|
16
17
|
const defaultPoint = [...props.pointRef.value];
|
|
17
18
|
const pointRef = ref(defaultPoint);
|
|
18
19
|
const { readyPromise, language, hkGovernRegeoProxyUrl, gaodeRegeoProxyUrl } = useMapSupplier();
|
|
19
|
-
const { toCoordinateType } = useMapGCJ02();
|
|
20
20
|
const place = reactive({
|
|
21
21
|
lng: pointRef.value[0],
|
|
22
22
|
lat: pointRef.value[1],
|
|
@@ -34,6 +34,7 @@ const useAmapPlace = (props) => {
|
|
|
34
34
|
place.name = value.name;
|
|
35
35
|
place.displayName = value.displayName;
|
|
36
36
|
};
|
|
37
|
+
const { getPlaceByRegeo: getPlaceByGmapRegeo } = useGmapPlace(props);
|
|
37
38
|
const getPlaceByRegeo = ([lng, lat], opt) => {
|
|
38
39
|
const signal = AbortSignalAny([opt == null ? void 0 : opt.signal, inputSignal]);
|
|
39
40
|
const regeoPromise = new Promise((resolve) => {
|
|
@@ -42,37 +43,13 @@ const useAmapPlace = (props) => {
|
|
|
42
43
|
const displayName = emptyPlaceName;
|
|
43
44
|
resolve({ lng, lat, name, displayName, pointSource: PointSource.OTHERS });
|
|
44
45
|
};
|
|
46
|
+
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
47
|
+
if (isUseHKGovern) {
|
|
48
|
+
return getPlaceByGmapRegeo([lng, lat], opt).then((res) => resolve(res));
|
|
49
|
+
}
|
|
45
50
|
readyPromise.then(() => {
|
|
46
51
|
const pipeTw = createPipeTw(language === "zh-TW");
|
|
47
52
|
const isChinese = inChina([lng, lat]) || inTaiwan([lng, lat]);
|
|
48
|
-
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
49
|
-
const startTime = Date.now();
|
|
50
|
-
let hkReturned = !isUseHKGovern;
|
|
51
|
-
let amapReturned = false;
|
|
52
|
-
if (isUseHKGovern) {
|
|
53
|
-
const [finalLng, finalLat] = toLocalWgs84Force([lng, lat], toCoordinateType([lng, lat]));
|
|
54
|
-
console.log("lng:", lng, finalLng, "lat:", lat, finalLat);
|
|
55
|
-
apiHongKongGovernDriving({
|
|
56
|
-
proxyUrl: hkGovernRegeoProxyUrl,
|
|
57
|
-
lng: finalLng,
|
|
58
|
-
lat: finalLat,
|
|
59
|
-
language: language === "zh-TW" ? "zh" : language
|
|
60
|
-
}).then(({ result, origin }) => {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
const hkGovernRes = getHKGovernResult((_b = (_a = result == null ? void 0 : result.data) == null ? void 0 : _a.rawResponse) == null ? void 0 : _b.results, origin);
|
|
63
|
-
if (!amapReturned && hkGovernRes) {
|
|
64
|
-
const name = language === "en" ? hkGovernRes.ename : hkGovernRes.cname;
|
|
65
|
-
hkReturned = true;
|
|
66
|
-
resolve({
|
|
67
|
-
lng,
|
|
68
|
-
lat,
|
|
69
|
-
name,
|
|
70
|
-
displayName: name,
|
|
71
|
-
pointSource: PointSource.HKGOV
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
53
|
if (gaodeRegeoProxyUrl) {
|
|
77
54
|
apiGaodeRegeo({
|
|
78
55
|
proxyUrl: gaodeRegeoProxyUrl,
|
|
@@ -81,16 +58,6 @@ const useAmapPlace = (props) => {
|
|
|
81
58
|
language: language === "en" ? "en" : "zh_cn"
|
|
82
59
|
}).then(async (result) => {
|
|
83
60
|
clearTimeout(timer);
|
|
84
|
-
if (isUseHKGovern) {
|
|
85
|
-
const diff = Date.now() - startTime;
|
|
86
|
-
console.log("==time of AmapReGeo==", diff);
|
|
87
|
-
const rest = HK_GOVERN_API_TIMEOUT - diff;
|
|
88
|
-
if (rest >= 0)
|
|
89
|
-
await sleep(rest);
|
|
90
|
-
console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
|
|
91
|
-
if (hkReturned)
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
61
|
const { formatted_address, addressComponent } = result.regeocode;
|
|
95
62
|
const _formmatted_address = typeof formatted_address === "string" ? formatted_address : "";
|
|
96
63
|
const name = _formmatted_address || emptyPlaceName;
|
|
@@ -98,7 +65,6 @@ const useAmapPlace = (props) => {
|
|
|
98
65
|
isChinese,
|
|
99
66
|
...addressComponent
|
|
100
67
|
});
|
|
101
|
-
amapReturned = true;
|
|
102
68
|
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName), pointSource: PointSource.GAODE });
|
|
103
69
|
}).catch(() => {
|
|
104
70
|
handleFailed();
|
|
@@ -107,16 +73,6 @@ const useAmapPlace = (props) => {
|
|
|
107
73
|
const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
|
|
108
74
|
geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
|
|
109
75
|
clearTimeout(timer);
|
|
110
|
-
if (isUseHKGovern) {
|
|
111
|
-
const diff = Date.now() - startTime;
|
|
112
|
-
console.log("==time of AmapReGeo==", diff);
|
|
113
|
-
const rest = HK_GOVERN_API_TIMEOUT - diff;
|
|
114
|
-
if (rest >= 0)
|
|
115
|
-
await sleep(rest);
|
|
116
|
-
console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
|
|
117
|
-
if (hkReturned)
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
76
|
switch (status) {
|
|
121
77
|
case "complete": {
|
|
122
78
|
const { formattedAddress, addressComponent } = result.regeocode;
|
|
@@ -125,7 +81,6 @@ const useAmapPlace = (props) => {
|
|
|
125
81
|
isChinese,
|
|
126
82
|
...addressComponent
|
|
127
83
|
});
|
|
128
|
-
amapReturned = true;
|
|
129
84
|
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName), pointSource: PointSource.GAODE });
|
|
130
85
|
return;
|
|
131
86
|
}
|
|
@@ -159,7 +114,8 @@ const useGmapPlace = (props) => {
|
|
|
159
114
|
const { signal: inputSignal, onChange, emptyPlaceName } = props;
|
|
160
115
|
const defaultPoint = [...props.pointRef.value];
|
|
161
116
|
const pointRef = ref(defaultPoint);
|
|
162
|
-
const { readyPromise, language } = useMapSupplier();
|
|
117
|
+
const { readyPromise, language, googleRegeoProxyUrl, hkGovernRegeoProxyUrl } = useMapSupplier();
|
|
118
|
+
const { toCoordinateType } = useMapGCJ02();
|
|
163
119
|
const { idx: placeKey, update } = useUpdate();
|
|
164
120
|
const place = reactive({
|
|
165
121
|
lng: pointRef.value[0],
|
|
@@ -178,6 +134,7 @@ const useGmapPlace = (props) => {
|
|
|
178
134
|
place.displayName = value.displayName;
|
|
179
135
|
};
|
|
180
136
|
const getPlaceByRegeo = ([lng, lat], opt) => {
|
|
137
|
+
const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
|
|
181
138
|
const signal = AbortSignalAny([opt == null ? void 0 : opt.signal, inputSignal]);
|
|
182
139
|
const regeoPromise = new Promise((resolve) => {
|
|
183
140
|
const handleFailed = (err) => {
|
|
@@ -187,14 +144,86 @@ const useGmapPlace = (props) => {
|
|
|
187
144
|
const displayName = emptyPlaceName;
|
|
188
145
|
resolve({ lng, lat, name, displayName, pointSource: PointSource.OTHERS });
|
|
189
146
|
};
|
|
190
|
-
readyPromise.then(() => {
|
|
191
|
-
|
|
147
|
+
readyPromise.then(async () => {
|
|
148
|
+
var _a;
|
|
192
149
|
const pipeTw = createPipeTw(language === "zh-TW");
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
150
|
+
let hkReturned = false;
|
|
151
|
+
let mapReturned = false;
|
|
152
|
+
if (isUseHKGovern) {
|
|
153
|
+
const [finalLng, finalLat] = toLocalWgs84Force([lng, lat], toCoordinateType([lng, lat]));
|
|
154
|
+
console.log("lng:", lng, finalLng, "lat:", lat, finalLat);
|
|
155
|
+
apiHongKongGovernDriving({
|
|
156
|
+
proxyUrl: hkGovernRegeoProxyUrl,
|
|
157
|
+
lng: finalLng,
|
|
158
|
+
lat: finalLat,
|
|
159
|
+
language: language === "zh-TW" ? "zh" : language
|
|
160
|
+
}).then(({ result, origin }) => {
|
|
161
|
+
var _a2, _b;
|
|
162
|
+
const hkGovernRes = getHKGovernResult((_b = (_a2 = result == null ? void 0 : result.data) == null ? void 0 : _a2.rawResponse) == null ? void 0 : _b.results, origin);
|
|
163
|
+
if (mapReturned || !hkGovernRes)
|
|
164
|
+
return;
|
|
165
|
+
const name = language === "en" ? hkGovernRes.ename : hkGovernRes.cname;
|
|
166
|
+
hkReturned = true;
|
|
167
|
+
const addressInfo = {
|
|
168
|
+
lng,
|
|
169
|
+
lat,
|
|
170
|
+
name,
|
|
171
|
+
displayName: name,
|
|
172
|
+
pointSource: PointSource.HKGOV
|
|
173
|
+
};
|
|
174
|
+
console.log("==港府接口返回结果==", JSON.stringify(addressInfo));
|
|
175
|
+
resolve(addressInfo);
|
|
176
|
+
});
|
|
177
|
+
await sleep(HK_GOVERN_API_TIMEOUT);
|
|
178
|
+
if ((_a = props.findAttachedPlaceDone) == null ? void 0 : _a.value)
|
|
179
|
+
return;
|
|
180
|
+
if (hkReturned)
|
|
181
|
+
return;
|
|
182
|
+
console.log("==1s后推荐点和港府均未返回,开始请求谷歌逆地理==");
|
|
183
|
+
}
|
|
184
|
+
if (googleRegeoProxyUrl) {
|
|
185
|
+
apiGoogleRegeo({
|
|
186
|
+
proxyUrl: googleRegeoProxyUrl,
|
|
187
|
+
lng,
|
|
188
|
+
lat,
|
|
189
|
+
language
|
|
190
|
+
}).then(({ results }) => {
|
|
191
|
+
var _a2, _b;
|
|
192
|
+
const name = ((_a2 = results[0]) == null ? void 0 : _a2.formatted_address) || emptyPlaceName;
|
|
193
|
+
const displayName = gmapPlaceName2DisplayName(name, (_b = results[0]) == null ? void 0 : _b.address_components);
|
|
194
|
+
if (hkReturned)
|
|
195
|
+
return;
|
|
196
|
+
mapReturned = true;
|
|
197
|
+
const addressInfo = {
|
|
198
|
+
lng,
|
|
199
|
+
lat,
|
|
200
|
+
name: pipeTw(name),
|
|
201
|
+
displayName: pipeTw(displayName),
|
|
202
|
+
pointSource: PointSource.GOOGLE
|
|
203
|
+
};
|
|
204
|
+
console.log("==谷歌逆地理返回结果==", JSON.stringify(addressInfo));
|
|
205
|
+
resolve(addressInfo);
|
|
206
|
+
}).catch(handleFailed);
|
|
207
|
+
} else {
|
|
208
|
+
const geocoder = new google.maps.Geocoder();
|
|
209
|
+
geocoder.geocode({ language, location: { lng, lat } }).finally(() => clearTimeout(timer)).then(({ results }) => {
|
|
210
|
+
var _a2, _b;
|
|
211
|
+
const name = ((_a2 = results[0]) == null ? void 0 : _a2.formatted_address) || emptyPlaceName;
|
|
212
|
+
const displayName = gmapPlaceName2DisplayName(name, (_b = results[0]) == null ? void 0 : _b.address_components);
|
|
213
|
+
if (hkReturned)
|
|
214
|
+
return;
|
|
215
|
+
mapReturned = true;
|
|
216
|
+
const addressInfo = {
|
|
217
|
+
lng,
|
|
218
|
+
lat,
|
|
219
|
+
name: pipeTw(name),
|
|
220
|
+
displayName: pipeTw(displayName),
|
|
221
|
+
pointSource: PointSource.GOOGLE
|
|
222
|
+
};
|
|
223
|
+
console.log("==谷歌逆地理返回结果==", JSON.stringify(addressInfo));
|
|
224
|
+
resolve(addressInfo);
|
|
225
|
+
}).catch(handleFailed);
|
|
226
|
+
}
|
|
198
227
|
}, handleFailed);
|
|
199
228
|
const timer = setTimeout(() => {
|
|
200
229
|
console.warn("谷歌逆地理请求超时!");
|
|
@@ -52,6 +52,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
52
52
|
onChangePlace
|
|
53
53
|
} = props;
|
|
54
54
|
const availableRef = ref(true);
|
|
55
|
+
const findAttachedPlaceDone = ref(false);
|
|
55
56
|
const recommendTypeRef = ref(DEFAULT_RECOMMEND_TYPE);
|
|
56
57
|
const placeCandidatesRef = ref([]);
|
|
57
58
|
const zoneRef = ref();
|
|
@@ -60,7 +61,8 @@ const useMapRecomendPlace = (props) => {
|
|
|
60
61
|
const { getPlaceByRegeo } = useMapPlace({
|
|
61
62
|
emptyPlaceName,
|
|
62
63
|
pointRef: ref([...defaultPoint]),
|
|
63
|
-
signal: inputSignal
|
|
64
|
+
signal: inputSignal,
|
|
65
|
+
findAttachedPlaceDone
|
|
64
66
|
});
|
|
65
67
|
const recomendPlace = reactive({
|
|
66
68
|
lng: defaultPoint[0],
|
|
@@ -104,22 +106,30 @@ const useMapRecomendPlace = (props) => {
|
|
|
104
106
|
const [lng, lat] = point;
|
|
105
107
|
const { type, zone, available, candidates } = prevState;
|
|
106
108
|
if (!zone || !apiLocalIsPointInRing(point, zone.path)) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
findAttachedPlaceDone.value = false;
|
|
111
|
+
const reGeoPlacePromiseIgnored = recoverablyIgnoreManualAbortReject(
|
|
112
|
+
getPlaceByRegeo(point, opt)
|
|
113
|
+
);
|
|
114
|
+
findAttachedPlace({ lng, lat, name: "", displayName: "" }, opt).then(async ({
|
|
115
|
+
place: closestPlace,
|
|
116
|
+
candidates: candidates2,
|
|
117
|
+
available: available2,
|
|
118
|
+
type: type2,
|
|
119
|
+
zone: zone2
|
|
120
|
+
}) => {
|
|
121
|
+
findAttachedPlaceDone.value = true;
|
|
122
|
+
const adsorbed = isPlacesInclude(candidates2, closestPlace);
|
|
123
|
+
console.log("==推荐点接口==", `是否吸附:${adsorbed}`, `地址:${JSON.stringify(closestPlace)}`);
|
|
124
|
+
if (adsorbed) {
|
|
125
|
+
resolve({ place: { ...closestPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 });
|
|
126
|
+
} else {
|
|
127
|
+
const regeoPlace = await reGeoPlacePromiseIgnored.recover();
|
|
128
|
+
console.log("==RegeoPlace==", regeoPlace);
|
|
129
|
+
resolve({ place: { ...regeoPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
123
133
|
}
|
|
124
134
|
if (type === "Forbidden") {
|
|
125
135
|
const regeoPlace = await getPlaceByRegeo(point, opt);
|
|
@@ -14,6 +14,7 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
|
|
|
14
14
|
googleSnapRoadProxyUrl?: string;
|
|
15
15
|
hkGovernRegeoProxyUrl?: string;
|
|
16
16
|
gaodeRegeoProxyUrl?: string;
|
|
17
|
+
googleRegeoProxyUrl?: string;
|
|
17
18
|
themeVariables?: MapThemeVariables;
|
|
18
19
|
renderLoadFailedTitle?: (status: Status) => string | undefined;
|
|
19
20
|
renderLoadFailedDescription?: (status: Status) => string | undefined;
|
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.
|
|
3
|
+
const pkgVersion = "2.21.0-gmapCost2";
|
|
4
4
|
const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
|
|
5
5
|
const enableSessionLogKey = (key) => {
|
|
6
6
|
const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
|
|
@@ -191,6 +191,8 @@ const EMPTY_REGEX = /^$/;
|
|
|
191
191
|
const POSTAL_CODE_ZH_DESC = "邮政编码:";
|
|
192
192
|
function gmapPlaceName2DisplayName(name, addressComponents) {
|
|
193
193
|
var _a, _b;
|
|
194
|
+
if (!addressComponents)
|
|
195
|
+
return name;
|
|
194
196
|
const addressComponentMap = gmapAddressComponentList2AddressComponentMap(addressComponents);
|
|
195
197
|
const streetNumberComponent = addressComponentMap["street_number"];
|
|
196
198
|
const routeComponent = addressComponentMap["route"];
|