@heycar/heycars-map 0.3.0 → 0.3.1

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.
@@ -1,15 +1,17 @@
1
1
  import { ref, watch } from "vue-demi";
2
2
  import type { AutoCompletePlace, City } from "../types/interface";
3
+ import { MapLogProps, useMapLogVariable } from "./useMapLog";
3
4
  import { useMapSupplier } from "./useMapSupplier";
4
5
  import { useUpdate } from "./useUdate";
5
6
 
6
- export interface UseMapAutoCompleteProps {
7
+ export interface UseMapAutoCompleteProps extends MapLogProps {
7
8
  city: City;
8
9
  }
9
10
 
10
11
  export const useAmapAutoComplete = (props: UseMapAutoCompleteProps) => {
11
12
  const { city } = props;
12
13
  const cityRef = ref(city);
14
+ useMapLogVariable(props, "useAmapAutoComplete", cityRef, "cityRef");
13
15
  const { readyPromise } = useMapSupplier();
14
16
  const keywordRef = ref("");
15
17
  const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
@@ -4,9 +4,21 @@ export interface MapLogProps {
4
4
  log?: boolean;
5
5
  }
6
6
 
7
- export const useMapLog = <P extends MapLogProps>(props: P, name: string) => {
7
+ export const useMapLog = <P extends MapLogProps>(props: P, prefix: string) => {
8
8
  watchEffect(() => {
9
9
  if (!props.log) return;
10
- console.log(`log ${name} props = `, { ...props });
10
+ console.log(`log ${prefix} props = `, { ...props });
11
+ });
12
+ };
13
+
14
+ export const useMapLogVariable = <P extends MapLogProps>(
15
+ props: P,
16
+ prefix: string,
17
+ variable: any,
18
+ name: string
19
+ ) => {
20
+ watchEffect(() => {
21
+ if (!props.log) return;
22
+ console.log(`log ${prefix} ${name} = `, { ...variable });
11
23
  });
12
24
  };
@@ -34,12 +34,14 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
34
34
  ? addressComponent.city
35
35
  : addressComponent.province;
36
36
  const countryName = addressComponent.country;
37
+ const cityParentName = addressComponent.province;
37
38
  place.name = name;
38
39
  place.lng = lng;
39
40
  place.lat = lat;
40
41
  place.cityName = cityName;
42
+ place.cityParentName = cityParentName;
41
43
  place.countryName = countryName;
42
- onChange?.({ lng, lat, name, cityName, countryName });
44
+ onChange?.({ lng, lat, name, cityName, cityParentName, countryName });
43
45
  return;
44
46
  }
45
47
 
@@ -70,13 +72,15 @@ export const useGmapPlace = (props: UseMapPlaceProps) => {
70
72
  const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
71
73
  const name = results[0].formatted_address;
72
74
  const cityName = geocoderResult2cityName(results[0]);
75
+ const cityParentName = results.slice(-2)[0].address_components[0].long_name;
73
76
  const countryName = results.slice(-1)[0].address_components[0].long_name;
74
77
  place.lng = lng;
75
78
  place.lat = lat;
76
79
  place.name = name;
77
80
  place.cityName = cityName;
81
+ place.cityParentName = cityParentName;
78
82
  place.countryName = countryName;
79
- onChange?.({ lng, lat, name, cityName, countryName });
83
+ onChange?.({ lng, lat, name, cityName, cityParentName, countryName });
80
84
  }
81
85
  );
82
86
  return { place, updatePlace };
@@ -1,8 +1,9 @@
1
1
  import type { Ref } from "vue-demi";
2
2
  import { useMapAutoComplete } from "../hooks/useMapAutoComplete";
3
3
  import { useMapBoundCity } from "../hooks/useMapCityBound";
4
+ import type { MapLogProps } from "../hooks/useMapLog";
4
5
 
5
- export interface UseBusinessMapAutoCompleteProps {
6
+ export interface UseBusinessMapAutoCompleteProps extends MapLogProps {
6
7
  cityNameRef: Ref<string>;
7
8
  }
8
9
 
@@ -12,7 +13,7 @@ export const useBusinessMapAutoComplete = (props: UseBusinessMapAutoCompleteProp
12
13
  cityNameRef,
13
14
  onChange: (v) => setCity(v),
14
15
  });
15
- const { autoCompletePlaces, setKeyword, setCity } = useMapAutoComplete({ city });
16
+ const { autoCompletePlaces, setKeyword, setCity } = useMapAutoComplete({ city, log: props.log });
16
17
  const handleKeywordInput = (e: Event) => {
17
18
  const target = e.target as HTMLInputElement;
18
19
  setKeyword(target.value);
@@ -7,6 +7,7 @@ export type Place = {
7
7
  lat: number;
8
8
  name: string;
9
9
  cityName?: string;
10
+ cityParentName?: string;
10
11
  countryName?: string;
11
12
  };
12
13