@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
package/README.md
CHANGED
|
@@ -130,6 +130,10 @@ export type RecommendType = "Restricted" | "Forbidden" | "Recommend";
|
|
|
130
130
|
gmapKey={gmapApiKey}
|
|
131
131
|
// 使用哪个地图供应商,目前两个供应商: amap 高德 / gmap 谷歌
|
|
132
132
|
supplier={"amap"}
|
|
133
|
+
// 可选,高德驾车路线规划代理地址
|
|
134
|
+
gaodeDirectionDrivingProxyUrl="/overseas/amap/driveGuide"
|
|
135
|
+
// 可选,高德步行路线规划代理地址
|
|
136
|
+
gaodeDirectionWalkingProxyUrl="/overseas/amap/walkingGuide"
|
|
133
137
|
// 可选,谷歌路线纠偏代理地址
|
|
134
138
|
googleSnapRoadProxyUrl="/overseas/maps/snapToRoads"
|
|
135
139
|
// 可选,谷歌路线规划代理地址
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Point } from "../types/interface";
|
|
2
|
+
type GaodeMaybeEmpty<T> = T | [];
|
|
3
|
+
export declare enum GaodeDirectionStatus {
|
|
4
|
+
SUCCESS = "1",
|
|
5
|
+
FAIL = "0"
|
|
6
|
+
}
|
|
7
|
+
export interface GaodeMeasurableObject {
|
|
8
|
+
distance: GaodeMaybeEmpty<`${number}`>;
|
|
9
|
+
duration: GaodeMaybeEmpty<`${number}`>;
|
|
10
|
+
}
|
|
11
|
+
export interface GaodeDirectionBasicStep extends GaodeMeasurableObject {
|
|
12
|
+
polyline: GaodeMaybeEmpty<string>;
|
|
13
|
+
}
|
|
14
|
+
export type GaodeDirectionResponse = {
|
|
15
|
+
status: GaodeDirectionStatus;
|
|
16
|
+
info: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const gaodeDirectionStatus2amapDirectionCallbackStatus: (status: GaodeDirectionStatus) => AMap.DirectionCallbackStatus;
|
|
19
|
+
export declare function isGaodeDirectionResponse(value: unknown): value is GaodeDirectionResponse;
|
|
20
|
+
export declare function isGaodeDirectionStatus(value: unknown): value is GaodeDirectionStatus;
|
|
21
|
+
export declare function assertGaodeDirectionStatus(value: unknown): asserts value is GaodeDirectionStatus;
|
|
22
|
+
export declare function isGaodeNumberableString(value: unknown): value is GaodeMaybeEmpty<`${number}`>;
|
|
23
|
+
export declare function isGaodeDirectionPolyline(value: unknown): value is GaodeMaybeEmpty<string>;
|
|
24
|
+
export declare function isGaodeMeasurableObject(value: unknown): value is GaodeMeasurableObject;
|
|
25
|
+
export declare function isGaodeDirectionBasicStep(value: unknown): value is GaodeDirectionBasicStep;
|
|
26
|
+
export interface ApiGaodeDirectionDrivingOutput {
|
|
27
|
+
status: AMap.DirectionCallbackStatus;
|
|
28
|
+
error_message: string;
|
|
29
|
+
routes: AMap.DrivingRoute[];
|
|
30
|
+
}
|
|
31
|
+
interface ApiGaodeDirectionDrivingProps {
|
|
32
|
+
proxyUrl?: string;
|
|
33
|
+
origin: Point[];
|
|
34
|
+
destination: Point;
|
|
35
|
+
extensions?: "base" | "all";
|
|
36
|
+
destinationid?: string;
|
|
37
|
+
destinationtype?: string;
|
|
38
|
+
strategy?: AMap.DrivingOptions["policy"];
|
|
39
|
+
waypoints?: Point[];
|
|
40
|
+
avoidpolygons?: string;
|
|
41
|
+
province?: AMap.DrivingOptions["province"];
|
|
42
|
+
number?: AMap.DrivingOptions["number"];
|
|
43
|
+
cartype?: 0 | 1 | 2;
|
|
44
|
+
ferry?: AMap.DrivingOptions["ferry"];
|
|
45
|
+
roadaggregation?: boolean;
|
|
46
|
+
nosteps?: 0 | 1;
|
|
47
|
+
output?: "JSON" | "XML";
|
|
48
|
+
}
|
|
49
|
+
export declare function apiGaodeDirectionDriving(props: ApiGaodeDirectionDrivingProps): Promise<ApiGaodeDirectionDrivingOutput>;
|
|
50
|
+
export {};
|
|
@@ -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/v2/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 { 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" | "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("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", "googleDirectionsProxyUrl", "googleSnapRoadProxyUrl", "renderLoadFailedTitle", "renderLoadFailedDescription"]);
|
|
53
|
+
}).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleSnapRoadProxyUrl", "renderLoadFailedTitle", "renderLoadFailedDescription"]);
|
|
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
|
-
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;
|