@heycar/heycars-map 0.2.4 → 0.2.6

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 (63) hide show
  1. package/README.md +1 -0
  2. package/dist/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +13 -0
  3. package/dist/business-components/BusinessQuotingMap/index.d.ts +1 -0
  4. package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +24 -0
  5. package/dist/business-components/BusinessTaxiServiceMap/index.d.ts +1 -0
  6. package/dist/business-components/FitView/FitView.d.ts +9 -0
  7. package/dist/business-components/FitView/index.d.ts +1 -0
  8. package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +18309 -4
  9. package/dist/business-components/PickupPoints/PickupPoints.d.ts +2 -1
  10. package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +5 -3
  11. package/dist/business-components/TaxiCar/TaxiCar.d.ts +18309 -4
  12. package/dist/business-components/WalkingRoute/WalkingRoute.d.ts +0 -1
  13. package/dist/components/AmapMarker/AmapMarker.d.ts +5 -2
  14. package/dist/components/Demo/DemoBusinessQuoting.d.ts +1 -0
  15. package/dist/components/Demo/DemoBusinessTaxiService.d.ts +2 -0
  16. package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +5 -2
  17. package/dist/hooks/useGeoLocation.d.ts +4 -0
  18. package/dist/hooks/useMap.d.ts +4 -0
  19. package/dist/hooks/useMapAutoComplete.d.ts +3 -0
  20. package/dist/hooks/useMapFitView.d.ts +6 -2296
  21. package/dist/hooks/useMapPlace.d.ts +3 -0
  22. package/dist/hooks/useMapRecomendPlace.d.ts +6 -0
  23. package/dist/hooks/useOverlay.d.ts +1 -0
  24. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -0
  25. package/dist/hooks-business/useBusinessMapRecomendPlace.d.ts +6 -1
  26. package/dist/hooks-business/{useBusinessMapFitView.d.ts → useBusinessQuotingMap.d.ts} +494 -742
  27. package/dist/hooks-business/useBusinessTaxiServiceMap.d.ts +2049 -0
  28. package/dist/index.cjs +56 -56
  29. package/dist/index.d.ts +2 -1
  30. package/dist/index.js +2389 -1921
  31. package/dist/types/interface.d.ts +2 -0
  32. package/dist/utils/compare.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/src/App.tsx +4 -2
  35. package/src/business-components/BusinessQuotingMap/BusinessQuotingMap.tsx +49 -0
  36. package/src/business-components/BusinessQuotingMap/index.ts +1 -0
  37. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +358 -0
  38. package/src/business-components/BusinessTaxiServiceMap/index.ts +1 -0
  39. package/src/business-components/FitView/FitView.tsx +14 -0
  40. package/src/business-components/FitView/index.ts +1 -0
  41. package/src/business-components/PassengerCircle/PassengerCircle.tsx +26 -8
  42. package/src/business-components/PickupPoints/PickupPoints.tsx +8 -2
  43. package/src/business-components/PlaceCircle/PlaceCircle.tsx +29 -5
  44. package/src/business-components/TaxiCar/TaxiCar.tsx +18 -6
  45. package/src/business-components/WalkingRoute/WalkingRoute.tsx +0 -1
  46. package/src/components/AmapMarker/AmapMarker.ts +10 -3
  47. package/src/components/Demo/DemoBusinessQuoting.tsx +39 -0
  48. package/src/components/Demo/DemoBusinessTaxiService.tsx +53 -0
  49. package/src/components/Demo/HeycarDemo.tsx +19 -10
  50. package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +15 -4
  51. package/src/hooks/useGeoLocation.ts +7 -3
  52. package/src/hooks/useMap.ts +15 -1
  53. package/src/hooks/useMapFitView.ts +8 -1
  54. package/src/hooks/useOverlay.ts +1 -0
  55. package/src/hooks/useWalkingRoute.ts +14 -9
  56. package/src/hooks-business/useBusinessMapRecomendPlace.ts +24 -0
  57. package/src/hooks-business/useBusinessQuotingMap.ts +11 -0
  58. package/src/hooks-business/useBusinessTaxiServiceMap.ts +12 -0
  59. package/src/index.ts +2 -1
  60. package/src/types/interface.ts +13 -0
  61. package/src/utils/compare.ts +4 -1
  62. package/todo.md +7 -0
  63. package/src/hooks-business/useBusinessMapFitView.ts +0 -6
@@ -3,17 +3,18 @@ import imgTaxicar from "../../assets/icons/svg/taxi-car.svg";
3
3
  import { AmapMarker } from "../../components/AmapMarker";
4
4
  import { GmapAdvancedMarkerView } from "../../components/GmapAdvancedMarkerView/GmapAdvancedMarkerView";
5
5
  import { useMapSupplier } from "../../hooks/useMapSupplier";
6
+ import type { AmapOverlay, GmapOverlay, MapRegisterOverlayProps } from "../../hooks/useOverlay";
6
7
  import { createElement, defineSetup } from "../../types/helper";
7
8
  import { createDom } from "../../utils/dom";
8
9
  import { decodeAsterisk, vec2lnglat } from "../../utils/transform";
9
10
  import * as css from "./TaxiCar.css";
10
11
 
11
- export interface TaxiCarProps {
12
+ export interface TaxiCarProps<T> extends MapRegisterOverlayProps<T> {
12
13
  position: [number, number];
13
14
  angle?: number;
14
15
  title?: string;
15
16
  }
16
- export const ATaxiCar = defineSetup(function ATaxiCar(props: TaxiCarProps) {
17
+ export const ATaxiCar = defineSetup(function ATaxiCar(props: TaxiCarProps<AmapOverlay>) {
17
18
  const contentRef = computed(() => {
18
19
  const titleRow = !props.title
19
20
  ? ""
@@ -34,11 +35,16 @@ export const ATaxiCar = defineSetup(function ATaxiCar(props: TaxiCarProps) {
34
35
  `;
35
36
  });
36
37
  return () => (
37
- <AmapMarker position={props.position} content={contentRef.value} anchor={"bottom-center"} />
38
+ <AmapMarker
39
+ position={props.position}
40
+ content={contentRef.value}
41
+ anchor={"bottom-center"}
42
+ registerOverlay={props.registerOverlay}
43
+ />
38
44
  );
39
45
  });
40
46
 
41
- export const GTaxiCar = defineSetup(function GTaxiCar(props: TaxiCarProps) {
47
+ export const GTaxiCar = defineSetup(function GTaxiCar(props: TaxiCarProps<GmapOverlay>) {
42
48
  const contentRef = computed(() => {
43
49
  const titleRow = !props.title
44
50
  ? ""
@@ -63,12 +69,18 @@ export const GTaxiCar = defineSetup(function GTaxiCar(props: TaxiCarProps) {
63
69
  });
64
70
  return () => {
65
71
  return (
66
- <GmapAdvancedMarkerView position={vec2lnglat(props.position)} content={contentRef.value} />
72
+ <GmapAdvancedMarkerView
73
+ position={vec2lnglat(props.position)}
74
+ content={contentRef.value}
75
+ registerOverlay={props.registerOverlay}
76
+ />
67
77
  );
68
78
  };
69
79
  });
70
80
 
71
- export const TaxiCar = defineSetup(function TaxiCar(props: TaxiCarProps) {
81
+ export const TaxiCar = defineSetup(function TaxiCar(
82
+ props: TaxiCarProps<AmapOverlay> | TaxiCarProps<GmapOverlay>
83
+ ) {
72
84
  const payload = useMapSupplier();
73
85
  return () => {
74
86
  return createElement(payload.supplier === "gmap" ? GTaxiCar : ATaxiCar, {
@@ -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,39 @@
1
+ import { BusinessQuotingMap } from "../../business-components/BusinessQuotingMap";
2
+ import { useBusinessQuotingMap } from "../../hooks-business/useBusinessQuotingMap";
3
+ import { defineSetup } from "../../types/helper";
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 DemoBusinessQuoting = defineSetup(function DemoBusinessTaxiService() {
13
+ return () => (
14
+ <MapProvider
15
+ amapKey={amapApiKey}
16
+ amapSecret={amapApiSecret}
17
+ gmapId={gmapId}
18
+ gmapKey={gmapApiKey}
19
+ supplier={"amap"}
20
+ >
21
+ <SomeQuotingPage />
22
+ </MapProvider>
23
+ );
24
+ });
25
+
26
+ const SomeQuotingPage = defineSetup(function SomeQuotingPage() {
27
+ const { setMap, setFitView, registerFitVeiw } = useBusinessQuotingMap();
28
+ return () => (
29
+ <BusinessQuotingMap
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
+ renderDescription={({ distance, duration }) => `全程 *${distance}公里* 约行驶 *${duration}*`}
34
+ mapRef={setMap}
35
+ registerOverlay={registerFitVeiw}
36
+ onMapMounted={setFitView}
37
+ />
38
+ );
39
+ });
@@ -0,0 +1,53 @@
1
+ import { BusinessTaxiServiceMap } from "../../business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap";
2
+ import { useBusinessTaxiServiceMap } from "../../hooks-business/useBusinessTaxiServiceMap";
3
+ import { defineSetup } from "../../types/helper";
4
+ import type { Point } from "../../types/interface";
5
+ import { MapProvider } from "../MapProvider/MapProvider";
6
+ import * as css from "./Demo.css";
7
+
8
+ const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
9
+ const gmapId = import.meta.env.VITE_GMAP_MAP_ID;
10
+ const amapApiKey = import.meta.env.VITE_AMAP_API_KEY;
11
+ const amapApiSecret = import.meta.env.VITE_AMAP_API_SECRET;
12
+
13
+ export const DemoBusinessTaxiService = defineSetup(function DemoBusinessTaxiService() {
14
+ return () => (
15
+ <MapProvider
16
+ amapKey={amapApiKey}
17
+ amapSecret={amapApiSecret}
18
+ gmapId={gmapId}
19
+ gmapKey={gmapApiKey}
20
+ supplier={"amap"}
21
+ >
22
+ <TaxiCarServicePage />
23
+ </MapProvider>
24
+ );
25
+ });
26
+
27
+ export const TaxiCarServicePage = defineSetup(function TaxiCarServicePage() {
28
+ const { setMap, setFitView, registerFitVeiw } = useBusinessTaxiServiceMap();
29
+ const getDriverPosition = () => Promise.resolve([121.42, 31.25] as Point);
30
+ return () => (
31
+ <BusinessTaxiServiceMap
32
+ class={css.demo}
33
+ from={{ lng: 121.4, lat: 31.2, name: "from place name" }}
34
+ to={{ lng: 121.5, lat: 31.4, name: "to place name" }}
35
+ driverStatus="book-driverStartService"
36
+ bookDispatchingTitle="2月14日 11:00 用车"
37
+ bookDispatchedTitle="司机位置将在临近出发时间展示"
38
+ dispatchingTitle="正在为您搜索附近司机"
39
+ driverArrivedTitle="司机已等待 00:35"
40
+ renderStartSerivceTitle={({ distance, duration }) =>
41
+ `距你*${distance}*公里, *${duration}*分钟`
42
+ }
43
+ renderInServiceTitle={({ distance, duration }) =>
44
+ `距离终点${distance}公里, 预计${duration}分钟`
45
+ }
46
+ getDriverPosition={getDriverPosition}
47
+ interval={5000}
48
+ mapRef={setMap}
49
+ registerOverlay={registerFitVeiw}
50
+ onMapMounted={setFitView}
51
+ />
52
+ );
53
+ });
@@ -1,8 +1,5 @@
1
1
  import { computed } from "vue-demi";
2
- import { DrivingLine } from "../../business-components/DrivingLine";
3
- import { DrivingRoute } from "../../business-components/DrivingRoute";
4
- import { PlaceCircle } from "../../business-components/PlaceCircle";
5
- import { TaxiCar } from "../../business-components/TaxiCar";
2
+ import { PickupPoints } from "../../business-components/PickupPoints";
6
3
  import { useBusinessMapAutoComplete } from "../../hooks-business/useBusinessMapAutoComplete";
7
4
  import {
8
5
  useBusinessMapRecomendPlace,
@@ -27,7 +24,7 @@ export const HeycarDemo = defineSetup(function HeycarDemo() {
27
24
  amapSecret={amapApiSecret}
28
25
  gmapId={gmapId}
29
26
  gmapKey={gmapApiKey}
30
- supplier={"gmap"}
27
+ supplier={"amap"}
31
28
  >
32
29
  <SomeHomePage />
33
30
  </MapProvider>
@@ -74,7 +71,10 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
74
71
  ) => {
75
72
  const { lat, lng } = place;
76
73
  console.log("getRecomendPlace context?.source = ", context?.source);
77
- 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
+ ];
78
78
  };
79
79
  const {
80
80
  centerPlace,
@@ -84,7 +84,9 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
84
84
  geoLoading,
85
85
  geoPosition,
86
86
  setCenterPlaceByRecomand,
87
+ setCenterByPlace,
87
88
  } = useBusinessMapRecomendPlace({
89
+ geoDefaultPosition: [0, 0],
88
90
  mapRef,
89
91
  recomendPlaceGeoLimit: 300,
90
92
  recomendPlaceDragLimit: 30,
@@ -135,7 +137,7 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
135
137
  title={"end point"}
136
138
  type="end"
137
139
  /> */}
138
- {/* <PickupPoints places={placeCandidates.value} /> */}
140
+ <PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} />
139
141
  {/* <AddressBox
140
142
  type="box"
141
143
  position={centerPoint.value}
@@ -150,16 +152,23 @@ export const SomeHomePage = defineSetup(function SomeHomePage() {
150
152
  ]}
151
153
  labels={["place name 1", "place name 2"]}
152
154
  /> */}
153
- <DrivingRoute
155
+ {/* <DrivingRoute
154
156
  from={[121, 31]}
155
157
  to={[121.6, 31.3]}
156
158
  render={({ path, angle }) => [
157
159
  <DrivingLine path={path} />,
158
160
  <TaxiCar position={[121, 31]} angle={angle} />,
159
161
  ]}
160
- />
162
+ /> */}
161
163
  {/* <PassengerCircle position={centerPoint.value} size="small" /> */}
162
- <PlaceCircle position={centerPoint.value} label={"some place"} hideIcon />
164
+ {/* <PlaceCircle
165
+ position={centerPoint.value}
166
+ label={"some place"}
167
+ hideIcon
168
+ onClick={() => {
169
+ debugger;
170
+ }}
171
+ /> */}
163
172
  {/* <WalkingRoute
164
173
  from={centerPoint.value}
165
174
  to={[centerPoint.value[0] + 0.01, centerPoint.value[1] + 0.01]}
@@ -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
  });
@@ -2,11 +2,13 @@ import { ref, watch } from "vue-demi";
2
2
  import type { Point } from "../types/interface";
3
3
 
4
4
  export interface UseGeoLocationProps {
5
+ geoDefaultPosition?: Point;
5
6
  onChange?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
6
7
  onLoad?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
8
+ onLoadDefault?: (value: { position: Point }) => any;
7
9
  }
8
10
  export const useGeoLocation = (props?: UseGeoLocationProps) => {
9
- const { onChange, onLoad } = props ?? {};
11
+ const { onChange, onLoad, onLoadDefault, geoDefaultPosition } = props ?? {};
10
12
  const loading = ref(false);
11
13
  const readyRef = ref(false);
12
14
  const errorRef = ref<GeolocationPositionError>();
@@ -15,8 +17,8 @@ export const useGeoLocation = (props?: UseGeoLocationProps) => {
15
17
  altitude: 0,
16
18
  altitudeAccuracy: 0,
17
19
  heading: 0,
18
- latitude: 0,
19
- longitude: 0,
20
+ latitude: geoDefaultPosition?.[1] ?? 0,
21
+ longitude: geoDefaultPosition?.[0] ?? 0,
20
22
  speed: 0,
21
23
  });
22
24
  const positionRef = ref<Point>([coordinateRef.value.longitude, coordinateRef.value.latitude]);
@@ -40,6 +42,8 @@ export const useGeoLocation = (props?: UseGeoLocationProps) => {
40
42
  (error) => {
41
43
  loading.value = false;
42
44
  errorRef.value = error;
45
+ const position = props?.geoDefaultPosition;
46
+ if (position) onLoadDefault?.({ position });
43
47
  console.log("errorRef = ", errorRef);
44
48
  },
45
49
  // todo 要不要 timeout
@@ -1,4 +1,4 @@
1
- import { inject, provide, ShallowRef } from "vue-demi";
1
+ import { inject, provide, ShallowRef, watch } from "vue-demi";
2
2
  import type { MapShallowRef } from "../types/interface";
3
3
  import { useMapSupplier } from "./useMapSupplier";
4
4
 
@@ -27,3 +27,17 @@ export const provideMap = (mapRef: MapShallowRef) => {
27
27
  ? provideGmap(mapRef as MapShallowRef<google.maps.Map>)
28
28
  : provideAmap(mapRef as MapShallowRef<AMap.Map>);
29
29
  };
30
+
31
+ export interface MapMountedProps {
32
+ onMapMounted?: () => any;
33
+ }
34
+ export const onMapMounted = (callback: (...args: any) => any) => {
35
+ const mapRef = useMap();
36
+ watch(
37
+ () => mapRef.value,
38
+ (map) => {
39
+ if (!map) return;
40
+ Promise.resolve().then(callback);
41
+ }
42
+ );
43
+ };
@@ -13,6 +13,11 @@ type UseAmapFitViewPropsForListeners = {
13
13
  // onZoomEnd?: MapEventHandler<AMap.Map>;
14
14
  };
15
15
 
16
+ export interface UseMapFitViewOutput<L> {
17
+ setFitView: () => void;
18
+ registerFitVeiw: RegisterOverlay<L>;
19
+ }
20
+
16
21
  export interface UseMapFitViewProps<M = AMap.Map | google.maps.Map> {
17
22
  mapRef: MapShallowRef<M>;
18
23
  padding?: [number, number, number, number];
@@ -119,7 +124,9 @@ export const useGmapFitView = (props: UseMapFitViewProps<google.maps.Map>) => {
119
124
  return { registerFitVeiw, setFitView };
120
125
  };
121
126
 
122
- export const useMapFitView = (props: UseMapFitViewProps) => {
127
+ export const useMapFitView = (
128
+ props: UseMapFitViewProps
129
+ ): UseMapFitViewOutput<AmapOverlay> | UseMapFitViewOutput<GmapOverlay> => {
123
130
  const { supplier } = useMapSupplier();
124
131
  return supplier === "gmap"
125
132
  ? useGmapFitView(props as UseMapFitViewProps<google.maps.Map>)
@@ -1,6 +1,7 @@
1
1
  import { ShallowRef, watch } from "vue-demi";
2
2
  import type { RegisterOverlay } from "../types/interface";
3
3
 
4
+ export type MROP = MapRegisterOverlayProps<AmapOverlay> | MapRegisterOverlayProps<GmapOverlay>;
4
5
  export interface MapRegisterOverlayProps<T> {
5
6
  registerOverlay?: RegisterOverlay<T>;
6
7
  }
@@ -19,11 +19,14 @@ export const useAWalkingRoute = (props: UseWalkingRouteProps) => {
19
19
  case "complete": {
20
20
  let path: Point[] = [];
21
21
  const walkingResult = result as AMap.WalkingResult;
22
- for (const route of walkingResult.routes) {
23
- for (const step of route.steps) {
24
- const stepPath = step.path.map<Point>(({ lng, lat }) => [lng, lat]);
25
- path = path.concat(stepPath);
26
- }
22
+ if (!walkingResult.routes) {
23
+ return;
24
+ }
25
+ const firstRoute = walkingResult.routes[0];
26
+ console.log("firstRoute = ", firstRoute);
27
+ for (const step of firstRoute.steps) {
28
+ const stepPath = step.path.map<Point>(({ lng, lat }) => [lng, lat]);
29
+ path = path.concat(stepPath);
27
30
  }
28
31
  pathRef.value = path;
29
32
  return;
@@ -56,10 +59,12 @@ export const useGWalkingRoute = (props: UseWalkingRouteProps) => {
56
59
  switch (status) {
57
60
  case google.maps.DirectionsStatus.OK: {
58
61
  let path: Point[] = [];
59
- result?.routes.map((route) => {
60
- const stepPath = route.overview_path.map<Point>((item) => [item.lng(), item.lat()]);
61
- path = path.concat(stepPath);
62
- });
62
+ const firstRoute = result!.routes[0];
63
+ const stepPath = firstRoute.overview_path.map<Point>((item) => [
64
+ item.lng(),
65
+ item.lat(),
66
+ ]);
67
+ path = path.concat(stepPath);
63
68
  pathRef.value = path;
64
69
  return;
65
70
  }
@@ -13,9 +13,11 @@ export interface UseBusinessMapRecomendPlaceProps
13
13
  extends Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
14
14
  mapRef: MapShallowRef;
15
15
  defaultCenterPoint?: Point;
16
+ geoDefaultPosition?: Point;
16
17
  recomendPlaceGeoLimit: number;
17
18
  recomendPlaceDragLimit: number;
18
19
  onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
20
+ onLoadDefaultGeoLocation?: UseGeoLocationProps["onLoadDefault"];
19
21
  onChangeByDrag?: UseMapDragProps["onChange"];
20
22
  onChangeGeoLocation?: UseGeoLocationProps["onChange"];
21
23
  onChangePlace?: UseMapPlaceProps["onChange"];
@@ -24,11 +26,13 @@ export interface UseBusinessMapRecomendPlaceProps
24
26
  export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlaceProps) => {
25
27
  const {
26
28
  mapRef,
29
+ geoDefaultPosition,
27
30
  getRecomendPlace,
28
31
  defaultCenterPoint,
29
32
  recomendPlaceDragLimit,
30
33
  recomendPlaceGeoLimit,
31
34
  onLoadGeoLocation,
35
+ onLoadDefaultGeoLocation,
32
36
  onChangeByDrag,
33
37
  onChangeGeoLocation,
34
38
  onChangePlace,
@@ -49,6 +53,12 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
49
53
  centerPlace.lat = point[1];
50
54
  updatePlace();
51
55
  };
56
+ const setCenterByPlace = (place: Place) => {
57
+ centerSource.source = "api";
58
+ centerPlace.lng = place.lng;
59
+ centerPlace.lat = place.lat;
60
+ centerPlace.name = place.name;
61
+ };
52
62
  if (defaultCenterPoint) {
53
63
  // default 主入口
54
64
  readyPromise.then(() => {
@@ -57,6 +67,7 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
57
67
  });
58
68
  }
59
69
  const { geoLoading, geoError, geoPosition, geoCoordinate, geoReady } = useGeoLocation({
70
+ geoDefaultPosition,
60
71
  onLoad: async (value) => {
61
72
  // geo 主入口
62
73
  // 如果设置了默认位置,就不在拿 gps 作为默认位置
@@ -69,6 +80,18 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
69
80
  }
70
81
  onLoadGeoLocation?.(value);
71
82
  },
83
+ onLoadDefault: async (value) => {
84
+ // geo default position 主入口
85
+ // 如果设置了默认位置,就不在拿 gps 作为默认位置
86
+ if (!defaultCenterPoint) {
87
+ await readyPromise;
88
+ centerSource.source = "geo";
89
+ centerPlace.lng = value.position[0];
90
+ centerPlace.lat = value.position[1];
91
+ updatePlace();
92
+ }
93
+ onLoadDefaultGeoLocation?.(value);
94
+ },
72
95
  onChange: onChangeGeoLocation,
73
96
  });
74
97
  const { isDragging } = useMapDrag({
@@ -123,5 +146,6 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
123
146
  centerPoint,
124
147
  placeCandidates,
125
148
  setCenterPlaceByRecomand,
149
+ setCenterByPlace,
126
150
  };
127
151
  };
@@ -0,0 +1,11 @@
1
+ import { useHeycarMap } from "../hooks/useHeycarMap";
2
+ import { useMapFitView } from "../hooks/useMapFitView";
3
+
4
+ export const useBusinessQuotingMap = () => {
5
+ const { setMap, mapRef } = useHeycarMap();
6
+ const { registerFitVeiw, setFitView } = useMapFitView({
7
+ mapRef,
8
+ padding: [25, 20, 15, 15],
9
+ });
10
+ return { setMap, registerFitVeiw, setFitView };
11
+ };
@@ -0,0 +1,12 @@
1
+ import { useHeycarMap } from "../hooks/useHeycarMap";
2
+ import { useMapFitView } from "../hooks/useMapFitView";
3
+
4
+ export const useBusinessTaxiServiceMap = () => {
5
+ const { mapRef, setMap } = useHeycarMap();
6
+ const { registerFitVeiw, setFitView } = useMapFitView({
7
+ mapRef,
8
+ autoFitTimeout: 5000,
9
+ padding: [25, 20, 15, 15],
10
+ });
11
+ return { setMap, registerFitVeiw, setFitView };
12
+ };
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./style.css";
2
2
  export { AddressBox } from "./business-components/AddressBox";
3
+ export { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap";
3
4
  export { DrivingLine } from "./business-components/DrivingLine";
4
5
  export { DrivingRoute } from "./business-components/DrivingRoute";
5
6
  export { PassengerCircle } from "./business-components/PassengerCircle";
@@ -12,8 +13,8 @@ export { WalkingRoute } from "./business-components/WalkingRoute";
12
13
  export { WaveCircle } from "./business-components/WaveCircle";
13
14
  export * from "./components/MapProvider";
14
15
  export * from "./hooks-business/useBusinessMapAutoComplete";
15
- export * from "./hooks-business/useBusinessMapFitView";
16
16
  export * from "./hooks-business/useBusinessMapRecomendPlace";
17
+ export * from "./hooks-business/useBusinessTaxiServiceMap";
17
18
  export { useDrivingRoute } from "./hooks/useDrivingRoute";
18
19
  export { useGeoLocation } from "./hooks/useGeoLocation";
19
20
  export { useHeycarMap } from "./hooks/useHeycarMap";
@@ -7,6 +7,7 @@ export type Place = {
7
7
  lat: number;
8
8
  name: string;
9
9
  cityName?: string;
10
+ cityId?: string;
10
11
  };
11
12
 
12
13
  export interface AutoCompletePlace extends Place {
@@ -34,3 +35,15 @@ export interface Route {
34
35
  distance: number;
35
36
  duration: number;
36
37
  }
38
+
39
+ export type DriverStatus =
40
+ | "dispatching"
41
+ | "book-dispatching"
42
+ | "dispatched"
43
+ | "driverStartService"
44
+ | "book-driverStartService"
45
+ | "book-dispatched"
46
+ | "driverArrived"
47
+ | "inService"
48
+ | "canceled"
49
+ | "endService";
@@ -162,7 +162,10 @@ export function watchPostEffectForAMapEvent<
162
162
  });
163
163
  }
164
164
 
165
- export function watchPostEffectForGMapEvent<T extends google.maps.MVCObject, P>(
165
+ export function watchPostEffectForGMapEvent<
166
+ T extends google.maps.MVCObject | google.maps.marker.AdvancedMarkerView,
167
+ P
168
+ >(
166
169
  targetRef: ShallowRef<T | undefined> | Ref<T | undefined> | undefined,
167
170
  props: P,
168
171
  emit: EmitFn<EmitByProps<P>>,
package/todo.md CHANGED
@@ -16,3 +16,10 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
16
16
  5. home 页面用户 出发点与终点小于 200 米,需要提示,需要导出接口
17
17
  6. walkingRoute 显示报错
18
18
  7. 需要一个手段让 fitview 初始化起作用
19
+
20
+ ---
21
+
22
+ 1. locator 的气泡也要支持点击
23
+ 2. locator 气泡长度限制
24
+ 3. locator 拖动次数多了会不更新
25
+ 4. 郝瑞 searh Place 接口搜索次数多了会不更新
@@ -1,6 +0,0 @@
1
- import { useMapFitView, UseMapFitViewProps } from "../hooks/useMapFitView";
2
-
3
- export type UseBusinessMapFitViewProps = Pick<UseMapFitViewProps, "mapRef" | "autoFitTimeout">;
4
- export const useBusinessMapFitView = (props: UseBusinessMapFitViewProps) => {
5
- return useMapFitView({ ...props, padding: [25, 20, 15, 15] });
6
- };