@heycar/heycars-map 0.3.1 → 0.3.3

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.
package/todo.md CHANGED
@@ -13,13 +13,9 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
13
13
 
14
14
  ---
15
15
 
16
- 1. locator 的气泡也要支持点击
17
- 2. locator 气泡长度限制
18
16
  3. locator 拖动次数多了会不更新
19
- 4. 郝瑞 searh Place 接口搜索次数多了会不更新
20
17
 
21
18
  ---
22
19
 
23
20
  1. 定位失败的视觉稿文字提示
24
- 2. 用户手动输入地址,然后跳回 home 页面, centerplace 的 name 不正确
25
- 3. 用户地址搜索,先设置台湾,搜个结果,然后切换城市到新加坡,搜索到结果依然是台湾
21
+ 2. 用户地址搜索,先设置台湾,搜个结果,然后切换城市到新加坡,搜索到结果依然是台湾
@@ -1,57 +0,0 @@
1
- import { UseGeoLocationProps } from "../hooks/useGeoLocation";
2
- import { UseMapDragProps } from "../hooks/useMapDrag";
3
- import type { UseMapPlaceProps } from "../hooks/useMapPlace";
4
- import { UseMapRecomendPlaceProps } from "../hooks/useMapRecomendPlace";
5
- import type { MapShallowRef, Place, Point } from "../types/interface";
6
- interface CenterPlaceSource {
7
- source: "default" | "geo" | "drag" | "recomend" | "api";
8
- }
9
- export interface UseLagecyMapRecomendPlace extends Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
10
- mapRef: MapShallowRef;
11
- defaultCenterPoint?: Point;
12
- geoDefaultPosition?: Point;
13
- recomendPlaceGeoLimit: number;
14
- recomendPlaceDragLimit: number;
15
- onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
16
- onLoadDefaultGeoLocation?: UseGeoLocationProps["onLoadDefault"];
17
- onChangeByDrag?: UseMapDragProps["onChange"];
18
- onChangeGeoLocation?: UseGeoLocationProps["onChange"];
19
- onChangePlace?: UseMapPlaceProps["onChange"];
20
- onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
21
- }
22
- export declare const useLagecyMapRecomendPlace: (props: UseLagecyMapRecomendPlace) => {
23
- isDragging: import("vue-demi").Ref<boolean>;
24
- geoLoading: import("vue-demi").Ref<boolean>;
25
- geoError: import("vue-demi").Ref<GeolocationPositionError | undefined>;
26
- geoPosition: import("vue-demi").Ref<[number, number]>;
27
- geoCoordinate: import("vue-demi").Ref<{
28
- readonly accuracy: number;
29
- readonly altitude: number | null;
30
- readonly altitudeAccuracy: number | null;
31
- readonly heading: number | null;
32
- readonly latitude: number;
33
- readonly longitude: number;
34
- readonly speed: number | null;
35
- }>;
36
- geoReady: import("vue-demi").Ref<boolean>;
37
- centerPlace: {
38
- lng: number;
39
- lat: number;
40
- name: string;
41
- cityName?: string | undefined;
42
- cityParentName?: string | undefined;
43
- countryName?: string | undefined;
44
- };
45
- centerPoint: import("vue-demi").ComputedRef<Point>;
46
- placeCandidates: import("vue-demi").Ref<{
47
- lng: number;
48
- lat: number;
49
- name: string;
50
- cityName?: string | undefined;
51
- cityParentName?: string | undefined;
52
- countryName?: string | undefined;
53
- }[]>;
54
- setCenterPlaceByRecomand: (point: Point) => void;
55
- setCenterByPlace: (place: Place) => void;
56
- };
57
- export {};
@@ -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
- };