@heycar/heycars-map 0.3.0 → 0.3.2

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 (31) hide show
  1. package/README.md +1 -1
  2. package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +3 -1
  3. package/dist/hooks/useMapAutoComplete.d.ts +10 -6
  4. package/dist/hooks/useMapCityBound.d.ts +5 -5
  5. package/dist/hooks/useMapLog.d.ts +2 -1
  6. package/dist/hooks/useMapPlace.d.ts +13 -2
  7. package/dist/hooks/useMapRecomendPlace.d.ts +12 -2
  8. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +4 -2
  9. package/dist/hooks-business/useBusinessRecomendPlaceMap.d.ts +4 -2
  10. package/dist/index.cjs +52 -52
  11. package/dist/index.js +1095 -1064
  12. package/dist/style.css +1 -1
  13. package/dist/types/interface.d.ts +2 -1
  14. package/package.json +1 -1
  15. package/src/Demo/DemoBusinessRecomendPlace.tsx +16 -8
  16. package/src/Demo/sample.json +793 -0
  17. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.css.ts +2 -0
  18. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +5 -3
  19. package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +26 -22
  20. package/src/hooks/useGeoLocation.ts +6 -2
  21. package/src/hooks/useMapAutoComplete.ts +7 -5
  22. package/src/hooks/useMapCityBound.ts +5 -5
  23. package/src/hooks/useMapDrag.ts +7 -2
  24. package/src/hooks/useMapLog.ts +14 -2
  25. package/src/hooks/useMapPlace.ts +39 -16
  26. package/src/hooks/useMapRecomendPlace.ts +17 -4
  27. package/src/hooks-business/useBusinessMapAutoComplete.ts +3 -2
  28. package/src/hooks-business/useBusinessRecomendPlaceMap.ts +5 -5
  29. package/src/types/interface.ts +2 -1
  30. package/dist/hooks-business/useLagecyMapRecomendPlace.d.ts +0 -55
  31. package/src/hooks-business/useLagecyMapRecomendPlace.ts +0 -152
@@ -1,152 +0,0 @@
1
- import { computed, reactive } from "vue-demi";
2
- import { useGeoLocation, UseGeoLocationProps } from "../hooks/useGeoLocation";
3
- import { useMapDrag, UseMapDragProps } from "../hooks/useMapDrag";
4
- import type { UseMapPlaceProps } from "../hooks/useMapPlace";
5
- import { useMapRecomendPlace, UseMapRecomendPlaceProps } from "../hooks/useMapRecomendPlace";
6
- import { useMapSupplier } from "../hooks/useMapSupplier";
7
- import type { MapShallowRef, Place, Point } from "../types/interface";
8
-
9
- interface CenterPlaceSource {
10
- source: "default" | "geo" | "drag" | "recomend" | "api";
11
- }
12
- export interface UseLagecyMapRecomendPlace
13
- extends Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
14
- mapRef: MapShallowRef;
15
- defaultCenterPoint?: Point;
16
- geoDefaultPosition?: Point;
17
- recomendPlaceGeoLimit: number;
18
- recomendPlaceDragLimit: number;
19
- onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
20
- onLoadDefaultGeoLocation?: UseGeoLocationProps["onLoadDefault"];
21
- onChangeByDrag?: UseMapDragProps["onChange"];
22
- onChangeGeoLocation?: UseGeoLocationProps["onChange"];
23
- onChangePlace?: UseMapPlaceProps["onChange"];
24
- onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
25
- }
26
- export const useLagecyMapRecomendPlace = (props: UseLagecyMapRecomendPlace) => {
27
- const {
28
- mapRef,
29
- geoDefaultPosition,
30
- getRecomendPlace,
31
- defaultCenterPoint,
32
- recomendPlaceDragLimit,
33
- recomendPlaceGeoLimit,
34
- onLoadGeoLocation,
35
- onLoadDefaultGeoLocation,
36
- onChangeByDrag,
37
- onChangeGeoLocation,
38
- onChangePlace,
39
- onChangeRecomandPlace,
40
- } = props;
41
- const { readyPromise } = useMapSupplier();
42
- const centerPlace = reactive<Place>({
43
- lng: defaultCenterPoint?.[0] ?? 0,
44
- lat: defaultCenterPoint?.[1] ?? 0,
45
- name: "",
46
- cityName: undefined,
47
- });
48
- const centerPoint = computed<Point>(() => [centerPlace.lng, centerPlace.lat]);
49
- const centerSource: CenterPlaceSource = { source: "geo" };
50
- const setCenterPlaceByRecomand = (point: Point) => {
51
- centerSource.source = "api";
52
- centerPlace.lng = point[0];
53
- centerPlace.lat = point[1];
54
- updatePlace();
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
- };
62
- if (defaultCenterPoint) {
63
- // default 主入口
64
- readyPromise.then(() => {
65
- centerSource.source = "default";
66
- updatePlace();
67
- });
68
- }
69
- const { geoLoading, geoError, geoPosition, geoCoordinate, geoReady } = useGeoLocation({
70
- geoDefaultPosition,
71
- onLoad: async (value) => {
72
- // geo 主入口
73
- // 如果设置了默认位置,就不在拿 gps 作为默认位置
74
- if (!defaultCenterPoint) {
75
- await readyPromise;
76
- centerSource.source = "geo";
77
- centerPlace.lng = value.position[0];
78
- centerPlace.lat = value.position[1];
79
- updatePlace();
80
- }
81
- onLoadGeoLocation?.(value);
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
- },
95
- onChange: onChangeGeoLocation,
96
- });
97
- const { isDragging } = useMapDrag({
98
- mapRef,
99
- onChange: (point) => {
100
- centerSource.source = "drag";
101
- centerPlace.lng = point[0];
102
- centerPlace.lat = point[1];
103
- updatePlace();
104
- onChangeByDrag?.(point);
105
- },
106
- });
107
- const { updatePlace, updateRecomandPlace, placeCandidates } = useMapRecomendPlace({
108
- pointRef: centerPoint,
109
- context: centerSource,
110
- getRecomendPlace,
111
- getLimit: (context) => {
112
- const source = context?.source;
113
- switch (source) {
114
- case "drag":
115
- case "api":
116
- return recomendPlaceDragLimit;
117
- case "geo":
118
- case "default":
119
- return recomendPlaceGeoLimit;
120
- default:
121
- throw new Error(`MyError: should not call getLimit on source: ${source}`);
122
- }
123
- },
124
- onChangePlace: (place) => {
125
- Object.assign(centerPlace, { ...place });
126
- if (centerSource.source !== "recomend") {
127
- updateRecomandPlace();
128
- }
129
- onChangePlace?.(place);
130
- },
131
- onChange: (place) => {
132
- centerSource.source = "recomend";
133
- Object.assign(centerPlace, { ...place });
134
- updatePlace();
135
- onChangeRecomandPlace?.(place);
136
- },
137
- });
138
-
139
- return {
140
- isDragging,
141
- geoLoading,
142
- geoError,
143
- geoPosition,
144
- geoCoordinate,
145
- geoReady,
146
- centerPlace,
147
- centerPoint,
148
- placeCandidates,
149
- setCenterPlaceByRecomand,
150
- setCenterByPlace,
151
- };
152
- };