@heycar/heycars-map 2.6.1 → 2.7.1
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/README.md +4 -0
- package/dist/v2/api/gaodeDirectionDriving.d.ts +50 -0
- package/dist/v2/api/gaodeDirectionDriving.js +157 -0
- package/dist/v2/api/gaodeDirectionWalking.d.ts +15 -0
- package/dist/v2/api/gaodeDirectionWalking.js +105 -0
- package/dist/v2/api/geometry.js +3 -3
- package/dist/v2/api/googleDirections.d.ts +2 -2
- package/dist/v2/api/googleDirections.js +9 -6
- 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 +4 -3
- package/dist/v2/hooks/useMapCoordinatify.js +1 -1
- package/dist/v2/hooks/useMapGCJ02.js +11 -1
- package/dist/v2/hooks/useMapGraspRoad.js +3 -3
- package/dist/v2/hooks/useMapInChina.d.ts +1 -0
- package/dist/v2/hooks/useMapInChina.js +166 -0
- package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
- package/dist/v2/hooks/useWalkingRoute.js +6 -3
- package/dist/v2/types/amap/driving.d.ts +3 -2
- package/dist/v2/types/amap/walking.d.ts +1 -1
- package/dist/v2/utils/compatibleDrivingRoute.d.ts +1 -0
- package/dist/v2/utils/compatibleDrivingRoute.js +39 -0
- package/dist/v2/utils/compatibleGraspRoad.d.ts +1 -0
- package/dist/v2/utils/compatibleGraspRoad.js +7 -0
- package/dist/v2/utils/compatibleWalkingRoute.d.ts +1 -0
- package/dist/v2/utils/compatibleWalkingRoute.js +26 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v2/utils/platform.js +1 -1
- package/dist/v2/utils/transform.d.ts +3 -0
- package/dist/v2/utils/transform.js +14 -2
- package/dist/v2/utils/typeChecking.js +1 -0
- package/dist/v3/api/gaodeDirectionDriving.d.ts +50 -0
- package/dist/v3/api/gaodeDirectionDriving.js +157 -0
- package/dist/v3/api/gaodeDirectionWalking.d.ts +15 -0
- package/dist/v3/api/gaodeDirectionWalking.js +105 -0
- package/dist/v3/api/geometry.js +3 -3
- package/dist/v3/api/googleDirections.d.ts +2 -2
- package/dist/v3/api/googleDirections.js +9 -6
- 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 +4 -3
- package/dist/v3/hooks/useMapCoordinatify.js +1 -1
- package/dist/v3/hooks/useMapGCJ02.js +11 -1
- package/dist/v3/hooks/useMapGraspRoad.js +3 -3
- package/dist/v3/hooks/useMapInChina.d.ts +1 -0
- package/dist/v3/hooks/useMapInChina.js +166 -0
- package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
- package/dist/v3/hooks/useWalkingRoute.js +6 -3
- package/dist/v3/types/amap/driving.d.ts +3 -2
- package/dist/v3/types/amap/walking.d.ts +1 -1
- package/dist/v3/utils/compatibleDrivingRoute.d.ts +1 -0
- package/dist/v3/utils/compatibleDrivingRoute.js +39 -0
- package/dist/v3/utils/compatibleGraspRoad.d.ts +1 -0
- package/dist/v3/utils/compatibleGraspRoad.js +7 -0
- package/dist/v3/utils/compatibleWalkingRoute.d.ts +1 -0
- package/dist/v3/utils/compatibleWalkingRoute.js +26 -0
- package/dist/v3/utils/log.js +1 -1
- package/dist/v3/utils/platform.js +1 -1
- package/dist/v3/utils/transform.d.ts +3 -0
- package/dist/v3/utils/transform.js +14 -2
- package/dist/v3/utils/typeChecking.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
|
|
2
|
+
import { createTypeError, isProxyServiceError } from "../utils/typeChecking.js";
|
|
3
|
+
const GAODE_POLYLINE_REGEX = /^(?:\d*\.\d+,\d*\.\d+)?(?:;\d*\.\d+,\d*\.\d+)*$/;
|
|
4
|
+
var GaodeDirectionStatus = /* @__PURE__ */ ((GaodeDirectionStatus2) => {
|
|
5
|
+
GaodeDirectionStatus2["SUCCESS"] = "1";
|
|
6
|
+
GaodeDirectionStatus2["FAIL"] = "0";
|
|
7
|
+
return GaodeDirectionStatus2;
|
|
8
|
+
})(GaodeDirectionStatus || {});
|
|
9
|
+
const gaodeDirectionStatus2amapDirectionCallbackStatus = (status) => {
|
|
10
|
+
return status === "1" ? "complete" : "error";
|
|
11
|
+
};
|
|
12
|
+
function isGaodeDirectionResponse(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && "status" in value && isGaodeDirectionStatus(value.status) && "info" in value && typeof value.info === "string";
|
|
14
|
+
}
|
|
15
|
+
function isGaodeDirectionStatus(value) {
|
|
16
|
+
return value === "1" || value === "0";
|
|
17
|
+
}
|
|
18
|
+
function assertGaodeDirectionStatus(value) {
|
|
19
|
+
if (isGaodeDirectionStatus(value))
|
|
20
|
+
return;
|
|
21
|
+
throw createTypeError("GaodeDirectionStatus", value);
|
|
22
|
+
}
|
|
23
|
+
function isGaodeNumberableString(value) {
|
|
24
|
+
return typeof value === "string" && !isNaN(parseFloat(value)) || isGaodeEmptyValue(value);
|
|
25
|
+
}
|
|
26
|
+
function isGaodeDirectionPolyline(value) {
|
|
27
|
+
return typeof value === "string" && GAODE_POLYLINE_REGEX.test(value) || isGaodeEmptyValue(value);
|
|
28
|
+
}
|
|
29
|
+
function isGaodeMeasurableObject(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && "distance" in value && isGaodeNumberableString(value.distance) && "duration" in value && isGaodeNumberableString(value.duration);
|
|
31
|
+
}
|
|
32
|
+
function isGaodeDirectionBasicStep(value) {
|
|
33
|
+
return isGaodeMeasurableObject(value) && "polyline" in value && isGaodeDirectionPolyline(value.polyline);
|
|
34
|
+
}
|
|
35
|
+
function isGaodeEmptyValue(value) {
|
|
36
|
+
return Array.isArray(value) && value.length === 0;
|
|
37
|
+
}
|
|
38
|
+
function assertGaodoDirectionDrivingStep(value) {
|
|
39
|
+
if (isGaodeDirectionBasicStep(value))
|
|
40
|
+
return;
|
|
41
|
+
throw createTypeError("GaodeDirectionDrivingStep", value);
|
|
42
|
+
}
|
|
43
|
+
function assertGaodeDirectionDrivingRoutePath(value) {
|
|
44
|
+
if (!isGaodeMeasurableObject(value) || !("tolls" in value) || !isGaodeNumberableString(value.tolls) || !("steps" in value) || !Array.isArray(value.steps)) {
|
|
45
|
+
throw createTypeError("GaodeDirectionDrivingRoutePath", value);
|
|
46
|
+
}
|
|
47
|
+
value.steps.forEach(assertGaodoDirectionDrivingStep);
|
|
48
|
+
}
|
|
49
|
+
function assertGaodeDirectionDrivingRoute(value) {
|
|
50
|
+
if (typeof value !== "object" || value === null || !("paths" in value) || !Array.isArray(value.paths)) {
|
|
51
|
+
throw createTypeError("GaodeDirectionDrivingRoute", value);
|
|
52
|
+
}
|
|
53
|
+
value.paths.forEach(assertGaodeDirectionDrivingRoutePath);
|
|
54
|
+
}
|
|
55
|
+
function assertGaodeDirectionDrivingResponse(value) {
|
|
56
|
+
if (!isGaodeDirectionResponse(value) || !("route" in value)) {
|
|
57
|
+
throw createTypeError("GaodeDirectionDrivingResponse", value);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
assertGaodeDirectionDrivingRoute(value.route);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const { message: detail } = error;
|
|
63
|
+
throw createTypeError("GaodeDirectionDrivingResponse", value, detail);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function gaodeDirectionDrivingRoute2amapDrivingRoute(gaodeRoute) {
|
|
67
|
+
return gaodeRoute.paths.map((routePath) => {
|
|
68
|
+
const { distance, duration, tolls, steps: godeDirectionSteps } = routePath;
|
|
69
|
+
const steps = godeDirectionSteps.map((directionStep) => {
|
|
70
|
+
const { distance: distance2, duration: duration2, polyline } = directionStep;
|
|
71
|
+
return {
|
|
72
|
+
distance: Number(distance2),
|
|
73
|
+
time: Number(duration2),
|
|
74
|
+
path: gaodePolyline2amapLngLat(String(polyline))
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
distance: Number(distance),
|
|
79
|
+
time: Number(duration),
|
|
80
|
+
tolls: Number(tolls),
|
|
81
|
+
steps
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async function apiGaodeDirectionDriving(props) {
|
|
86
|
+
const { proxyUrl, origin, destination, waypoints, extensions = "all" } = props;
|
|
87
|
+
if (!proxyUrl) {
|
|
88
|
+
const error_message = "Warning: gaode direction driving service is bypassed due to proxyUrl is not provided!";
|
|
89
|
+
console.warn(error_message);
|
|
90
|
+
return { status: "no_data", routes: [], error_message };
|
|
91
|
+
}
|
|
92
|
+
const { protocol, host } = location;
|
|
93
|
+
const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
|
|
94
|
+
const url = new URL(proxyUrl, baseUrl);
|
|
95
|
+
url.searchParams.set("origin", gaodePointsStringify(origin));
|
|
96
|
+
url.searchParams.set("destination", gaodePointsStringify([destination]));
|
|
97
|
+
url.searchParams.set("extensions", extensions);
|
|
98
|
+
if (waypoints && waypoints.length > 0)
|
|
99
|
+
url.searchParams.set("waypoints", gaodePointsStringify(waypoints));
|
|
100
|
+
for (const key of [
|
|
101
|
+
"destinationid",
|
|
102
|
+
"destinationtype",
|
|
103
|
+
"strategy",
|
|
104
|
+
"waypoints",
|
|
105
|
+
"avoidpolygons",
|
|
106
|
+
"province",
|
|
107
|
+
"number",
|
|
108
|
+
"cartype",
|
|
109
|
+
"ferry",
|
|
110
|
+
"roadaggregation",
|
|
111
|
+
"nosteps",
|
|
112
|
+
"output"
|
|
113
|
+
]) {
|
|
114
|
+
if (props[key] !== void 0)
|
|
115
|
+
url.searchParams.set(key, String(props[key]));
|
|
116
|
+
}
|
|
117
|
+
const response = await fetch(url);
|
|
118
|
+
if (response.ok) {
|
|
119
|
+
const result = await response.json();
|
|
120
|
+
assertGaodeDirectionDrivingResponse(result);
|
|
121
|
+
const { status, info: error_message, route } = result;
|
|
122
|
+
return {
|
|
123
|
+
status: gaodeDirectionStatus2amapDirectionCallbackStatus(status),
|
|
124
|
+
error_message,
|
|
125
|
+
routes: gaodeDirectionDrivingRoute2amapDrivingRoute(route)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const error = await response.json();
|
|
129
|
+
if (isProxyServiceError(error)) {
|
|
130
|
+
const { code, msg } = error;
|
|
131
|
+
throw new Error(`apiGaodeDirectionDriving proxy failed code: ${code}, msg:
|
|
132
|
+
${msg}`);
|
|
133
|
+
}
|
|
134
|
+
if (isGaodeDirectionResponse(error)) {
|
|
135
|
+
const { status: serviceStatus, info: error_message } = error;
|
|
136
|
+
const status = gaodeDirectionStatus2amapDirectionCallbackStatus(serviceStatus);
|
|
137
|
+
throw new Error(
|
|
138
|
+
`apiGaodeDirectionDriving failed status: ${status}, message:
|
|
139
|
+
${error_message}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
throw new Error(
|
|
143
|
+
`apiGaodeDirectionDriving failed with unrecognized server response: ${JSON.stringify(error)}`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
GaodeDirectionStatus,
|
|
148
|
+
apiGaodeDirectionDriving,
|
|
149
|
+
assertGaodeDirectionStatus,
|
|
150
|
+
gaodeDirectionStatus2amapDirectionCallbackStatus,
|
|
151
|
+
isGaodeDirectionBasicStep,
|
|
152
|
+
isGaodeDirectionPolyline,
|
|
153
|
+
isGaodeDirectionResponse,
|
|
154
|
+
isGaodeDirectionStatus,
|
|
155
|
+
isGaodeMeasurableObject,
|
|
156
|
+
isGaodeNumberableString
|
|
157
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Point } from "../types/interface";
|
|
2
|
+
import { type ApiGaodeDirectionDrivingOutput } from "./gaodeDirectionDriving";
|
|
3
|
+
export interface ApiGaodeDirectionWalkingProps {
|
|
4
|
+
proxyUrl?: string;
|
|
5
|
+
origin: Point;
|
|
6
|
+
destination: Point;
|
|
7
|
+
origin_id?: string;
|
|
8
|
+
destination_id?: string;
|
|
9
|
+
output?: "JSON" | "XML";
|
|
10
|
+
}
|
|
11
|
+
interface ApiGaodeDirectionWalkingOutput extends Omit<ApiGaodeDirectionDrivingOutput, "routes"> {
|
|
12
|
+
routes: AMap.WalkRoute[];
|
|
13
|
+
}
|
|
14
|
+
export declare function apiGaodeDirectionWalking(props: ApiGaodeDirectionWalkingProps): Promise<ApiGaodeDirectionWalkingOutput>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
|
|
2
|
+
import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
|
|
3
|
+
import { gaodeDirectionStatus2amapDirectionCallbackStatus, isGaodeDirectionResponse, isGaodeMeasurableObject, isGaodeDirectionBasicStep } from "./gaodeDirectionDriving.js";
|
|
4
|
+
function assertGaodoDirectionWalkingStep(value) {
|
|
5
|
+
if (isGaodeDirectionBasicStep(value))
|
|
6
|
+
return;
|
|
7
|
+
throw createTypeError("GaodeDirectionWalkingStep", value);
|
|
8
|
+
}
|
|
9
|
+
function assertGaodeDirectionWalkingRoutePath(value) {
|
|
10
|
+
if (!isGaodeMeasurableObject(value) || !("steps" in value) || !Array.isArray(value.steps)) {
|
|
11
|
+
throw createTypeError("GaodeDirectionWalkingRoutePath", value);
|
|
12
|
+
}
|
|
13
|
+
value.steps.forEach(assertGaodoDirectionWalkingStep);
|
|
14
|
+
}
|
|
15
|
+
function assertGaodeDirectionWalkingRoute(value) {
|
|
16
|
+
if (typeof value !== "object" || value === null || !("paths" in value) || !Array.isArray(value.paths)) {
|
|
17
|
+
throw createTypeError("GaodeDirectionRoute", value);
|
|
18
|
+
}
|
|
19
|
+
value.paths.forEach(assertGaodeDirectionWalkingRoutePath);
|
|
20
|
+
}
|
|
21
|
+
function assertGaodeDirectionWalkingResponse(value) {
|
|
22
|
+
if (!isGaodeDirectionResponse(value) || !("route" in value)) {
|
|
23
|
+
throw createTypeError("GaodeDirectionWalkingResponse", value);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
assertGaodeDirectionWalkingRoute(value.route);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const { message: detail } = error;
|
|
29
|
+
throw createTypeError("GaodeDirectionWalkingResponse", value, detail);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function gaodeDirectionWalkingRoute2amapWalkRoute(gaodeRoute) {
|
|
33
|
+
return gaodeRoute.paths.map((routePath) => {
|
|
34
|
+
const { distance, duration, steps: godeDirectionSteps } = routePath;
|
|
35
|
+
const steps = godeDirectionSteps.map((directionStep) => {
|
|
36
|
+
const { distance: distance2, duration: duration2, polyline } = directionStep;
|
|
37
|
+
return {
|
|
38
|
+
distance: Number(distance2),
|
|
39
|
+
time: Number(duration2),
|
|
40
|
+
path: gaodePolyline2amapLngLat(String(polyline))
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
distance: Number(distance),
|
|
45
|
+
time: Number(duration),
|
|
46
|
+
steps
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function apiGaodeDirectionWalking(props) {
|
|
51
|
+
const { proxyUrl, origin, destination } = props;
|
|
52
|
+
if (!proxyUrl) {
|
|
53
|
+
const error_message = "Warning: gaode direction walking service is bypassed due to proxyUrl is not provided!";
|
|
54
|
+
console.warn(error_message);
|
|
55
|
+
return {
|
|
56
|
+
status: "no_data",
|
|
57
|
+
routes: [],
|
|
58
|
+
error_message
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const { protocol, host } = location;
|
|
62
|
+
const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
|
|
63
|
+
const url = new URL(proxyUrl, baseUrl);
|
|
64
|
+
url.searchParams.set("origin", gaodePointsStringify([origin]));
|
|
65
|
+
url.searchParams.set("destination", gaodePointsStringify([destination]));
|
|
66
|
+
for (const key of [
|
|
67
|
+
"origin_id",
|
|
68
|
+
"destination_id",
|
|
69
|
+
"output"
|
|
70
|
+
]) {
|
|
71
|
+
if (props[key] !== void 0)
|
|
72
|
+
url.searchParams.set(key, String(props[key]));
|
|
73
|
+
}
|
|
74
|
+
const response = await fetch(url);
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
const result = await response.json();
|
|
77
|
+
assertGaodeDirectionWalkingResponse(result);
|
|
78
|
+
const { status, info: error_message, route } = result;
|
|
79
|
+
return {
|
|
80
|
+
status: gaodeDirectionStatus2amapDirectionCallbackStatus(status),
|
|
81
|
+
error_message,
|
|
82
|
+
routes: gaodeDirectionWalkingRoute2amapWalkRoute(route)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const error = await response.json();
|
|
86
|
+
if (isProxyServiceError(error)) {
|
|
87
|
+
const { code, msg } = error;
|
|
88
|
+
throw new Error(`apiGaodeDirectionWalking proxy failed code: ${code}, msg:
|
|
89
|
+
${msg}`);
|
|
90
|
+
}
|
|
91
|
+
if (isGaodeDirectionResponse(error)) {
|
|
92
|
+
const { status: serviceStatus, info: error_message } = error;
|
|
93
|
+
const status = gaodeDirectionStatus2amapDirectionCallbackStatus(serviceStatus);
|
|
94
|
+
throw new Error(
|
|
95
|
+
`apiGaodeDirectionWalking failed status: ${status}, message:
|
|
96
|
+
${error_message}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
throw new Error(
|
|
100
|
+
`apiGaodeDirectionWalking failed with unrecognized server response: ${JSON.stringify(error)}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
apiGaodeDirectionWalking
|
|
105
|
+
};
|
package/dist/v3/api/geometry.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { e as exported } from "../chunks/gcoord.esm-bundler.3f2f1369.js";
|
|
2
|
+
import { isAccuryEqual } from "../utils/transform.js";
|
|
2
3
|
import { toCoordinatePointType } from "../utils/typeChecking.js";
|
|
3
|
-
const GCOORD_ACCURCY_RANGE = 1e-6;
|
|
4
4
|
function isCoordinatePointEqual(input1, input2) {
|
|
5
5
|
if (!input2)
|
|
6
6
|
return false;
|
|
7
7
|
const p1 = toCoordinatePointType(input1);
|
|
8
8
|
const p2 = toCoordinatePointType(input2);
|
|
9
9
|
if (p1.type === p2.type)
|
|
10
|
-
return p1.lng
|
|
10
|
+
return isAccuryEqual(p1.lng, p2.lng) && isAccuryEqual(p1.lat, p2.lat);
|
|
11
11
|
const { lng: x1, lat: y1 } = p1.type === "gcj02" ? p1 : p2;
|
|
12
12
|
const wgsPoint = p1.type === "gcj02" ? p2 : p1;
|
|
13
13
|
const { lng, lat } = wgsPoint;
|
|
14
14
|
const [x2, y2] = exported.transform([lng, lat], exported.WGS84, exported.GCJ02);
|
|
15
|
-
return
|
|
15
|
+
return isAccuryEqual(x1, x2) && isAccuryEqual(y1, y2);
|
|
16
16
|
}
|
|
17
17
|
export {
|
|
18
18
|
isCoordinatePointEqual
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="google.maps" />
|
|
2
2
|
import type { Point } from "../types/interface";
|
|
3
|
-
type
|
|
3
|
+
type GoogleDirectionsStatus = `${google.maps.DirectionsStatus}`;
|
|
4
4
|
export interface GoogleDirectionsResponse extends Pick<google.maps.DirectionsResult, "routes" | "geocoded_waypoints" | "available_travel_modes"> {
|
|
5
|
-
status:
|
|
5
|
+
status: GoogleDirectionsStatus;
|
|
6
6
|
error_message?: string;
|
|
7
7
|
}
|
|
8
8
|
export interface ApiGoogleDirectionsProps {
|
|
@@ -19,12 +19,12 @@ function isGoogleDuration(value) {
|
|
|
19
19
|
function isGoogleDirectionsPolyline(value) {
|
|
20
20
|
return typeof value === "object" && value !== null && "points" in value && typeof value.points === "string";
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function isGoogleMeasurableObject(value) {
|
|
23
23
|
return typeof value === "object" && value !== null && (!("distance" in value) || value.distance === void 0 || isGoogleDistance(value.distance)) && (!("duration" in value) || value.duration === void 0 || isGoogleDuration(value.duration));
|
|
24
24
|
}
|
|
25
25
|
function assertGoogleDirectionsStep(value) {
|
|
26
26
|
const error = createTypeError("google.maps.DirectionsStep", value);
|
|
27
|
-
if (!
|
|
27
|
+
if (!isGoogleMeasurableObject(value))
|
|
28
28
|
throw error;
|
|
29
29
|
if (!("polyline" in value)) {
|
|
30
30
|
value.path = [];
|
|
@@ -37,7 +37,7 @@ function assertGoogleDirectionsStep(value) {
|
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
function assertGoogleDirectionsLeg(value) {
|
|
40
|
-
if (!
|
|
40
|
+
if (!isGoogleMeasurableObject(value) || !("steps" in value) || !Array.isArray(value.steps))
|
|
41
41
|
throw createTypeError("google.maps.DirectionsLeg", value);
|
|
42
42
|
try {
|
|
43
43
|
for (const step of value.steps) {
|
|
@@ -83,12 +83,15 @@ function isGoogleDirectionsError(error) {
|
|
|
83
83
|
}
|
|
84
84
|
async function apiGoogleDirections(props) {
|
|
85
85
|
const { proxyUrl, origin, destination, waypoints, avoid } = props;
|
|
86
|
-
if (!proxyUrl)
|
|
86
|
+
if (!proxyUrl) {
|
|
87
|
+
const error_message = "Warning: google directions service is bypassed due to proxyUrl is not provided!";
|
|
88
|
+
console.warn(error_message);
|
|
87
89
|
return {
|
|
88
90
|
status: "ZERO_RESULTS",
|
|
89
91
|
routes: [],
|
|
90
|
-
error_message
|
|
92
|
+
error_message
|
|
91
93
|
};
|
|
94
|
+
}
|
|
92
95
|
const { protocol, host } = location;
|
|
93
96
|
const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
|
|
94
97
|
const url = new URL(proxyUrl, baseUrl);
|
|
@@ -111,7 +114,7 @@ async function apiGoogleDirections(props) {
|
|
|
111
114
|
"transit_routing_preference"
|
|
112
115
|
]) {
|
|
113
116
|
if (props[key] !== void 0)
|
|
114
|
-
url.searchParams.set(key, String(key));
|
|
117
|
+
url.searchParams.set(key, String(props[key]));
|
|
115
118
|
}
|
|
116
119
|
const response = await fetch(url);
|
|
117
120
|
if (response.ok) {
|
|
@@ -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" | "googleDirectionsProxyUrl" | "googleSnapRoadProxyUrl" | "renderLoadFailedTitle" | "renderLoadFailedDescription">;
|
|
8
|
+
export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleSnapRoadProxyUrl" | "renderLoadFailedTitle" | "renderLoadFailedDescription">;
|
|
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", "googleDirectionsProxyUrl", "googleSnapRoadProxyUrl", "renderLoadFailedTitle", "renderLoadFailedDescription"]);
|
|
56
|
+
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleSnapRoadProxyUrl", "renderLoadFailedTitle", "renderLoadFailedDescription"]);
|
|
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
|
-
import { googleServiceApiDrivingRoute, amapJsApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
|
|
4
|
-
import { inTaiwan } from "./useMapInChina.js";
|
|
3
|
+
import { googleServiceApiDrivingRoute, amapJsApiDrivingRoute, gaodeServiceApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
|
|
4
|
+
import { inTaiwan, inKorean } from "./useMapInChina.js";
|
|
5
5
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
6
6
|
const useADrivingRoute = (props) => {
|
|
7
7
|
const { googleDirectionsProxyUrl } = useMapSupplier();
|
|
@@ -30,10 +30,11 @@ const useADrivingRoute = (props) => {
|
|
|
30
30
|
return { route: outputRoute, apiMapDrivingRoute };
|
|
31
31
|
};
|
|
32
32
|
const useGDrivingRoute = (props) => {
|
|
33
|
+
const { gaodeDirectionDrivingProxyUrl } = useMapSupplier();
|
|
33
34
|
const outputRoute = reactive({ path: [], distance: 0, duration: 0, steps: [] });
|
|
34
35
|
const gmapDirectionsService = new google.maps.DirectionsService();
|
|
35
36
|
const apiMapDrivingRoute = (from, to) => {
|
|
36
|
-
return gmapJsApiDrivingRoute(from, to, gmapDirectionsService);
|
|
37
|
+
return gaodeDirectionDrivingProxyUrl && inKorean(from) ? gaodeServiceApiDrivingRoute(from, to, gaodeDirectionDrivingProxyUrl) : gmapJsApiDrivingRoute(from, to, gmapDirectionsService);
|
|
37
38
|
};
|
|
38
39
|
watchPostEffectForDeepOption(
|
|
39
40
|
() => {
|
|
@@ -13,7 +13,7 @@ function useMapCoordinatify() {
|
|
|
13
13
|
return [lng, lat];
|
|
14
14
|
if (type === "wgs84") {
|
|
15
15
|
if (!inChina([lng, lat]))
|
|
16
|
-
|
|
16
|
+
console.error(`国外(或台湾)经纬度收到火星坐标系数据: ${JSON.stringify(value)}`);
|
|
17
17
|
return toLocalWgs84([lng, lat]);
|
|
18
18
|
}
|
|
19
19
|
return toLocalGcj02([lng, lat]);
|
|
@@ -19,7 +19,17 @@ const useAmapGCJ02 = () => {
|
|
|
19
19
|
};
|
|
20
20
|
const toLocalGcj02Points = (points) => points.map(toLocalGcj02);
|
|
21
21
|
const toLocalWgs84 = (point) => {
|
|
22
|
-
|
|
22
|
+
console.error(`高德地图为什么要转 wgs84: ${JSON.stringify(point)}`);
|
|
23
|
+
try {
|
|
24
|
+
if (inChina(point))
|
|
25
|
+
return point;
|
|
26
|
+
return exported.transform(point, exported.GCJ02, exported.WGS1984);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
const error = err;
|
|
29
|
+
console.error(`本地转换WGS84失败: ${error.message}
|
|
30
|
+
${error.stack}`);
|
|
31
|
+
return point;
|
|
32
|
+
}
|
|
23
33
|
};
|
|
24
34
|
const toGcj02Points = async (points) => {
|
|
25
35
|
return toLocalGcj02Points(points);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ref } from "vue-demi";
|
|
2
2
|
import { watchEffectForDeepOption } from "../utils/compare.js";
|
|
3
|
-
import { googleServiceApiGraspRoad, amapJsApiGraspRoad } from "../utils/compatibleGraspRoad.js";
|
|
3
|
+
import { googleServiceApiGraspRoad, amapJsApiGraspRoad, bypassGraspRoad } from "../utils/compatibleGraspRoad.js";
|
|
4
4
|
import { lnglat2point } from "../utils/transform.js";
|
|
5
5
|
import { useMapAngle } from "./useMapAngle.js";
|
|
6
|
-
import { inTaiwan } from "./useMapInChina.js";
|
|
6
|
+
import { inTaiwan, inKorean } from "./useMapInChina.js";
|
|
7
7
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
8
8
|
const useAmapGraspRoad = (props) => {
|
|
9
9
|
const pathRef = ref([]);
|
|
@@ -32,7 +32,7 @@ const useGmapGraspRoad = (props) => {
|
|
|
32
32
|
const { googleSnapRoadProxyUrl } = useMapSupplier();
|
|
33
33
|
const { apiMapComputeHeading } = useMapAngle();
|
|
34
34
|
const apiMapToGraspRoadPath = (tracks) => {
|
|
35
|
-
return googleServiceApiGraspRoad(tracks, apiMapComputeHeading, googleSnapRoadProxyUrl);
|
|
35
|
+
return inKorean(lnglat2point(tracks[tracks.length - 1])) ? bypassGraspRoad(tracks, apiMapComputeHeading) : googleServiceApiGraspRoad(tracks, apiMapComputeHeading, googleSnapRoadProxyUrl);
|
|
36
36
|
};
|
|
37
37
|
watchEffectForDeepOption(
|
|
38
38
|
() => props ? [...props.tracks] : void 0,
|
|
@@ -3,3 +3,4 @@ export declare const inChina: (point: Point) => boolean;
|
|
|
3
3
|
export declare const inHongkong: (point: Point) => boolean;
|
|
4
4
|
export declare const inMacau: (point: Point) => boolean;
|
|
5
5
|
export declare const inTaiwan: (point: Point) => boolean;
|
|
6
|
+
export declare const inKorean: (point: Point) => boolean;
|
|
@@ -2399,6 +2399,168 @@ const hongkongBounds = [
|
|
|
2399
2399
|
22.504768
|
|
2400
2400
|
]
|
|
2401
2401
|
];
|
|
2402
|
+
const koreanBounds = [
|
|
2403
|
+
[
|
|
2404
|
+
125.637366,
|
|
2405
|
+
37.690714
|
|
2406
|
+
],
|
|
2407
|
+
[
|
|
2408
|
+
125.694873,
|
|
2409
|
+
37.699096
|
|
2410
|
+
],
|
|
2411
|
+
[
|
|
2412
|
+
126.005108,
|
|
2413
|
+
37.687121
|
|
2414
|
+
],
|
|
2415
|
+
[
|
|
2416
|
+
126.076236,
|
|
2417
|
+
37.713464
|
|
2418
|
+
],
|
|
2419
|
+
[
|
|
2420
|
+
126.174603,
|
|
2421
|
+
37.717055
|
|
2422
|
+
],
|
|
2423
|
+
[
|
|
2424
|
+
126.20033,
|
|
2425
|
+
37.742191
|
|
2426
|
+
],
|
|
2427
|
+
[
|
|
2428
|
+
126.185196,
|
|
2429
|
+
37.802002
|
|
2430
|
+
],
|
|
2431
|
+
[
|
|
2432
|
+
126.21849,
|
|
2433
|
+
37.828304
|
|
2434
|
+
],
|
|
2435
|
+
[
|
|
2436
|
+
126.409171,
|
|
2437
|
+
37.846231
|
|
2438
|
+
],
|
|
2439
|
+
[
|
|
2440
|
+
126.447005,
|
|
2441
|
+
37.835475
|
|
2442
|
+
],
|
|
2443
|
+
[
|
|
2444
|
+
126.468192,
|
|
2445
|
+
37.812763
|
|
2446
|
+
],
|
|
2447
|
+
[
|
|
2448
|
+
126.584719,
|
|
2449
|
+
37.762532
|
|
2450
|
+
],
|
|
2451
|
+
[
|
|
2452
|
+
126.659196,
|
|
2453
|
+
37.782212
|
|
2454
|
+
],
|
|
2455
|
+
[
|
|
2456
|
+
126.672837,
|
|
2457
|
+
37.831992
|
|
2458
|
+
],
|
|
2459
|
+
[
|
|
2460
|
+
126.688926,
|
|
2461
|
+
37.841344
|
|
2462
|
+
],
|
|
2463
|
+
[
|
|
2464
|
+
126.673713,
|
|
2465
|
+
37.953188
|
|
2466
|
+
],
|
|
2467
|
+
[
|
|
2468
|
+
126.713155,
|
|
2469
|
+
37.954484
|
|
2470
|
+
],
|
|
2471
|
+
[
|
|
2472
|
+
126.813404,
|
|
2473
|
+
38.002414
|
|
2474
|
+
],
|
|
2475
|
+
[
|
|
2476
|
+
126.861063,
|
|
2477
|
+
38.048372
|
|
2478
|
+
],
|
|
2479
|
+
[
|
|
2480
|
+
126.881335,
|
|
2481
|
+
38.103823
|
|
2482
|
+
],
|
|
2483
|
+
[
|
|
2484
|
+
126.956105,
|
|
2485
|
+
38.136251
|
|
2486
|
+
],
|
|
2487
|
+
[
|
|
2488
|
+
126.98678,
|
|
2489
|
+
38.212363
|
|
2490
|
+
],
|
|
2491
|
+
[
|
|
2492
|
+
127.137287,
|
|
2493
|
+
38.314008
|
|
2494
|
+
],
|
|
2495
|
+
[
|
|
2496
|
+
127.395491,
|
|
2497
|
+
38.336596
|
|
2498
|
+
],
|
|
2499
|
+
[
|
|
2500
|
+
127.510661,
|
|
2501
|
+
38.301619
|
|
2502
|
+
],
|
|
2503
|
+
[
|
|
2504
|
+
127.575676,
|
|
2505
|
+
38.336596
|
|
2506
|
+
],
|
|
2507
|
+
[
|
|
2508
|
+
127.793013,
|
|
2509
|
+
38.338053
|
|
2510
|
+
],
|
|
2511
|
+
[
|
|
2512
|
+
127.825612,
|
|
2513
|
+
38.308727
|
|
2514
|
+
],
|
|
2515
|
+
[
|
|
2516
|
+
127.890403,
|
|
2517
|
+
38.334143
|
|
2518
|
+
],
|
|
2519
|
+
[
|
|
2520
|
+
128.054781,
|
|
2521
|
+
38.307786
|
|
2522
|
+
],
|
|
2523
|
+
[
|
|
2524
|
+
128.20836,
|
|
2525
|
+
38.374602
|
|
2526
|
+
],
|
|
2527
|
+
[
|
|
2528
|
+
128.280817,
|
|
2529
|
+
38.444051
|
|
2530
|
+
],
|
|
2531
|
+
[
|
|
2532
|
+
128.302796,
|
|
2533
|
+
38.480152
|
|
2534
|
+
],
|
|
2535
|
+
[
|
|
2536
|
+
128.306013,
|
|
2537
|
+
38.59379
|
|
2538
|
+
],
|
|
2539
|
+
[
|
|
2540
|
+
128.35855,
|
|
2541
|
+
38.618926
|
|
2542
|
+
],
|
|
2543
|
+
[
|
|
2544
|
+
131.378464,
|
|
2545
|
+
37.526365
|
|
2546
|
+
],
|
|
2547
|
+
[
|
|
2548
|
+
129.520972,
|
|
2549
|
+
35.161674
|
|
2550
|
+
],
|
|
2551
|
+
[
|
|
2552
|
+
127.276802,
|
|
2553
|
+
33.309556
|
|
2554
|
+
],
|
|
2555
|
+
[
|
|
2556
|
+
125.675231,
|
|
2557
|
+
32.793646
|
|
2558
|
+
],
|
|
2559
|
+
[
|
|
2560
|
+
124.454296,
|
|
2561
|
+
34.226423
|
|
2562
|
+
]
|
|
2563
|
+
];
|
|
2402
2564
|
const macauBounds = [
|
|
2403
2565
|
[
|
|
2404
2566
|
113.540194,
|
|
@@ -2627,9 +2789,13 @@ const inMacau = (point) => {
|
|
|
2627
2789
|
const inTaiwan = (point) => {
|
|
2628
2790
|
return pointInPolygon(point, taiwanBounds) >= 0;
|
|
2629
2791
|
};
|
|
2792
|
+
const inKorean = (point) => {
|
|
2793
|
+
return pointInPolygon(point, koreanBounds) >= 0;
|
|
2794
|
+
};
|
|
2630
2795
|
export {
|
|
2631
2796
|
inChina,
|
|
2632
2797
|
inHongkong,
|
|
2798
|
+
inKorean,
|
|
2633
2799
|
inMacau,
|
|
2634
2800
|
inTaiwan
|
|
2635
2801
|
};
|
|
@@ -7,6 +7,8 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
|
|
|
7
7
|
readyPromise: UseMapLoaderOutput["readyPromise"];
|
|
8
8
|
status: Status;
|
|
9
9
|
pingStatus: ConnectionStatus;
|
|
10
|
+
gaodeDirectionDrivingProxyUrl?: string;
|
|
11
|
+
gaodeDirectionWalkingProxyUrl?: string;
|
|
10
12
|
googleDirectionsProxyUrl?: string;
|
|
11
13
|
googleSnapRoadProxyUrl?: string;
|
|
12
14
|
renderLoadFailedTitle?: (status: Status) => string | undefined;
|