@heycar/heycars-map 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +4 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/v2/api/gaodeDirectionDriving.d.ts +50 -0
  5. package/dist/v2/api/gaodeDirectionDriving.js +157 -0
  6. package/dist/v2/api/gaodeDirectionWalking.d.ts +15 -0
  7. package/dist/v2/api/gaodeDirectionWalking.js +105 -0
  8. package/dist/v2/api/geometry.js +3 -3
  9. package/dist/v2/api/googleDirections.d.ts +2 -2
  10. package/dist/v2/api/googleDirections.js +9 -6
  11. package/dist/v2/components/Gmap/Gmap.js +7 -1
  12. package/dist/v2/components/MapProvider/MapProvider.d.ts +1 -1
  13. package/dist/v2/components/MapProvider/MapProvider.js +1 -1
  14. package/dist/v2/hooks/useDrivingRoute.js +4 -3
  15. package/dist/v2/hooks/useMapCoordinatify.js +1 -1
  16. package/dist/v2/hooks/useMapGraspRoad.js +3 -3
  17. package/dist/v2/hooks/useMapInChina.d.ts +1 -0
  18. package/dist/v2/hooks/useMapInChina.js +166 -0
  19. package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
  20. package/dist/v2/hooks/useWalkingRoute.js +6 -3
  21. package/dist/v2/types/amap/driving.d.ts +3 -2
  22. package/dist/v2/types/amap/walking.d.ts +1 -1
  23. package/dist/v2/utils/compatibleDrivingRoute.d.ts +1 -0
  24. package/dist/v2/utils/compatibleDrivingRoute.js +39 -0
  25. package/dist/v2/utils/compatibleGraspRoad.d.ts +1 -0
  26. package/dist/v2/utils/compatibleGraspRoad.js +7 -0
  27. package/dist/v2/utils/compatibleWalkingRoute.d.ts +1 -0
  28. package/dist/v2/utils/compatibleWalkingRoute.js +26 -0
  29. package/dist/v2/utils/log.js +1 -1
  30. package/dist/v2/utils/platform.js +1 -1
  31. package/dist/v2/utils/transform.d.ts +3 -0
  32. package/dist/v2/utils/transform.js +14 -2
  33. package/dist/v2/utils/typeChecking.js +1 -0
  34. package/dist/v3/api/gaodeDirectionDriving.d.ts +50 -0
  35. package/dist/v3/api/gaodeDirectionDriving.js +157 -0
  36. package/dist/v3/api/gaodeDirectionWalking.d.ts +15 -0
  37. package/dist/v3/api/gaodeDirectionWalking.js +105 -0
  38. package/dist/v3/api/geometry.js +3 -3
  39. package/dist/v3/api/googleDirections.d.ts +2 -2
  40. package/dist/v3/api/googleDirections.js +9 -6
  41. package/dist/v3/components/Gmap/Gmap.js +7 -1
  42. package/dist/v3/components/MapProvider/MapProvider.d.ts +1 -1
  43. package/dist/v3/components/MapProvider/MapProvider.js +1 -1
  44. package/dist/v3/hooks/useDrivingRoute.js +4 -3
  45. package/dist/v3/hooks/useMapCoordinatify.js +1 -1
  46. package/dist/v3/hooks/useMapGraspRoad.js +3 -3
  47. package/dist/v3/hooks/useMapInChina.d.ts +1 -0
  48. package/dist/v3/hooks/useMapInChina.js +166 -0
  49. package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
  50. package/dist/v3/hooks/useWalkingRoute.js +6 -3
  51. package/dist/v3/types/amap/driving.d.ts +3 -2
  52. package/dist/v3/types/amap/walking.d.ts +1 -1
  53. package/dist/v3/utils/compatibleDrivingRoute.d.ts +1 -0
  54. package/dist/v3/utils/compatibleDrivingRoute.js +39 -0
  55. package/dist/v3/utils/compatibleGraspRoad.d.ts +1 -0
  56. package/dist/v3/utils/compatibleGraspRoad.js +7 -0
  57. package/dist/v3/utils/compatibleWalkingRoute.d.ts +1 -0
  58. package/dist/v3/utils/compatibleWalkingRoute.js +26 -0
  59. package/dist/v3/utils/log.js +1 -1
  60. package/dist/v3/utils/platform.js +1 -1
  61. package/dist/v3/utils/transform.d.ts +3 -0
  62. package/dist/v3/utils/transform.js +14 -2
  63. package/dist/v3/utils/typeChecking.js +1 -0
  64. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { shallowRef } from "vue-demi";
2
2
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
- import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
4
- import { inTaiwan } from "./useMapInChina.js";
3
+ import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
4
+ import { inTaiwan, inKorean } from "./useMapInChina.js";
5
5
  import { useMapSupplier } from "./useMapSupplier.js";
6
6
  const useAWalkingRoute = (props) => {
7
7
  const { googleDirectionsProxyUrl } = useMapSupplier();
@@ -24,10 +24,13 @@ const useAWalkingRoute = (props) => {
24
24
  return pathRef;
25
25
  };
26
26
  const useGWalkingRoute = (props) => {
27
+ const { gaodeDirectionWalkingProxyUrl } = useMapSupplier();
27
28
  const pathRef = shallowRef([]);
28
29
  const gmapDirectionsService = new google.maps.DirectionsService();
29
30
  const apiMapWalkingRoute = (from, to) => {
30
- return gmapJsApiWalkingRoute(from, to, gmapDirectionsService);
31
+ if (inKorean(from))
32
+ return Promise.resolve([]);
33
+ return gaodeDirectionWalkingProxyUrl && inKorean(from) ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : gmapJsApiWalkingRoute(from, to, gmapDirectionsService);
31
34
  };
32
35
  watchPostEffectForDeepOption(
33
36
  () => {
@@ -22,7 +22,7 @@ declare global {
22
22
  tolls: number;
23
23
  tolls_distance: number;
24
24
  restriction: number;
25
- steps: (DriveStepBasic | DriveStepDetail)[];
25
+ steps: (DriveStepBasic & DriveStepDetail)[];
26
26
  }
27
27
  interface DriveStepBasic {
28
28
  start_location: LngLat;
@@ -68,7 +68,8 @@ declare global {
68
68
  taxi_cost: number;
69
69
  routes: DrivingRoute[];
70
70
  }
71
- type DrivingCallback = (status: "complete" | "error" | "no_data", result: DrivingResult | Error | 0) => void;
71
+ type DirectionCallbackStatus = "complete" | "error" | "no_data";
72
+ type DrivingCallback = (status: DirectionCallbackStatus, result: DrivingResult | Error | 0) => void;
72
73
  class Driving {
73
74
  constructor(option: DrivingOptions);
74
75
  search(origin: LngLat, destination: LngLat, opts: {
@@ -32,7 +32,7 @@ declare global {
32
32
  count: number;
33
33
  routes: WalkRoute[];
34
34
  }
35
- type WalkingCallback = (status: "complete" | "error" | "no_data", result: WalkingResult | Error | 0) => void;
35
+ type WalkingCallback = (status: DirectionCallbackStatus, result: WalkingResult | Error | 0) => void;
36
36
  class Walking {
37
37
  constructor(option: WalkingOptions);
38
38
  search(origin: LngLat, destination: LngLat, callback: WalkingCallback): void;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="google.maps" />
2
2
  import type { Point, Route } from "../types/interface";
3
3
  export declare function amapJsApiDrivingRoute(from: Point, to: Point, amapDriving: AMap.Driving): Promise<Route>;
4
+ export declare function gaodeServiceApiDrivingRoute(from: Point, to: Point, proxyUrl: string): Promise<Route>;
4
5
  export declare function gmapJsApiDrivingRoute(from: Point, to: Point, gmapDirectionsService: google.maps.DirectionsService): Promise<Route>;
5
6
  export declare function googleServiceApiDrivingRoute(from: Point, to: Point, proxyUrl: string): Promise<Route>;
@@ -1,3 +1,4 @@
1
+ import { apiGaodeDirectionDriving } from "../api/gaodeDirectionDriving.js";
1
2
  import { apiGoogleDirections } from "../api/googleDirections.js";
2
3
  function amapJsApiDrivingRoute(from, to, amapDriving) {
3
4
  return new Promise((resolve, reject) => {
@@ -41,6 +42,43 @@ function amapJsApiDrivingRoute(from, to, amapDriving) {
41
42
  );
42
43
  });
43
44
  }
45
+ async function gaodeServiceApiDrivingRoute(from, to, proxyUrl) {
46
+ const { status, routes, error_message } = await apiGaodeDirectionDriving({
47
+ proxyUrl,
48
+ origin: [from],
49
+ destination: to
50
+ });
51
+ switch (status) {
52
+ case "complete": {
53
+ let path = [];
54
+ const routeSteps = [];
55
+ const firstRoute = routes[0];
56
+ if (!firstRoute)
57
+ return { path: [], distance: 0, duration: 0, steps: [] };
58
+ for (const step of firstRoute.steps) {
59
+ const basicStep = step;
60
+ const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
61
+ path = path.concat(stepPath);
62
+ routeSteps.push({
63
+ path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
64
+ duration: basicStep.time,
65
+ distance: basicStep.distance
66
+ });
67
+ }
68
+ return {
69
+ path,
70
+ distance: firstRoute.distance,
71
+ duration: firstRoute.time,
72
+ tolls: firstRoute.tolls,
73
+ steps: routeSteps
74
+ };
75
+ }
76
+ case "no_data":
77
+ return { path: [], distance: 0, duration: 0, steps: [] };
78
+ default:
79
+ throw Error(error_message);
80
+ }
81
+ }
44
82
  function gmapJsApiDrivingRoute(from, to, gmapDirectionsService) {
45
83
  return new Promise((resolve, reject) => {
46
84
  gmapDirectionsService.route(
@@ -125,6 +163,7 @@ async function googleServiceApiDrivingRoute(from, to, proxyUrl) {
125
163
  }
126
164
  export {
127
165
  amapJsApiDrivingRoute,
166
+ gaodeServiceApiDrivingRoute,
128
167
  gmapJsApiDrivingRoute,
129
168
  googleServiceApiDrivingRoute
130
169
  };
@@ -6,3 +6,4 @@ export interface ApiGraspRoadOutput {
6
6
  }
7
7
  export declare function amapJsApiGraspRoad(tracks: TrackPoint[], amapGraspRoad: AMap.GraspRoad, apiMapComputeHeading: ApiMapComputeHeading): Promise<ApiGraspRoadOutput>;
8
8
  export declare function googleServiceApiGraspRoad(tracks: TrackPoint[], apiMapComputeHeading: ApiMapComputeHeading, proxyUrl?: string): Promise<ApiGraspRoadOutput>;
9
+ export declare function bypassGraspRoad(tracks: TrackPoint[], apiMapComputeHeading: ApiMapComputeHeading): Promise<ApiGraspRoadOutput>;
@@ -61,7 +61,14 @@ async function googleServiceApiGraspRoad(tracks, apiMapComputeHeading, proxyUrl)
61
61
  const angle = (_d = apiMapComputeHeading(path[path.length - 2], path[path.length - 1])) != null ? _d : 0;
62
62
  return { path, angle };
63
63
  }
64
+ async function bypassGraspRoad(tracks, apiMapComputeHeading) {
65
+ var _a;
66
+ const path = tracks.map(lnglat2point);
67
+ const angle = (_a = apiMapComputeHeading(path[0], path[1])) != null ? _a : 0;
68
+ return { path, angle };
69
+ }
64
70
  export {
65
71
  amapJsApiGraspRoad,
72
+ bypassGraspRoad,
66
73
  googleServiceApiGraspRoad
67
74
  };
@@ -1,5 +1,6 @@
1
1
  /// <reference types="google.maps" />
2
2
  import type { Point } from "../types/interface";
3
3
  export declare function amapJsApiWalkingRoute(from: Point, to: Point, amapWalking: AMap.Walking): Promise<Point[]>;
4
+ export declare function gaodeServiceApiWalkingRoute(from: Point, to: Point, proxyUrl: string): Promise<Point[]>;
4
5
  export declare function gmapJsApiWalkingRoute(from: Point, to: Point, gmapDirectionsService: google.maps.DirectionsService): Promise<Point[]>;
5
6
  export declare function googleServiceApiWalkingRoute(from: Point, to: Point, proxyUrl: string): Promise<Point[]>;
@@ -1,3 +1,4 @@
1
+ import { apiGaodeDirectionWalking } from "../api/gaodeDirectionWalking.js";
1
2
  import { apiGoogleDirections } from "../api/googleDirections.js";
2
3
  const isIgnoredAmapTimeoutError = (err) => err === "RETURN_TIMEOUT";
3
4
  function amapJsApiWalkingRoute(from, to, amapWalking) {
@@ -29,6 +30,30 @@ function amapJsApiWalkingRoute(from, to, amapWalking) {
29
30
  });
30
31
  });
31
32
  }
33
+ async function gaodeServiceApiWalkingRoute(from, to, proxyUrl) {
34
+ const { status, routes, error_message } = await apiGaodeDirectionWalking({
35
+ proxyUrl,
36
+ origin: from,
37
+ destination: to
38
+ });
39
+ switch (status) {
40
+ case "complete": {
41
+ let path = [];
42
+ if (!routes)
43
+ return [];
44
+ const firstRoute = routes[0];
45
+ for (const step of firstRoute.steps) {
46
+ const stepPath = step.path.map(({ lng, lat }) => [lng, lat]);
47
+ path = path.concat(stepPath);
48
+ }
49
+ return path;
50
+ }
51
+ case "no_data":
52
+ return [];
53
+ default:
54
+ throw Error(error_message);
55
+ }
56
+ }
32
57
  function gmapJsApiWalkingRoute(from, to, gmapDirectionsService) {
33
58
  return new Promise((resolve, reject) => {
34
59
  gmapDirectionsService.route(
@@ -76,6 +101,7 @@ async function googleServiceApiWalkingRoute(from, to, proxyUrl) {
76
101
  }
77
102
  export {
78
103
  amapJsApiWalkingRoute,
104
+ gaodeServiceApiWalkingRoute,
79
105
  gmapJsApiWalkingRoute,
80
106
  googleServiceApiWalkingRoute
81
107
  };
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.6.0";
3
+ const pkgVersion = "2.7.0";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -50,7 +50,7 @@ const detectOSPlatform = () => {
50
50
  if (typeof navigator === "undefined")
51
51
  return "OTHER";
52
52
  const userAgent = navigator.userAgent || navigator.vendor;
53
- if (/android/i.test(userAgent)) {
53
+ if (/android/i.test(userAgent) || /OpenHarmony/i.test(userAgent)) {
54
54
  return "ANDROID";
55
55
  }
56
56
  if (/iPad|iPhone|iPod/.test(userAgent) && !globalThis.MSStream) {
@@ -3,12 +3,14 @@ import type { Language, LngLatLiterial, Place, Point, TrackPoint, Zone } from ".
3
3
  import type { AlipayMyGetLocationSuccessResponse } from "../types/my";
4
4
  import type { WxGetLocationSuccessResponse } from "../types/wx";
5
5
  import { BRWOSER_PLATFORM } from "./platform";
6
+ export declare const isAccuryEqual: (x: number, y?: number) => boolean;
6
7
  export declare const vec2lnglat: ([lng, lat]: [number, number]) => LngLatLiterial;
7
8
  export declare const lnglat2point: ({ lng, lat }: {
8
9
  lng: number;
9
10
  lat: number;
10
11
  }) => Point;
11
12
  export declare const googlePointsStringify: (points: Point[]) => string;
13
+ export declare const gaodePointsStringify: (points: Point[]) => string;
12
14
  export interface AsteriskItem {
13
15
  type: "normal" | "emphasize";
14
16
  value: string;
@@ -44,4 +46,5 @@ type MaybeFunctionToFunction<T> = T extends (...args: any) => any ? T : () => T;
44
46
  export declare const maybeFunctionToFunction: <T>(value: T) => MaybeFunctionToFunction<T>;
45
47
  export declare const signal2promise: (signal?: AbortSignal) => Promise<any>;
46
48
  export declare const googleEncodedPolyline2googleLatLng: (value: string) => google.maps.LatLng[];
49
+ export declare const gaodePolyline2amapLngLat: (value: string) => AMap.LngLat[];
47
50
  export {};
@@ -35,12 +35,15 @@ var decode = function(encodedPath, precision) {
35
35
  path.length = pointIndex;
36
36
  return path;
37
37
  };
38
+ const GCOORD_ACCURCY_RANGE = 1e-6;
39
+ const isAccuryEqual = (x, y) => y === void 0 ? false : Math.abs(x - y) <= GCOORD_ACCURCY_RANGE;
38
40
  const vec2lnglat = ([lng, lat]) => ({
39
41
  lng: Number(lng),
40
42
  lat: Number(lat)
41
43
  });
42
44
  const lnglat2point = ({ lng, lat }) => [lng, lat];
43
45
  const googlePointsStringify = (points) => points.map(([lng, lat]) => `${lat},${lng}`).join("|");
46
+ const gaodePointsStringify = (points) => points.map(([lng, lat]) => `${lng},${lat}`).join(";");
44
47
  const decodeAsterisk = (encodedValue) => {
45
48
  const result = [];
46
49
  const tokens = encodedValue.split("*");
@@ -99,10 +102,10 @@ const pipeOnlyLastEffect = (fn) => {
99
102
  };
100
103
  };
101
104
  const isPlaceEqual = (p1, p2) => {
102
- return p1.lng === (p2 == null ? void 0 : p2.lng) && p1.lat === (p2 == null ? void 0 : p2.lat);
105
+ return isAccuryEqual(p1.lng, p2 == null ? void 0 : p2.lng) && isAccuryEqual(p1.lat, p2 == null ? void 0 : p2.lat);
103
106
  };
104
107
  const isPointEqual = (p1, p2) => {
105
- return p1[0] === (p2 == null ? void 0 : p2[0]) && p1[1] === (p2 == null ? void 0 : p2[1]);
108
+ return isAccuryEqual(p1[0], p2 == null ? void 0 : p2[0]) && isAccuryEqual(p1[1], p2 == null ? void 0 : p2[1]);
106
109
  };
107
110
  const isGeoPositionEqual = (p1, p2) => {
108
111
  if (!p2)
@@ -287,6 +290,12 @@ const signal2promise = (signal) => {
287
290
  const googleEncodedPolyline2googleLatLng = (value) => {
288
291
  return decode(value).map(([lat, lng]) => new GoogleLatLng({ lng, lat }));
289
292
  };
293
+ const gaodePolyline2amapLngLat = (value) => {
294
+ return value.split(";").map((lnglatString) => {
295
+ const [lng, lat] = lnglatString.split(",").map(Number);
296
+ return { lng, lat };
297
+ });
298
+ };
290
299
  export {
291
300
  alipayMyGetLocationError2GeolocationPositionErrorCode,
292
301
  alipayMyGetLocationSuccessResponse2GeolocationPosition,
@@ -296,10 +305,13 @@ export {
296
305
  decodeAsterisk,
297
306
  deltaZoom2animationDuration,
298
307
  distanceVw2animationDuration,
308
+ gaodePointsStringify,
309
+ gaodePolyline2amapLngLat,
299
310
  geoPositionError2businessTimeout,
300
311
  gmapPlaceName2DisplayName,
301
312
  googleEncodedPolyline2googleLatLng,
302
313
  googlePointsStringify,
314
+ isAccuryEqual,
303
315
  isGeoPositionEqual,
304
316
  isPlaceEqual,
305
317
  isPointEqual,
@@ -4,6 +4,7 @@ const createTypeError = (typeName, value, detail) => {
4
4
  `MyTypeError: expect type: ${typeName}, but received: ${JSON.stringify(
5
5
  value
6
6
  )}
7
+
7
8
  Type Error Details: ${detail}`
8
9
  );
9
10
  return new Error(`MyTypeError: expect type: ${typeName}, but received: ${JSON.stringify(value)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",