@heycar/heycars-map 0.1.7 → 0.1.9

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.
Files changed (41) hide show
  1. package/dist/business-components/WalkingRoute/WalkingRoute.d.ts +13 -0
  2. package/dist/business-components/WalkingRoute/index.d.ts +1 -0
  3. package/dist/components/Demo/HeycarDemo.d.ts +1 -0
  4. package/dist/components/Demo/SearchDemo.d.ts +1 -0
  5. package/dist/components/Demo/country.d.ts +5 -0
  6. package/dist/components/Demo/searchResult.d.ts +8 -0
  7. package/dist/hooks/useGeoLocation.d.ts +8 -4
  8. package/dist/hooks/useMapAutoComplete.d.ts +42 -0
  9. package/dist/hooks/useMapCityBound.d.ts +10 -0
  10. package/dist/hooks/useMapPlace.d.ts +3 -0
  11. package/dist/hooks/useMapRecomendPlace.d.ts +6 -0
  12. package/dist/hooks/useWalkingRoute.d.ts +9 -0
  13. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +17 -0
  14. package/dist/hooks-business/useBusinessMapRecomendPlace.d.ts +17 -2
  15. package/dist/index.cjs +52 -52
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.js +1223 -987
  18. package/dist/types/interface.d.ts +14 -0
  19. package/dist/utils/transform.d.ts +1 -0
  20. package/package.json +1 -1
  21. package/src/App.tsx +1 -0
  22. package/src/business-components/WalkingRoute/WalkingRoute.tsx +48 -0
  23. package/src/business-components/WalkingRoute/index.ts +1 -0
  24. package/src/components/Demo/HeycarDemo.tsx +65 -19
  25. package/src/components/Demo/SearchDemo.tsx +167 -0
  26. package/src/components/Demo/country.ts +4179 -0
  27. package/src/components/Demo/searchResult.ts +8235 -0
  28. package/src/hooks/useDrivingRoute.ts +1 -1
  29. package/src/hooks/useGeoLocation.ts +37 -24
  30. package/src/hooks/useMapAutoComplete.ts +116 -0
  31. package/src/hooks/useMapCityBound.ts +52 -0
  32. package/src/hooks/useMapPlace.ts +14 -5
  33. package/src/hooks/useWalkingRoute.ts +70 -0
  34. package/src/hooks-business/useBusinessMapAutoComplete.ts +15 -0
  35. package/src/hooks-business/useBusinessMapRecomendPlace.ts +45 -13
  36. package/src/index.ts +3 -1
  37. package/src/types/amap/place.d.ts +1 -1
  38. package/src/types/amap/walking.d.ts +3 -1
  39. package/src/types/interface.ts +16 -0
  40. package/src/utils/transform.ts +13 -0
  41. package/todo.md +3 -0
@@ -55,7 +55,7 @@ export const useGDrivingRoute = (props: UseDrivingRouteProps) => {
55
55
  .route({
56
56
  origin: { lng: from[0], lat: from[1] },
57
57
  destination: { lng: to[0], lat: to[1] },
58
- travelMode: google.maps.TravelMode.WALKING,
58
+ travelMode: google.maps.TravelMode.DRIVING,
59
59
  })
60
60
  .then((result) => {
61
61
  let path: Point[] = [];
@@ -1,12 +1,13 @@
1
- import { ref, watchEffect } from "vue-demi";
1
+ import { ref, watch } from "vue-demi";
2
2
  import type { MapShallowRef, Point } from "../types/interface";
3
3
 
4
4
  export interface UseGeoLocationProps {
5
5
  mapRef: MapShallowRef;
6
6
  onChange?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
7
+ onLoad?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
7
8
  }
8
9
  export const useGeoLocation = (props: UseGeoLocationProps) => {
9
- const { mapRef, onChange } = props;
10
+ const { onChange, onLoad } = props;
10
11
  const loading = ref(false);
11
12
  const errorRef = ref<GeolocationPositionError>();
12
13
  const coordinateRef = ref<GeolocationCoordinates>({
@@ -19,26 +20,38 @@ export const useGeoLocation = (props: UseGeoLocationProps) => {
19
20
  speed: 0,
20
21
  });
21
22
  const positionRef = ref<Point>([coordinateRef.value.longitude, coordinateRef.value.latitude]);
22
- watchEffect(() => {
23
- mapRef.value;
24
- loading.value = true;
25
- navigator.geolocation.getCurrentPosition(
26
- (position) => {
27
- loading.value = false;
28
- const coordinate = position.coords;
29
- const point: Point = [position.coords.longitude, position.coords.latitude];
30
- coordinateRef.value = coordinate;
31
- positionRef.value = point;
32
- onChange?.({ position: point, coordinate });
33
- },
34
- (error) => {
35
- loading.value = false;
36
- errorRef.value = error;
37
- console.log("errorRef = ", errorRef);
38
- }
39
- // todo 要不要 timeout
40
- // { timeout: 5000 * 1000 }
41
- );
42
- });
43
- return { errorRef, positionRef, coordinateRef, loading };
23
+ watch(
24
+ () => true,
25
+ (_1, _2, onCleanup) => {
26
+ loading.value = true;
27
+ const watchId = navigator.geolocation.watchPosition(
28
+ (position) => {
29
+ const coordinate = position.coords;
30
+ const point: Point = [position.coords.longitude, position.coords.latitude];
31
+ coordinateRef.value = coordinate;
32
+ positionRef.value = point;
33
+ if (loading.value) {
34
+ loading.value = false;
35
+ onLoad?.({ position: point, coordinate });
36
+ }
37
+ onChange?.({ position: point, coordinate });
38
+ },
39
+ (error) => {
40
+ loading.value = false;
41
+ errorRef.value = error;
42
+ console.log("errorRef = ", errorRef);
43
+ },
44
+ // todo 要不要 timeout
45
+ { timeout: 5000, maximumAge: 0, enableHighAccuracy: true }
46
+ );
47
+ onCleanup(() => navigator.geolocation.clearWatch(watchId));
48
+ },
49
+ { immediate: true }
50
+ );
51
+ return {
52
+ geoError: errorRef,
53
+ geoPosition: positionRef,
54
+ geoCoordinate: coordinateRef,
55
+ geoLoading: loading,
56
+ };
44
57
  };
@@ -0,0 +1,116 @@
1
+ import { ref, watch } from "vue-demi";
2
+ import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
3
+ import type { AutoCompletePlace, City, MapShallowRef } from "../types/interface";
4
+ import { useMapReady } from "./useMapReady";
5
+ import { useUpdate } from "./useUdate";
6
+
7
+ export interface UseMapAutoCompleteProps<M = AMap.Map | google.maps.Map> {
8
+ mapRef: MapShallowRef<M>;
9
+ city: City;
10
+ }
11
+
12
+ export const useAmapAutoComplete = (props: UseMapAutoCompleteProps<AMap.Map>) => {
13
+ const { city, mapRef } = props;
14
+ const cityRef = ref(city);
15
+ const { readyRef } = useMapReady(mapRef);
16
+ const keywordRef = ref("");
17
+ const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
18
+ const { update, idx: updateKey } = useUpdate();
19
+ const setCity = (value: City) => {
20
+ cityRef.value = value;
21
+ update();
22
+ };
23
+ const setKeyword = (value: string) => {
24
+ keywordRef.value = value;
25
+ update();
26
+ };
27
+ watch(
28
+ () => updateKey.value,
29
+ () => {
30
+ if (!readyRef.value) return;
31
+ const amapPlaceSearch = new AMap.PlaceSearch({ city: cityRef.value.name });
32
+ amapPlaceSearch.search(keywordRef.value, (status, result) => {
33
+ console.log("status, result = ", status, result);
34
+ switch (status) {
35
+ case "complete": {
36
+ 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
+ })
43
+ );
44
+ return;
45
+ }
46
+ case "no_data":
47
+ autoCompletePlacesRef.value = [];
48
+ return;
49
+ default:
50
+ throw result;
51
+ }
52
+ });
53
+ },
54
+ {
55
+ immediate: true,
56
+ }
57
+ );
58
+ return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
59
+ };
60
+
61
+ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps<google.maps.Map>) => {
62
+ const { city, mapRef } = props;
63
+ const cityRef = ref(city);
64
+ const { readyRef } = useMapReady(mapRef);
65
+ const keywordRef = ref("");
66
+ const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
67
+ const { update, idx: updateKey } = useUpdate();
68
+ const setCity = (value: City) => {
69
+ cityRef.value = value;
70
+ update();
71
+ };
72
+ const setKeyword = (value: string) => {
73
+ keywordRef.value = value;
74
+ update();
75
+ };
76
+ const div = document.createElement("div");
77
+ watch(
78
+ () => updateKey.value,
79
+ async () => {
80
+ if (!readyRef.value || !keywordRef.value) return;
81
+ const gmapPlacesService = new google.maps.places.PlacesService(div);
82
+ gmapPlacesService.textSearch(
83
+ {
84
+ query: keywordRef.value,
85
+ bounds: cityRef.value.bound,
86
+ },
87
+ (result, status) => {
88
+ switch (status) {
89
+ case google.maps.places.PlacesServiceStatus.OK:
90
+ autoCompletePlacesRef.value = result!.map(
91
+ ({ geometry, name, formatted_address }) => ({
92
+ lng: geometry?.location?.lng() ?? 0,
93
+ lat: geometry?.location?.lat() ?? 0,
94
+ name: name ?? "",
95
+ description: formatted_address ?? "",
96
+ })
97
+ );
98
+ return;
99
+ case google.maps.places.PlacesServiceStatus.ZERO_RESULTS:
100
+ case google.maps.places.PlacesServiceStatus.NOT_FOUND:
101
+ autoCompletePlacesRef.value = [];
102
+ return;
103
+ }
104
+ }
105
+ );
106
+ }
107
+ );
108
+ return { setKeyword, setCity, autoCompletePlaces: autoCompletePlacesRef };
109
+ };
110
+
111
+ export const useMapAutoComplete = (props: UseMapAutoCompleteProps) => {
112
+ const { supplier } = useMapSupplier();
113
+ return supplier === "gmap"
114
+ ? useGmapAutoComplete(props as UseMapAutoCompleteProps<google.maps.Map>)
115
+ : useAmapAutoComplete(props as UseMapAutoCompleteProps<AMap.Map>);
116
+ };
@@ -0,0 +1,52 @@
1
+ import { reactive, watchEffect } from "vue-demi";
2
+ import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
3
+ import { LANGUAGE } from "../types/helper";
4
+ import type { City, MapShallowRef } from "../types/interface";
5
+ import { useMapReady } from "./useMapReady";
6
+
7
+ export interface UseMapCityBoundProps<M = AMap.Map | google.maps.Map> {
8
+ mapRef: MapShallowRef<M>;
9
+ cityName: string;
10
+ onChange?: (value: City) => any;
11
+ }
12
+ export const useGmapBoundCity = (props: UseMapCityBoundProps): City => {
13
+ const { mapRef, cityName, onChange } = props;
14
+ const { readyRef } = useMapReady(mapRef);
15
+ const bound = reactive<google.maps.LatLngBoundsLiteral>({
16
+ east: 0,
17
+ north: 0,
18
+ south: 0,
19
+ west: 0,
20
+ });
21
+ watchEffect(async () => {
22
+ if (!readyRef.value) return;
23
+ const geocoder = new google.maps.Geocoder();
24
+ // todo 这里不是唯一的
25
+ const { results } = await geocoder.geocode({
26
+ address: cityName,
27
+ componentRestrictions: {
28
+ administrativeArea: "administrative_area_level_1",
29
+ },
30
+ language: LANGUAGE,
31
+ });
32
+ if (results.length !== 1) {
33
+ throw new Error("MyError: multiple city found");
34
+ }
35
+ const { geometry } = results[0];
36
+ const cityBound = geometry.bounds?.toJSON() ?? geometry.viewport.toJSON();
37
+ Object.assign(bound, { ...cityBound });
38
+ onChange?.({ name: cityName, bound: cityBound });
39
+ });
40
+ return { bound, name: cityName };
41
+ };
42
+
43
+ export const useAmapBoundCity = (props: UseMapCityBoundProps): City => {
44
+ return { name: props.cityName };
45
+ };
46
+
47
+ export const useMapBoundCity = (props: UseMapCityBoundProps) => {
48
+ const { supplier } = useMapSupplier();
49
+ return supplier === "gmap"
50
+ ? useGmapBoundCity(props as UseMapCityBoundProps<google.maps.Map>)
51
+ : useAmapBoundCity(props as UseMapCityBoundProps<AMap.Map>);
52
+ };
@@ -2,7 +2,7 @@ import { reactive, Ref, watch } from "vue-demi";
2
2
  import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
3
3
  import { LANGUAGE } from "../types/helper";
4
4
  import type { MapShallowRef, Place, Point } from "../types/interface";
5
- import { pipeAsync } from "../utils/transform";
5
+ import { geocoderResult2cityName, pipeAsync } from "../utils/transform";
6
6
  import { useMapReady } from "./useMapReady";
7
7
  import { useUpdate } from "./useUdate";
8
8
 
@@ -15,7 +15,12 @@ export const useAmapPlace = (props: UseMapPlaceProps<AMap.Map>) => {
15
15
  const { mapRef, pointRef, onChange } = props;
16
16
  const { readyRef } = useMapReady(mapRef);
17
17
  const { idx: placeKey, update: updatePlace } = useUpdate();
18
- const place = reactive<Place>({ lng: pointRef.value[0], lat: pointRef.value[1], name: "" });
18
+ const place = reactive<Place>({
19
+ lng: pointRef.value[0],
20
+ lat: pointRef.value[1],
21
+ name: "",
22
+ cityName: undefined,
23
+ });
19
24
  watch(
20
25
  () => placeKey.value,
21
26
  () => {
@@ -25,11 +30,14 @@ export const useAmapPlace = (props: UseMapPlaceProps<AMap.Map>) => {
25
30
  geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
26
31
  switch (status) {
27
32
  case "complete": {
28
- const name = (result as AMap.ReGeocoderResult).regeocode.formattedAddress;
33
+ const { formattedAddress: name, addressComponent } = (result as AMap.ReGeocoderResult)
34
+ .regeocode;
35
+ const cityName = addressComponent.city ?? addressComponent.province;
29
36
  place.name = name;
30
37
  place.lng = lng;
31
38
  place.lat = lat;
32
- pipeAsync(onChange)?.({ lng, lat, name });
39
+ place.cityName = cityName;
40
+ pipeAsync(onChange)?.({ lng, lat, name, cityName });
33
41
  return;
34
42
  }
35
43
 
@@ -59,10 +67,11 @@ export const useGmapPlace = (props: UseMapPlaceProps<google.maps.Map>) => {
59
67
  const [lng, lat] = pointRef.value;
60
68
  const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
61
69
  const name = results[0].formatted_address;
70
+ const cityName = geocoderResult2cityName(results[0]);
62
71
  place.name = name;
63
72
  place.lng = lng;
64
73
  place.lat = lat;
65
- pipeAsync(onChange)?.({ lng, lat, name });
74
+ pipeAsync(onChange)?.({ lng, lat, name, cityName });
66
75
  }
67
76
  );
68
77
  return { place, updatePlace };
@@ -0,0 +1,70 @@
1
+ import { ShallowRef, shallowRef } from "vue-demi";
2
+ import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
3
+ import type { Point } from "../types/interface";
4
+ import { watchPostEffectForDeepOption } from "../utils/compare";
5
+
6
+ export interface UseWalkingRouteProps {
7
+ from: Point;
8
+ to: Point;
9
+ }
10
+
11
+ export const useAWalkingRoute = (props: UseWalkingRouteProps) => {
12
+ const pathRef = shallowRef<Point[]>([]);
13
+ const amapWalking = new AMap.Walking({});
14
+ watchPostEffectForDeepOption(
15
+ () => ({ ...props }),
16
+ ({ from, to }) => {
17
+ amapWalking.search(AMap.LngLat.from(from), AMap.LngLat.from(to), (status, result) => {
18
+ switch (status) {
19
+ case "complete": {
20
+ let path: Point[] = [];
21
+ const walkingResult = result as AMap.WalkingResult;
22
+ for (const route of walkingResult.routes) {
23
+ for (const step of route.steps) {
24
+ const stepPath = step.path.map<Point>(({ lng, lat }) => [lng, lat]);
25
+ path = path.concat(stepPath);
26
+ }
27
+ }
28
+ pathRef.value = path;
29
+ return;
30
+ }
31
+ case "no_data":
32
+ return;
33
+ default:
34
+ throw result;
35
+ }
36
+ });
37
+ }
38
+ );
39
+ return pathRef;
40
+ };
41
+
42
+ export const useGWalkingRoute = (props: UseWalkingRouteProps) => {
43
+ const pathRef = shallowRef<Point[]>([]);
44
+ const gmapDirectionsService = new google.maps.DirectionsService();
45
+ watchPostEffectForDeepOption(
46
+ () => ({ ...props }),
47
+ ({ from, to }) => {
48
+ gmapDirectionsService
49
+ .route({
50
+ origin: { lng: from[0], lat: from[1] },
51
+ destination: { lng: to[0], lat: to[1] },
52
+ travelMode: google.maps.TravelMode.WALKING,
53
+ })
54
+ .then((result) => {
55
+ let path: Point[] = [];
56
+ result.routes.map((route) => {
57
+ const stepPath = route.overview_path.map<Point>((item) => [item.lng(), item.lat()]);
58
+ path = path.concat(stepPath);
59
+ });
60
+ pathRef.value = path;
61
+ });
62
+ }
63
+ );
64
+ return pathRef;
65
+ };
66
+
67
+ export const useWalkingRoute = (props: UseWalkingRouteProps): ShallowRef<Point[]> => {
68
+ const { supplier } = useMapSupplier();
69
+ return supplier === "gmap" ? useGWalkingRoute(props) : useAWalkingRoute(props);
70
+ };
@@ -0,0 +1,15 @@
1
+ import { useMapAutoComplete } from "../hooks/useMapAutoComplete";
2
+ import { useMapBoundCity } from "../hooks/useMapCityBound";
3
+ import type { MapShallowRef } from "../types/interface";
4
+
5
+ export interface UseBusinessMapAutoCompleteProps {
6
+ mapRef: MapShallowRef;
7
+ defaultCityName: string;
8
+ }
9
+
10
+ export const useBusinessMapAutoComplete = (props: UseBusinessMapAutoCompleteProps) => {
11
+ const { mapRef, defaultCityName } = props;
12
+ const city = useMapBoundCity({ mapRef, cityName: defaultCityName, onChange: (v) => setCity(v) });
13
+ const { autoCompletePlaces, setKeyword, setCity } = useMapAutoComplete({ mapRef, city });
14
+ return { autoCompletePlaces, setKeyword, setCity };
15
+ };
@@ -6,43 +6,70 @@ import { useMapRecomendPlace, UseMapRecomendPlaceProps } from "../hooks/useMapRe
6
6
  import type { Place, Point } from "../types/interface";
7
7
 
8
8
  interface CenterPlaceSource {
9
- source: "geo" | "drag" | "recomend";
9
+ source: "default" | "geo" | "drag" | "recomend" | "api";
10
10
  }
11
11
  export interface UseBusinessMapRecomendPlaceProps
12
12
  extends Pick<
13
13
  UseMapRecomendPlaceProps<AMap.Map | google.maps.Map, CenterPlaceSource>,
14
14
  "getRecomendPlace" | "mapRef"
15
15
  > {
16
+ defaultCenterPoint?: Point;
16
17
  recomendPlaceGeoLimit: number;
17
18
  recomendPlaceDragLimit: number;
19
+ onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
18
20
  onChangeByDrag?: UseMapDragProps["onChange"];
19
21
  onChangeGeoLocation?: UseGeoLocationProps["onChange"];
20
22
  onChangePlace?: UseMapPlaceProps["onChange"];
21
23
  onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
22
24
  }
23
25
  export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlaceProps) => {
24
- const centerPlace = reactive<Place>({ lng: 0, lat: 0, name: "" });
25
- const centerPoint = computed<Point>(() => [centerPlace.lng, centerPlace.lat]);
26
- const centerSource: CenterPlaceSource = { source: "geo" };
27
26
  const {
28
27
  mapRef,
29
28
  getRecomendPlace,
29
+ defaultCenterPoint,
30
30
  recomendPlaceDragLimit,
31
31
  recomendPlaceGeoLimit,
32
+ onLoadGeoLocation,
32
33
  onChangeByDrag,
33
34
  onChangeGeoLocation,
34
35
  onChangePlace,
35
36
  onChangeRecomandPlace,
36
37
  } = props;
37
- const { loading, errorRef } = useGeoLocation({
38
- mapRef,
39
- onChange: (value) => {
40
- centerSource.source = "geo";
41
- centerPlace.lng = value.position[0];
42
- centerPlace.lat = value.position[1];
38
+ const centerPlace = reactive<Place>({
39
+ lng: defaultCenterPoint?.[0] ?? 0,
40
+ lat: defaultCenterPoint?.[1] ?? 0,
41
+ name: "",
42
+ cityName: undefined,
43
+ });
44
+ const centerPoint = computed<Point>(() => [centerPlace.lng, centerPlace.lat]);
45
+ const centerSource: CenterPlaceSource = { source: "geo" };
46
+ const setCenterPlaceByRecomand = (point: Point) => {
47
+ centerSource.source = "api";
48
+ centerPlace.lng = point[0];
49
+ centerPlace.lat = point[1];
50
+ updatePlace();
51
+ };
52
+ if (defaultCenterPoint) {
53
+ // default 主入口
54
+ Promise.resolve().then(() => {
55
+ centerSource.source = "default";
43
56
  updatePlace();
44
- onChangeGeoLocation?.(value);
57
+ });
58
+ }
59
+ const { geoLoading, geoError, geoPosition, geoCoordinate } = useGeoLocation({
60
+ mapRef,
61
+ onLoad: (value) => {
62
+ // geo 主入口
63
+ // 如果设置了默认位置,就不在拿 gps 作为默认位置
64
+ if (!defaultCenterPoint) {
65
+ centerSource.source = "geo";
66
+ centerPlace.lng = value.position[0];
67
+ centerPlace.lat = value.position[1];
68
+ updatePlace();
69
+ }
70
+ onLoadGeoLocation?.(value);
45
71
  },
72
+ onChange: onChangeGeoLocation,
46
73
  });
47
74
  const { isDragging } = useMapDrag({
48
75
  mapRef,
@@ -62,8 +89,10 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
62
89
  const source = context?.source;
63
90
  switch (source) {
64
91
  case "drag":
92
+ case "api":
65
93
  return recomendPlaceDragLimit;
66
94
  case "geo":
95
+ case "default":
67
96
  return recomendPlaceGeoLimit;
68
97
  default:
69
98
  throw new Error(`MyError: should not call getLimit on source: ${source}`);
@@ -86,10 +115,13 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
86
115
  });
87
116
  return {
88
117
  isDragging,
89
- isGeoLoading: loading,
90
- geoError: errorRef,
118
+ geoLoading,
119
+ geoError,
120
+ geoPosition,
121
+ geoCoordinate,
91
122
  centerPlace,
92
123
  centerPoint,
93
124
  placeCandidates,
125
+ setCenterPlaceByRecomand,
94
126
  };
95
127
  };
package/src/index.ts CHANGED
@@ -8,9 +8,11 @@ export { PlaceCircle } from "./business-components/PlaceCircle";
8
8
  export { StartEndPoint } from "./business-components/StartEndPoint";
9
9
  export { TaxiCar } from "./business-components/TaxiCar";
10
10
  export { WalkingLine } from "./business-components/WalkingLine";
11
+ export { WalkingRoute } from "./business-components/WalkingRoute";
11
12
  export { WaveCircle } from "./business-components/WaveCircle";
12
13
  export * from "./components/MapProvider";
13
- export { useBusinessMapRecomendPlace } from "./hooks-business/useBusinessMapRecomendPlace";
14
+ export * from "./hooks-business/useBusinessMapAutoComplete";
15
+ export * from "./hooks-business/useBusinessMapRecomendPlace";
14
16
  export { useDrivingRoute } from "./hooks/useDrivingRoute";
15
17
  export { useGeoLocation } from "./hooks/useGeoLocation";
16
18
  export { useHeycarMap } from "./hooks/useHeycarMap";
@@ -21,7 +21,7 @@ declare global {
21
21
  // 兴趣点类型
22
22
  type: string;
23
23
  // 兴趣点经纬度
24
- location: string;
24
+ location: AMap.LngLat;
25
25
  // 地址
26
26
  address: string;
27
27
  // 离中心点距离,仅周边查询返回
@@ -18,7 +18,7 @@ declare global {
18
18
  autoFitView?: boolean;
19
19
  }
20
20
 
21
- export interface WalkingRoute {
21
+ export interface WalkRoute {
22
22
  // 起点到终点总步行距离,单位:米
23
23
  distance: number;
24
24
  // 步行时间预计,单位:秒
@@ -57,6 +57,8 @@ declare global {
57
57
  end: POI;
58
58
  // 步行导航路段数目
59
59
  count: number;
60
+ // 步行规划路线列表
61
+ routes: WalkRoute[];
60
62
  }
61
63
 
62
64
  export type WalkingCallback = (
@@ -6,4 +6,20 @@ export type Place = {
6
6
  lng: number;
7
7
  lat: number;
8
8
  name: string;
9
+ cityName?: string;
10
+ };
11
+
12
+ export interface AutoCompletePlace extends Place {
13
+ placeId?: string;
14
+ description: string;
15
+ }
16
+
17
+ export type City = {
18
+ bound?: {
19
+ east: number;
20
+ north: number;
21
+ south: number;
22
+ west: number;
23
+ };
24
+ name: string;
9
25
  };
@@ -45,3 +45,16 @@ export const pipeAsync =
45
45
  (...args: P) => {
46
46
  setTimeout(() => fn?.(...args));
47
47
  };
48
+
49
+ export const geocoderResult2cityName = (value: google.maps.GeocoderResult): string | undefined => {
50
+ const { address_components } = value;
51
+ const address = address_components.find(
52
+ (item) =>
53
+ item.types[0] === "administrative_area_level_1" ||
54
+ item.types[0] === "administrative_area_level_2"
55
+ );
56
+ if (address) return address.long_name;
57
+ const countryIdx = address_components.findIndex((item) => item.types[0] === "country");
58
+ if (countryIdx > 0) return address_components[countryIdx - 1].long_name;
59
+ return undefined;
60
+ };
package/todo.md CHANGED
@@ -8,3 +8,6 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
8
8
  5. 高德地图加载期间出现大量的请求
9
9
  6. google/高德 坐标系转化
10
10
  7. 车辆行驶 fitview
11
+
12
+ 8. 缺用户定位
13
+ 9. 当用户外部进入,url 传入的地址,需要地图支持