@heycar/heycars-map 0.2.9 → 0.2.10

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 (37) hide show
  1. package/dist/Demo/DemoBusinessTaxiEnd.d.ts +4 -1
  2. package/dist/api/contants.d.ts +2 -0
  3. package/dist/business-components/AddressBox/AddressBox.d.ts +2 -1
  4. package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -1
  5. package/dist/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.d.ts +4 -3
  6. package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +2 -1
  7. package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +2 -1
  8. package/dist/business-components/PickupPoints/PickupPoints.d.ts +2 -1
  9. package/dist/components/MapProvider/MapProvider.d.ts +2 -1
  10. package/dist/hooks/useMapAutoComplete.d.ts +3 -3
  11. package/dist/hooks/useMapLog.d.ts +4 -0
  12. package/dist/hooks/useMapPlace.d.ts +3 -3
  13. package/dist/hooks/useMapRecomendPlace.d.ts +6 -6
  14. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -1
  15. package/dist/hooks-business/useBusinessRecomendPlaceMap.d.ts +2 -2
  16. package/dist/hooks-business/useLagecyMapRecomendPlace.d.ts +2 -2
  17. package/dist/index.cjs +52 -52
  18. package/dist/index.js +644 -628
  19. package/dist/types/interface.d.ts +1 -1
  20. package/dist/utils/helper.d.ts +2 -0
  21. package/package.json +1 -1
  22. package/src/App.tsx +3 -3
  23. package/src/Demo/DemoBusinessRecomendPlace.tsx +42 -12
  24. package/src/Demo/DemoBusinessTaxiEnd.tsx +34 -9
  25. package/src/api/contants.ts +3 -0
  26. package/src/business-components/AddressBox/AddressBox.tsx +4 -1
  27. package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +8 -3
  28. package/src/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.tsx +21 -11
  29. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +3 -0
  30. package/src/business-components/PassengerCircle/PassengerCircle.tsx +4 -1
  31. package/src/business-components/PickupPoints/PickupPoints.tsx +3 -1
  32. package/src/components/MapProvider/MapProvider.tsx +4 -1
  33. package/src/hooks/useMapLog.ts +12 -0
  34. package/src/hooks/useMapPlace.ts +8 -3
  35. package/src/types/amap/geocoder.d.ts +2 -0
  36. package/src/types/interface.ts +1 -1
  37. package/src/utils/helper.ts +5 -0
@@ -7,7 +7,7 @@ export type Place = {
7
7
  lat: number;
8
8
  name: string;
9
9
  cityName?: string;
10
- cityId?: string;
10
+ countryName?: string;
11
11
  };
12
12
  export interface AutoCompletePlace extends Place {
13
13
  placeId?: string;
@@ -0,0 +1,2 @@
1
+ import type { Place } from "../types/interface";
2
+ export declare const isPlace: (place: Partial<Place>) => place is Place;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
package/src/App.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineComponent } from "vue-demi";
2
2
  import { MapProvider } from "./components/MapProvider";
3
- import { DemoBusinessRecomendPlace } from "./Demo/DemoBusinessRecomendPlace";
3
+ import { DemoBusinessTaxiEnd } from "./Demo/DemoBusinessTaxiEnd";
4
4
 
5
5
  const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
6
6
  const gmapId = import.meta.env.VITE_GMAP_MAP_ID;
@@ -17,10 +17,10 @@ export const App = defineComponent({
17
17
  gmapKey={gmapApiKey}
18
18
  supplier={"amap"}
19
19
  >
20
- <DemoBusinessRecomendPlace />
20
+ {/* <DemoBusinessRecomendPlace /> */}
21
21
  {/* <DemoBusinessQuoting /> */}
22
22
  {/* <DemoBusinessTaxiService /> */}
23
- {/* <DemoBusinessTaxiEnd /> */}
23
+ <DemoBusinessTaxiEnd />
24
24
  </MapProvider>
25
25
  );
26
26
  },
@@ -14,13 +14,19 @@ const SomeAutoComplete = defineSetup(function SomeAutoComplete(props: { cityName
14
14
  });
15
15
  (window as any).setCity = setCity;
16
16
  return () => {
17
- const list = autoCompletePlaces.value.map((place) => [
18
- <input onInput={handleKeywordInput} />,
17
+ const list = autoCompletePlaces.value.map((place) => (
19
18
  <div>
20
19
  {place.lng} | {place.lat} | {place.name} | {place.description}
21
- </div>,
22
- ]);
23
- return <div>{list}</div>;
20
+ </div>
21
+ ));
22
+ return (
23
+ <div>
24
+ <div>
25
+ <input onInput={handleKeywordInput} />
26
+ </div>
27
+ {list}
28
+ </div>
29
+ );
24
30
  };
25
31
  });
26
32
 
@@ -31,6 +37,33 @@ export const DemoBusinessRecomendPlace = defineSetup(function DemoBusinessRecome
31
37
  ) => {
32
38
  const { lat, lng } = place;
33
39
  console.log("getRecomendPlace context?.source = ", context?.source);
40
+ return [
41
+ {
42
+ address: "2 College Ave West, Stephen Riady Centre, Singapore 138607",
43
+ distance: 68,
44
+ lat: 1.2961134,
45
+ lng: 103.7722912,
46
+ name: "2 College Ave West, Stephen Riady Centre, Singapore 138607",
47
+ reqFrom: "Recent",
48
+ },
49
+ {
50
+ address: "10 Architecture Drive, Singapore",
51
+ distance: 71,
52
+ lat: 1.2969847,
53
+ lng: 103.7714507,
54
+ name: "Centre for English Language Communication (CELC)",
55
+ reqFrom: "public",
56
+ },
57
+ {
58
+ address: "10 Kent Ridge Crescent, #01-02 Block AS8",
59
+ distance: 75,
60
+ lat: 1.295979,
61
+ lng: 103.7720608,
62
+ name: "The Coffee Roaster Cafe @ NUS",
63
+ reqFrom: "public",
64
+ },
65
+ ];
66
+
34
67
  return [
35
68
  { lat: lat + 0.0001, lng: lng + 0.0001, name: "place name 1" },
36
69
  { lat: lat + 0.002, lng: lng + 0.002, name: "place name 2" },
@@ -38,24 +71,21 @@ export const DemoBusinessRecomendPlace = defineSetup(function DemoBusinessRecome
38
71
  };
39
72
  const { centerPlace, placeCandidates, setCenterPlaceByRecomand, mapContext, apiMapDistance } =
40
73
  useBusinessRecomendPlaceMap();
41
- setTimeout(() => {
42
- const distance = apiMapDistance([0, 0], [1, 1]);
43
- console.log("distance = ", distance);
44
- }, 2000);
45
74
  (window as any).setCenterPlaceByRecomand = setCenterPlaceByRecomand;
46
75
  return () => {
47
76
  return (
48
77
  <div>
49
78
  placeCandidates: {placeCandidates} <br />
50
79
  centerPlace: {centerPlace.lng} | {centerPlace.lat} | {centerPlace.name} |{" "}
51
- {centerPlace.cityName} <br />
52
- <SomeAutoComplete cityName="上海市"></SomeAutoComplete>
80
+ {centerPlace.cityName} | {centerPlace.countryName} <br />
81
+ <SomeAutoComplete cityName="Taiwan"></SomeAutoComplete>
53
82
  <BusinessRecomendPlaceMap
83
+ log
54
84
  class={css.demo}
55
85
  unavailableTitle={"当前区域暂未开通服务"}
56
86
  noRecomendDescription={"附近无推荐上车地点"}
57
87
  recomendDescription={"最佳上车地点"}
58
- geoDefaultPosition={[121, 31]}
88
+ geoDefaultPosition={[103.771994, 1.296648]}
59
89
  getRecomendPlace={getRecomendPlace}
60
90
  mapContext={mapContext}
61
91
  onGeoError={(e) => console.log("onGeoError e = ", e)}
@@ -1,13 +1,38 @@
1
+ import { defineComponent } from "vue";
1
2
  import { BusinessTaxiEndMap } from "../business-components/BusinessTaxiEndMap";
2
- import { defineSetup } from "../types/helper";
3
3
  import * as css from "./Demo.css";
4
4
 
5
- export const DemoBusinessTaxiEnd = defineSetup(function DemoBusinessTaxiEnd() {
6
- return () => (
7
- <BusinessTaxiEndMap
8
- class={css.demo}
9
- from={{ lng: 121.4, lat: 31.2, name: "from place name" }}
10
- to={{ lng: 121.5, lat: 31.4, name: "to place name" }}
11
- />
12
- );
5
+ export const DemoBusinessTaxiEnd = defineComponent({
6
+ name: "DemoBusinessTaxiEnd",
7
+ data() {
8
+ return {
9
+ from: {},
10
+ to: {},
11
+ };
12
+ },
13
+ created() {
14
+ setTimeout(() => {
15
+ this.from = {
16
+ lng: 103.7719939,
17
+ lat: 1.296648,
18
+ name: "2 College Ave West, Stephen Riady Centre, Singapore 138607",
19
+ };
20
+ this.to = {
21
+ lng: 103.781421,
22
+ lat: 1.283855,
23
+ name: "虎豹别墅 (Haw Par Villa)",
24
+ };
25
+ }, 2000);
26
+ },
27
+ render() {
28
+ const { from, to } = this;
29
+ return (
30
+ <div>
31
+ <div>
32
+ {JSON.stringify(from)} | {JSON.stringify(to)}
33
+ </div>
34
+ <BusinessTaxiEndMap class={css.demo} from={from} to={to} log />
35
+ </div>
36
+ );
37
+ },
13
38
  });
@@ -0,0 +1,3 @@
1
+ import type { Point } from "../types/interface";
2
+
3
+ export const BEIJIN_POINT: Point = [116.2317, 39.5427];
@@ -3,6 +3,7 @@ import imgArrowRight from "../../assets/icons/svg/arrow-right.svg";
3
3
  import imgPlaceCircle from "../../assets/icons/svg/place-circle.svg";
4
4
  import { AmapMarker } from "../../components/AmapMarker";
5
5
  import { GmapAdvancedMarkerView } from "../../components/GmapAdvancedMarkerView/GmapAdvancedMarkerView";
6
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
6
7
  import { useMapSupplier } from "../../hooks/useMapSupplier";
7
8
  import { createElement, defineSetup } from "../../types/helper";
8
9
  import type { Point } from "../../types/interface";
@@ -11,13 +12,14 @@ import { vec2lnglat } from "../../utils/transform";
11
12
  import { AAddressLocator, GAddressLocator } from "../AddressLocator";
12
13
  import * as css from "./AddressBox.css";
13
14
 
14
- export interface AddressBoxProps {
15
+ export interface AddressBoxProps extends MapLogProps {
15
16
  type: "box" | "locator";
16
17
  position: Point;
17
18
  title: string;
18
19
  description?: string;
19
20
  }
20
21
  export const AAddressBox = defineSetup(function AAddressBox(props: AddressBoxProps) {
22
+ useMapLog(props, "AAddressBox");
21
23
  const contentRef = computed(
22
24
  () => `
23
25
  <div class="${css.addressBoxLayout}">
@@ -42,6 +44,7 @@ export const AAddressBox = defineSetup(function AAddressBox(props: AddressBoxPro
42
44
  });
43
45
 
44
46
  export const GAddressBox = defineSetup(function GAddressBox(props: AddressBoxProps) {
47
+ useMapLog(props, "GAddressBox");
45
48
  const contentRef = computed(() =>
46
49
  createDom(
47
50
  "div",
@@ -4,6 +4,7 @@ import type { BusinessRecomendPlaceContext } from "../../hooks-business/useBusin
4
4
  import { useGeoLocation, UseGeoLocationProps } from "../../hooks/useGeoLocation";
5
5
  import { useHeycarMap } from "../../hooks/useHeycarMap";
6
6
  import { useMapDrag, UseMapDragProps } from "../../hooks/useMapDrag";
7
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
7
8
  import type { UseMapPlaceProps } from "../../hooks/useMapPlace";
8
9
  import { useMapRecomendPlace, UseMapRecomendPlaceProps } from "../../hooks/useMapRecomendPlace";
9
10
  import { useMapSupplier } from "../../hooks/useMapSupplier";
@@ -20,7 +21,8 @@ export interface CenterPlaceSource {
20
21
  }
21
22
  export interface BusinessRecomendPlaceMapProps
22
23
  extends Omit<HeycarMapProps, "center" | "zoom" | "mapRef">,
23
- Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
24
+ Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace">,
25
+ MapLogProps {
24
26
  unavailableTitle: string;
25
27
  recomendDescription: string;
26
28
  noRecomendDescription: string;
@@ -36,6 +38,7 @@ export interface BusinessRecomendPlaceMapProps
36
38
  }
37
39
  export const BusinessRecomendPlaceMap = defineLagecySetup(
38
40
  (props: BusinessRecomendPlaceMapProps, { emit }) => {
41
+ useMapLog(props, "BusinessRecomendPlaceMap");
39
42
  const { geoDefaultPosition, getRecomendPlace, mapContext } = props;
40
43
  const { mapRef, setMap, panTo } = useHeycarMap();
41
44
  const { readyPromise } = useMapSupplier();
@@ -141,20 +144,22 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
141
144
  ? props.recomendDescription
142
145
  : props.noRecomendDescription;
143
146
  return (
144
- <HeycarMap center={centerPoint.value} zoom={18} mapRef={setMap}>
147
+ <HeycarMap center={centerPoint.value} zoom={18} mapRef={setMap} log={props.log}>
145
148
  <PassengerCircle position={geoPosition.value} />
146
- <PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} />
149
+ <PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} log={props.log} />
147
150
  <AddressBox
148
151
  position={centerPoint.value}
149
152
  title={availableRef.value ? centerPlace.name : props.unavailableTitle}
150
153
  description={description}
151
154
  type={isDragging.value ? "locator" : "box"}
155
+ log={props.log}
152
156
  />
153
157
  </HeycarMap>
154
158
  );
155
159
  };
156
160
  }
157
161
  ).props([
162
+ "log",
158
163
  "unavailableTitle",
159
164
  "recomendDescription",
160
165
  "noRecomendDescription",
@@ -1,16 +1,20 @@
1
+ import { BEIJIN_POINT } from "../../api/contants";
1
2
  import { HeycarMap } from "../../components/MapProvider";
2
3
  import { useHeycarMap } from "../../hooks/useHeycarMap";
3
4
  import { useMapFitView } from "../../hooks/useMapFitView";
5
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
4
6
  import { defineSetup } from "../../types/helper";
5
- import type { Place } from "../../types/interface";
7
+ import type { Place, Point } from "../../types/interface";
8
+ import { isPlace } from "../../utils/helper";
6
9
  import { place2point } from "../../utils/transform";
7
10
  import { SectionEndService } from "../BusinessTaxiServiceMap";
8
11
 
9
- export interface BusinessTaxiEndMapProps {
10
- from: Place;
11
- to: Place;
12
+ export interface BusinessTaxiEndMapProps extends MapLogProps {
13
+ from: Partial<Place>;
14
+ to: Partial<Place>;
12
15
  }
13
16
  export const BusinessTaxiEndMap = defineSetup((props: BusinessTaxiEndMapProps) => {
17
+ useMapLog(props, "BusinessTaxiEndMap");
14
18
  const { mapRef, setMap } = useHeycarMap();
15
19
  const { registerFitVeiw, setFitView } = useMapFitView({
16
20
  mapRef,
@@ -19,14 +23,20 @@ export const BusinessTaxiEndMap = defineSetup((props: BusinessTaxiEndMapProps) =
19
23
  });
20
24
  return () => {
21
25
  const { from, to } = props;
26
+ const isReady = isPlace(from) && isPlace(to);
27
+ const center = isReady ? place2point(from) : ([...BEIJIN_POINT] as Point);
28
+ const zoom = isReady ? 13 : 3;
22
29
  return (
23
- <HeycarMap center={place2point(from)} zoom={13} mapRef={setMap}>
24
- <SectionEndService
25
- from={from}
26
- to={to}
27
- registerOverlay={registerFitVeiw}
28
- onMapMounted={setFitView}
29
- />
30
+ <HeycarMap center={center} zoom={zoom} mapRef={setMap} log={props.log}>
31
+ {isReady && (
32
+ <SectionEndService
33
+ from={from}
34
+ to={to}
35
+ registerOverlay={registerFitVeiw}
36
+ onMapMounted={setFitView}
37
+ log={props.log}
38
+ />
39
+ )}
30
40
  </HeycarMap>
31
41
  );
32
42
  };
@@ -2,6 +2,7 @@ import { ref, watch } from "vue-demi";
2
2
  import { HeycarMap, HeycarMapProps } from "../../components/MapProvider";
3
3
  import { useGeoLocation } from "../../hooks/useGeoLocation";
4
4
  import { MapMountedProps, onMapMounted } from "../../hooks/useMap";
5
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
5
6
  import type { MROP } from "../../hooks/useOverlay";
6
7
  import { defineLagecySetup, defineSetup } from "../../types/helper";
7
8
  import type { DriverStatus, Place, Point } from "../../types/interface";
@@ -199,11 +200,13 @@ const SectionCanceled = defineSetup((props: SectionCanceledProps, { emit }) => {
199
200
  });
200
201
 
201
202
  export type SectionEndServiceProps = MROP &
203
+ MapLogProps &
202
204
  MapMountedProps & {
203
205
  from: Place;
204
206
  to: Place;
205
207
  };
206
208
  export const SectionEndService = defineSetup((props: SectionEndServiceProps, { emit }) => {
209
+ useMapLog(props, "SectionEndService");
207
210
  onMapMounted(() => emit("mapMounted"));
208
211
  return () => {
209
212
  const { from: fromPlace, to: toPlace, registerOverlay } = props;
@@ -3,6 +3,7 @@ import imgPassengerCircle from "../../assets/icons/svg/passenger-circle.svg";
3
3
  import imgPlaceCircle from "../../assets/icons/svg/place-circle.svg";
4
4
  import { AmapMarker } from "../../components/AmapMarker";
5
5
  import { GmapAdvancedMarkerView } from "../../components/GmapAdvancedMarkerView";
6
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
6
7
  import { useMapSupplier } from "../../hooks/useMapSupplier";
7
8
  import type { AmapOverlay, GmapOverlay, MapRegisterOverlayProps } from "../../hooks/useOverlay";
8
9
  import { createElement, defineSetup } from "../../types/helper";
@@ -11,13 +12,14 @@ import { vec2lnglat } from "../../utils/transform";
11
12
 
12
13
  import * as css from "./PassengerCircle.css";
13
14
 
14
- interface PassengerCircleProps<T> extends MapRegisterOverlayProps<T> {
15
+ interface PassengerCircleProps<T> extends MapRegisterOverlayProps<T>, MapLogProps {
15
16
  position: [number, number];
16
17
  size?: "small" | "large";
17
18
  }
18
19
  export const APassengerCircle = defineSetup(function APassengerCircle(
19
20
  props: PassengerCircleProps<AmapOverlay>
20
21
  ) {
22
+ useMapLog(props, "APassengerCircle");
21
23
  const contentRef = computed(() => {
22
24
  const { size = "large" } = props;
23
25
  const src = size === "large" ? imgPassengerCircle : imgPlaceCircle;
@@ -40,6 +42,7 @@ export const APassengerCircle = defineSetup(function APassengerCircle(
40
42
  export const GPassengerCircle = defineSetup(function GPassengerCircle(
41
43
  props: PassengerCircleProps<GmapOverlay>
42
44
  ) {
45
+ useMapLog(props, "GPassengerCircle");
43
46
  const contentRef = computed(() => {
44
47
  const { size = "large" } = props;
45
48
  const src = size === "large" ? imgPassengerCircle : imgPlaceCircle;
@@ -1,13 +1,15 @@
1
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
1
2
  import { defineSetup } from "../../types/helper";
2
3
  import type { Place } from "../../types/interface";
3
4
  import { place2point } from "../../utils/transform";
4
5
  import { PlaceCircle } from "../PlaceCircle";
5
6
 
6
- export interface PickupPointsProps {
7
+ export interface PickupPointsProps extends MapLogProps {
7
8
  places: Place[];
8
9
  onClick?: (value: Place) => any;
9
10
  }
10
11
  export const PickupPoints = defineSetup(function PickupPoints(props: PickupPointsProps, { emit }) {
12
+ useMapLog(props, "PickupPoints");
11
13
  return () => (
12
14
  <div>
13
15
  {props.places.map((place) => (
@@ -1,5 +1,6 @@
1
1
  import type { SetMap } from "../../hooks/useHeycarMap";
2
2
  import { GmapLoaderProps, Status, useMapLoader, UseMapLoaderProps } from "../../hooks/useMapLoader";
3
+ import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
3
4
  import { MapSupplierPayolad, provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier";
4
5
  import { defineLagecySetup } from "../../types/helper";
5
6
  import { language2vectorMapForeign, vec2lnglat } from "../../utils/transform";
@@ -25,7 +26,8 @@ export const MapProvider = defineLagecySetup(function MapProvider(
25
26
 
26
27
  export interface HeycarMapProps
27
28
  extends Pick<GmapLoaderProps, "fallback" | "loading">,
28
- Pick<AmapProps, "center" | "zoom"> {
29
+ Pick<AmapProps, "center" | "zoom">,
30
+ MapLogProps {
29
31
  mapRef?: SetMap<AMap.Map> | SetMap<google.maps.Map>;
30
32
  onDragEnd?: (value: [number, number]) => any;
31
33
  }
@@ -33,6 +35,7 @@ export const HeycarMap = defineLagecySetup(function HeycarMap(
33
35
  props: HeycarMapProps,
34
36
  { slots, emit }
35
37
  ) {
38
+ useMapLog(props, "HeycarMap");
36
39
  const payload = useMapSupplier();
37
40
  const gmapDebouncedEmit: GmapProps["onDragEnd"] = ({ target }) => {
38
41
  const { lng, lat } = target.getCenter() as google.maps.LatLng;
@@ -0,0 +1,12 @@
1
+ import { watchEffect } from "vue-demi";
2
+
3
+ export interface MapLogProps {
4
+ log?: boolean;
5
+ }
6
+
7
+ export const useMapLog = <P extends MapLogProps>(props: P, name: string) => {
8
+ watchEffect(() => {
9
+ if (!props.log) return;
10
+ console.log(`log ${name} props = `, { ...props });
11
+ });
12
+ };
@@ -33,11 +33,13 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
33
33
  const cityName = addressComponent.city
34
34
  ? addressComponent.city
35
35
  : addressComponent.province;
36
+ const countryName = addressComponent.country;
36
37
  place.name = name;
37
38
  place.lng = lng;
38
39
  place.lat = lat;
39
40
  place.cityName = cityName;
40
- onChange?.({ lng, lat, name, cityName });
41
+ place.countryName = countryName;
42
+ onChange?.({ lng, lat, name, cityName, countryName });
41
43
  return;
42
44
  }
43
45
 
@@ -68,10 +70,13 @@ export const useGmapPlace = (props: UseMapPlaceProps) => {
68
70
  const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
69
71
  const name = results[0].formatted_address;
70
72
  const cityName = geocoderResult2cityName(results[0]);
71
- place.name = name;
73
+ const countryName = results.slice(-1)[0].address_components[0].long_name;
72
74
  place.lng = lng;
73
75
  place.lat = lat;
74
- onChange?.({ lng, lat, name, cityName });
76
+ place.name = name;
77
+ place.cityName = cityName;
78
+ place.countryName = countryName;
79
+ onChange?.({ lng, lat, name, cityName, countryName });
75
80
  }
76
81
  );
77
82
  return { place, updatePlace };
@@ -165,6 +165,8 @@ declare global {
165
165
  }
166
166
 
167
167
  export interface AddressComponent {
168
+ // 国家名称,例如: 日本
169
+ country: string;
168
170
  // 坐标点所在省名称 例如:北京市
169
171
  province: string;
170
172
  // 坐标点所在城市名称 请注意:当城市是省直辖县时返回为空,以及城市为北京、上海、天津、重庆四个直辖市时,该字段返回为空;省直辖县列表
@@ -7,7 +7,7 @@ export type Place = {
7
7
  lat: number;
8
8
  name: string;
9
9
  cityName?: string;
10
- cityId?: string;
10
+ countryName?: string;
11
11
  };
12
12
 
13
13
  export interface AutoCompletePlace extends Place {
@@ -0,0 +1,5 @@
1
+ import type { Place } from "../types/interface";
2
+
3
+ export const isPlace = (place: Partial<Place>): place is Place => {
4
+ return place.lng !== undefined && place.lat !== undefined;
5
+ };