@heycar/heycars-map 0.3.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
@@ -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} onClick={handleClick}>
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} onClick={handleClick} />
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 { updatePlace, setPlace, updateRecomandPlace, placeCandidates, availableRef } =
105
- useMapRecomendPlace({
106
- pointRef: centerPoint,
107
- context: centerSource,
108
- getRecomendPlace,
109
- getLimit: (context) => {
110
- const source = context?.source;
111
- switch (source) {
112
- case "drag":
113
- case "api":
114
- return RECOMMEND_PLACE_LIMIT;
115
- case "geo":
116
- case "default":
117
- return Infinity;
118
- default:
119
- throw new Error(`MyError: should not call getLimit on source: ${source}`);
120
- }
121
- },
122
- onChangePlace: (place) => {
123
- if (centerSource.source !== "recomend") {
124
- updateRecomandPlace();
125
- }
126
- emit("changePlace", place);
127
- },
128
- onChange: (place) => {
129
- centerSource.source = "recomend";
130
- Object.assign(centerPlace, { ...place });
131
- emit("changeRecomandPlace", place);
132
- },
133
- onChangeCity: (value) => {
134
- emit("changeCity", value);
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
  });
@@ -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/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. 用户地址搜索,先设置台湾,搜个结果,然后切换城市到新加坡,搜索到结果依然是台湾