@heycar/heycars-map 2.5.3 → 2.6.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.
Files changed (96) 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/Demo/DemoBusinessRecomendPlace.js +1 -1
  5. package/dist/v2/api/contants.d.ts +3 -3
  6. package/dist/v2/api/contants.js +3 -3
  7. package/dist/v2/api/googleDirections.d.ts +26 -0
  8. package/dist/v2/api/googleDirections.js +139 -0
  9. package/dist/v2/api/googleSnapRoad.d.ts +0 -1
  10. package/dist/v2/api/googleSnapRoad.js +6 -14
  11. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
  12. package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  13. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +4 -3
  14. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +0 -1
  15. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +1 -3
  16. package/dist/v2/chunks/{BusinessRecomendPlaceMap.824002ef.js → BusinessRecomendPlaceMap.7b67c30c.js} +3 -2
  17. package/dist/v2/components/Gmap/Gmap.js +15 -3
  18. package/dist/v2/components/MapProvider/MapProvider.d.ts +1 -1
  19. package/dist/v2/components/MapProvider/MapProvider.js +6 -2
  20. package/dist/v2/hooks/useDrivingRoute.js +5 -82
  21. package/dist/v2/hooks/useMapAngle.d.ts +4 -3
  22. package/dist/v2/hooks/useMapCoordinatify.js +1 -1
  23. package/dist/v2/hooks/useMapFitView.js +4 -2
  24. package/dist/v2/hooks/useMapGraspRoad.d.ts +5 -8
  25. package/dist/v2/hooks/useMapGraspRoad.js +9 -60
  26. package/dist/v2/hooks/useMapInChina.d.ts +1 -0
  27. package/dist/v2/hooks/useMapInChina.js +28 -2
  28. package/dist/v2/hooks/useMapPlace.js +3 -3
  29. package/dist/v2/hooks/useMapRecomendPlace.js +2 -1
  30. package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
  31. package/dist/v2/hooks/useResizeObserver.d.ts +1 -0
  32. package/dist/v2/hooks/useResizeObserver.js +3 -1
  33. package/dist/v2/hooks/useWalkingRoute.js +21 -60
  34. package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  35. package/dist/v2/index.js +1 -1
  36. package/dist/v2/types/interface.d.ts +5 -0
  37. package/dist/v2/utils/compatibleDrivingRoute.d.ts +5 -0
  38. package/dist/v2/utils/compatibleDrivingRoute.js +130 -0
  39. package/dist/v2/utils/compatibleGoogleTypes.d.ts +11 -0
  40. package/dist/v2/utils/compatibleGoogleTypes.js +38 -0
  41. package/dist/v2/utils/compatibleGraspRoad.d.ts +8 -0
  42. package/dist/v2/utils/compatibleGraspRoad.js +67 -0
  43. package/dist/v2/utils/compatibleWalkingRoute.d.ts +5 -0
  44. package/dist/v2/utils/compatibleWalkingRoute.js +81 -0
  45. package/dist/v2/utils/log.js +1 -1
  46. package/dist/v2/utils/transform.d.ts +3 -1
  47. package/dist/v2/utils/transform.js +46 -5
  48. package/dist/v2/utils/typeChecking.d.ts +3 -1
  49. package/dist/v2/utils/typeChecking.js +5 -0
  50. package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
  51. package/dist/v3/api/contants.d.ts +3 -3
  52. package/dist/v3/api/contants.js +3 -3
  53. package/dist/v3/api/googleDirections.d.ts +26 -0
  54. package/dist/v3/api/googleDirections.js +139 -0
  55. package/dist/v3/api/googleSnapRoad.d.ts +0 -1
  56. package/dist/v3/api/googleSnapRoad.js +6 -14
  57. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
  58. package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  59. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +4 -3
  60. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +0 -1
  61. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +1 -3
  62. package/dist/v3/chunks/{BusinessRecomendPlaceMap.d14dbe4e.js → BusinessRecomendPlaceMap.8ce05cf5.js} +3 -2
  63. package/dist/v3/components/Gmap/Gmap.js +15 -3
  64. package/dist/v3/components/MapProvider/MapProvider.d.ts +1 -1
  65. package/dist/v3/components/MapProvider/MapProvider.js +6 -2
  66. package/dist/v3/hooks/useDrivingRoute.js +5 -82
  67. package/dist/v3/hooks/useMapAngle.d.ts +4 -3
  68. package/dist/v3/hooks/useMapCoordinatify.js +1 -1
  69. package/dist/v3/hooks/useMapFitView.js +4 -2
  70. package/dist/v3/hooks/useMapGraspRoad.d.ts +5 -8
  71. package/dist/v3/hooks/useMapGraspRoad.js +9 -60
  72. package/dist/v3/hooks/useMapInChina.d.ts +1 -0
  73. package/dist/v3/hooks/useMapInChina.js +28 -2
  74. package/dist/v3/hooks/useMapPlace.js +3 -3
  75. package/dist/v3/hooks/useMapRecomendPlace.js +2 -1
  76. package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
  77. package/dist/v3/hooks/useResizeObserver.d.ts +1 -0
  78. package/dist/v3/hooks/useResizeObserver.js +3 -1
  79. package/dist/v3/hooks/useWalkingRoute.js +21 -60
  80. package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  81. package/dist/v3/index.js +1 -1
  82. package/dist/v3/types/interface.d.ts +5 -0
  83. package/dist/v3/utils/compatibleDrivingRoute.d.ts +5 -0
  84. package/dist/v3/utils/compatibleDrivingRoute.js +130 -0
  85. package/dist/v3/utils/compatibleGoogleTypes.d.ts +11 -0
  86. package/dist/v3/utils/compatibleGoogleTypes.js +38 -0
  87. package/dist/v3/utils/compatibleGraspRoad.d.ts +8 -0
  88. package/dist/v3/utils/compatibleGraspRoad.js +67 -0
  89. package/dist/v3/utils/compatibleWalkingRoute.d.ts +5 -0
  90. package/dist/v3/utils/compatibleWalkingRoute.js +81 -0
  91. package/dist/v3/utils/log.js +1 -1
  92. package/dist/v3/utils/transform.d.ts +3 -1
  93. package/dist/v3/utils/transform.js +46 -5
  94. package/dist/v3/utils/typeChecking.d.ts +3 -1
  95. package/dist/v3/utils/typeChecking.js +5 -0
  96. package/package.json +2 -1
@@ -0,0 +1,130 @@
1
+ import { apiGoogleDirections } from "../api/googleDirections.js";
2
+ function amapJsApiDrivingRoute(from, to, amapDriving) {
3
+ return new Promise((resolve, reject) => {
4
+ amapDriving.search(
5
+ AMap.LngLat.from(from),
6
+ AMap.LngLat.from(to),
7
+ { waypoints: [] },
8
+ (status, result) => {
9
+ switch (status) {
10
+ case "complete": {
11
+ let path = [];
12
+ const drivingResult = result;
13
+ const routeSteps = [];
14
+ const firstRoute = drivingResult.routes[0];
15
+ if (!firstRoute)
16
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
17
+ for (const step of firstRoute.steps) {
18
+ const basicStep = step;
19
+ const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
20
+ path = path.concat(stepPath);
21
+ routeSteps.push({
22
+ path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
23
+ duration: basicStep.time,
24
+ distance: basicStep.distance
25
+ });
26
+ }
27
+ return resolve({
28
+ path,
29
+ distance: firstRoute.distance,
30
+ duration: firstRoute.time,
31
+ tolls: firstRoute.tolls,
32
+ steps: routeSteps
33
+ });
34
+ }
35
+ case "no_data":
36
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
37
+ default:
38
+ return reject(result);
39
+ }
40
+ }
41
+ );
42
+ });
43
+ }
44
+ function gmapJsApiDrivingRoute(from, to, gmapDirectionsService) {
45
+ return new Promise((resolve, reject) => {
46
+ gmapDirectionsService.route(
47
+ {
48
+ origin: { lng: from[0], lat: from[1] },
49
+ destination: { lng: to[0], lat: to[1] },
50
+ travelMode: google.maps.TravelMode.DRIVING
51
+ },
52
+ (result, status) => {
53
+ var _a, _b, _c, _d, _e, _f, _g, _h;
54
+ switch (status) {
55
+ case "OK": {
56
+ let path = [];
57
+ let distance = 0;
58
+ let duration = 0;
59
+ const routeSteps = [];
60
+ const firstRoute = result.routes[0];
61
+ if (!firstRoute)
62
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
63
+ for (const leg of firstRoute.legs) {
64
+ distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
65
+ duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
66
+ for (const step of leg.steps) {
67
+ const stepPath = step.path.map(({ lng, lat }) => [lng(), lat()]);
68
+ path = path.concat(stepPath);
69
+ routeSteps.push({
70
+ path: stepPath,
71
+ distance: (_f = (_e = step.distance) == null ? void 0 : _e.value) != null ? _f : 0,
72
+ duration: (_h = (_g = step.duration) == null ? void 0 : _g.value) != null ? _h : 0
73
+ });
74
+ }
75
+ }
76
+ return resolve({ path, distance, duration, steps: routeSteps });
77
+ }
78
+ case "ZERO_RESULTS":
79
+ case "NOT_FOUND":
80
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
81
+ default:
82
+ return reject(new Error(status));
83
+ }
84
+ }
85
+ );
86
+ });
87
+ }
88
+ async function googleServiceApiDrivingRoute(from, to, proxyUrl) {
89
+ var _a, _b, _c, _d, _e, _f, _g, _h;
90
+ const { status, routes, error_message } = await apiGoogleDirections({
91
+ proxyUrl,
92
+ origin: from,
93
+ destination: to
94
+ });
95
+ switch (status) {
96
+ case "OK": {
97
+ let path = [];
98
+ let distance = 0;
99
+ let duration = 0;
100
+ const routeSteps = [];
101
+ const firstRoute = routes[0];
102
+ if (!firstRoute)
103
+ return { path: [], distance: 0, duration: 0, steps: [] };
104
+ for (const leg of firstRoute.legs) {
105
+ distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
106
+ duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
107
+ for (const step of leg.steps) {
108
+ const stepPath = step.path.map(({ lng, lat }) => [lng(), lat()]);
109
+ path = path.concat(stepPath);
110
+ routeSteps.push({
111
+ path: stepPath,
112
+ distance: (_f = (_e = step.distance) == null ? void 0 : _e.value) != null ? _f : 0,
113
+ duration: (_h = (_g = step.duration) == null ? void 0 : _g.value) != null ? _h : 0
114
+ });
115
+ }
116
+ }
117
+ return { path, distance, duration, steps: routeSteps };
118
+ }
119
+ case "ZERO_RESULTS":
120
+ case "NOT_FOUND":
121
+ return { path: [], distance: 0, duration: 0, steps: [] };
122
+ default:
123
+ throw Error(error_message != null ? error_message : status);
124
+ }
125
+ }
126
+ export {
127
+ amapJsApiDrivingRoute,
128
+ gmapJsApiDrivingRoute,
129
+ googleServiceApiDrivingRoute
130
+ };
@@ -0,0 +1,11 @@
1
+ /// <reference types="google.maps" />
2
+ export declare class GoogleLatLng implements google.maps.LatLng {
3
+ private json;
4
+ constructor(value: google.maps.LatLngLiteral);
5
+ lng(): number;
6
+ lat(): number;
7
+ equals(other: google.maps.LatLng | null): boolean;
8
+ toJSON(): google.maps.LatLngLiteral;
9
+ toString(): string;
10
+ toUrlValue(precision?: number | undefined): string;
11
+ }
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ class GoogleLatLng {
8
+ constructor(value) {
9
+ __publicField(this, "json");
10
+ this.json = value;
11
+ this.lng = this.lng.bind(this);
12
+ this.lat = this.lat.bind(this);
13
+ }
14
+ lng() {
15
+ return this.json.lng;
16
+ }
17
+ lat() {
18
+ return this.json.lat;
19
+ }
20
+ equals(other) {
21
+ const { lng, lat } = this.json;
22
+ return lng === (other == null ? void 0 : other.lng()) && lat === other.lat();
23
+ }
24
+ toJSON() {
25
+ return { ...this.json };
26
+ }
27
+ toString() {
28
+ const { lng, lat } = this.json;
29
+ return `(${lat}, ${lng})`;
30
+ }
31
+ toUrlValue(precision = 7) {
32
+ const { lng, lat } = this.json;
33
+ return `${lat.toPrecision(precision)},${lng.toPrecision(precision)}`;
34
+ }
35
+ }
36
+ export {
37
+ GoogleLatLng
38
+ };
@@ -0,0 +1,8 @@
1
+ import type { ApiMapComputeHeading } from "../hooks/useMapAngle";
2
+ import type { Point, TrackPoint } from "../types/interface";
3
+ export interface ApiGraspRoadOutput {
4
+ path: Point[];
5
+ angle: number;
6
+ }
7
+ export declare function amapJsApiGraspRoad(tracks: TrackPoint[], amapGraspRoad: AMap.GraspRoad, apiMapComputeHeading: ApiMapComputeHeading): Promise<ApiGraspRoadOutput>;
8
+ export declare function googleServiceApiGraspRoad(tracks: TrackPoint[], apiMapComputeHeading: ApiMapComputeHeading, proxyUrl?: string): Promise<ApiGraspRoadOutput>;
@@ -0,0 +1,67 @@
1
+ import { apiGoogleSnapRoad } from "../api/googleSnapRoad.js";
2
+ import { inChina } from "../hooks/useMapInChina.js";
3
+ import { lnglat2point, trackPoints2amapGraspRoadPoints } from "./transform.js";
4
+ const GRASP_ROAD_INPUT_MIN_AMOUNT = 2;
5
+ const GRASP_ROAD_INPUT_MAX_AMOUNT = 500;
6
+ function amapJsApiGraspRoad(tracks, amapGraspRoad, apiMapComputeHeading) {
7
+ return new Promise((resolve) => {
8
+ var _a, _b, _c;
9
+ if (tracks.length < GRASP_ROAD_INPUT_MIN_AMOUNT) {
10
+ const path = tracks.map(lnglat2point);
11
+ const angle = (_b = (_a = tracks[tracks.length - 1]) == null ? void 0 : _a.angle) != null ? _b : 0;
12
+ return resolve({ path, angle });
13
+ }
14
+ const lastPoint = lnglat2point(tracks[tracks.length - 1]);
15
+ if (!inChina(lastPoint)) {
16
+ const path = tracks.map(lnglat2point);
17
+ const angle = (_c = apiMapComputeHeading(path[path.length - 2], path[path.length - 1])) != null ? _c : 0;
18
+ return resolve({ path, angle });
19
+ }
20
+ const amount = Math.min(GRASP_ROAD_INPUT_MAX_AMOUNT, tracks.length);
21
+ const graspRoadPoints = trackPoints2amapGraspRoadPoints(tracks.slice(-amount));
22
+ amapGraspRoad.driving(graspRoadPoints, (error, result) => {
23
+ var _a2, _b2;
24
+ if (error) {
25
+ console.error("高德地图路线纠偏失败!原因如下:\n", error);
26
+ const path2 = tracks.map(lnglat2point);
27
+ const angle2 = (_a2 = apiMapComputeHeading(path2[0], path2[1])) != null ? _a2 : 0;
28
+ return resolve({ path: path2, angle: angle2 });
29
+ }
30
+ const path = result.data.points.map(({ x, y }) => [x, y]);
31
+ const angle = (_b2 = apiMapComputeHeading(path[path.length - 2], path[path.length - 1])) != null ? _b2 : 0;
32
+ resolve({ path, angle });
33
+ });
34
+ });
35
+ }
36
+ async function googleServiceApiGraspRoad(tracks, apiMapComputeHeading, proxyUrl) {
37
+ var _a, _b, _c, _d;
38
+ let result;
39
+ if (tracks.length < GRASP_ROAD_INPUT_MIN_AMOUNT) {
40
+ const path2 = tracks.map(lnglat2point);
41
+ const angle2 = (_b = (_a = tracks[tracks.length - 1]) == null ? void 0 : _a.angle) != null ? _b : 0;
42
+ return { path: path2, angle: angle2 };
43
+ }
44
+ const amount = Math.min(GRASP_ROAD_INPUT_MAX_AMOUNT, tracks.length);
45
+ const snapRoadPath = tracks.slice(-amount).map(lnglat2point);
46
+ try {
47
+ result = await apiGoogleSnapRoad({ path: snapRoadPath, proxyUrl });
48
+ } catch (error) {
49
+ console.error("谷歌地图路线纠偏失败!原因如下:\n", error);
50
+ const path2 = tracks.map(lnglat2point);
51
+ const angle2 = (_c = apiMapComputeHeading(path2[0], path2[1])) != null ? _c : 0;
52
+ return { path: path2, angle: angle2 };
53
+ }
54
+ const { snappedPoints, warningMessage } = result;
55
+ if (warningMessage)
56
+ console.warn("apiGoogleSnapRoad warning: ", warningMessage);
57
+ const path = snappedPoints.map((item) => [
58
+ item.location.longitude,
59
+ item.location.latitude
60
+ ]);
61
+ const angle = (_d = apiMapComputeHeading(path[path.length - 2], path[path.length - 1])) != null ? _d : 0;
62
+ return { path, angle };
63
+ }
64
+ export {
65
+ amapJsApiGraspRoad,
66
+ googleServiceApiGraspRoad
67
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="google.maps" />
2
+ import type { Point } from "../types/interface";
3
+ export declare function amapJsApiWalkingRoute(from: Point, to: Point, amapWalking: AMap.Walking): Promise<Point[]>;
4
+ export declare function gmapJsApiWalkingRoute(from: Point, to: Point, gmapDirectionsService: google.maps.DirectionsService): Promise<Point[]>;
5
+ export declare function googleServiceApiWalkingRoute(from: Point, to: Point, proxyUrl: string): Promise<Point[]>;
@@ -0,0 +1,81 @@
1
+ import { apiGoogleDirections } from "../api/googleDirections.js";
2
+ const isIgnoredAmapTimeoutError = (err) => err === "RETURN_TIMEOUT";
3
+ function amapJsApiWalkingRoute(from, to, amapWalking) {
4
+ return new Promise((resolve, reject) => {
5
+ amapWalking.search(AMap.LngLat.from(from), AMap.LngLat.from(to), (status, result) => {
6
+ switch (status) {
7
+ case "complete": {
8
+ let path = [];
9
+ const walkingResult = result;
10
+ if (!walkingResult.routes) {
11
+ return resolve([]);
12
+ }
13
+ const firstRoute = walkingResult.routes[0];
14
+ for (const step of firstRoute.steps) {
15
+ const stepPath = step.path.map(({ lng, lat }) => [lng, lat]);
16
+ path = path.concat(stepPath);
17
+ }
18
+ return resolve(path);
19
+ }
20
+ case "no_data":
21
+ return resolve([]);
22
+ default:
23
+ if (isIgnoredAmapTimeoutError(result)) {
24
+ console.warn(result);
25
+ return resolve([]);
26
+ }
27
+ return reject(result);
28
+ }
29
+ });
30
+ });
31
+ }
32
+ function gmapJsApiWalkingRoute(from, to, gmapDirectionsService) {
33
+ return new Promise((resolve, reject) => {
34
+ gmapDirectionsService.route(
35
+ {
36
+ origin: { lng: from[0], lat: from[1] },
37
+ destination: { lng: to[0], lat: to[1] },
38
+ travelMode: google.maps.TravelMode.WALKING
39
+ },
40
+ (result, status) => {
41
+ switch (status) {
42
+ case "OK": {
43
+ const { overview_path } = result.routes[0];
44
+ const path = overview_path.map(({ lng, lat }) => [lng(), lat()]);
45
+ return resolve(path);
46
+ }
47
+ case "ZERO_RESULTS":
48
+ case "NOT_FOUND":
49
+ return resolve([]);
50
+ default:
51
+ return reject(new Error(status));
52
+ }
53
+ }
54
+ );
55
+ });
56
+ }
57
+ async function googleServiceApiWalkingRoute(from, to, proxyUrl) {
58
+ const { status, routes, error_message } = await apiGoogleDirections({
59
+ proxyUrl,
60
+ mode: "WALKING",
61
+ origin: from,
62
+ destination: to
63
+ });
64
+ switch (status) {
65
+ case "OK": {
66
+ const { overview_path } = routes[0];
67
+ const path = overview_path.map(({ lng, lat }) => [lng(), lat()]);
68
+ return path;
69
+ }
70
+ case "ZERO_RESULTS":
71
+ case "NOT_FOUND":
72
+ return [];
73
+ default:
74
+ throw Error(error_message != null ? error_message : status);
75
+ }
76
+ }
77
+ export {
78
+ amapJsApiWalkingRoute,
79
+ gmapJsApiWalkingRoute,
80
+ googleServiceApiWalkingRoute
81
+ };
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.5.2";
3
+ const pkgVersion = "2.6.1";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -8,6 +8,7 @@ export declare const lnglat2point: ({ lng, lat }: {
8
8
  lng: number;
9
9
  lat: number;
10
10
  }) => Point;
11
+ export declare const googlePointsStringify: (points: Point[]) => string;
11
12
  export interface AsteriskItem {
12
13
  type: "normal" | "emphasize";
13
14
  value: string;
@@ -27,7 +28,7 @@ export declare const isPointEqual: (p1: Point, p2?: Point) => boolean;
27
28
  export declare const isGeoPositionEqual: (p1: GeolocationPosition, p2?: GeolocationPosition) => boolean;
28
29
  export declare const isZoneEqual: (z1: Zone, z2?: Zone) => boolean;
29
30
  interface AmapPlaceName2DisplayNameOptions extends AMap.AddressComponent {
30
- isChina: boolean;
31
+ isChinese: boolean;
31
32
  }
32
33
  export declare const amapPlaceName2DisplayName: (name: string, options: AmapPlaceName2DisplayNameOptions) => string;
33
34
  export declare function gmapPlaceName2DisplayName(name: string, addressComponents: google.maps.GeocoderAddressComponent[]): string;
@@ -42,4 +43,5 @@ export declare const businessCandidatesToAdsorptionPlace: (places: Place[]) => P
42
43
  type MaybeFunctionToFunction<T> = T extends (...args: any) => any ? T : () => T;
43
44
  export declare const maybeFunctionToFunction: <T>(value: T) => MaybeFunctionToFunction<T>;
44
45
  export declare const signal2promise: (signal?: AbortSignal) => Promise<any>;
46
+ export declare const googleEncodedPolyline2googleLatLng: (value: string) => google.maps.LatLng[];
45
47
  export {};
@@ -1,10 +1,46 @@
1
1
  import { MIN_ANIMATION_DURATION, ANIMATION_DURATION_FOR_100VW, ANIMATION_DURATION_PER_ZOOM } from "../api/contants.js";
2
+ import { GoogleLatLng } from "./compatibleGoogleTypes.js";
2
3
  import { BRWOSER_PLATFORM } from "./platform.js";
4
+ var decode = function(encodedPath, precision) {
5
+ if (precision === void 0) {
6
+ precision = 5;
7
+ }
8
+ var factor = Math.pow(10, precision);
9
+ var len = encodedPath.length;
10
+ var path = new Array(Math.floor(encodedPath.length / 2));
11
+ var index = 0;
12
+ var lat = 0;
13
+ var lng = 0;
14
+ var pointIndex = 0;
15
+ for (; index < len; ++pointIndex) {
16
+ var result = 1;
17
+ var shift = 0;
18
+ var b = void 0;
19
+ do {
20
+ b = encodedPath.charCodeAt(index++) - 63 - 1;
21
+ result += b << shift;
22
+ shift += 5;
23
+ } while (b >= 31);
24
+ lat += result & 1 ? ~(result >> 1) : result >> 1;
25
+ result = 1;
26
+ shift = 0;
27
+ do {
28
+ b = encodedPath.charCodeAt(index++) - 63 - 1;
29
+ result += b << shift;
30
+ shift += 5;
31
+ } while (b >= 31);
32
+ lng += result & 1 ? ~(result >> 1) : result >> 1;
33
+ path[pointIndex] = [lat / factor, lng / factor];
34
+ }
35
+ path.length = pointIndex;
36
+ return path;
37
+ };
3
38
  const vec2lnglat = ([lng, lat]) => ({
4
39
  lng: Number(lng),
5
40
  lat: Number(lat)
6
41
  });
7
42
  const lnglat2point = ({ lng, lat }) => [lng, lat];
43
+ const googlePointsStringify = (points) => points.map(([lng, lat]) => `${lat},${lng}`).join("|");
8
44
  const decodeAsterisk = (encodedValue) => {
9
45
  const result = [];
10
46
  const tokens = encodedValue.split("*");
@@ -77,12 +113,12 @@ const isZoneEqual = (z1, z2) => {
77
113
  return z1.name === (z2 == null ? void 0 : z2.name) && z1.path.every((point, idx) => isPointEqual(point, z2 == null ? void 0 : z2.path[idx]));
78
114
  };
79
115
  const amapPlaceName2DisplayName = (name, options) => {
80
- const { isChina } = options;
116
+ const { isChinese } = options;
81
117
  if (!name)
82
118
  return name;
83
- return isChina ? amapPlaceName2DisplayNameInChina(name, options) : amapPlaceName2DisplayNameOutChina(name, options);
119
+ return isChinese ? amapPlaceName2DisplayNameInChinese(name, options) : amapPlaceName2DisplayNameOutChinese(name, options);
84
120
  };
85
- function amapPlaceName2DisplayNameInChina(name, options) {
121
+ function amapPlaceName2DisplayNameInChinese(name, options) {
86
122
  const { province, city, district, township, building, neighborhood } = options;
87
123
  if (building)
88
124
  return building;
@@ -101,7 +137,7 @@ function amapPlaceName2DisplayNameInChina(name, options) {
101
137
  return replacedName.trim() ? replacedName : result;
102
138
  }
103
139
  const NOT_ONLY_NUMBERS_REGEX = /[^\d\s-]/;
104
- function amapPlaceName2DisplayNameOutChina(name, options) {
140
+ function amapPlaceName2DisplayNameOutChinese(name, options) {
105
141
  const { adcode, province, city, district, township, street, streetNumber } = options;
106
142
  if (street === "Unnamed Road")
107
143
  return name;
@@ -183,7 +219,7 @@ const distanceVw2animationDuration = (distance) => {
183
219
  return Math.max(MIN_ANIMATION_DURATION, ANIMATION_DURATION_FOR_100VW * distance / 100);
184
220
  };
185
221
  const deltaZoom2animationDuration = (deltaZoom) => {
186
- return Math.max(MIN_ANIMATION_DURATION * 4, Math.abs(deltaZoom) * ANIMATION_DURATION_PER_ZOOM);
222
+ return Math.max(MIN_ANIMATION_DURATION * 2, Math.abs(deltaZoom) * ANIMATION_DURATION_PER_ZOOM);
187
223
  };
188
224
  const wxGetLocationSuccessResponse2GeolocationPosition = (res) => {
189
225
  const { longitude, latitude, accuracy } = res;
@@ -248,6 +284,9 @@ const signal2promise = (signal) => {
248
284
  signal == null ? void 0 : signal.addEventListener("abort", () => reject(signal.reason));
249
285
  });
250
286
  };
287
+ const googleEncodedPolyline2googleLatLng = (value) => {
288
+ return decode(value).map(([lat, lng]) => new GoogleLatLng({ lng, lat }));
289
+ };
251
290
  export {
252
291
  alipayMyGetLocationError2GeolocationPositionErrorCode,
253
292
  alipayMyGetLocationSuccessResponse2GeolocationPosition,
@@ -259,6 +298,8 @@ export {
259
298
  distanceVw2animationDuration,
260
299
  geoPositionError2businessTimeout,
261
300
  gmapPlaceName2DisplayName,
301
+ googleEncodedPolyline2googleLatLng,
302
+ googlePointsStringify,
262
303
  isGeoPositionEqual,
263
304
  isPlaceEqual,
264
305
  isPointEqual,
@@ -1,4 +1,5 @@
1
- import type { CoordinatePlace, CoordinatePoint, CoordinateRecommendZonePlaces, CoordinateTrackPoint, CoordinateType, CoordinateZone, RecommendType } from "../types/interface";
1
+ import type { CoordinatePlace, CoordinatePoint, CoordinateRecommendZonePlaces, CoordinateTrackPoint, CoordinateType, CoordinateZone, ProxyServiceError, RecommendType } from "../types/interface";
2
+ export declare const createTypeError: (typeName: string, value: unknown, detail?: string) => Error;
2
3
  export declare function isCoordinateType(type: unknown): type is CoordinateType;
3
4
  export declare function isRecommendType(type: unknown): type is RecommendType;
4
5
  export declare function toRecommendType(type: unknown): RecommendType;
@@ -40,4 +41,5 @@ interface MaybeCoordinateTrackPoint {
40
41
  timestamp?: number | string;
41
42
  }
42
43
  export declare const toCoordinateTrackPoint: (value?: MaybeCoordinateTrackPoint) => CoordinateTrackPoint;
44
+ export declare function isProxyServiceError(error: unknown): error is ProxyServiceError;
43
45
  export {};
@@ -105,10 +105,15 @@ const toCoordinateTrackPoint = (value) => {
105
105
  }
106
106
  return { lng, lat, type, angle, speed, timestamp };
107
107
  };
108
+ function isProxyServiceError(error) {
109
+ return !!error && typeof error === "object" && "msg" in error && "code" in error;
110
+ }
108
111
  export {
109
112
  assertNoConflictTypeAndZone,
113
+ createTypeError,
110
114
  isCoordinatePoint,
111
115
  isCoordinateType,
116
+ isProxyServiceError,
112
117
  isRecommendType,
113
118
  toCoordinatePlaceType,
114
119
  toCoordinatePointType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.5.3",
3
+ "version": "2.6.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",
@@ -37,6 +37,7 @@
37
37
  "dependencies": {
38
38
  "@amap/amap-jsapi-types": "^0.0.13",
39
39
  "@googlemaps/js-api-loader": "1.16.6",
40
+ "@googlemaps/polyline-codec": "^1.0.28",
40
41
  "@googlemaps/typescript-guards": "^2.0.3",
41
42
  "@heycar/amap-jsapi-loader": "npm:@heycar/amap-jsapi-loader@1.0.1-fetchPriority",
42
43
  "@types/google.maps": "^3.54.10",