@heycar/heycars-map 0.2.6 → 0.2.8

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 (36) hide show
  1. package/dist/business-components/AbsoluteAddressBox/AbsoluteAddressBox.d.ts +2 -0
  2. package/dist/business-components/AbsoluteAddressBox/index.d.ts +1 -0
  3. package/dist/business-components/AddressBox/AddressBox.d.ts +1 -2
  4. package/dist/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +2 -3
  5. package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +24 -0
  6. package/dist/business-components/BusinessRecomendPlaceMap/index.d.ts +1 -0
  7. package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +2 -3
  8. package/dist/business-components/FitView/FitView.d.ts +3 -1
  9. package/dist/hooks/useGeoLocation.d.ts +1 -0
  10. package/dist/hooks-business/useBusinessRecomendPlaceMap.d.ts +27 -0
  11. package/dist/hooks-business/{useBusinessMapRecomendPlace.d.ts → useLagecyMapRecomendPlace.d.ts} +2 -2
  12. package/dist/index.cjs +50 -50
  13. package/dist/index.d.ts +4 -1
  14. package/dist/index.js +1564 -1403
  15. package/dist/style.css +1 -1
  16. package/dist/types/interface.d.ts +2 -1
  17. package/package.json +1 -1
  18. package/src/App.tsx +3 -3
  19. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +8 -0
  20. package/src/business-components/AbsoluteAddressBox/index.ts +1 -0
  21. package/src/business-components/AddressBox/AddressBox.tsx +1 -1
  22. package/src/business-components/BusinessQuotingMap/BusinessQuotingMap.tsx +4 -4
  23. package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +157 -0
  24. package/src/business-components/BusinessRecomendPlaceMap/index.ts +1 -0
  25. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +115 -101
  26. package/src/business-components/FitView/FitView.tsx +10 -2
  27. package/src/business-components/PlaceCircle/PlaceCircle.tsx +15 -19
  28. package/src/components/Demo/DemoBusinessQuoting.tsx +1 -2
  29. package/src/components/Demo/DemoBusinessTaxiService.tsx +0 -1
  30. package/src/components/Demo/HeycarDemo.tsx +21 -98
  31. package/src/hooks/useGeoLocation.ts +3 -1
  32. package/src/hooks/useMapFitView.ts +18 -16
  33. package/src/hooks-business/useBusinessRecomendPlaceMap.ts +45 -0
  34. package/src/hooks-business/{useBusinessMapRecomendPlace.ts → useLagecyMapRecomendPlace.ts} +3 -2
  35. package/src/index.ts +4 -1
  36. package/src/types/interface.ts +12 -1
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .rgf09w0{width:7.1045vw;height:10.93vw;display:flex}._15rq2xn0{display:flex;flex-direction:column;align-items:center;margin-bottom:-1.6vw}._15rq2xn1{padding:2.13vw 4.5vw 2.67vw 4.27vw;display:flex;align-items:center;background:linear-gradient(90deg,#79AFFF 0%,#5C8DFF 32%,#507FFF 75%,#4471FF 100%);border-radius:3.2vw}._15rq2xn2{font-size:3.47vw;font-family:PingFangSC-Semibold,PingFang SC;font-weight:600;color:#fff;line-height:4.8vw;white-space:nowrap}._15rq2xn3{font-size:2.93vw;font-family:PingFangSC-Regular,PingFang SC;font-weight:400;color:#eafaf8;line-height:4.27vw;white-space:nowrap;opacity:.8}._15rq2xn4{margin-left:3.2vw;width:1.44vw;height:2.4vw}._15rq2xn5{width:.8vw;height:4vw;background:#4C80FF;border-radius:0vw 0vw 26.67vw 26.67vw;z-index:1}._15rq2xn6{margin-top:-1.5vw;width:3.2vw;height:3.2vw}._1l6offo0{display:flex}._1l6offo1{width:4.53vw;height:4.53vw;margin-bottom:-2.265vw}._1l6offo2{width:16.27vw;height:16.27vw;margin-bottom:-8.135vw}.fhyw80{display:flex;align-items:center}.fhyw81{flex-direction:row-reverse}.fhyw83{margin-right:-2.265vw}.fhyw84{margin-left:-2.265vw}.fhyw85{margin-bottom:-2.265vw}.fhyw86{margin-right:calc(50% - 2.265vw)}.fhyw87{margin-left:calc(50% - 2.265vw)}.fhyw88{display:flex;width:4.53vw;height:4.53vw}.fhyw89{opacity:0}.fhyw8b{font-size:3.47vw;font-family:PingFangSC-Semibold,PingFang SC;font-weight:600;color:#243e66;line-height:4.53vw;white-space:nowrap}._4a4ovk0{margin-bottom:-.4vw;display:flex;flex-direction:column;align-items:center}._4a4ovk1{padding:1.07vw 2.4vw 1.6vw 2.67vw;background:#FFFFFF;box-shadow:0 .53vw 2.4vw #3f3f3f33;border-radius:2.13vw}._4a4ovk2{padding:2.67vw 2.67vw 2.4vw 3.2vw;background:#FFFFFF;box-shadow:0 0 2.67vw #4e556c26;border-radius:4.8vw;font-size:3.2vw;font-family:PingFangSC-Medium,PingFang SC;font-weight:500;color:#1e1e1e;line-height:4.53vw;white-space:nowrap}._4a4ovk3{font-size:3.2vw;font-family:PingFangSC-Medium,PingFang SC;font-weight:500;color:#1e1e1e;line-height:4.53vw;white-space:nowrap}._4a4ovk4{font-size:2.4vw;font-family:PingFangSC-Regular,PingFang SC;font-weight:400;color:#7e7e7e;line-height:3.47vw;white-space:nowrap}._4a4ovk5{color:#4471ff;font-family:PingFangSC-Medium,PingFang SC;font-weight:500}._4a4ovk6{margin-top:1.33vw;width:6.192vw;height:7.998vw}._4a4ovk7{margin-top:2.4vw;width:6.192vw;height:7.998vw}._65j3sr1{margin-top:1.87vw;margin-bottom:-5.5vw;width:6vw;height:11vw}@keyframes rrvp0y0{0%{transform:scale(0);opacity:1}33.33%{transform:scale(.5);opacity:1}66.66%{transform:scale(1);opacity:0}to{transform:scale(1);opacity:0}}@keyframes rrvp0y1{0%{transform:scale(0);opacity:0}33.33%{transform:scale(0);opacity:1}66.66%{transform:scale(.5);opacity:1}to{transform:scale(1);opacity:0}}.rrvp0y2{display:flex;margin-bottom:-30.935vw;width:61.87vw;height:61.87vw;animation-name:rrvp0y0;animation-duration:3s;animation-iteration-count:infinite;animation-timing-function:linear}.rrvp0y3{animation-name:rrvp0y1}
1
+ .rgf09w0{width:7.1045vw;height:10.93vw;display:flex}._15rq2xn0{display:flex;flex-direction:column;align-items:center;margin-bottom:-1.6vw}._15rq2xn1{padding:2.13vw 4.5vw 2.67vw 4.27vw;display:flex;align-items:center;background:linear-gradient(90deg,#79AFFF 0%,#5C8DFF 32%,#507FFF 75%,#4471FF 100%);border-radius:3.2vw}._15rq2xn2{font-size:3.47vw;font-family:PingFangSC-Semibold,PingFang SC;font-weight:600;color:#fff;line-height:4.8vw;white-space:nowrap}._15rq2xn3{font-size:2.93vw;font-family:PingFangSC-Regular,PingFang SC;font-weight:400;color:#eafaf8;line-height:4.27vw;white-space:nowrap;opacity:.8}._15rq2xn4{margin-left:3.2vw;width:1.44vw;height:2.4vw}._15rq2xn5{width:.8vw;height:4vw;background:#4C80FF;border-radius:0vw 0vw 26.67vw 26.67vw;z-index:1}._15rq2xn6{margin-top:-1.5vw;width:3.2vw;height:3.2vw}._4a4ovk0{margin-bottom:-.4vw;display:flex;flex-direction:column;align-items:center}._4a4ovk1{padding:1.07vw 2.4vw 1.6vw 2.67vw;background:#FFFFFF;box-shadow:0 .53vw 2.4vw #3f3f3f33;border-radius:2.13vw}._4a4ovk2{padding:2.67vw 2.67vw 2.4vw 3.2vw;background:#FFFFFF;box-shadow:0 0 2.67vw #4e556c26;border-radius:4.8vw;font-size:3.2vw;font-family:PingFangSC-Medium,PingFang SC;font-weight:500;color:#1e1e1e;line-height:4.53vw;white-space:nowrap}._4a4ovk3{font-size:3.2vw;font-family:PingFangSC-Medium,PingFang SC;font-weight:500;color:#1e1e1e;line-height:4.53vw;white-space:nowrap}._4a4ovk4{font-size:2.4vw;font-family:PingFangSC-Regular,PingFang SC;font-weight:400;color:#7e7e7e;line-height:3.47vw;white-space:nowrap}._4a4ovk5{color:#4471ff;font-family:PingFangSC-Medium,PingFang SC;font-weight:500}._4a4ovk6{margin-top:1.33vw;width:6.192vw;height:7.998vw}._4a4ovk7{margin-top:2.4vw;width:6.192vw;height:7.998vw}._1l6offo0{display:flex}._1l6offo1{width:4.53vw;height:4.53vw;margin-bottom:-2.265vw}._1l6offo2{width:16.27vw;height:16.27vw;margin-bottom:-8.135vw}.fhyw80{display:flex;align-items:center}.fhyw81{flex-direction:row-reverse}.fhyw83{margin-right:-2.265vw}.fhyw84{margin-left:-2.265vw}.fhyw85{margin-bottom:-2.265vw}.fhyw86{margin-right:calc(50% - 2.265vw)}.fhyw87{margin-left:calc(50% - 2.265vw)}.fhyw88{display:flex;width:4.53vw;height:4.53vw}.fhyw89{opacity:0}.fhyw8b{font-size:3.47vw;font-family:PingFangSC-Semibold,PingFang SC;font-weight:600;color:#243e66;line-height:4.53vw;white-space:nowrap}._65j3sr1{margin-top:1.87vw;margin-bottom:-5.5vw;width:6vw;height:11vw}@keyframes rrvp0y0{0%{transform:scale(0);opacity:1}33.33%{transform:scale(.5);opacity:1}66.66%{transform:scale(1);opacity:0}to{transform:scale(1);opacity:0}}@keyframes rrvp0y1{0%{transform:scale(0);opacity:0}33.33%{transform:scale(0);opacity:1}66.66%{transform:scale(.5);opacity:1}to{transform:scale(1);opacity:0}}.rrvp0y2{display:flex;margin-bottom:-30.935vw;width:61.87vw;height:61.87vw;animation-name:rrvp0y0;animation-duration:3s;animation-iteration-count:infinite;animation-timing-function:linear}.rrvp0y3{animation-name:rrvp0y1}
@@ -25,10 +25,11 @@ export type City = {
25
25
  export interface RegisterOverlay<T> {
26
26
  add: (overlay: T) => void;
27
27
  remove: (overlay: T) => void;
28
+ setFitView: () => void;
28
29
  }
29
30
  export interface Route {
30
31
  path: Point[];
31
32
  distance: number;
32
33
  duration: number;
33
34
  }
34
- export type DriverStatus = "dispatching" | "book-dispatching" | "dispatched" | "driverStartService" | "book-driverStartService" | "book-dispatched" | "driverArrived" | "inService" | "canceled" | "endService";
35
+ 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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
package/src/App.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineComponent } from "vue-demi";
2
- import { DemoBusinessQuoting } from "./components/Demo/DemoBusinessQuoting";
2
+ import { HeycarDemo } from "./components/Demo/HeycarDemo";
3
3
 
4
4
  export const App = defineComponent({
5
5
  setup() {
@@ -7,7 +7,7 @@ export const App = defineComponent({
7
7
  // return () => <ABusinessDemo />;
8
8
  // return () => <SearchDemo />;
9
9
  // return () => <DemoBusinessTaxiService />;
10
- return () => <DemoBusinessQuoting />;
11
- // return () => <HeycarDemo />;
10
+ // return () => <DemoBusinessQuoting />;
11
+ return () => <HeycarDemo />;
12
12
  },
13
13
  });
@@ -0,0 +1,8 @@
1
+ import { defineSetup } from "../../types/helper";
2
+ import type { AddressBoxProps } from "../AddressBox";
3
+
4
+ export const AbsoluteAddressBox = defineSetup((props: AddressBoxProps) => {
5
+ return () => {
6
+ return <div></div>;
7
+ };
8
+ });
@@ -0,0 +1 @@
1
+ export * from "./AbsoluteAddressBox";
@@ -11,7 +11,7 @@ import { vec2lnglat } from "../../utils/transform";
11
11
  import { AAddressLocator, GAddressLocator } from "../AddressLocator";
12
12
  import * as css from "./AddressBox.css";
13
13
 
14
- interface AddressBoxProps {
14
+ export interface AddressBoxProps {
15
15
  type: "box" | "locator";
16
16
  position: Point;
17
17
  title: string;
@@ -1,16 +1,15 @@
1
1
  import { HeycarMap, HeycarMapProps } from "../../components/MapProvider";
2
- import type { MapMountedProps } from "../../hooks/useMap";
3
2
  import type { MROP } from "../../hooks/useOverlay";
4
3
  import { defineLagecySetup } from "../../types/helper";
5
4
  import type { Place } from "../../types/interface";
6
5
  import { place2point } from "../../utils/transform";
7
6
  import { DrivingLine } from "../DrivingLine";
8
7
  import { DrivingRoute } from "../DrivingRoute";
8
+ import { FitViewOnce } from "../FitView";
9
9
  import { StartEndPoint } from "../StartEndPoint";
10
10
 
11
11
  export type BusinessQuotingMapProps = Omit<HeycarMapProps, "center" | "zoom"> &
12
- MROP &
13
- MapMountedProps & {
12
+ Required<MROP> & {
14
13
  from: Place;
15
14
  to: Place;
16
15
  renderDescription: (titleProps: { distance: number; duration: number }) => string;
@@ -42,7 +41,8 @@ export const BusinessQuotingMap = defineLagecySetup((props: BusinessQuotingMapPr
42
41
  description={renderDescription({ distance, duration })}
43
42
  />,
44
43
  ]}
45
- ></DrivingRoute>
44
+ />
45
+ <FitViewOnce registerOverlay={registerOverlay} />
46
46
  </HeycarMap>
47
47
  );
48
48
  };
@@ -0,0 +1,157 @@
1
+ import { computed, reactive, watchEffect } from "vue";
2
+ import { HeycarMap, HeycarMapProps } from "../../components/MapProvider";
3
+ import type { BusinessRecomendPlaceContext } from "../../hooks-business/useBusinessRecomendPlaceMap";
4
+ import { useGeoLocation, UseGeoLocationProps } from "../../hooks/useGeoLocation";
5
+ import { useHeycarMap } from "../../hooks/useHeycarMap";
6
+ import { useMapDrag, UseMapDragProps } from "../../hooks/useMapDrag";
7
+ import type { UseMapPlaceProps } from "../../hooks/useMapPlace";
8
+ import { useMapRecomendPlace, UseMapRecomendPlaceProps } from "../../hooks/useMapRecomendPlace";
9
+ import { useMapSupplier } from "../../hooks/useMapSupplier";
10
+ import { defineLagecySetup } from "../../types/helper";
11
+ import type { Place, Point } from "../../types/interface";
12
+ import { AddressBox } from "../AddressBox";
13
+ import { PassengerCircle } from "../PassengerCircle";
14
+ import { PickupPoints } from "../PickupPoints";
15
+
16
+ const RECOMMEND_PLACE_LIMIT = 30;
17
+
18
+ export interface CenterPlaceSource {
19
+ source: "default" | "geo" | "drag" | "recomend" | "api";
20
+ }
21
+ export interface BusinessRecomendPlaceMapProps
22
+ extends Omit<HeycarMapProps, "center" | "zoom" | "mapRef">,
23
+ Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
24
+ title: string;
25
+ description: string;
26
+ geoDefaultPosition?: Point;
27
+ mapContext: BusinessRecomendPlaceContext;
28
+ onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
29
+ onLoadDefaultGeoLocation?: UseGeoLocationProps["onLoadDefault"];
30
+ onChangeByDrag?: UseMapDragProps["onChange"];
31
+ onChangeGeoLocation?: UseGeoLocationProps["onChange"];
32
+ onChangePlace?: UseMapPlaceProps["onChange"];
33
+ onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
34
+ onGeoError?: UseGeoLocationProps["onError"];
35
+ }
36
+ export const BusinessRecomendPlaceMap = defineLagecySetup(
37
+ (props: BusinessRecomendPlaceMapProps, { emit }) => {
38
+ const { geoDefaultPosition, getRecomendPlace, mapContext } = props;
39
+ const { mapRef, setMap, panTo } = useHeycarMap();
40
+ const { readyPromise } = useMapSupplier();
41
+ const centerPlace = reactive<Place>({
42
+ lng: geoDefaultPosition?.[0] ?? 0,
43
+ lat: geoDefaultPosition?.[1] ?? 0,
44
+ name: "",
45
+ cityName: undefined,
46
+ });
47
+ const centerPoint = computed<Point>(() => [centerPlace.lng, centerPlace.lat]);
48
+ const centerSource: CenterPlaceSource = { source: "geo" };
49
+ const setCenterPlaceByRecomand = (point: Point) => {
50
+ centerSource.source = "api";
51
+ centerPlace.lng = point[0];
52
+ centerPlace.lat = point[1];
53
+ updatePlace();
54
+ };
55
+ mapContext.setCenterPlaceByRecomand = setCenterPlaceByRecomand;
56
+ mapContext.panTo = panTo;
57
+ const setCenterByPlace = (place: Place) => {
58
+ centerSource.source = "api";
59
+ centerPlace.lng = place.lng;
60
+ centerPlace.lat = place.lat;
61
+ centerPlace.name = place.name;
62
+ };
63
+
64
+ const { geoPosition } = useGeoLocation({
65
+ geoDefaultPosition,
66
+ onLoad: async (value) => {
67
+ // geo 主入口
68
+ await readyPromise;
69
+ centerSource.source = "geo";
70
+ centerPlace.lng = value.position[0];
71
+ centerPlace.lat = value.position[1];
72
+ updatePlace();
73
+ emit("loadGeoLocation", value);
74
+ },
75
+ onLoadDefault: async (value) => {
76
+ // geo default position 主入口
77
+ await readyPromise;
78
+ centerSource.source = "geo";
79
+ centerPlace.lng = value.position[0];
80
+ centerPlace.lat = value.position[1];
81
+ updatePlace();
82
+ emit("loadDefaultGeoLocation", value);
83
+ },
84
+ onChange: (v) => emit("changeGeoLocation", v),
85
+ onError: (e) => emit("geoError", e),
86
+ });
87
+ const { isDragging } = useMapDrag({
88
+ mapRef,
89
+ onChange: (point) => {
90
+ centerSource.source = "drag";
91
+ centerPlace.lng = point[0];
92
+ centerPlace.lat = point[1];
93
+ updatePlace();
94
+ emit("changeByDrag", point);
95
+ },
96
+ });
97
+ const { updatePlace, updateRecomandPlace, placeCandidates } = useMapRecomendPlace({
98
+ pointRef: centerPoint,
99
+ context: centerSource,
100
+ getRecomendPlace,
101
+ getLimit: (context) => {
102
+ const source = context?.source;
103
+ switch (source) {
104
+ case "drag":
105
+ case "api":
106
+ return RECOMMEND_PLACE_LIMIT;
107
+ case "geo":
108
+ case "default":
109
+ return Infinity;
110
+ default:
111
+ throw new Error(`MyError: should not call getLimit on source: ${source}`);
112
+ }
113
+ },
114
+ onChangePlace: (place) => {
115
+ Object.assign(centerPlace, { ...place });
116
+ if (centerSource.source !== "recomend") {
117
+ updateRecomandPlace();
118
+ }
119
+ emit("changePlace", place);
120
+ },
121
+ onChange: (place) => {
122
+ centerSource.source = "recomend";
123
+ Object.assign(centerPlace, { ...place });
124
+ updatePlace();
125
+ emit("changeRecomandPlace", place);
126
+ },
127
+ });
128
+ watchEffect(() => {
129
+ mapContext.onChangeCenterPlace({ ...centerPlace });
130
+ });
131
+ watchEffect(() => {
132
+ mapContext.onChangeRecomendPlaces([...placeCandidates.value]);
133
+ });
134
+ return () => {
135
+ return (
136
+ <HeycarMap center={centerPoint.value} zoom={18} mapRef={setMap}>
137
+ <PassengerCircle position={geoPosition.value} />
138
+ <PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} />
139
+ <AddressBox
140
+ position={centerPoint.value}
141
+ title={props.title}
142
+ description={props.description}
143
+ type={isDragging ? "locator" : "box"}
144
+ />
145
+ </HeycarMap>
146
+ );
147
+ };
148
+ }
149
+ ).props([
150
+ "description",
151
+ "fallback",
152
+ "geoDefaultPosition",
153
+ "getRecomendPlace",
154
+ "loading",
155
+ "mapContext",
156
+ "title",
157
+ ]);
@@ -0,0 +1 @@
1
+ export * from "./BusinessRecomendPlaceMap";
@@ -222,8 +222,7 @@ const SectionEndService = defineSetup((props: SectionEndServiceProps, { emit })
222
222
  });
223
223
 
224
224
  export type BusinessTaxiServiceMapProps = Omit<HeycarMapProps, "center" | "zoom"> &
225
- MROP &
226
- MapMountedProps & {
225
+ Required<MROP> & {
227
226
  from: Place;
228
227
  to: Place;
229
228
  // @example 正在为您搜索附近司机
@@ -237,109 +236,124 @@ export type BusinessTaxiServiceMapProps = Omit<HeycarMapProps, "center" | "zoom"
237
236
  renderInServiceTitle: (titleProps: { distance: number; duration: number }) => string;
238
237
  getDriverPosition: () => Promise<Point>;
239
238
  };
240
- export const BusinessTaxiServiceMap = defineLagecySetup(
241
- (props: BusinessTaxiServiceMapProps, { emit }) => {
239
+ export const BusinessTaxiServiceMap = defineLagecySetup((props: BusinessTaxiServiceMapProps) => {
240
+ const {
241
+ from,
242
+ interval,
243
+ registerOverlay,
244
+ mapRef,
245
+ getDriverPosition,
246
+ renderStartSerivceTitle,
247
+ renderInServiceTitle,
248
+ } = props;
249
+ const { setFitView } = registerOverlay;
250
+ const { geoPosition } = useGeoLocation({ geoDefaultPosition: place2point(from) });
251
+ const carPositionRef = ref<Point>(place2point(props.from));
252
+ watch(
253
+ () => props.driverStatus,
254
+ (status, _, onCleanup) => {
255
+ if (!STATUS_NEED_CAR_POSITION.includes(status)) return;
256
+ const timer = setInterval(() => {
257
+ getDriverPosition().then((pos) => (carPositionRef.value = pos));
258
+ }, interval);
259
+ onCleanup(() => clearInterval(timer));
260
+ },
261
+ { immediate: true }
262
+ );
263
+ return () => {
242
264
  const {
265
+ driverStatus,
243
266
  from,
244
- interval,
245
- registerOverlay,
246
- mapRef,
247
- getDriverPosition,
248
- renderStartSerivceTitle,
249
- renderInServiceTitle,
267
+ to,
268
+ dispatchingTitle,
269
+ bookDispatchingTitle,
270
+ bookDispatchedTitle,
271
+ driverArrivedTitle,
250
272
  } = props;
251
- const { geoPosition } = useGeoLocation({ geoDefaultPosition: place2point(from) });
252
- const carPositionRef = ref<Point>(place2point(props.from));
253
- const handleMounted = () => emit("mapMounted");
254
- watch(
255
- () => props.driverStatus,
256
- (status, _, onCleanup) => {
257
- if (!STATUS_NEED_CAR_POSITION.includes(status)) return;
258
- const timer = setInterval(() => {
259
- getDriverPosition().then((pos) => (carPositionRef.value = pos));
260
- }, interval);
261
- onCleanup(() => clearInterval(timer));
262
- },
263
- { immediate: true }
273
+ const carPosition = carPositionRef.value;
274
+ return (
275
+ <HeycarMap center={place2point(from)} zoom={13} mapRef={mapRef}>
276
+ {driverStatus === "dispatching" ? (
277
+ <SectionDispatching
278
+ from={from}
279
+ title={dispatchingTitle}
280
+ registerOverlay={registerOverlay}
281
+ onMapMounted={setFitView}
282
+ />
283
+ ) : driverStatus === "book-dispatching" ? (
284
+ <SectionDispatching
285
+ from={from}
286
+ title={bookDispatchingTitle}
287
+ registerOverlay={registerOverlay}
288
+ onMapMounted={setFitView}
289
+ />
290
+ ) : driverStatus === "dispatched" ||
291
+ driverStatus === "driverStartService" ||
292
+ driverStatus === "book-driverStartService" ? (
293
+ <SectionDriverStartService
294
+ from={from}
295
+ carPosition={carPosition}
296
+ passengerPosition={geoPosition.value}
297
+ renderTitle={renderStartSerivceTitle}
298
+ registerOverlay={registerOverlay}
299
+ onMapMounted={setFitView}
300
+ />
301
+ ) : driverStatus === "book-dispatched" ? (
302
+ <SectionBookDispatched
303
+ from={from}
304
+ passengerPosition={geoPosition.value}
305
+ title={bookDispatchedTitle}
306
+ registerOverlay={registerOverlay}
307
+ onMapMounted={setFitView}
308
+ />
309
+ ) : driverStatus === "inService" ? (
310
+ <SectionInService
311
+ to={to}
312
+ carPosition={carPosition}
313
+ renderTitle={renderInServiceTitle}
314
+ registerOverlay={registerOverlay}
315
+ onMapMounted={setFitView}
316
+ />
317
+ ) : driverStatus === "driverArrived" ? (
318
+ <SectionDriverArrived
319
+ from={from}
320
+ carPosition={carPosition}
321
+ passengerPosition={geoPosition.value}
322
+ title={driverArrivedTitle}
323
+ registerOverlay={registerOverlay}
324
+ onMapMounted={setFitView}
325
+ />
326
+ ) : driverStatus === "canceled" || driverStatus === "canceling" ? (
327
+ <SectionCanceled from={from} to={to} registerOverlay={registerOverlay} />
328
+ ) : driverStatus === "endService" ||
329
+ driverStatus === "completed" ||
330
+ driverStatus === "banlanceRefund" ||
331
+ driverStatus === "waitBanlanceRefund" ||
332
+ driverStatus === "rechargePayed" ||
333
+ driverStatus === "waitRechargePay" ||
334
+ driverStatus === "payed" ||
335
+ driverStatus === "waitpay" ||
336
+ driverStatus === "refund" ||
337
+ driverStatus === "confirmed" ? (
338
+ <SectionEndService
339
+ from={from}
340
+ to={to}
341
+ registerOverlay={registerOverlay}
342
+ onMapMounted={setFitView}
343
+ />
344
+ ) : (
345
+ // 匹配不到就显示灰色路线
346
+ <SectionEndService
347
+ from={from}
348
+ to={to}
349
+ registerOverlay={registerOverlay}
350
+ onMapMounted={setFitView}
351
+ />
352
+ )}
353
+ </HeycarMap>
264
354
  );
265
- return () => {
266
- const {
267
- driverStatus,
268
- from,
269
- to,
270
- dispatchingTitle,
271
- bookDispatchingTitle,
272
- bookDispatchedTitle,
273
- driverArrivedTitle,
274
- } = props;
275
- const carPosition = carPositionRef.value;
276
- return (
277
- <HeycarMap center={place2point(from)} zoom={13} mapRef={mapRef}>
278
- {driverStatus === "dispatching" ? (
279
- <SectionDispatching
280
- from={from}
281
- title={dispatchingTitle}
282
- registerOverlay={registerOverlay}
283
- onMapMounted={handleMounted}
284
- />
285
- ) : driverStatus === "book-dispatching" ? (
286
- <SectionDispatching
287
- from={from}
288
- title={bookDispatchingTitle}
289
- registerOverlay={registerOverlay}
290
- onMapMounted={handleMounted}
291
- />
292
- ) : driverStatus === "dispatched" ||
293
- driverStatus === "driverStartService" ||
294
- driverStatus === "book-driverStartService" ? (
295
- <SectionDriverStartService
296
- from={from}
297
- carPosition={carPosition}
298
- passengerPosition={geoPosition.value}
299
- renderTitle={renderStartSerivceTitle}
300
- registerOverlay={registerOverlay}
301
- onMapMounted={handleMounted}
302
- />
303
- ) : driverStatus === "book-dispatched" ? (
304
- <SectionBookDispatched
305
- from={from}
306
- passengerPosition={geoPosition.value}
307
- title={bookDispatchedTitle}
308
- registerOverlay={registerOverlay}
309
- onMapMounted={handleMounted}
310
- />
311
- ) : driverStatus === "inService" ? (
312
- <SectionInService
313
- to={to}
314
- carPosition={carPosition}
315
- renderTitle={renderInServiceTitle}
316
- registerOverlay={registerOverlay}
317
- onMapMounted={handleMounted}
318
- />
319
- ) : driverStatus === "driverArrived" ? (
320
- <SectionDriverArrived
321
- from={from}
322
- carPosition={carPosition}
323
- passengerPosition={geoPosition.value}
324
- title={driverArrivedTitle}
325
- registerOverlay={registerOverlay}
326
- onMapMounted={handleMounted}
327
- />
328
- ) : driverStatus === "canceled" ? (
329
- <SectionCanceled from={from} to={to} registerOverlay={registerOverlay} />
330
- ) : driverStatus === "endService" ? (
331
- <SectionEndService
332
- from={from}
333
- to={to}
334
- registerOverlay={registerOverlay}
335
- onMapMounted={handleMounted}
336
- />
337
- ) : null}
338
- </HeycarMap>
339
- );
340
- };
341
- }
342
- ).props([
355
+ };
356
+ }).props([
343
357
  "bookDispatchedTitle",
344
358
  "bookDispatchingTitle",
345
359
  "dispatchingTitle",
@@ -1,6 +1,6 @@
1
- import { useMap } from "../../hooks/useMap";
1
+ import { onMapMounted, useMap } from "../../hooks/useMap";
2
2
  import { useMapFitView, UseMapFitViewOutput, UseMapFitViewProps } from "../../hooks/useMapFitView";
3
- import type { AmapOverlay, GmapOverlay } from "../../hooks/useOverlay";
3
+ import type { AmapOverlay, GmapOverlay, MROP } from "../../hooks/useOverlay";
4
4
  import { defineSetup, VNodeChild } from "../../types/helper";
5
5
 
6
6
  type FitViewRenderProps = UseMapFitViewOutput<AmapOverlay> | UseMapFitViewOutput<GmapOverlay>;
@@ -12,3 +12,11 @@ export const FitView = defineSetup(function FitView(props: FitViewProps, { slots
12
12
  const ctx = useMapFitView({ ...props, mapRef });
13
13
  return () => <div>{slots.render?.(ctx)}</div>;
14
14
  });
15
+
16
+ export type FitViewOnceProps = Required<MROP>;
17
+ export const FitViewOnce = defineSetup(function FitViewOnce(props: FitViewOnceProps, { slots }) {
18
+ const { registerOverlay } = props;
19
+ const { setFitView } = registerOverlay;
20
+ onMapMounted(setFitView);
21
+ return () => <div>{slots.default?.()}</div>;
22
+ });
@@ -7,7 +7,7 @@ import {
7
7
  } from "../../components/GmapAdvancedMarkerView";
8
8
  import { useMapSupplier } from "../../hooks/useMapSupplier";
9
9
  import { AnchorType } from "../../types/amap/marker";
10
- import { createElement, defineLagecySetup, defineSetup } from "../../types/helper";
10
+ import { createElement, defineSetup } from "../../types/helper";
11
11
  import type { Point } from "../../types/interface";
12
12
  import { createDom } from "../../utils/dom";
13
13
  import { vec2lnglat } from "../../utils/transform";
@@ -20,10 +20,7 @@ export interface PlaceCircleProps {
20
20
  hideIcon?: boolean;
21
21
  onClick?: (value: Point) => any;
22
22
  }
23
- export const APlaceCircle = defineLagecySetup(function APlaceCircle(
24
- props: PlaceCircleProps,
25
- { emit }
26
- ) {
23
+ export const APlaceCircle = defineSetup(function APlaceCircle(props: PlaceCircleProps, { emit }) {
27
24
  const textAlignRef = computed(() => props.textAlign ?? "right");
28
25
  const contentRef = computed(() => {
29
26
  const { hideIcon = false } = props;
@@ -46,20 +43,19 @@ export const APlaceCircle = defineLagecySetup(function APlaceCircle(
46
43
  console.log("on amap marker e = ", e);
47
44
  emit("click", props.position);
48
45
  };
49
- return () => (
50
- <AmapMarker
51
- position={props.position}
52
- content={props.label ? contentRef.value : contentWithoutLabelRef.value}
53
- anchor={textAlignRef.value === "left" ? AnchorType.middleRight : AnchorType.middleLeft}
54
- onClick={handleClick}
55
- />
56
- );
57
- }).props(["hideIcon", "label", "position", "textAlign"]);
46
+ return () => {
47
+ return (
48
+ <AmapMarker
49
+ position={props.position}
50
+ content={props.label ? contentRef.value : contentWithoutLabelRef.value}
51
+ anchor={textAlignRef.value === "left" ? AnchorType.middleRight : AnchorType.middleLeft}
52
+ onClick={handleClick}
53
+ />
54
+ );
55
+ };
56
+ });
58
57
 
59
- export const GPlaceCircle = defineLagecySetup(function GPlaceCircle(
60
- props: PlaceCircleProps,
61
- { emit }
62
- ) {
58
+ export const GPlaceCircle = defineSetup(function GPlaceCircle(props: PlaceCircleProps, { emit }) {
63
59
  const textAlignRef = computed(() => props.textAlign ?? "right");
64
60
  const contentRef = computed(() => {
65
61
  const { hideIcon = false } = props;
@@ -96,7 +92,7 @@ export const GPlaceCircle = defineLagecySetup(function GPlaceCircle(
96
92
  onClick={handleClick}
97
93
  />
98
94
  );
99
- }).props(["hideIcon", "label", "position", "textAlign"]);
95
+ });
100
96
 
101
97
  export const PlaceCircle = defineSetup(function PlaceCircle(props: PlaceCircleProps, { emit }) {
102
98
  const payload = useMapSupplier();
@@ -24,7 +24,7 @@ export const DemoBusinessQuoting = defineSetup(function DemoBusinessTaxiService(
24
24
  });
25
25
 
26
26
  const SomeQuotingPage = defineSetup(function SomeQuotingPage() {
27
- const { setMap, setFitView, registerFitVeiw } = useBusinessQuotingMap();
27
+ const { setMap, registerFitVeiw } = useBusinessQuotingMap();
28
28
  return () => (
29
29
  <BusinessQuotingMap
30
30
  class={css.demo}
@@ -33,7 +33,6 @@ const SomeQuotingPage = defineSetup(function SomeQuotingPage() {
33
33
  renderDescription={({ distance, duration }) => `全程 *${distance}公里* 约行驶 *${duration}*`}
34
34
  mapRef={setMap}
35
35
  registerOverlay={registerFitVeiw}
36
- onMapMounted={setFitView}
37
36
  />
38
37
  );
39
38
  });
@@ -47,7 +47,6 @@ export const TaxiCarServicePage = defineSetup(function TaxiCarServicePage() {
47
47
  interval={5000}
48
48
  mapRef={setMap}
49
49
  registerOverlay={registerFitVeiw}
50
- onMapMounted={setFitView}
51
50
  />
52
51
  );
53
52
  });