@heycar/heycars-map 0.3.2 → 0.3.4
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/dist/hooks/useMapAutoComplete.d.ts +3 -0
- package/dist/hooks/useMapPlace.d.ts +3 -0
- package/dist/hooks/useMapRecomendPlace.d.ts +3 -0
- package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -0
- package/dist/index.cjs +52 -52
- package/dist/index.js +1023 -1006
- package/dist/types/interface.d.ts +1 -0
- package/package.json +1 -1
- package/src/Demo/DemoBusinessRecomendPlace.tsx +1 -1
- package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +3 -5
- package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +40 -33
- package/src/hooks/useMapAutoComplete.ts +27 -12
- package/src/hooks/useMapPlace.ts +21 -2
- package/src/hooks/useMapRecomendPlace.ts +4 -2
- package/src/types/interface.ts +1 -0
- package/todo.md +1 -5
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ const SomeAutoComplete = defineSetup(function SomeAutoComplete(props: { cityName
|
|
|
18
18
|
return () => {
|
|
19
19
|
const list = autoCompletePlaces.value.map((place) => (
|
|
20
20
|
<div>
|
|
21
|
-
{place.lng} | {place.lat} | {place.name} | {place.description}
|
|
21
|
+
{place.lng} | {place.lat} | {place.name} | {place.description} | {place.distance}
|
|
22
22
|
</div>
|
|
23
23
|
));
|
|
24
24
|
return (
|
|
@@ -25,14 +25,12 @@ export const AbsoluteAddressBox = defineSetup(function AbsoluteAddressBox(
|
|
|
25
25
|
);
|
|
26
26
|
return (
|
|
27
27
|
<div class={css.absoluteAddressBoxLayout}>
|
|
28
|
-
<div class={css.absoluteAddressBox}>
|
|
28
|
+
<div class={css.absoluteAddressBox} onClick={handleClick}>
|
|
29
29
|
<div class={css.boxTextLayout}>
|
|
30
|
-
<div class={css.boxTitle}
|
|
31
|
-
{title}
|
|
32
|
-
</div>
|
|
30
|
+
<div class={css.boxTitle}>{title}</div>
|
|
33
31
|
{description && <div class={css.boxDescription}>{description}</div>}
|
|
34
32
|
</div>
|
|
35
|
-
<img class={css.arrowRight} src={imgArrowRight}
|
|
33
|
+
<img class={css.arrowRight} src={imgArrowRight} />
|
|
36
34
|
</div>
|
|
37
35
|
<i class={css.straightLine} />
|
|
38
36
|
</div>
|
|
@@ -59,6 +59,7 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
59
59
|
const setCenterPlaceByUserSpecified = (place: Place) => {
|
|
60
60
|
centerSource.source = "api";
|
|
61
61
|
setPlace(place);
|
|
62
|
+
updateCity(place);
|
|
62
63
|
updateRecomandPlace();
|
|
63
64
|
};
|
|
64
65
|
const setCenterByPlace = (place: Place) => {
|
|
@@ -101,39 +102,45 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
101
102
|
emit("changeByDrag", point);
|
|
102
103
|
},
|
|
103
104
|
});
|
|
104
|
-
const {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
105
|
+
const {
|
|
106
|
+
updatePlace,
|
|
107
|
+
setPlace,
|
|
108
|
+
updateCity,
|
|
109
|
+
updateRecomandPlace,
|
|
110
|
+
placeCandidates,
|
|
111
|
+
availableRef,
|
|
112
|
+
} = useMapRecomendPlace({
|
|
113
|
+
pointRef: centerPoint,
|
|
114
|
+
context: centerSource,
|
|
115
|
+
getRecomendPlace,
|
|
116
|
+
getLimit: (context) => {
|
|
117
|
+
const source = context?.source;
|
|
118
|
+
switch (source) {
|
|
119
|
+
case "drag":
|
|
120
|
+
case "api":
|
|
121
|
+
return RECOMMEND_PLACE_LIMIT;
|
|
122
|
+
case "geo":
|
|
123
|
+
case "default":
|
|
124
|
+
return Infinity;
|
|
125
|
+
default:
|
|
126
|
+
throw new Error(`MyError: should not call getLimit on source: ${source}`);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
onChangePlace: (place) => {
|
|
130
|
+
if (centerSource.source !== "recomend") {
|
|
131
|
+
updateRecomandPlace();
|
|
132
|
+
}
|
|
133
|
+
emit("changePlace", place);
|
|
134
|
+
},
|
|
135
|
+
onChange: (place) => {
|
|
136
|
+
centerSource.source = "recomend";
|
|
137
|
+
Object.assign(centerPlace, { ...place });
|
|
138
|
+
emit("changeRecomandPlace", place);
|
|
139
|
+
},
|
|
140
|
+
onChangeCity: (value) => {
|
|
141
|
+
emit("changeCity", value);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
137
144
|
watchEffect(() => {
|
|
138
145
|
mapContext.onChangeCenterPlace({ ...centerPlace });
|
|
139
146
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ref, watch } from "vue-demi";
|
|
2
2
|
import type { AutoCompletePlace, Region } from "../types/interface";
|
|
3
|
+
import { useGeoLocation } from "./useGeoLocation";
|
|
4
|
+
import { useMapGeometry } from "./useMapGeometry";
|
|
3
5
|
import { MapLogProps, useMapLogVariable } from "./useMapLog";
|
|
4
6
|
import { useMapSupplier } from "./useMapSupplier";
|
|
5
7
|
import { useUpdate } from "./useUdate";
|
|
@@ -13,6 +15,8 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
13
15
|
const cityRef = ref(city);
|
|
14
16
|
useMapLogVariable(props, "useAmapAutoComplete", cityRef, "cityRef");
|
|
15
17
|
const { readyPromise } = useMapSupplier();
|
|
18
|
+
const { apiMapDistance } = useMapGeometry();
|
|
19
|
+
const { geoPosition } = useGeoLocation();
|
|
16
20
|
const keywordRef = ref("");
|
|
17
21
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
18
22
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -31,15 +35,20 @@ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
31
35
|
await readyPromise;
|
|
32
36
|
const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
|
|
33
37
|
amapPlaceSearch.search(keywordRef.value, (status, result) => {
|
|
38
|
+
const from = geoPosition.value;
|
|
34
39
|
switch (status) {
|
|
35
40
|
case "complete": {
|
|
36
41
|
autoCompletePlacesRef.value = (result as AMap.PlaceSearchResult).poiList.pois.map(
|
|
37
|
-
(poi) =>
|
|
38
|
-
lat
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
(poi) => {
|
|
43
|
+
const { lat, lng } = poi.location;
|
|
44
|
+
return {
|
|
45
|
+
lat,
|
|
46
|
+
lng,
|
|
47
|
+
name: poi.name,
|
|
48
|
+
description: poi.address,
|
|
49
|
+
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
);
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
@@ -62,6 +71,8 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
62
71
|
const { city } = props;
|
|
63
72
|
const cityRef = ref({ ...city });
|
|
64
73
|
const { readyPromise } = useMapSupplier();
|
|
74
|
+
const { apiMapDistance } = useMapGeometry();
|
|
75
|
+
const { geoPosition } = useGeoLocation();
|
|
65
76
|
const keywordRef = ref("");
|
|
66
77
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
67
78
|
const { update, idx: updateKey } = useUpdate();
|
|
@@ -86,16 +97,20 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
86
97
|
bounds: cityRef.value.bound,
|
|
87
98
|
},
|
|
88
99
|
(result, status) => {
|
|
100
|
+
const from = geoPosition.value;
|
|
89
101
|
switch (status) {
|
|
90
102
|
case google.maps.places.PlacesServiceStatus.OK:
|
|
91
|
-
autoCompletePlacesRef.value = result!.map(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
autoCompletePlacesRef.value = result!.map(({ geometry, name, formatted_address }) => {
|
|
104
|
+
const lng = geometry?.location?.lng() ?? 0;
|
|
105
|
+
const lat = geometry?.location?.lat() ?? 0;
|
|
106
|
+
return {
|
|
107
|
+
lng,
|
|
108
|
+
lat,
|
|
95
109
|
name: name ?? "",
|
|
96
110
|
description: formatted_address ?? "",
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
distance: from ? apiMapDistance(from, [lng, lat]) : undefined,
|
|
112
|
+
};
|
|
113
|
+
});
|
|
99
114
|
return;
|
|
100
115
|
case google.maps.places.PlacesServiceStatus.ZERO_RESULTS:
|
|
101
116
|
case google.maps.places.PlacesServiceStatus.NOT_FOUND:
|
package/src/hooks/useMapPlace.ts
CHANGED
|
@@ -25,6 +25,17 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
|
|
|
25
25
|
name: "",
|
|
26
26
|
});
|
|
27
27
|
const { idx: placeKey, update } = useUpdate();
|
|
28
|
+
const updateCity = (value: Place) => {
|
|
29
|
+
const geocoder = new AMap.Geocoder({ lang: LANGUAGE });
|
|
30
|
+
const { lng, lat } = value;
|
|
31
|
+
geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
|
|
32
|
+
if (status !== "complete") return;
|
|
33
|
+
const { addressComponent } = (result as AMap.ReGeocoderResult).regeocode;
|
|
34
|
+
const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
|
|
35
|
+
const cityParentName = addressComponent.province;
|
|
36
|
+
onChangeCity?.({ cityName, cityParentName });
|
|
37
|
+
});
|
|
38
|
+
};
|
|
28
39
|
const updatePlace = (value: Point) => {
|
|
29
40
|
pointRef.value = value;
|
|
30
41
|
update();
|
|
@@ -67,7 +78,7 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
|
|
|
67
78
|
});
|
|
68
79
|
}
|
|
69
80
|
);
|
|
70
|
-
return { place, updatePlace, setPlace };
|
|
81
|
+
return { place, updatePlace, setPlace, updateCity };
|
|
71
82
|
};
|
|
72
83
|
|
|
73
84
|
export const useGmapPlace = (props: UseMapPlaceProps) => {
|
|
@@ -84,6 +95,14 @@ export const useGmapPlace = (props: UseMapPlaceProps) => {
|
|
|
84
95
|
place.lat = value.lat;
|
|
85
96
|
place.name = value.name;
|
|
86
97
|
};
|
|
98
|
+
const updateCity = async (value: Place) => {
|
|
99
|
+
const geocoder = new google.maps.Geocoder();
|
|
100
|
+
const { lng, lat } = value;
|
|
101
|
+
const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
|
|
102
|
+
const cityName = geocoderResult2cityName(results[0]);
|
|
103
|
+
const cityParentName = results.slice(-2)[0].address_components[0].long_name;
|
|
104
|
+
onChangeCity?.({ cityName, cityParentName });
|
|
105
|
+
};
|
|
87
106
|
watch(
|
|
88
107
|
() => placeKey.value,
|
|
89
108
|
async () => {
|
|
@@ -102,7 +121,7 @@ export const useGmapPlace = (props: UseMapPlaceProps) => {
|
|
|
102
121
|
onChangeCity?.({ cityName, cityParentName });
|
|
103
122
|
}
|
|
104
123
|
);
|
|
105
|
-
return { place, updatePlace, setPlace };
|
|
124
|
+
return { place, updatePlace, setPlace, updateCity };
|
|
106
125
|
};
|
|
107
126
|
|
|
108
127
|
export const useMapPlace = (props: UseMapPlaceProps) => {
|
|
@@ -46,7 +46,7 @@ export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
46
46
|
const placeCandidatesRef = ref<Place[]>([]);
|
|
47
47
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
48
48
|
const { readyPromise } = useMapSupplier();
|
|
49
|
-
const { place, updatePlace, setPlace } = useAmapPlace({
|
|
49
|
+
const { place, updatePlace, setPlace, updateCity } = useAmapPlace({
|
|
50
50
|
pointRef,
|
|
51
51
|
onChange: onChangePlace,
|
|
52
52
|
onChangeCity,
|
|
@@ -80,6 +80,7 @@ export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
80
80
|
updateRecomandPlace,
|
|
81
81
|
updatePlace,
|
|
82
82
|
setPlace,
|
|
83
|
+
updateCity,
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
86
|
|
|
@@ -90,7 +91,7 @@ export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
90
91
|
const placeCandidatesRef = ref<Place[]>([]);
|
|
91
92
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
92
93
|
const { readyPromise } = useMapSupplier();
|
|
93
|
-
const { place, updatePlace, setPlace } = useGmapPlace({
|
|
94
|
+
const { place, updatePlace, setPlace, updateCity } = useGmapPlace({
|
|
94
95
|
pointRef,
|
|
95
96
|
onChange: onChangePlace,
|
|
96
97
|
onChangeCity,
|
|
@@ -124,6 +125,7 @@ export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
124
125
|
updateRecomandPlace,
|
|
125
126
|
updatePlace,
|
|
126
127
|
setPlace,
|
|
128
|
+
updateCity,
|
|
127
129
|
};
|
|
128
130
|
};
|
|
129
131
|
|
package/src/types/interface.ts
CHANGED
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.
|
|
25
|
-
3. 用户地址搜索,先设置台湾,搜个结果,然后切换城市到新加坡,搜索到结果依然是台湾
|
|
21
|
+
2. 用户地址搜索,先设置台湾,搜个结果,然后切换城市到新加坡,搜索到结果依然是台湾
|