@heycar/heycars-map 0.3.3 → 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.
@@ -13,6 +13,7 @@ export type Place = {
13
13
  export interface AutoCompletePlace extends Place {
14
14
  placeId?: string;
15
15
  description: string;
16
+ distance?: number;
16
17
  }
17
18
  export type Region = {
18
19
  bound?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
@@ -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 (
@@ -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: poi.location.lat,
39
- lng: poi.location.lng,
40
- name: poi.name,
41
- description: poi.address,
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
- ({ geometry, name, formatted_address }) => ({
93
- lng: geometry?.location?.lng() ?? 0,
94
- lat: geometry?.location?.lat() ?? 0,
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:
@@ -14,6 +14,7 @@ export type Place = {
14
14
  export interface AutoCompletePlace extends Place {
15
15
  placeId?: string;
16
16
  description: string;
17
+ distance?: number;
17
18
  }
18
19
 
19
20
  export type Region = {