@heycar/heycars-map 2.7.2 → 2.8.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 (47) hide show
  1. package/dist/v2/api/gaodeDirectionDriving.js +21 -6
  2. package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.js +6 -4
  3. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +23 -14
  4. package/dist/v2/business-components/DrivingLine/DrivingLine.d.ts +5 -1
  5. package/dist/v2/business-components/DrivingLine/DrivingLine.js +44 -10
  6. package/dist/v2/business-components/DrivingRoute/DrivingRoute.d.ts +2 -1
  7. package/dist/v2/business-components/DrivingRoute/DrivingRoute.js +4 -2
  8. package/dist/v2/business-components/TrafficDrivingLine/TrafficDrivingLine.d.ts +6 -0
  9. package/dist/v2/business-components/TrafficDrivingLine/TrafficDrivingLine.js +117 -0
  10. package/dist/v2/business-components/TrafficDrivingLine/index.d.ts +1 -0
  11. package/dist/v2/business-components/TrafficDrivingLine/index.js +4 -0
  12. package/dist/v2/components/AmapMarker/AmapMarker.js +0 -2
  13. package/dist/v2/hooks/useDeviationCorrectionDrivingRoute.d.ts +2 -0
  14. package/dist/v2/hooks/useDeviationCorrectionDrivingRoute.js +6 -2
  15. package/dist/v2/hooks/useDrivingRoute.d.ts +3 -0
  16. package/dist/v2/hooks/useDrivingRoute.js +2 -1
  17. package/dist/v2/hooks/useDrivingTrackCorrection.d.ts +1 -0
  18. package/dist/v2/types/amap/driving.d.ts +2 -1
  19. package/dist/v2/types/interface.d.ts +6 -0
  20. package/dist/v2/utils/compatibleDrivingRoute.js +29 -2
  21. package/dist/v2/utils/log.js +1 -1
  22. package/dist/v2/utils/transform.d.ts +4 -1
  23. package/dist/v2/utils/transform.js +23 -1
  24. package/dist/v3/api/gaodeDirectionDriving.js +21 -6
  25. package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.js +6 -4
  26. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +23 -14
  27. package/dist/v3/business-components/DrivingLine/DrivingLine.d.ts +5 -1
  28. package/dist/v3/business-components/DrivingLine/DrivingLine.js +44 -10
  29. package/dist/v3/business-components/DrivingRoute/DrivingRoute.d.ts +2 -1
  30. package/dist/v3/business-components/DrivingRoute/DrivingRoute.js +4 -2
  31. package/dist/v3/business-components/TrafficDrivingLine/TrafficDrivingLine.d.ts +8 -0
  32. package/dist/v3/business-components/TrafficDrivingLine/TrafficDrivingLine.js +115 -0
  33. package/dist/v3/business-components/TrafficDrivingLine/index.d.ts +1 -0
  34. package/dist/v3/business-components/TrafficDrivingLine/index.js +4 -0
  35. package/dist/v3/components/AmapMarker/AmapMarker.js +0 -2
  36. package/dist/v3/hooks/useDeviationCorrectionDrivingRoute.d.ts +2 -0
  37. package/dist/v3/hooks/useDeviationCorrectionDrivingRoute.js +6 -2
  38. package/dist/v3/hooks/useDrivingRoute.d.ts +3 -0
  39. package/dist/v3/hooks/useDrivingRoute.js +2 -1
  40. package/dist/v3/hooks/useDrivingTrackCorrection.d.ts +1 -0
  41. package/dist/v3/types/amap/driving.d.ts +2 -1
  42. package/dist/v3/types/interface.d.ts +6 -0
  43. package/dist/v3/utils/compatibleDrivingRoute.js +29 -2
  44. package/dist/v3/utils/log.js +1 -1
  45. package/dist/v3/utils/transform.d.ts +4 -1
  46. package/dist/v3/utils/transform.js +23 -1
  47. package/package.json +1 -1
@@ -1,5 +1,24 @@
1
1
  import { apiGaodeDirectionDriving } from "../api/gaodeDirectionDriving.js";
2
2
  import { apiGoogleDirections } from "../api/googleDirections.js";
3
+ import { amapTraffic2trafficStatus, stringifyPoint } from "./transform.js";
4
+ const amapTmcs2trafficJams = (tmcs) => {
5
+ const trafficJams = {};
6
+ let prevStatus = "UNKNOWN";
7
+ for (const tmc of tmcs) {
8
+ const { path } = tmc;
9
+ if (!path)
10
+ continue;
11
+ for (const { lng, lat } of path) {
12
+ const status = amapTraffic2trafficStatus(tmc.status);
13
+ trafficJams[stringifyPoint([lng, lat])] = {
14
+ before: prevStatus,
15
+ after: status
16
+ };
17
+ prevStatus = status;
18
+ }
19
+ }
20
+ return trafficJams;
21
+ };
3
22
  function amapJsApiDrivingRoute(from, to, amapDriving) {
4
23
  return new Promise((resolve, reject) => {
5
24
  amapDriving.search(
@@ -7,9 +26,11 @@ function amapJsApiDrivingRoute(from, to, amapDriving) {
7
26
  AMap.LngLat.from(to),
8
27
  { waypoints: [] },
9
28
  (status, result) => {
29
+ const trafficJams = {};
10
30
  switch (status) {
11
31
  case "complete": {
12
32
  let path = [];
33
+ let tmcs = [];
13
34
  const drivingResult = result;
14
35
  const routeSteps = [];
15
36
  const firstRoute = drivingResult.routes[0];
@@ -19,18 +40,21 @@ function amapJsApiDrivingRoute(from, to, amapDriving) {
19
40
  const basicStep = step;
20
41
  const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
21
42
  path = path.concat(stepPath);
43
+ tmcs = tmcs.concat(basicStep.tmcs);
22
44
  routeSteps.push({
23
45
  path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
24
46
  duration: basicStep.time,
25
47
  distance: basicStep.distance
26
48
  });
27
49
  }
50
+ Object.assign(trafficJams, amapTmcs2trafficJams(tmcs));
28
51
  return resolve({
29
52
  path,
30
53
  distance: firstRoute.distance,
31
54
  duration: firstRoute.time,
32
55
  tolls: firstRoute.tolls,
33
- steps: routeSteps
56
+ steps: routeSteps,
57
+ trafficJams
34
58
  });
35
59
  }
36
60
  case "no_data":
@@ -48,6 +72,7 @@ async function gaodeServiceApiDrivingRoute(from, to, proxyUrl) {
48
72
  origin: [from],
49
73
  destination: to
50
74
  });
75
+ const trafficJams = {};
51
76
  switch (status) {
52
77
  case "complete": {
53
78
  let path = [];
@@ -59,6 +84,7 @@ async function gaodeServiceApiDrivingRoute(from, to, proxyUrl) {
59
84
  const basicStep = step;
60
85
  const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
61
86
  path = path.concat(stepPath);
87
+ Object.assign(trafficJams, amapTmcs2trafficJams(basicStep.tmcs));
62
88
  routeSteps.push({
63
89
  path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
64
90
  duration: basicStep.time,
@@ -70,7 +96,8 @@ async function gaodeServiceApiDrivingRoute(from, to, proxyUrl) {
70
96
  distance: firstRoute.distance,
71
97
  duration: firstRoute.time,
72
98
  tolls: firstRoute.tolls,
73
- steps: routeSteps
99
+ steps: routeSteps,
100
+ trafficJams
74
101
  };
75
102
  }
76
103
  case "no_data":
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.7.2";
3
+ const pkgVersion = "2.8.1";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="google.maps" />
2
- import type { LngLatLiterial, Place, Point, TrackPoint, Zone } from "../types/interface";
2
+ import type { LngLatLiterial, Place, Point, TrackPoint, TrafficStatus, Zone } from "../types/interface";
3
3
  import type { AlipayMyGetLocationSuccessResponse } from "../types/my";
4
4
  import type { WxGetLocationSuccessResponse } from "../types/wx";
5
5
  import { BRWOSER_PLATFORM } from "./platform";
@@ -9,6 +9,7 @@ export declare const lnglat2point: ({ lng, lat }: {
9
9
  lng: number;
10
10
  lat: number;
11
11
  }) => Point;
12
+ export declare const stringifyPoint: (p: Point) => `${number},${number}`;
12
13
  export declare const googlePointsStringify: (points: Point[]) => string;
13
14
  export declare const gaodePointsStringify: (points: Point[]) => string;
14
15
  export interface AsteriskItem {
@@ -24,6 +25,7 @@ export declare const pipeAsync: <P extends any[]>(fn?: ((...args: P) => any) | u
24
25
  export declare const pipeDefer: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => Promise<R>;
25
26
  export declare const pipeOnlyLastEffect: <P extends any[], R>(fn: (...arg: P) => Promise<R>) => (...args: P) => Promise<R>;
26
27
  export declare const isPlaceEqual: (p1: Place, p2?: Place) => boolean;
28
+ export declare const isPointExactEqual: (p1: Point, p2?: Point) => boolean;
27
29
  export declare const isPointEqual: (p1: Point, p2?: Point) => boolean;
28
30
  export declare const isGeoPositionEqual: (p1: GeolocationPosition, p2?: GeolocationPosition) => boolean;
29
31
  export declare const isZoneEqual: (z1: Zone, z2?: Zone) => boolean;
@@ -45,4 +47,5 @@ export declare const maybeFunctionToFunction: <T>(value: T) => MaybeFunctionToFu
45
47
  export declare const signal2promise: (signal?: AbortSignal) => Promise<any>;
46
48
  export declare const googleEncodedPolyline2googleLatLng: (value: string) => google.maps.LatLng[];
47
49
  export declare const gaodePolyline2amapLngLat: (value: string) => AMap.LngLat[];
50
+ export declare const amapTraffic2trafficStatus: (value?: AMap.TMC["status"]) => TrafficStatus;
48
51
  export {};
@@ -42,8 +42,9 @@ const vec2lnglat = ([lng, lat]) => ({
42
42
  lat: Number(lat)
43
43
  });
44
44
  const lnglat2point = ({ lng, lat }) => [lng, lat];
45
+ const stringifyPoint = (p) => `${p[0]},${p[1]}`;
45
46
  const googlePointsStringify = (points) => points.map(([lng, lat]) => `${lat},${lng}`).join("|");
46
- const gaodePointsStringify = (points) => points.map(([lng, lat]) => `${lng},${lat}`).join(";");
47
+ const gaodePointsStringify = (points) => points.map(stringifyPoint).join(";");
47
48
  const decodeAsterisk = (encodedValue) => {
48
49
  const result = [];
49
50
  const tokens = encodedValue.split("*");
@@ -95,6 +96,9 @@ const pipeOnlyLastEffect = (fn) => {
95
96
  const isPlaceEqual = (p1, p2) => {
96
97
  return isAccuryEqual(p1.lng, p2 == null ? void 0 : p2.lng) && isAccuryEqual(p1.lat, p2 == null ? void 0 : p2.lat);
97
98
  };
99
+ const isPointExactEqual = (p1, p2) => {
100
+ return p1[0] === (p2 == null ? void 0 : p2[0]) && p1[1] === (p2 == null ? void 0 : p2[1]);
101
+ };
98
102
  const isPointEqual = (p1, p2) => {
99
103
  return isAccuryEqual(p1[0], p2 == null ? void 0 : p2[0]) && isAccuryEqual(p1[1], p2 == null ? void 0 : p2[1]);
100
104
  };
@@ -287,10 +291,26 @@ const gaodePolyline2amapLngLat = (value) => {
287
291
  return { lng, lat };
288
292
  });
289
293
  };
294
+ const amapTraffic2trafficStatus = (value) => {
295
+ switch (value) {
296
+ case void 0:
297
+ case "未知":
298
+ return "UNKNOWN";
299
+ case "畅通":
300
+ return "NORMAL";
301
+ case "缓行":
302
+ return "SLOW";
303
+ case "拥堵":
304
+ return "TRAFFIC_JAM";
305
+ case "严重拥堵":
306
+ return "HEAVY_TRAFFIC_JAM";
307
+ }
308
+ };
290
309
  export {
291
310
  alipayMyGetLocationError2GeolocationPositionErrorCode,
292
311
  alipayMyGetLocationSuccessResponse2GeolocationPosition,
293
312
  amapPlaceName2DisplayName,
313
+ amapTraffic2trafficStatus,
294
314
  businessCandidatesToAdsorptionPlace,
295
315
  combineHandler,
296
316
  decodeAsterisk,
@@ -306,6 +326,7 @@ export {
306
326
  isGeoPositionEqual,
307
327
  isPlaceEqual,
308
328
  isPointEqual,
329
+ isPointExactEqual,
309
330
  isZoneEqual,
310
331
  lnglat2point,
311
332
  maybeFunctionToFunction,
@@ -316,6 +337,7 @@ export {
316
337
  property2emitEventName,
317
338
  property2mapEventName,
318
339
  signal2promise,
340
+ stringifyPoint,
319
341
  trackPoints2amapGraspRoadPoints,
320
342
  vec2lnglat,
321
343
  wxGetLocationSuccessResponse2GeolocationPosition
@@ -1,6 +1,6 @@
1
1
  import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
2
2
  import { createTypeError, isProxyServiceError } from "../utils/typeChecking.js";
3
- const GAODE_POLYLINE_REGEX = /^(?:\d*\.\d+,\d*\.\d+)?(?:;\d*\.\d+,\d*\.\d+)*$/;
3
+ const GAODE_POLYLINE_REGEX = /^(?:-?\d*\.\d+,-?\d*\.\d+)?(?:;-?\d*\.\d+,-?\d*\.\d+)*$/;
4
4
  var GaodeDirectionStatus = /* @__PURE__ */ ((GaodeDirectionStatus2) => {
5
5
  GaodeDirectionStatus2["SUCCESS"] = "1";
6
6
  GaodeDirectionStatus2["FAIL"] = "0";
@@ -35,10 +35,19 @@ function isGaodeDirectionBasicStep(value) {
35
35
  function isGaodeEmptyValue(value) {
36
36
  return Array.isArray(value) && value.length === 0;
37
37
  }
38
- function assertGaodoDirectionDrivingStep(value) {
39
- if (isGaodeDirectionBasicStep(value))
38
+ function isAmapTmcStatus(value) {
39
+ return value === "未知" || value === "畅通" || value === "缓行" || value === "拥堵" || value === "严重拥堵";
40
+ }
41
+ function assertGaodeDirectionDrivingTmc(value) {
42
+ if (typeof value === "object" && value !== null && "status" in value && isAmapTmcStatus(value.status) && "polyline" in value && isGaodeDirectionPolyline(value.polyline))
40
43
  return;
41
- throw createTypeError("GaodeDirectionDrivingStep", value);
44
+ throw createTypeError("GaodeDirectionDrivingTmc", value);
45
+ }
46
+ function assertGaodoDirectionDrivingStep(value) {
47
+ if (!isGaodeDirectionBasicStep(value) || !("tmcs" in value) || !Array.isArray(value.tmcs)) {
48
+ throw createTypeError("GaodeDirectionDrivingStep", value);
49
+ }
50
+ value.tmcs.forEach(assertGaodeDirectionDrivingTmc);
42
51
  }
43
52
  function assertGaodeDirectionDrivingRoutePath(value) {
44
53
  if (!isGaodeMeasurableObject(value) || !("tolls" in value) || !isGaodeNumberableString(value.tolls) || !("steps" in value) || !Array.isArray(value.steps)) {
@@ -63,15 +72,21 @@ function assertGaodeDirectionDrivingResponse(value) {
63
72
  throw createTypeError("GaodeDirectionDrivingResponse", value, detail);
64
73
  }
65
74
  }
75
+ function gaodeDirectionDrivingTmc2amapTmc(gaodeTmc) {
76
+ const { status, polyline } = gaodeTmc;
77
+ const path = gaodePolyline2amapLngLat(String(polyline));
78
+ return { status, path };
79
+ }
66
80
  function gaodeDirectionDrivingRoute2amapDrivingRoute(gaodeRoute) {
67
81
  return gaodeRoute.paths.map((routePath) => {
68
82
  const { distance, duration, tolls, steps: godeDirectionSteps } = routePath;
69
83
  const steps = godeDirectionSteps.map((directionStep) => {
70
- const { distance: distance2, duration: duration2, polyline } = directionStep;
84
+ const { distance: distance2, duration: duration2, polyline, tmcs } = directionStep;
71
85
  return {
72
86
  distance: Number(distance2),
73
87
  time: Number(duration2),
74
- path: gaodePolyline2amapLngLat(String(polyline))
88
+ path: gaodePolyline2amapLngLat(String(polyline)),
89
+ tmcs: tmcs.map(gaodeDirectionDrivingTmc2amapTmc)
75
90
  };
76
91
  });
77
92
  return {
@@ -9,10 +9,10 @@ import { defineSetup, defineLagecySetup } from "../../types/helper.js";
9
9
  import { generateCreateElementV2PropsOn } from "../../utils/compare.js";
10
10
  import { place2point, pipeDefer } from "../../utils/transform.js";
11
11
  import { toCoordinatePlaceType } from "../../utils/typeChecking.js";
12
- import { DrivingLine } from "../DrivingLine/DrivingLine.js";
13
12
  import { DrivingRoute } from "../DrivingRoute/DrivingRoute.js";
14
13
  import { FitViewOnce, createFittableRegisterOverlay } from "../FitView/FitView.js";
15
14
  import { StartEndPoint } from "../StartEndPoint/StartEndPoint.js";
15
+ import { TrafficDrivingLine } from "../TrafficDrivingLine/TrafficDrivingLine.js";
16
16
  const BUSINESS_QUOTING_FITVIEW_PANDING = [26, 26, 19, 26];
17
17
  const BusinessQuotingMapInner = defineSetup("BusinessQuotingMapInner", function(props, {
18
18
  emit,
@@ -83,9 +83,11 @@ const BusinessQuotingMapInner = defineSetup("BusinessQuotingMapInner", function(
83
83
  path,
84
84
  distance,
85
85
  duration,
86
- tolls
87
- }) => [createVNode(DrivingLine, {
88
- "path": path
86
+ tolls,
87
+ trafficJams
88
+ }) => [createVNode(TrafficDrivingLine, {
89
+ "path": path,
90
+ "trafficJams": trafficJams
89
91
  }, null), createVNode(StartEndPoint, {
90
92
  "type": "end",
91
93
  "registerOverlay": fittableRegistryOverlay,
@@ -14,12 +14,13 @@ import { ConditionalFittablePassengerCircle } from "../PassengerCircle/Passenger
14
14
  import { PlaceCircle } from "../PlaceCircle/PlaceCircle.js";
15
15
  import { StartEndPoint } from "../StartEndPoint/StartEndPoint.js";
16
16
  import { TaxiCar } from "../TaxiCar/TaxiCar.js";
17
+ import { TrafficDrivingLine } from "../TrafficDrivingLine/TrafficDrivingLine.js";
17
18
  import { WalkingLine } from "../WalkingLine/WalkingLine.js";
18
19
  import { WalkingRoute } from "../WalkingRoute/WalkingRoute.js";
19
20
  import { WaveCircle } from "../WaveCircle/WaveCircle.js";
20
21
  const IS_ENABLE_AUXILIARY_GRASP_ROAD = apiGetAuxiliaryGrapStatus();
21
22
  const PASSENGER_DISTANCE_MAX = 2e3;
22
- const PASSENGER_DISTANCE_MIN = 10;
23
+ const PASSENGER_DISTANCE_MIN = 20;
23
24
  const AUTO_FIT_VIEW_INTERVAL = IS_ENABLE_AUXILIARY_GRASP_ROAD ? 24 * 3600 * 1e3 : 15e3;
24
25
  const carDurationWithinMinDistance = (distance) => Math.floor(distance / 5);
25
26
  const SectionDispatching = defineSetup("SectionDispatching", function(props) {
@@ -77,9 +78,11 @@ const SectionConfirmed = defineSetup("SectionConfirmed", function(props) {
77
78
  "to": to,
78
79
  "from": from,
79
80
  "render": ({
80
- path
81
- }) => createVNode(DrivingLine, {
82
- "path": path
81
+ path,
82
+ trafficJams
83
+ }) => createVNode(TrafficDrivingLine, {
84
+ "path": path,
85
+ "trafficJams": trafficJams
83
86
  }, null)
84
87
  }, null), createVNode(ConditionalFittablePassengerCircle, {
85
88
  "position": passengerPosition,
@@ -162,11 +165,13 @@ const SectionDriverStartService = defineSetup("SectionDriverStartService", funct
162
165
  path,
163
166
  angle,
164
167
  distance,
165
- duration
168
+ duration,
169
+ trafficJams
166
170
  }) => {
167
171
  var _a;
168
- return [createVNode(DrivingLine, {
169
- "path": path
172
+ return [createVNode(TrafficDrivingLine, {
173
+ "path": path,
174
+ "trafficJams": trafficJams
170
175
  }, null), createVNode(TaxiCar, {
171
176
  "position": (_a = path[0]) != null ? _a : carPosition,
172
177
  "angle": angle != null ? angle : carAngle,
@@ -233,9 +238,11 @@ const SectionBookDispatched = defineSetup("SectionBookDispatched", function(prop
233
238
  "to": to,
234
239
  "from": from,
235
240
  "render": ({
236
- path
237
- }) => createVNode(DrivingLine, {
238
- "path": path
241
+ path,
242
+ trafficJams
243
+ }) => createVNode(TrafficDrivingLine, {
244
+ "path": path,
245
+ "trafficJams": trafficJams
239
246
  }, null)
240
247
  }, null), !!passengerPosition && passengerDistance && passengerDistance < PASSENGER_DISTANCE_MAX && passengerDistance > PASSENGER_DISTANCE_MIN && createVNode(WalkingRoute, {
241
248
  "from": passengerPosition,
@@ -370,11 +377,13 @@ const SectionInService = defineSetup("SectionInService", function(props) {
370
377
  path,
371
378
  angle,
372
379
  distance,
373
- duration
380
+ duration,
381
+ trafficJams
374
382
  }) => {
375
383
  var _a;
376
- return [createVNode(DrivingLine, {
377
- "path": path
384
+ return [createVNode(TrafficDrivingLine, {
385
+ "path": path,
386
+ "trafficJams": trafficJams
378
387
  }, null), createVNode(TaxiCar, {
379
388
  "position": (_a = path[0]) != null ? _a : carPosition,
380
389
  "angle": angle != null ? angle : carAngle,
@@ -479,7 +488,7 @@ const SectionEndService = defineSetup("SectionEndService", function(props) {
479
488
  path
480
489
  }) => createVNode(DrivingLine, {
481
490
  "path": path,
482
- "done": true
491
+ "status": "DONE"
483
492
  }, null)
484
493
  }, null), createVNode(StartEndPoint, {
485
494
  "type": "start",
@@ -1,6 +1,9 @@
1
+ import type { TrafficStatus } from "../../types/interface";
2
+ type DrivingLineStatus = TrafficStatus | "DONE";
1
3
  export interface DrivingLineProps {
2
- done?: boolean;
4
+ status?: DrivingLineStatus;
3
5
  path: [number, number][];
6
+ lineCap?: AMap.LineSharedOptions["lineCap"];
4
7
  }
5
8
  export declare const ADrivingLine: import("vue-demi").DefineComponent<import("vue-demi").ComponentObjectPropsOptions<DrivingLineProps>, 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<DrivingLineProps, Required<DrivingLineProps>>, never, import("vue-demi").PublicProps, DrivingLineProps, DrivingLineProps, import("vue-demi").SlotsType<{} & {
6
9
  default?: import("../../demi-polyfill").Slot | undefined;
@@ -11,3 +14,4 @@ export declare const GDrivingLine: import("vue-demi").DefineComponent<import("vu
11
14
  export declare const DrivingLine: import("vue-demi").DefineComponent<import("vue-demi").ComponentObjectPropsOptions<DrivingLineProps>, 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<DrivingLineProps, Required<DrivingLineProps>>, never, import("vue-demi").PublicProps, DrivingLineProps, DrivingLineProps, import("vue-demi").SlotsType<{} & {
12
15
  default?: import("../../demi-polyfill").Slot | undefined;
13
16
  }>>;
17
+ export {};
@@ -7,24 +7,55 @@ import { createElement } from "../../demi-polyfill/demi-polyfill.js";
7
7
  import { useMapSupplier } from "../../hooks/useMapSupplier.js";
8
8
  import { defineSetup } from "../../types/helper.js";
9
9
  import { vec2lnglat } from "../../utils/transform.js";
10
+ const trafficInnerColors = {
11
+ // UNKNOWN: "#487BF4",
12
+ UNKNOWN: "#00C875",
13
+ NORMAL: "#00C875",
14
+ SLOW: "#F9D100",
15
+ TRAFFIC_JAM: "#EB0E33",
16
+ HEAVY_TRAFFIC_JAM: "#99001A",
17
+ DONE: "#96B2CA"
18
+ };
19
+ const trafficOuterColors = {
20
+ // UNKNOWN: "#4175F1",
21
+ UNKNOWN: "#008559",
22
+ NORMAL: "#008559",
23
+ SLOW: "#B29400",
24
+ TRAFFIC_JAM: "#990D24",
25
+ HEAVY_TRAFFIC_JAM: "#4D000D",
26
+ DONE: "#7693AF"
27
+ };
28
+ const trafficBorderColors = {
29
+ // UNKNOWN: "#6C95F5",
30
+ UNKNOWN: "#00C875",
31
+ NORMAL: "#00C875",
32
+ SLOW: "#F9D100",
33
+ TRAFFIC_JAM: "#EB0E33",
34
+ HEAVY_TRAFFIC_JAM: "#99001A",
35
+ DONE: "#7693AF"
36
+ };
10
37
  const ADrivingLine = defineSetup("ADrivingLine", function(props) {
11
38
  return () => {
39
+ const {
40
+ status = "UNKNOWN",
41
+ lineCap = "round"
42
+ } = props;
12
43
  const vw = window.innerWidth * 0.01;
13
44
  const strokeWidth = 1 * vw;
14
45
  const borderWidth = 0.13 * vw;
15
46
  const dirWidth = 0.24 * vw;
16
47
  const outlineWidth = 0.4 * vw;
17
48
  const dashLength = 0.3 * vw;
18
- const strokeColorInner = props.done ? "#96B2CA" : "#487BF4";
19
- const strokeColorOuter = props.done ? "#7693AF" : "#4175F1";
20
- const strokeColorBorder = props.done ? "#7693AF" : "#6C95F5";
49
+ const strokeColorInner = trafficInnerColors[status];
50
+ const strokeColorOuter = trafficOuterColors[status];
51
+ const strokeColorBorder = trafficBorderColors[status];
21
52
  return createVNode("div", null, [createVNode(AmapPolyline, {
22
53
  "path": props.path,
23
54
  "strokeWeight": strokeWidth + 2 * borderWidth + 2 * outlineWidth,
24
55
  "strokeOpacity": 1,
25
56
  "strokeColor": strokeColorOuter,
26
57
  "lineJoin": "round",
27
- "lineCap": "round",
58
+ "lineCap": lineCap,
28
59
  "zIndex": ZINDEX_LINE_LAYER
29
60
  }, null), createVNode(AmapPolyline, {
30
61
  "path": props.path,
@@ -32,7 +63,7 @@ const ADrivingLine = defineSetup("ADrivingLine", function(props) {
32
63
  "strokeOpacity": 1,
33
64
  "strokeColor": strokeColorBorder,
34
65
  "lineJoin": "round",
35
- "lineCap": "round",
66
+ "lineCap": lineCap,
36
67
  "strokeStyle": "dashed",
37
68
  "strokeDasharray": [dashLength, dashLength * 0.5],
38
69
  "zIndex": ZINDEX_LINE_LAYER
@@ -42,7 +73,7 @@ const ADrivingLine = defineSetup("ADrivingLine", function(props) {
42
73
  "strokeOpacity": 1,
43
74
  "strokeColor": strokeColorInner,
44
75
  "lineJoin": "round",
45
- "lineCap": "round",
76
+ "lineCap": lineCap,
46
77
  "zIndex": ZINDEX_LINE_LAYER
47
78
  }, null), createVNode(AmapPolyline, {
48
79
  "showDir": true,
@@ -51,7 +82,7 @@ const ADrivingLine = defineSetup("ADrivingLine", function(props) {
51
82
  "strokeOpacity": 1,
52
83
  "strokeColor": "transparent",
53
84
  "lineJoin": "round",
54
- "lineCap": "round",
85
+ "lineCap": lineCap,
55
86
  "zIndex": ZINDEX_LINE_LAYER
56
87
  }, null)]);
57
88
  };
@@ -59,15 +90,18 @@ const ADrivingLine = defineSetup("ADrivingLine", function(props) {
59
90
  const GDrivingLine = defineSetup("GDrivingLine", function(props) {
60
91
  const pathRef = computed(() => props.path.map(vec2lnglat));
61
92
  return () => {
93
+ const {
94
+ status = "UNKNOWN"
95
+ } = props;
62
96
  const vw = window.innerWidth * 0.01;
63
97
  const repeat = 10 * vw;
64
98
  const strokeWidth = 1.25 * vw * 0.65;
65
99
  const borderWidth = 0.175 * vw * 0.65;
66
100
  const dirStrokeWeight = 0.375 * vw * 0.65;
67
101
  const outlineWidth = 0.45 * vw * 0.65;
68
- const strokeColorInner = props.done ? "#96B2CA" : "#487BF4";
69
- const strokeColorOuter = props.done ? "#7693AF" : "#4175F1";
70
- const strokeColorBorder = props.done ? "#7693AF" : "#6C95F5";
102
+ const strokeColorInner = trafficInnerColors[status];
103
+ const strokeColorOuter = trafficOuterColors[status];
104
+ const strokeColorBorder = trafficBorderColors[status];
71
105
  return createVNode("div", null, [createVNode(GmapPolyline, {
72
106
  "path": pathRef.value,
73
107
  "strokeWeight": strokeWidth + 2 * borderWidth + 2 * outlineWidth,
@@ -1,12 +1,13 @@
1
1
  import { type VNodeChild } from "../../demi-polyfill";
2
2
  import { type UseDrivingRouteProps } from "../../hooks/useDrivingRoute";
3
- import type { Point } from "../../types/interface";
3
+ import type { Point, TrafficJams } from "../../types/interface";
4
4
  export type DrivingRouteRenderProps = {
5
5
  path: Point[];
6
6
  angle?: number;
7
7
  distance: number;
8
8
  duration: number;
9
9
  tolls?: number;
10
+ trafficJams?: TrafficJams;
10
11
  };
11
12
  export interface DrivingRouteProps extends UseDrivingRouteProps {
12
13
  render?: (props: DrivingRouteRenderProps) => VNodeChild;
@@ -14,7 +14,8 @@ const ADrivingRoute = defineSetup("ADrivingRoute", function(props, {
14
14
  path,
15
15
  distance,
16
16
  duration,
17
- tolls
17
+ tolls,
18
+ trafficJams
18
19
  } = toRefs(useADrivingRoute(props).route);
19
20
  const {
20
21
  angleRef
@@ -29,7 +30,8 @@ const ADrivingRoute = defineSetup("ADrivingRoute", function(props, {
29
30
  angle: angleRef,
30
31
  distance,
31
32
  duration,
32
- tolls
33
+ tolls,
34
+ trafficJams
33
35
  }))]);
34
36
  };
35
37
  });
@@ -0,0 +1,8 @@
1
+ import type { Point, TrafficJams } from "../../types/interface";
2
+ export interface TrafficDrivingLineProps {
3
+ path: Point[];
4
+ trafficJams?: TrafficJams;
5
+ }
6
+ export declare const TrafficDrivingLine: import("vue").DefineComponent<import("vue").ComponentObjectPropsOptions<TrafficDrivingLineProps>, 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<TrafficDrivingLineProps, Required<TrafficDrivingLineProps>>, never, import("vue").PublicProps, TrafficDrivingLineProps, TrafficDrivingLineProps, import("vue").SlotsType<{} & {
7
+ default?: import("../../demi-polyfill").Slot | undefined;
8
+ }>>;
@@ -0,0 +1,115 @@
1
+ import { createVNode } from "vue";
2
+ import { defineSetup } from "../../types/helper.js";
3
+ import { stringifyPoint, isPointExactEqual } from "../../utils/transform.js";
4
+ import { DrivingLine } from "../DrivingLine/DrivingLine.js";
5
+ const toHalfPath = (path, isFromStart = true) => {
6
+ if (path.length < 2)
7
+ return path;
8
+ const [[x0, y0], [x1, y1]] = path;
9
+ const mid = [(x0 + x1) / 2, (y0 + y1) / 2];
10
+ return isFromStart ? [[x0, y0], mid] : [mid, [x1, y1]];
11
+ };
12
+ const isSlowOrJam = (status) => {
13
+ return status === "SLOW" || status === "TRAFFIC_JAM" || status === "HEAVY_TRAFFIC_JAM";
14
+ };
15
+ const justifyFirstPointStatus = (firstPointStatus, secondPointBeforeStatus) => {
16
+ return (firstPointStatus === void 0 || firstPointStatus === "UNKNOWN") && !!secondPointBeforeStatus && secondPointBeforeStatus !== "UNKNOWN" ? secondPointBeforeStatus : firstPointStatus != null ? firstPointStatus : "UNKNOWN";
17
+ };
18
+ const createMulitpleLineByTrafficJams = (path, trafficJams) => {
19
+ var _a, _b, _c, _d;
20
+ if (!trafficJams)
21
+ return [{
22
+ path,
23
+ status: "UNKNOWN"
24
+ }];
25
+ const firstPoint = path[0];
26
+ if (!firstPoint)
27
+ return [];
28
+ const multipleLines = [];
29
+ let line = {
30
+ path: [firstPoint],
31
+ status: justifyFirstPointStatus((_a = trafficJams[stringifyPoint(firstPoint)]) == null ? void 0 : _a.after, (_b = trafficJams[stringifyPoint(path[1])]) == null ? void 0 : _b.before)
32
+ };
33
+ for (let idx = 1; idx < path.length; idx++) {
34
+ const point = path[idx];
35
+ const traffic = (_d = (_c = trafficJams[stringifyPoint(point)]) == null ? void 0 : _c.after) != null ? _d : "UNKNOWN";
36
+ if (!isPointExactEqual(point, path[idx - 1]))
37
+ line.path.push(point);
38
+ if (traffic === line.status)
39
+ continue;
40
+ multipleLines.push(line);
41
+ line = {
42
+ path: [point],
43
+ status: traffic
44
+ };
45
+ }
46
+ multipleLines.push(line);
47
+ return multipleLines;
48
+ };
49
+ const beautifyMultipleLines = (lines) => {
50
+ const max = lines.length - 1;
51
+ if (max === 0)
52
+ return [{
53
+ ...lines[0],
54
+ lineCap: "round"
55
+ }];
56
+ const totalPath = lines.flatMap((line) => line.path);
57
+ const totalLine = {
58
+ path: totalPath,
59
+ status: "NORMAL",
60
+ lineCap: "round"
61
+ };
62
+ const roundCoveredLines = [];
63
+ const buttCoveredLines = [];
64
+ for (const line of lines) {
65
+ const {
66
+ path,
67
+ status
68
+ } = line;
69
+ if (!isSlowOrJam(status))
70
+ continue;
71
+ buttCoveredLines.push({
72
+ status,
73
+ path,
74
+ lineCap: "butt"
75
+ });
76
+ }
77
+ const first = lines[0];
78
+ const last = lines[lines.length - 1];
79
+ const ignoredLine = {
80
+ status: first.status,
81
+ path: first.path.slice(0, 2),
82
+ lineCap: "butt"
83
+ };
84
+ if (isSlowOrJam(first.status))
85
+ roundCoveredLines.push({
86
+ status: first.status,
87
+ path: toHalfPath(first.path.slice(0, 2)),
88
+ lineCap: "round"
89
+ });
90
+ if (isSlowOrJam(last.status))
91
+ roundCoveredLines.push({
92
+ status: last.status,
93
+ path: toHalfPath(last.path.slice(-2), false),
94
+ lineCap: "round"
95
+ });
96
+ return [ignoredLine, totalLine, ...roundCoveredLines, ...buttCoveredLines];
97
+ };
98
+ const TrafficDrivingLine = defineSetup("TrafficDrivingLine", function(props) {
99
+ return () => {
100
+ const {
101
+ path,
102
+ trafficJams
103
+ } = props;
104
+ const multipleLines = createMulitpleLineByTrafficJams(path, trafficJams);
105
+ const beautifiedLines = beautifyMultipleLines(multipleLines);
106
+ return createVNode("div", null, [beautifiedLines.map((line) => createVNode(DrivingLine, {
107
+ "path": line.path,
108
+ "status": line.status,
109
+ "lineCap": line.lineCap
110
+ }, null))]);
111
+ };
112
+ });
113
+ export {
114
+ TrafficDrivingLine
115
+ };
@@ -0,0 +1 @@
1
+ export * from "./TrafficDrivingLine";
@@ -0,0 +1,4 @@
1
+ import { TrafficDrivingLine } from "./TrafficDrivingLine.js";
2
+ export {
3
+ TrafficDrivingLine
4
+ };