@heycar/heycars-map 0.2.3 → 0.2.5

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 (43) hide show
  1. package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +22 -0
  2. package/dist/business-components/BusinessTaxiServiceMap/index.d.ts +1 -0
  3. package/dist/business-components/DrivingRoute/DrivingRoute.d.ts +2 -0
  4. package/dist/business-components/FitView/FitView.d.ts +9 -0
  5. package/dist/business-components/FitView/index.d.ts +1 -0
  6. package/dist/business-components/PickupPoints/PickupPoints.d.ts +2 -1
  7. package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +5 -3
  8. package/dist/business-components/WalkingRoute/WalkingRoute.d.ts +0 -1
  9. package/dist/components/AmapMarker/AmapMarker.d.ts +5 -2
  10. package/dist/components/Demo/DemoBusinessTaxiService.d.ts +2 -0
  11. package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +5 -2
  12. package/dist/hooks/useGeoLocation.d.ts +4 -0
  13. package/dist/hooks/useMapFitView.d.ts +6 -2296
  14. package/dist/hooks-business/useBusinessMapFitView.d.ts +2228 -2234
  15. package/dist/hooks-business/useBusinessMapRecomendPlace.d.ts +4 -1
  16. package/dist/index.cjs +52 -52
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +2072 -1698
  19. package/dist/types/interface.d.ts +1 -0
  20. package/dist/utils/compare.d.ts +1 -1
  21. package/package.json +1 -1
  22. package/src/App.tsx +1 -0
  23. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +285 -0
  24. package/src/business-components/BusinessTaxiServiceMap/index.ts +1 -0
  25. package/src/business-components/DrivingRoute/DrivingRoute.tsx +2 -0
  26. package/src/business-components/FitView/FitView.tsx +14 -0
  27. package/src/business-components/FitView/index.ts +1 -0
  28. package/src/business-components/PickupPoints/PickupPoints.tsx +8 -2
  29. package/src/business-components/PlaceCircle/PlaceCircle.tsx +32 -8
  30. package/src/business-components/WalkingRoute/WalkingRoute.tsx +0 -1
  31. package/src/components/AmapMarker/AmapMarker.ts +10 -3
  32. package/src/components/Demo/DemoBusinessTaxiService.tsx +48 -0
  33. package/src/components/Demo/HeycarDemo.tsx +18 -8
  34. package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +15 -4
  35. package/src/hooks/useDrivingRoute.ts +0 -2
  36. package/src/hooks/useGeoLocation.ts +5 -1
  37. package/src/hooks/useMapFitView.ts +8 -1
  38. package/src/hooks/useWalkingRoute.ts +15 -9
  39. package/src/hooks-business/useBusinessMapRecomendPlace.ts +23 -0
  40. package/src/index.ts +1 -0
  41. package/src/types/interface.ts +12 -0
  42. package/src/utils/compare.ts +4 -1
  43. package/todo.md +7 -0
@@ -30,3 +30,4 @@ export interface Route {
30
30
  distance: number;
31
31
  duration: number;
32
32
  }
33
+ export type DriverStatus = "dispatching" | "book-dispatching" | "dispatched" | "driverStartService" | "book-driverStartService" | "book-dispatched" | "driverArrived" | "inService" | "canceled" | "endService";
@@ -18,5 +18,5 @@ export declare function watchPostEffectForMapProperty<T, P>(targetRef: ShallowRe
18
18
  export declare function watchNoneImmediatePostEffectForMapProperty<T, P>(targetRef: ShallowRef<T | undefined> | Ref<T | undefined>, props: P, nameOptions: PickSettableOptions<T, keyof P>[], watchOptions?: WatchOptions<false>): void;
19
19
  type NamesRestrict<N, S extends string> = N extends `on${string}` ? Lowercase<N> extends `on${S}` ? N : never : never;
20
20
  export declare function watchPostEffectForAMapEvent<T extends AMap.Event, P, E extends string = AMap.EventType>(targetRef: ShallowRef<T | undefined> | Ref<T | undefined> | undefined, props: P, emit: EmitFn<EmitByProps<P>>, propertyNames: NamesRestrict<keyof P, E>[]): void;
21
- export declare function watchPostEffectForGMapEvent<T extends google.maps.MVCObject, P>(targetRef: ShallowRef<T | undefined> | Ref<T | undefined> | undefined, props: P, emit: EmitFn<EmitByProps<P>>, propertyNames: NamesRestrict<keyof P, string>[]): void;
21
+ export declare function watchPostEffectForGMapEvent<T extends google.maps.MVCObject | google.maps.marker.AdvancedMarkerView, P>(targetRef: ShallowRef<T | undefined> | Ref<T | undefined> | undefined, props: P, emit: EmitFn<EmitByProps<P>>, propertyNames: NamesRestrict<keyof P, string>[]): void;
22
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
package/src/App.tsx CHANGED
@@ -6,6 +6,7 @@ export const App = defineComponent({
6
6
  // return () => <Hello class={"helloclass2"} qyc={2} style={{ color: "red" }} />;
7
7
  // return () => <ABusinessDemo />;
8
8
  // return () => <SearchDemo />;
9
+ // return () => <DemoBusinessTaxiService />;
9
10
  return () => <HeycarDemo />;
10
11
  },
11
12
  });
@@ -0,0 +1,285 @@
1
+ import { ref, watch } from "vue-demi";
2
+ import { HeycarMap, HeycarMapProps } from "../../components/MapProvider";
3
+ import { useGeoLocation } from "../../hooks/useGeoLocation";
4
+ import { defineLagecySetup, defineSetup } from "../../types/helper";
5
+ import type { DriverStatus, Place, Point } from "../../types/interface";
6
+ import { place2point } from "../../utils/transform";
7
+ import { DrivingLine } from "../DrivingLine";
8
+ import { DrivingRoute, DrivingRouteRenderProps } from "../DrivingRoute";
9
+ import { PassengerCircle } from "../PassengerCircle";
10
+ import { PlaceCircle } from "../PlaceCircle";
11
+ import { StartEndPoint } from "../StartEndPoint";
12
+ import { TaxiCar } from "../TaxiCar";
13
+ import { WalkingLine } from "../WalkingLine";
14
+ import { WalkingRoute } from "../WalkingRoute";
15
+ import { WaveCircle } from "../WaveCircle";
16
+
17
+ const STATUS_NEED_CAR_POSITION: DriverStatus[] = [
18
+ "book-driverStartService",
19
+ "dispatched",
20
+ "driverStartService",
21
+ "inService",
22
+ "driverArrived",
23
+ ];
24
+
25
+ interface SectionDispatchingProps {
26
+ title: string;
27
+ from: Place;
28
+ }
29
+ const SectionDispatching = defineSetup((props: SectionDispatchingProps) => {
30
+ return () => {
31
+ const { from: fromPlace, title } = props;
32
+ const from = place2point(fromPlace);
33
+ return (
34
+ <div>
35
+ <StartEndPoint type="start" position={from} title={title} />
36
+ <WaveCircle position={from} />
37
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
38
+ </div>
39
+ );
40
+ };
41
+ });
42
+
43
+ interface SectionDriverStartServiceProps {
44
+ passengerPosition: Point;
45
+ carPosition: Point;
46
+ from: Place;
47
+ renderTitle: (props: Pick<DrivingRouteRenderProps, "duration" | "distance">) => string;
48
+ }
49
+ const SectionDriverStartService = defineSetup((props: SectionDriverStartServiceProps) => {
50
+ return () => {
51
+ const { from: fromPlace, carPosition, passengerPosition, renderTitle } = props;
52
+ const from = place2point(fromPlace);
53
+ return (
54
+ <div>
55
+ <StartEndPoint type="start" position={from} />
56
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
57
+ <DrivingRoute
58
+ from={carPosition}
59
+ to={from}
60
+ render={({ path, distance, duration }) => [
61
+ <DrivingLine path={path} />,
62
+ <TaxiCar position={carPosition} title={renderTitle({ distance, duration })} />,
63
+ ]}
64
+ />
65
+ <WalkingRoute
66
+ from={passengerPosition}
67
+ to={from}
68
+ render={({ path }) => <WalkingLine path={path} />}
69
+ />
70
+ <PassengerCircle position={passengerPosition} />
71
+ </div>
72
+ );
73
+ };
74
+ });
75
+
76
+ interface SectionBookDispatchedProps {
77
+ passengerPosition: Point;
78
+ from: Place;
79
+ // @example 司机位置将在临近出发时间展示
80
+ title: string;
81
+ }
82
+ const SectionBookDispatched = defineSetup((props: SectionBookDispatchedProps) => {
83
+ return () => {
84
+ const { from: fromPlace, passengerPosition, title } = props;
85
+ const from = place2point(fromPlace);
86
+ return (
87
+ <div>
88
+ <StartEndPoint type="start" position={from} title={title} />
89
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
90
+ <PassengerCircle position={passengerPosition}></PassengerCircle>
91
+ </div>
92
+ );
93
+ };
94
+ });
95
+
96
+ interface SectionDriverArrivedProps {
97
+ from: Place;
98
+ carPosition: Point;
99
+ passengerPosition: Point;
100
+ // @example 司机已等待 *00:35*
101
+ title: string;
102
+ }
103
+ const SectionDriverArrived = defineSetup((props: SectionDriverArrivedProps) => {
104
+ return () => {
105
+ const { from: fromPlace, carPosition, passengerPosition, title } = props;
106
+ const from = place2point(fromPlace);
107
+ return (
108
+ <div>
109
+ <TaxiCar position={carPosition} title={title} />
110
+ <StartEndPoint type="start" position={from} />
111
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
112
+ <WalkingRoute
113
+ from={passengerPosition}
114
+ to={from}
115
+ render={({ path }) => <WalkingLine path={path} />}
116
+ />
117
+ <PassengerCircle position={passengerPosition} size="small" />
118
+ </div>
119
+ );
120
+ };
121
+ });
122
+
123
+ interface SectionInServiceProps {
124
+ to: Place;
125
+ carPosition: Point;
126
+ renderTitle: (props: Pick<DrivingRouteRenderProps, "duration" | "distance">) => string;
127
+ }
128
+ const SectionInService = defineSetup((props: SectionInServiceProps) => {
129
+ return () => {
130
+ const { to: toPlace, carPosition, renderTitle } = props;
131
+ const to = place2point(toPlace);
132
+ return (
133
+ <div>
134
+ <StartEndPoint type="end" position={to} />
135
+ <PlaceCircle position={carPosition} label="'WebSter Dental Plaza'" hide-icon="true" />
136
+ <DrivingRoute
137
+ from={carPosition}
138
+ to={to}
139
+ render={({ path, distance, duration }) => [
140
+ <DrivingLine path={path} />,
141
+ <TaxiCar position={carPosition} title={renderTitle({ distance, duration })} />,
142
+ ]}
143
+ />
144
+ </div>
145
+ );
146
+ };
147
+ });
148
+
149
+ interface SectionCanceledProps {
150
+ from: Place;
151
+ to: Place;
152
+ }
153
+ const SectionCanceled = defineSetup((props: SectionCanceledProps) => {
154
+ return () => {
155
+ const { from: fromPlace, to: toPlace } = props;
156
+ const from = place2point(fromPlace);
157
+ const to = place2point(toPlace);
158
+ return (
159
+ <div>
160
+ <StartEndPoint type="start" position={from} />
161
+ <StartEndPoint type="end" position={to} />
162
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
163
+ <PlaceCircle position={to} label={toPlace.name} hideIcon />
164
+ </div>
165
+ );
166
+ };
167
+ });
168
+
169
+ interface SectionEndServiceProps {
170
+ from: Place;
171
+ to: Place;
172
+ }
173
+ const SectionEndService = defineSetup((props: SectionEndServiceProps) => {
174
+ return () => {
175
+ const { from: fromPlace, to: toPlace } = props;
176
+ const from = place2point(fromPlace);
177
+ const to = place2point(toPlace);
178
+ return (
179
+ <div>
180
+ <StartEndPoint type="start" position={from} />
181
+ <StartEndPoint type="end" position={to} />
182
+ <PlaceCircle position={from} label={fromPlace.name} hideIcon />
183
+ <PlaceCircle position={to} label={toPlace.name} hideIcon />
184
+ <DrivingRoute from={from} to={to} render={({ path }) => <DrivingLine path={path} done />} />
185
+ </div>
186
+ );
187
+ };
188
+ });
189
+
190
+ export interface BusinessTaxiServiceMapProps extends Omit<HeycarMapProps, "center" | "zoom"> {
191
+ from: Place;
192
+ to: Place;
193
+ // @example 正在为您搜索附近司机
194
+ dispatchingTitle: string;
195
+ bookDispatchingTitle: string;
196
+ bookDispatchedTitle: string;
197
+ driverArrivedTitle: string;
198
+ driverStatus: DriverStatus;
199
+ interval: number;
200
+ renderStartSerivceTitle: (titleProps: { distance: number; duration: number }) => string;
201
+ renderInServiceTitle: (titleProps: { distance: number; duration: number }) => string;
202
+ getDriverPosition: () => Promise<Point>;
203
+ }
204
+ export const BusinessTaxiServiceMap = defineLagecySetup((props: BusinessTaxiServiceMapProps) => {
205
+ const { interval, getDriverPosition } = props;
206
+ const { geoPosition } = useGeoLocation();
207
+ const carPositionRef = ref<Point>(place2point(props.from));
208
+ watch(
209
+ () => props.driverStatus,
210
+ (status, _, onCleanup) => {
211
+ if (!STATUS_NEED_CAR_POSITION.includes(status)) return;
212
+ const timer = setInterval(() => {
213
+ getDriverPosition().then((pos) => (carPositionRef.value = pos));
214
+ }, interval);
215
+ onCleanup(() => clearInterval(timer));
216
+ },
217
+ { immediate: true }
218
+ );
219
+ return () => {
220
+ const {
221
+ driverStatus,
222
+ from,
223
+ to,
224
+ dispatchingTitle,
225
+ bookDispatchingTitle,
226
+ bookDispatchedTitle,
227
+ driverArrivedTitle,
228
+ renderStartSerivceTitle,
229
+ renderInServiceTitle,
230
+ } = props;
231
+ const carPosition = carPositionRef.value;
232
+ return (
233
+ <HeycarMap center={place2point(from)} zoom={13}>
234
+ {driverStatus === "dispatching" ? (
235
+ <SectionDispatching from={from} title={dispatchingTitle} />
236
+ ) : driverStatus === "book-dispatching" ? (
237
+ <SectionDispatching from={from} title={bookDispatchingTitle} />
238
+ ) : driverStatus === "dispatched" ||
239
+ driverStatus === "driverStartService" ||
240
+ driverStatus === "book-driverStartService" ? (
241
+ <SectionDriverStartService
242
+ from={from}
243
+ carPosition={carPosition}
244
+ passengerPosition={geoPosition.value}
245
+ renderTitle={renderStartSerivceTitle}
246
+ />
247
+ ) : driverStatus === "book-dispatched" ? (
248
+ <SectionBookDispatched
249
+ from={from}
250
+ passengerPosition={geoPosition.value}
251
+ title={bookDispatchedTitle}
252
+ />
253
+ ) : driverStatus === "inService" ? (
254
+ <SectionInService to={to} carPosition={carPosition} renderTitle={renderInServiceTitle} />
255
+ ) : driverStatus === "driverArrived" ? (
256
+ <SectionDriverArrived
257
+ from={from}
258
+ carPosition={carPosition}
259
+ passengerPosition={geoPosition.value}
260
+ title={driverArrivedTitle}
261
+ />
262
+ ) : driverStatus === "canceled" ? (
263
+ <SectionCanceled from={from} to={to} />
264
+ ) : driverStatus === "endService" ? (
265
+ <SectionEndService from={from} to={to} />
266
+ ) : null}
267
+ </HeycarMap>
268
+ );
269
+ };
270
+ }).props([
271
+ "bookDispatchedTitle",
272
+ "bookDispatchingTitle",
273
+ "dispatchingTitle",
274
+ "driverArrivedTitle",
275
+ "driverStatus",
276
+ "fallback",
277
+ "from",
278
+ "getDriverPosition",
279
+ "interval",
280
+ "loading",
281
+ "mapRef",
282
+ "renderInServiceTitle",
283
+ "renderStartSerivceTitle",
284
+ "to",
285
+ ]);
@@ -0,0 +1 @@
1
+ export * from "./BusinessTaxiServiceMap";
@@ -13,6 +13,8 @@ import type { Point } from "../../types/interface";
13
13
  export type DrivingRouteRenderProps = {
14
14
  path: Point[];
15
15
  angle?: number;
16
+ distance: number;
17
+ duration: number;
16
18
  };
17
19
  export interface DrivingRouteProps extends UseDrivingRouteProps {
18
20
  render?: (props: DrivingRouteRenderProps) => VNodeChild;
@@ -0,0 +1,14 @@
1
+ import { useMap } from "../../hooks/useMap";
2
+ import { useMapFitView, UseMapFitViewOutput, UseMapFitViewProps } from "../../hooks/useMapFitView";
3
+ import type { AmapOverlay, GmapOverlay } from "../../hooks/useOverlay";
4
+ import { defineSetup, VNodeChild } from "../../types/helper";
5
+
6
+ type FitViewRenderProps = UseMapFitViewOutput<AmapOverlay> | UseMapFitViewOutput<GmapOverlay>;
7
+ export interface FitViewProps extends Omit<UseMapFitViewProps, "mapRef"> {
8
+ render?: (props: FitViewRenderProps) => VNodeChild;
9
+ }
10
+ export const FitView = defineSetup(function FitView(props: FitViewProps, { slots }) {
11
+ const mapRef = useMap();
12
+ const ctx = useMapFitView({ ...props, mapRef });
13
+ return () => <div>{slots.render?.(ctx)}</div>;
14
+ });
@@ -0,0 +1 @@
1
+ export * from "./FitView";
@@ -5,12 +5,18 @@ import { PlaceCircle } from "../PlaceCircle";
5
5
 
6
6
  export interface PickupPointsProps {
7
7
  places: Place[];
8
+ onClick?: (value: Place) => any;
8
9
  }
9
- export const PickupPoints = defineSetup(function PickupPoints(props: PickupPointsProps) {
10
+ export const PickupPoints = defineSetup(function PickupPoints(props: PickupPointsProps, { emit }) {
10
11
  return () => (
11
12
  <div>
12
13
  {props.places.map((place) => (
13
- <PlaceCircle position={place2point(place)} label={place.name} textAlign="left" />
14
+ <PlaceCircle
15
+ position={place2point(place)}
16
+ label={place.name}
17
+ textAlign="left"
18
+ onClick={() => emit("click", place)}
19
+ />
14
20
  ))}
15
21
  </div>
16
22
  );
@@ -1,10 +1,14 @@
1
1
  import { computed } from "vue-demi";
2
2
  import imgPlaceCircle from "../../assets/icons/svg/place-circle.svg";
3
- import { AmapMarker } from "../../components/AmapMarker";
4
- import { GmapAdvancedMarkerView } from "../../components/GmapAdvancedMarkerView";
3
+ import { AmapMarker, AmapMarkerProps } from "../../components/AmapMarker";
4
+ import {
5
+ GmapAdvancedMarkerView,
6
+ GmapAdvancedMarkerViewProps,
7
+ } from "../../components/GmapAdvancedMarkerView";
5
8
  import { useMapSupplier } from "../../hooks/useMapSupplier";
6
9
  import { AnchorType } from "../../types/amap/marker";
7
- import { createElement, defineSetup } from "../../types/helper";
10
+ import { createElement, defineLagecySetup, defineSetup } from "../../types/helper";
11
+ import type { Point } from "../../types/interface";
8
12
  import { createDom } from "../../utils/dom";
9
13
  import { vec2lnglat } from "../../utils/transform";
10
14
  import * as css from "./PlaceCircle.css";
@@ -14,8 +18,12 @@ export interface PlaceCircleProps {
14
18
  label?: string;
15
19
  textAlign?: "left" | "right";
16
20
  hideIcon?: boolean;
21
+ onClick?: (value: Point) => any;
17
22
  }
18
- export const APlaceCircle = defineSetup(function APlaceCircle(props: PlaceCircleProps) {
23
+ export const APlaceCircle = defineLagecySetup(function APlaceCircle(
24
+ props: PlaceCircleProps,
25
+ { emit }
26
+ ) {
19
27
  const textAlignRef = computed(() => props.textAlign ?? "right");
20
28
  const contentRef = computed(() => {
21
29
  const { hideIcon = false } = props;
@@ -34,16 +42,24 @@ export const APlaceCircle = defineSetup(function APlaceCircle(props: PlaceCircle
34
42
  textAlign: textAlignRef.value,
35
43
  })}" src="${imgPlaceCircle}">`;
36
44
  });
45
+ const handleClick: AmapMarkerProps["onClick"] = (e) => {
46
+ console.log("on amap marker e = ", e);
47
+ emit("click", props.position);
48
+ };
37
49
  return () => (
38
50
  <AmapMarker
39
51
  position={props.position}
40
52
  content={props.label ? contentRef.value : contentWithoutLabelRef.value}
41
53
  anchor={textAlignRef.value === "left" ? AnchorType.middleRight : AnchorType.middleLeft}
54
+ onClick={handleClick}
42
55
  />
43
56
  );
44
- });
57
+ }).props(["hideIcon", "label", "position", "textAlign"]);
45
58
 
46
- export const GPlaceCircle = defineSetup(function GPlaceCircle(props: PlaceCircleProps) {
59
+ export const GPlaceCircle = defineLagecySetup(function GPlaceCircle(
60
+ props: PlaceCircleProps,
61
+ { emit }
62
+ ) {
47
63
  const textAlignRef = computed(() => props.textAlign ?? "right");
48
64
  const contentRef = computed(() => {
49
65
  const { hideIcon = false } = props;
@@ -69,19 +85,27 @@ export const GPlaceCircle = defineSetup(function GPlaceCircle(props: PlaceCircle
69
85
  src: imgPlaceCircle,
70
86
  });
71
87
  });
88
+ const handleClick: GmapAdvancedMarkerViewProps["onClick"] = (e) => {
89
+ console.log("on gmap advanced marker view e = ", e);
90
+ emit("click", props.position);
91
+ };
72
92
  return () => (
73
93
  <GmapAdvancedMarkerView
74
94
  position={vec2lnglat(props.position)}
75
95
  content={props.label ? contentRef.value : contentWithoutLabelRef.value}
96
+ onClick={handleClick}
76
97
  />
77
98
  );
78
- });
99
+ }).props(["hideIcon", "label", "position", "textAlign"]);
79
100
 
80
- export const PlaceCircle = defineSetup(function PlaceCircle(props: PlaceCircleProps) {
101
+ export const PlaceCircle = defineSetup(function PlaceCircle(props: PlaceCircleProps, { emit }) {
81
102
  const payload = useMapSupplier();
82
103
  return () => {
83
104
  return createElement(payload.supplier === "gmap" ? GPlaceCircle : APlaceCircle, {
84
105
  attrs: props,
106
+ on: {
107
+ click: (value: any) => emit("click", value),
108
+ },
85
109
  });
86
110
  };
87
111
  });
@@ -10,7 +10,6 @@ import type { Point } from "../../types/interface";
10
10
 
11
11
  export type WalkingRouteRenderProps = {
12
12
  path: Point[];
13
- angle?: number;
14
13
  };
15
14
  export interface WalkingRouteProps extends UseWalkingRouteProps {
16
15
  render?: (props: WalkingRouteRenderProps) => VNodeChild;
@@ -2,11 +2,17 @@ import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
2
  import { useAmap } from "../../hooks/useMap";
3
3
  import { AmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
4
4
  import { defineSetup } from "../../types/helper";
5
- import { watchNoneImmediatePostEffectForMapProperty } from "../../utils/compare";
5
+ import type { MapEventHandler } from "../../types/mapHelper";
6
+ import {
7
+ watchNoneImmediatePostEffectForMapProperty,
8
+ watchPostEffectForAMapEvent,
9
+ } from "../../utils/compare";
6
10
 
7
- export type AmapMarkerProps = AMap.MarkerOptions & MapRegisterOverlayProps<AmapOverlay>;
11
+ export interface AmapMarkerProps extends AMap.MarkerOptions, MapRegisterOverlayProps<AmapOverlay> {
12
+ onClick?: MapEventHandler<AMap.Marker>;
13
+ }
8
14
 
9
- export const AmapMarker = defineSetup(function AmapMarker(props: AmapMarkerProps) {
15
+ export const AmapMarker = defineSetup(function AmapMarker(props: AmapMarkerProps, { emit }) {
10
16
  const { registerOverlay } = props;
11
17
  const markerRef = shallowRef<AMap.Marker>();
12
18
  const mapRef = useAmap();
@@ -37,5 +43,6 @@ export const AmapMarker = defineSetup(function AmapMarker(props: AmapMarkerProps
37
43
  { name: "title", defaultValue: "" },
38
44
  { name: "extData", defaultValue: "" },
39
45
  ]);
46
+ watchPostEffectForAMapEvent(markerRef, props, emit, ["onClick"]);
40
47
  return () => null;
41
48
  });
@@ -0,0 +1,48 @@
1
+ import { BusinessTaxiServiceMap } from "../../business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap";
2
+ import { defineSetup } from "../../types/helper";
3
+ import type { Point } from "../../types/interface";
4
+ import { MapProvider } from "../MapProvider/MapProvider";
5
+ import * as css from "./Demo.css";
6
+
7
+ const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
8
+ const gmapId = import.meta.env.VITE_GMAP_MAP_ID;
9
+ const amapApiKey = import.meta.env.VITE_AMAP_API_KEY;
10
+ const amapApiSecret = import.meta.env.VITE_AMAP_API_SECRET;
11
+
12
+ export const DemoBusinessTaxiService = defineSetup(function DemoBusinessTaxiService() {
13
+ return () => (
14
+ <MapProvider
15
+ amapKey={amapApiKey}
16
+ amapSecret={amapApiSecret}
17
+ gmapId={gmapId}
18
+ gmapKey={gmapApiKey}
19
+ supplier={"amap"}
20
+ >
21
+ <TaxiCarServicePage />
22
+ </MapProvider>
23
+ );
24
+ });
25
+
26
+ export const TaxiCarServicePage = defineSetup(function TaxiCarServicePage() {
27
+ const getDriverPosition = () => Promise.resolve([121.42, 31.25] as Point);
28
+ return () => (
29
+ <BusinessTaxiServiceMap
30
+ class={css.demo}
31
+ from={{ lng: 121.4, lat: 31.2, name: "from place name" }}
32
+ to={{ lng: 121.5, lat: 31.4, name: "to place name" }}
33
+ driverStatus="driverStartService"
34
+ bookDispatchingTitle="2月14日 11:00 用车"
35
+ bookDispatchedTitle="司机位置将在临近出发时间展示"
36
+ dispatchingTitle="正在为您搜索附近司机"
37
+ driverArrivedTitle="司机已等待 00:35"
38
+ renderStartSerivceTitle={({ distance, duration }) =>
39
+ `距你*${distance}*公里, *${duration}*分钟`
40
+ }
41
+ renderInServiceTitle={({ distance, duration }) =>
42
+ `距离终点${distance}公里, 预计${duration}分钟`
43
+ }
44
+ getDriverPosition={getDriverPosition}
45
+ interval={5000}
46
+ />
47
+ );
48
+ });
@@ -1,7 +1,5 @@
1
1
  import { computed } from "vue-demi";
2
- import { PlaceCircle } from "../../business-components/PlaceCircle";
3
- import { WalkingLine } from "../../business-components/WalkingLine";
4
- import { WalkingRoute } from "../../business-components/WalkingRoute";
2
+ import { PickupPoints } from "../../business-components/PickupPoints";
5
3
  import { useBusinessMapAutoComplete } from "../../hooks-business/useBusinessMapAutoComplete";
6
4
  import {
7
5
  useBusinessMapRecomendPlace,
@@ -73,7 +71,10 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
73
71
  ) => {
74
72
  const { lat, lng } = place;
75
73
  console.log("getRecomendPlace context?.source = ", context?.source);
76
- return [{ lat: lat + 0.0001, lng: lng + 0.0001, name: "place name 1" }];
74
+ return [
75
+ { lat: lat + 0.0001, lng: lng + 0.0001, name: "place name 1" },
76
+ { lat: lat + 0.002, lng: lng + 0.002, name: "place name 2" },
77
+ ];
77
78
  };
78
79
  const {
79
80
  centerPlace,
@@ -83,7 +84,9 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
83
84
  geoLoading,
84
85
  geoPosition,
85
86
  setCenterPlaceByRecomand,
87
+ setCenterByPlace,
86
88
  } = useBusinessMapRecomendPlace({
89
+ geoDefaultPosition: [0, 0],
87
90
  mapRef,
88
91
  recomendPlaceGeoLimit: 300,
89
92
  recomendPlaceDragLimit: 30,
@@ -134,7 +137,7 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
134
137
  title={"end point"}
135
138
  type="end"
136
139
  /> */}
137
- {/* <PickupPoints places={placeCandidates.value} /> */}
140
+ <PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} />
138
141
  {/* <AddressBox
139
142
  type="box"
140
143
  position={centerPoint.value}
@@ -158,12 +161,19 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
158
161
  ]}
159
162
  /> */}
160
163
  {/* <PassengerCircle position={centerPoint.value} size="small" /> */}
161
- <PlaceCircle position={centerPoint.value} label={"some place"} hideIcon />
162
- <WalkingRoute
164
+ {/* <PlaceCircle
165
+ position={centerPoint.value}
166
+ label={"some place"}
167
+ hideIcon
168
+ onClick={() => {
169
+ debugger;
170
+ }}
171
+ /> */}
172
+ {/* <WalkingRoute
163
173
  from={centerPoint.value}
164
174
  to={[centerPoint.value[0] + 0.01, centerPoint.value[1] + 0.01]}
165
175
  render={({ path }) => <WalkingLine path={path} />}
166
- />
176
+ /> */}
167
177
  </HeycarMap>
168
178
  </div>
169
179
  );
@@ -2,21 +2,31 @@ import { onMounted, onUnmounted, shallowRef, watch, watchPostEffect } from "vue-
2
2
  import { useGmap } from "../../hooks/useMap";
3
3
  import { GmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
4
4
  import { defineSetup } from "../../types/helper";
5
- import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
5
+ import type { MapEventHandler } from "../../types/mapHelper";
6
+ import {
7
+ watchNoneImmediatePostEffectForDeepOption,
8
+ watchPostEffectForGMapEvent,
9
+ } from "../../utils/compare";
6
10
 
7
- export type GmapAdvancedMarkerViewProps = google.maps.marker.AdvancedMarkerViewOptions &
8
- MapRegisterOverlayProps<GmapOverlay>;
11
+ export interface GmapAdvancedMarkerViewProps
12
+ extends google.maps.marker.AdvancedMarkerViewOptions,
13
+ MapRegisterOverlayProps<GmapOverlay> {
14
+ onClick?: MapEventHandler<google.maps.marker.AdvancedMarkerView>;
15
+ }
9
16
 
10
17
  export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerView(
11
- props: GmapAdvancedMarkerViewProps
18
+ props: GmapAdvancedMarkerViewProps,
19
+ { emit }
12
20
  ) {
13
21
  const { registerOverlay } = props;
14
22
  const markerRef = shallowRef<google.maps.marker.AdvancedMarkerView>();
15
23
  const mapRef = useGmap();
24
+ const handleClick: typeof emit = (name) => emit(name as any, { target: markerRef.value! });
16
25
  useMapOverlay({ registerOverlay, overlayRef: markerRef });
17
26
  onMounted(() => {
18
27
  const { registerOverlay, ...markerViewProps } = props;
19
28
  markerRef.value = new google.maps.marker.AdvancedMarkerView({ ...markerViewProps });
29
+ markerRef.value.addListener;
20
30
  });
21
31
  onUnmounted(() => {
22
32
  if (!markerRef.value) return;
@@ -48,5 +58,6 @@ export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerVie
48
58
  flush: "post",
49
59
  }
50
60
  );
61
+ watchPostEffectForGMapEvent(markerRef, props, handleClick, ["onClick"]);
51
62
  return () => null;
52
63
  });
@@ -69,13 +69,11 @@ export const useGDrivingRoute = (props: UseDrivingRouteProps) => {
69
69
  let distance = 0;
70
70
  let duration = 0;
71
71
  const firstRoute = result!.routes[0];
72
-
73
72
  const stepPath = firstRoute.overview_path.map<Point>((item) => [
74
73
  item.lng(),
75
74
  item.lat(),
76
75
  ]);
77
76
  path = path.concat(stepPath);
78
-
79
77
  for (const leg of firstRoute.legs) {
80
78
  distance += leg.distance?.value ?? 0;
81
79
  // todo 考虑用 duration_in_traffic 但这个字段上有条件的