@heycar/heycars-map 0.5.5 → 0.5.7

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.
@@ -7,10 +7,20 @@ export declare const useADrivingRoute: (props: UseDrivingRouteProps) => {
7
7
  path: [number, number][];
8
8
  distance: number;
9
9
  duration: number;
10
+ steps: {
11
+ path: [number, number][];
12
+ duration: number;
13
+ distance: number;
14
+ }[];
10
15
  };
11
16
  export declare const useGDrivingRoute: (props: UseDrivingRouteProps) => {
12
17
  path: [number, number][];
13
18
  distance: number;
14
19
  duration: number;
20
+ steps: {
21
+ path: [number, number][];
22
+ duration: number;
23
+ distance: number;
24
+ }[];
15
25
  };
16
26
  export declare const useDrivingRoute: (props: UseDrivingRouteProps) => Route;
@@ -0,0 +1,17 @@
1
+ import type { Point, Route } from "../types/interface";
2
+ interface UseDrivingTrackCorrectionProps {
3
+ track: Point[];
4
+ route: Route;
5
+ onDeviation: (point: Point) => any;
6
+ }
7
+ export declare const useDrivingTrackCorrection: (props: UseDrivingTrackCorrectionProps) => {
8
+ path: [number, number][];
9
+ distance: number;
10
+ duration: number;
11
+ steps: {
12
+ path: [number, number][];
13
+ duration: number;
14
+ distance: number;
15
+ }[];
16
+ };
17
+ export {};
@@ -1,10 +1,13 @@
1
1
  import type { Point } from "../types/interface";
2
2
  export declare const useAmapGeometry: () => {
3
3
  apiMapDistance: (from: Point, to: Point) => number | undefined;
4
+ apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
4
5
  };
5
6
  export declare const useGmapGeometry: () => {
6
7
  apiMapDistance: (from: Point, to: Point) => number | undefined;
8
+ apiMapDistanceToLine: (from: Point, line: Point[]) => 0 | undefined;
7
9
  };
8
10
  export declare const useMapGeometry: () => {
9
11
  apiMapDistance: (from: Point, to: Point) => number | undefined;
12
+ apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
10
13
  };
package/dist/index.cjs CHANGED
@@ -2324,7 +2324,7 @@ const DrivingLine = defineSetup(function DrivingLine2(props) {
2324
2324
  };
2325
2325
  });
2326
2326
  const useADrivingRoute = (props) => {
2327
- const outputRoute = Vue.reactive({ path: [], distance: 0, duration: 0 });
2327
+ const outputRoute = Vue.reactive({ path: [], distance: 0, duration: 0, steps: [] });
2328
2328
  const amapDriving = new AMap.Driving({});
2329
2329
  watchPostEffectForDeepOption(
2330
2330
  () => {
@@ -2341,21 +2341,29 @@ const useADrivingRoute = (props) => {
2341
2341
  case "complete": {
2342
2342
  let path = [];
2343
2343
  const drivingResult = result;
2344
+ const routeSteps = [];
2344
2345
  const firstRoute = drivingResult.routes[0];
2345
2346
  for (const step of firstRoute.steps) {
2346
2347
  const basicStep = step;
2347
2348
  const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
2348
2349
  path = path.concat(stepPath);
2350
+ routeSteps.push({
2351
+ path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
2352
+ duration: basicStep.time,
2353
+ distance: basicStep.distance
2354
+ });
2349
2355
  }
2350
2356
  outputRoute.path = path;
2351
2357
  outputRoute.distance = firstRoute.distance;
2352
2358
  outputRoute.duration = firstRoute.time;
2359
+ outputRoute.steps = routeSteps;
2353
2360
  return;
2354
2361
  }
2355
2362
  case "no_data":
2356
2363
  outputRoute.path = [];
2357
2364
  outputRoute.distance = 0;
2358
2365
  outputRoute.duration = 0;
2366
+ outputRoute.steps = [];
2359
2367
  return;
2360
2368
  default:
2361
2369
  throw result;
@@ -2367,7 +2375,7 @@ const useADrivingRoute = (props) => {
2367
2375
  return outputRoute;
2368
2376
  };
2369
2377
  const useGDrivingRoute = (props) => {
2370
- const outputRoute = Vue.reactive({ path: [], distance: 0, duration: 0 });
2378
+ const outputRoute = Vue.reactive({ path: [], distance: 0, duration: 0, steps: [] });
2371
2379
  const gmapDirectionsService = new google.maps.DirectionsService();
2372
2380
  watchPostEffectForDeepOption(
2373
2381
  () => ({ ...props }),
@@ -2379,25 +2387,31 @@ const useGDrivingRoute = (props) => {
2379
2387
  travelMode: google.maps.TravelMode.DRIVING
2380
2388
  },
2381
2389
  (result, status) => {
2382
- var _a, _b, _c, _d;
2390
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2383
2391
  switch (status) {
2384
2392
  case google.maps.DirectionsStatus.OK: {
2385
2393
  let path = [];
2386
2394
  let distance = 0;
2387
2395
  let duration = 0;
2396
+ const routeSteps = [];
2388
2397
  const firstRoute = result.routes[0];
2389
- const stepPath = firstRoute.overview_path.map((item) => [
2390
- item.lng(),
2391
- item.lat()
2392
- ]);
2393
- path = path.concat(stepPath);
2394
2398
  for (const leg of firstRoute.legs) {
2395
2399
  distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
2396
2400
  duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
2401
+ for (const step of leg.steps) {
2402
+ const stepPath = step.path.map(({ lng, lat }) => [lng(), lat()]);
2403
+ path = path.concat(stepPath);
2404
+ routeSteps.push({
2405
+ path: stepPath,
2406
+ distance: (_f = (_e = step.distance) == null ? void 0 : _e.value) != null ? _f : 0,
2407
+ duration: (_h = (_g = step.duration) == null ? void 0 : _g.value) != null ? _h : 0
2408
+ });
2409
+ }
2397
2410
  }
2398
2411
  outputRoute.path = path;
2399
2412
  outputRoute.distance = distance;
2400
2413
  outputRoute.duration = duration;
2414
+ outputRoute.steps = routeSteps;
2401
2415
  return;
2402
2416
  }
2403
2417
  case google.maps.DirectionsStatus.ZERO_RESULTS:
@@ -2405,6 +2419,7 @@ const useGDrivingRoute = (props) => {
2405
2419
  outputRoute.path = [];
2406
2420
  outputRoute.distance = 0;
2407
2421
  outputRoute.duration = 0;
2422
+ outputRoute.steps = [];
2408
2423
  return;
2409
2424
  default:
2410
2425
  throw new Error(status);
@@ -2549,11 +2564,20 @@ const useAmapFitView = (props) => {
2549
2564
  },
2550
2565
  setFitView
2551
2566
  };
2552
- const handleMoveEndOrZomEnd = () => {
2567
+ const handleDraggingOrZoomChange = () => {
2568
+ if (!autoFitTimeout || !timer)
2569
+ return;
2570
+ clearTimeout(timer);
2571
+ timer = void 0;
2572
+ };
2573
+ const handleMoveEndOrZomEnd = (eventName) => {
2574
+ spaceLog("useAmapFitViewHandleMoveEndOrZomEnd", "eventName = ", eventName);
2553
2575
  if (!autoFitTimeout)
2554
2576
  return;
2555
- if (timer)
2577
+ if (timer) {
2556
2578
  clearTimeout(timer);
2579
+ timer = void 0;
2580
+ }
2557
2581
  timer = setTimeout(() => {
2558
2582
  timer = void 0;
2559
2583
  setFitView();
@@ -2563,7 +2587,13 @@ const useAmapFitView = (props) => {
2563
2587
  mapRef,
2564
2588
  {},
2565
2589
  handleMoveEndOrZomEnd,
2566
- ["onDragEnd"]
2590
+ ["onDragEnd", "onZoomEnd"]
2591
+ );
2592
+ watchPostEffectForAMapEvent(
2593
+ mapRef,
2594
+ {},
2595
+ handleDraggingOrZoomChange,
2596
+ ["onDragging", "onZoomchange"]
2567
2597
  );
2568
2598
  return { registerFitVeiw, setFitView };
2569
2599
  };
@@ -2608,6 +2638,12 @@ const useGmapFitView = (props) => {
2608
2638
  },
2609
2639
  setFitView
2610
2640
  };
2641
+ const handleDrag = () => {
2642
+ if (!autoFitTimeout || !timer)
2643
+ return;
2644
+ clearTimeout(timer);
2645
+ timer = void 0;
2646
+ };
2611
2647
  const handleMoveEnd = () => {
2612
2648
  const eventSource = getMapEvnetSource();
2613
2649
  if (!autoFitTimeout || eventSource !== "user")
@@ -2626,6 +2662,9 @@ const useGmapFitView = (props) => {
2626
2662
  watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
2627
2663
  "onZoom_changed"
2628
2664
  ]);
2665
+ watchPostEffectForGMapEvent(mapRef, {}, handleDrag, [
2666
+ "onDrag"
2667
+ ]);
2629
2668
  return { registerFitVeiw, setFitView };
2630
2669
  };
2631
2670
  const useMapFitView = (props) => {
@@ -3232,7 +3271,6 @@ const useAmapPlace = (props) => {
3232
3271
  const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
3233
3272
  const cityParentName = addressComponent.province;
3234
3273
  const name = formattedAddress ? formattedAddress : emptyPlaceName;
3235
- console.log("geocoder.getAddress status, name, lng, lat = ", status, name, lng, lat);
3236
3274
  place.name = name;
3237
3275
  place.lng = lng;
3238
3276
  place.lat = lat;
@@ -3244,8 +3282,8 @@ const useAmapPlace = (props) => {
3244
3282
  place.name = emptyPlaceName;
3245
3283
  place.lng = lng;
3246
3284
  place.lat = lat;
3247
- console.log("geocoder.getAddress status, name, lng, lat = ", status, "", lng, lat);
3248
3285
  onChange == null ? void 0 : onChange({ lng, lat, name: "" });
3286
+ onChangeCity == null ? void 0 : onChangeCity({ cityName: "", cityParentName: "", countryName: "" });
3249
3287
  return;
3250
3288
  case "error":
3251
3289
  throw result;
@@ -4088,7 +4126,12 @@ const useAmapGeometry = () => {
4088
4126
  return void 0;
4089
4127
  return AMap.GeometryUtil.distance(from, to);
4090
4128
  };
4091
- return { apiMapDistance };
4129
+ const apiMapDistanceToLine = (from, line) => {
4130
+ if (payload.status !== Status.SUCCESS)
4131
+ return void 0;
4132
+ return AMap.GeometryUtil.distanceToLine(from, line);
4133
+ };
4134
+ return { apiMapDistance, apiMapDistanceToLine };
4092
4135
  };
4093
4136
  const useGmapGeometry = () => {
4094
4137
  const payload = useMapSupplier();
@@ -4097,7 +4140,12 @@ const useGmapGeometry = () => {
4097
4140
  return void 0;
4098
4141
  return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
4099
4142
  };
4100
- return { apiMapDistance };
4143
+ const apiMapDistanceToLine = (from, line) => {
4144
+ if (payload.status !== Status.SUCCESS)
4145
+ return void 0;
4146
+ return 0;
4147
+ };
4148
+ return { apiMapDistance, apiMapDistanceToLine };
4101
4149
  };
4102
4150
  const useMapGeometry = () => {
4103
4151
  const { supplier } = useMapSupplier();
package/dist/index.js CHANGED
@@ -2322,7 +2322,7 @@ const DrivingLine = defineSetup(function DrivingLine2(props) {
2322
2322
  };
2323
2323
  });
2324
2324
  const useADrivingRoute = (props) => {
2325
- const outputRoute = reactive({ path: [], distance: 0, duration: 0 });
2325
+ const outputRoute = reactive({ path: [], distance: 0, duration: 0, steps: [] });
2326
2326
  const amapDriving = new AMap.Driving({});
2327
2327
  watchPostEffectForDeepOption(
2328
2328
  () => {
@@ -2339,21 +2339,29 @@ const useADrivingRoute = (props) => {
2339
2339
  case "complete": {
2340
2340
  let path = [];
2341
2341
  const drivingResult = result;
2342
+ const routeSteps = [];
2342
2343
  const firstRoute = drivingResult.routes[0];
2343
2344
  for (const step of firstRoute.steps) {
2344
2345
  const basicStep = step;
2345
2346
  const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
2346
2347
  path = path.concat(stepPath);
2348
+ routeSteps.push({
2349
+ path: basicStep.path.map(({ lng, lat }) => [lng, lat]),
2350
+ duration: basicStep.time,
2351
+ distance: basicStep.distance
2352
+ });
2347
2353
  }
2348
2354
  outputRoute.path = path;
2349
2355
  outputRoute.distance = firstRoute.distance;
2350
2356
  outputRoute.duration = firstRoute.time;
2357
+ outputRoute.steps = routeSteps;
2351
2358
  return;
2352
2359
  }
2353
2360
  case "no_data":
2354
2361
  outputRoute.path = [];
2355
2362
  outputRoute.distance = 0;
2356
2363
  outputRoute.duration = 0;
2364
+ outputRoute.steps = [];
2357
2365
  return;
2358
2366
  default:
2359
2367
  throw result;
@@ -2365,7 +2373,7 @@ const useADrivingRoute = (props) => {
2365
2373
  return outputRoute;
2366
2374
  };
2367
2375
  const useGDrivingRoute = (props) => {
2368
- const outputRoute = reactive({ path: [], distance: 0, duration: 0 });
2376
+ const outputRoute = reactive({ path: [], distance: 0, duration: 0, steps: [] });
2369
2377
  const gmapDirectionsService = new google.maps.DirectionsService();
2370
2378
  watchPostEffectForDeepOption(
2371
2379
  () => ({ ...props }),
@@ -2377,25 +2385,31 @@ const useGDrivingRoute = (props) => {
2377
2385
  travelMode: google.maps.TravelMode.DRIVING
2378
2386
  },
2379
2387
  (result, status) => {
2380
- var _a, _b, _c, _d;
2388
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2381
2389
  switch (status) {
2382
2390
  case google.maps.DirectionsStatus.OK: {
2383
2391
  let path = [];
2384
2392
  let distance = 0;
2385
2393
  let duration = 0;
2394
+ const routeSteps = [];
2386
2395
  const firstRoute = result.routes[0];
2387
- const stepPath = firstRoute.overview_path.map((item) => [
2388
- item.lng(),
2389
- item.lat()
2390
- ]);
2391
- path = path.concat(stepPath);
2392
2396
  for (const leg of firstRoute.legs) {
2393
2397
  distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
2394
2398
  duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
2399
+ for (const step of leg.steps) {
2400
+ const stepPath = step.path.map(({ lng, lat }) => [lng(), lat()]);
2401
+ path = path.concat(stepPath);
2402
+ routeSteps.push({
2403
+ path: stepPath,
2404
+ distance: (_f = (_e = step.distance) == null ? void 0 : _e.value) != null ? _f : 0,
2405
+ duration: (_h = (_g = step.duration) == null ? void 0 : _g.value) != null ? _h : 0
2406
+ });
2407
+ }
2395
2408
  }
2396
2409
  outputRoute.path = path;
2397
2410
  outputRoute.distance = distance;
2398
2411
  outputRoute.duration = duration;
2412
+ outputRoute.steps = routeSteps;
2399
2413
  return;
2400
2414
  }
2401
2415
  case google.maps.DirectionsStatus.ZERO_RESULTS:
@@ -2403,6 +2417,7 @@ const useGDrivingRoute = (props) => {
2403
2417
  outputRoute.path = [];
2404
2418
  outputRoute.distance = 0;
2405
2419
  outputRoute.duration = 0;
2420
+ outputRoute.steps = [];
2406
2421
  return;
2407
2422
  default:
2408
2423
  throw new Error(status);
@@ -2547,11 +2562,20 @@ const useAmapFitView = (props) => {
2547
2562
  },
2548
2563
  setFitView
2549
2564
  };
2550
- const handleMoveEndOrZomEnd = () => {
2565
+ const handleDraggingOrZoomChange = () => {
2566
+ if (!autoFitTimeout || !timer)
2567
+ return;
2568
+ clearTimeout(timer);
2569
+ timer = void 0;
2570
+ };
2571
+ const handleMoveEndOrZomEnd = (eventName) => {
2572
+ spaceLog("useAmapFitViewHandleMoveEndOrZomEnd", "eventName = ", eventName);
2551
2573
  if (!autoFitTimeout)
2552
2574
  return;
2553
- if (timer)
2575
+ if (timer) {
2554
2576
  clearTimeout(timer);
2577
+ timer = void 0;
2578
+ }
2555
2579
  timer = setTimeout(() => {
2556
2580
  timer = void 0;
2557
2581
  setFitView();
@@ -2561,7 +2585,13 @@ const useAmapFitView = (props) => {
2561
2585
  mapRef,
2562
2586
  {},
2563
2587
  handleMoveEndOrZomEnd,
2564
- ["onDragEnd"]
2588
+ ["onDragEnd", "onZoomEnd"]
2589
+ );
2590
+ watchPostEffectForAMapEvent(
2591
+ mapRef,
2592
+ {},
2593
+ handleDraggingOrZoomChange,
2594
+ ["onDragging", "onZoomchange"]
2565
2595
  );
2566
2596
  return { registerFitVeiw, setFitView };
2567
2597
  };
@@ -2606,6 +2636,12 @@ const useGmapFitView = (props) => {
2606
2636
  },
2607
2637
  setFitView
2608
2638
  };
2639
+ const handleDrag = () => {
2640
+ if (!autoFitTimeout || !timer)
2641
+ return;
2642
+ clearTimeout(timer);
2643
+ timer = void 0;
2644
+ };
2609
2645
  const handleMoveEnd = () => {
2610
2646
  const eventSource = getMapEvnetSource();
2611
2647
  if (!autoFitTimeout || eventSource !== "user")
@@ -2624,6 +2660,9 @@ const useGmapFitView = (props) => {
2624
2660
  watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
2625
2661
  "onZoom_changed"
2626
2662
  ]);
2663
+ watchPostEffectForGMapEvent(mapRef, {}, handleDrag, [
2664
+ "onDrag"
2665
+ ]);
2627
2666
  return { registerFitVeiw, setFitView };
2628
2667
  };
2629
2668
  const useMapFitView = (props) => {
@@ -3230,7 +3269,6 @@ const useAmapPlace = (props) => {
3230
3269
  const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
3231
3270
  const cityParentName = addressComponent.province;
3232
3271
  const name = formattedAddress ? formattedAddress : emptyPlaceName;
3233
- console.log("geocoder.getAddress status, name, lng, lat = ", status, name, lng, lat);
3234
3272
  place.name = name;
3235
3273
  place.lng = lng;
3236
3274
  place.lat = lat;
@@ -3242,8 +3280,8 @@ const useAmapPlace = (props) => {
3242
3280
  place.name = emptyPlaceName;
3243
3281
  place.lng = lng;
3244
3282
  place.lat = lat;
3245
- console.log("geocoder.getAddress status, name, lng, lat = ", status, "", lng, lat);
3246
3283
  onChange == null ? void 0 : onChange({ lng, lat, name: "" });
3284
+ onChangeCity == null ? void 0 : onChangeCity({ cityName: "", cityParentName: "", countryName: "" });
3247
3285
  return;
3248
3286
  case "error":
3249
3287
  throw result;
@@ -4086,7 +4124,12 @@ const useAmapGeometry = () => {
4086
4124
  return void 0;
4087
4125
  return AMap.GeometryUtil.distance(from, to);
4088
4126
  };
4089
- return { apiMapDistance };
4127
+ const apiMapDistanceToLine = (from, line) => {
4128
+ if (payload.status !== Status.SUCCESS)
4129
+ return void 0;
4130
+ return AMap.GeometryUtil.distanceToLine(from, line);
4131
+ };
4132
+ return { apiMapDistance, apiMapDistanceToLine };
4090
4133
  };
4091
4134
  const useGmapGeometry = () => {
4092
4135
  const payload = useMapSupplier();
@@ -4095,7 +4138,12 @@ const useGmapGeometry = () => {
4095
4138
  return void 0;
4096
4139
  return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
4097
4140
  };
4098
- return { apiMapDistance };
4141
+ const apiMapDistanceToLine = (from, line) => {
4142
+ if (payload.status !== Status.SUCCESS)
4143
+ return void 0;
4144
+ return 0;
4145
+ };
4146
+ return { apiMapDistance, apiMapDistanceToLine };
4099
4147
  };
4100
4148
  const useMapGeometry = () => {
4101
4149
  const { supplier } = useMapSupplier();
@@ -29,9 +29,15 @@ export interface RegisterOverlay<T> {
29
29
  remove: (overlay: T) => void;
30
30
  setFitView: () => void;
31
31
  }
32
+ export interface RouteStep {
33
+ path: Point[];
34
+ duration: number;
35
+ distance: number;
36
+ }
32
37
  export interface Route {
33
38
  path: Point[];
34
39
  distance: number;
35
40
  duration: number;
41
+ steps: RouteStep[];
36
42
  }
37
43
  export type DriverStatus = "dispatching" | "book-dispatching" | "dispatched" | "driverStartService" | "book-driverStartService" | "book-dispatched" | "driverArrived" | "inService" | "canceled" | "endService" | "completed" | "canceling" | "banlanceRefund" | "waitBanlanceRefund" | "rechargePayed" | "waitRechargePay" | "payed" | "waitpay" | "refund" | "confirmed" | "assign";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
package/todo.md CHANGED
@@ -97,3 +97,7 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
97
97
 
98
98
  - 4977
99
99
  - 5381
100
+
101
+ 0.5.6
102
+
103
+ - 5455