@heycar/heycars-map 0.3.0 → 0.3.2
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/README.md +1 -1
- package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +3 -1
- package/dist/hooks/useMapAutoComplete.d.ts +10 -6
- package/dist/hooks/useMapCityBound.d.ts +5 -5
- package/dist/hooks/useMapLog.d.ts +2 -1
- package/dist/hooks/useMapPlace.d.ts +13 -2
- package/dist/hooks/useMapRecomendPlace.d.ts +12 -2
- package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +4 -2
- package/dist/hooks-business/useBusinessRecomendPlaceMap.d.ts +4 -2
- package/dist/index.cjs +52 -52
- package/dist/index.js +1095 -1064
- package/dist/style.css +1 -1
- package/dist/types/interface.d.ts +2 -1
- package/package.json +1 -1
- package/src/Demo/DemoBusinessRecomendPlace.tsx +16 -8
- package/src/Demo/sample.json +793 -0
- package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.css.ts +2 -0
- package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +5 -3
- package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +26 -22
- package/src/hooks/useGeoLocation.ts +6 -2
- package/src/hooks/useMapAutoComplete.ts +7 -5
- package/src/hooks/useMapCityBound.ts +5 -5
- package/src/hooks/useMapDrag.ts +7 -2
- package/src/hooks/useMapLog.ts +14 -2
- package/src/hooks/useMapPlace.ts +39 -16
- package/src/hooks/useMapRecomendPlace.ts +17 -4
- package/src/hooks-business/useBusinessMapAutoComplete.ts +3 -2
- package/src/hooks-business/useBusinessRecomendPlaceMap.ts +5 -5
- package/src/types/interface.ts +2 -1
- package/dist/hooks-business/useLagecyMapRecomendPlace.d.ts +0 -55
- package/src/hooks-business/useLagecyMapRecomendPlace.ts +0 -152
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { style } from "@vanilla-extract/css";
|
|
2
2
|
|
|
3
3
|
export const absoluteAddressBoxLayout = style({
|
|
4
|
+
pointerEvents: "none",
|
|
4
5
|
position: "absolute",
|
|
5
6
|
bottom: "50%",
|
|
6
7
|
left: 0,
|
|
@@ -14,6 +15,7 @@ export const absoluteAddressBoxLayout = style({
|
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
export const absoluteAddressBox = style({
|
|
18
|
+
pointerEvents: "auto",
|
|
17
19
|
padding: "2.67vw 4.27vw",
|
|
18
20
|
background: "linear-gradient(90deg, #79AFFF 0%, #5C8DFF 32%, #507FFF 75%, #4471FF 100%)",
|
|
19
21
|
borderRadius: "3.2vw",
|
|
@@ -25,12 +25,14 @@ 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}>
|
|
29
29
|
<div class={css.boxTextLayout}>
|
|
30
|
-
<div class={css.boxTitle}
|
|
30
|
+
<div class={css.boxTitle} onClick={handleClick}>
|
|
31
|
+
{title}
|
|
32
|
+
</div>
|
|
31
33
|
{description && <div class={css.boxDescription}>{description}</div>}
|
|
32
34
|
</div>
|
|
33
|
-
<img class={css.arrowRight} src={imgArrowRight} />
|
|
35
|
+
<img class={css.arrowRight} src={imgArrowRight} onClick={handleClick} />
|
|
34
36
|
</div>
|
|
35
37
|
<i class={css.straightLine} />
|
|
36
38
|
</div>
|
|
@@ -23,6 +23,7 @@ export interface BusinessRecomendPlaceMapProps
|
|
|
23
23
|
extends Omit<HeycarMapProps, "center" | "zoom" | "mapRef">,
|
|
24
24
|
Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace">,
|
|
25
25
|
MapLogProps {
|
|
26
|
+
geoLoadingTitle: string;
|
|
26
27
|
unavailableTitle: string;
|
|
27
28
|
recomendDescription: string;
|
|
28
29
|
noRecomendDescription: string;
|
|
@@ -33,6 +34,7 @@ export interface BusinessRecomendPlaceMapProps
|
|
|
33
34
|
onChangeByDrag?: UseMapDragProps["onChange"];
|
|
34
35
|
onChangeGeoLocation?: UseGeoLocationProps["onChange"];
|
|
35
36
|
onChangePlace?: UseMapPlaceProps["onChange"];
|
|
37
|
+
onChangeCity?: UseMapPlaceProps["onChangeCity"];
|
|
36
38
|
onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
|
|
37
39
|
onGeoError?: UseGeoLocationProps["onError"];
|
|
38
40
|
onClickLocator?: AbsoluteAddressBoxProps["onClick"];
|
|
@@ -47,15 +49,17 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
47
49
|
lng: geoDefaultPosition?.[0] ?? 0,
|
|
48
50
|
lat: geoDefaultPosition?.[1] ?? 0,
|
|
49
51
|
name: "",
|
|
50
|
-
cityName: undefined,
|
|
51
52
|
});
|
|
52
53
|
const centerPoint = computed<Point>(() => [centerPlace.lng, centerPlace.lat]);
|
|
53
54
|
const centerSource: CenterPlaceSource = { source: "geo" };
|
|
54
55
|
const setCenterPlaceByRecomand = (point: Point) => {
|
|
55
56
|
centerSource.source = "api";
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
updatePlace(point);
|
|
58
|
+
};
|
|
59
|
+
const setCenterPlaceByUserSpecified = (place: Place) => {
|
|
60
|
+
centerSource.source = "api";
|
|
61
|
+
setPlace(place);
|
|
62
|
+
updateRecomandPlace();
|
|
59
63
|
};
|
|
60
64
|
const setCenterByPlace = (place: Place) => {
|
|
61
65
|
centerSource.source = "api";
|
|
@@ -64,30 +68,26 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
64
68
|
centerPlace.name = place.name;
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
const { geoPosition, geoError } = useGeoLocation({
|
|
71
|
+
const { geoPosition, geoError, geoLoading } = useGeoLocation({
|
|
68
72
|
geoDefaultPosition,
|
|
69
73
|
onLoad: async (value) => {
|
|
70
74
|
// geo 主入口
|
|
71
75
|
await readyPromise;
|
|
72
76
|
centerSource.source = "geo";
|
|
73
|
-
|
|
74
|
-
centerPlace.lat = value.position[1];
|
|
75
|
-
updatePlace();
|
|
77
|
+
updatePlace(value.position);
|
|
76
78
|
emit("loadGeoLocation", value);
|
|
77
79
|
},
|
|
78
80
|
onLoadDefault: async (value) => {
|
|
79
81
|
// geo default position 主入口
|
|
80
82
|
await readyPromise;
|
|
81
83
|
centerSource.source = "geo";
|
|
82
|
-
|
|
83
|
-
centerPlace.lat = value.position[1];
|
|
84
|
-
updatePlace();
|
|
84
|
+
updatePlace(value.position);
|
|
85
85
|
emit("loadDefaultGeoLocation", value);
|
|
86
86
|
},
|
|
87
87
|
onChange: (v) => emit("changeGeoLocation", v),
|
|
88
88
|
onError: (e) => emit("geoError", e),
|
|
89
89
|
});
|
|
90
|
-
mapContext.
|
|
90
|
+
mapContext.setCenterPlaceByUserSpecified = setCenterPlaceByUserSpecified;
|
|
91
91
|
mapContext.panToGeoPositionByRecomend = () => {
|
|
92
92
|
if (geoError.value) return false;
|
|
93
93
|
setCenterPlaceByRecomand(geoPosition.value);
|
|
@@ -97,14 +97,12 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
97
97
|
mapRef,
|
|
98
98
|
onChange: (point) => {
|
|
99
99
|
centerSource.source = "drag";
|
|
100
|
-
|
|
101
|
-
centerPlace.lat = point[1];
|
|
102
|
-
updatePlace();
|
|
100
|
+
updatePlace(point);
|
|
103
101
|
emit("changeByDrag", point);
|
|
104
102
|
},
|
|
105
103
|
});
|
|
106
|
-
const { updatePlace, updateRecomandPlace, placeCandidates, availableRef } =
|
|
107
|
-
{
|
|
104
|
+
const { updatePlace, setPlace, updateRecomandPlace, placeCandidates, availableRef } =
|
|
105
|
+
useMapRecomendPlace({
|
|
108
106
|
pointRef: centerPoint,
|
|
109
107
|
context: centerSource,
|
|
110
108
|
getRecomendPlace,
|
|
@@ -122,7 +120,6 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
122
120
|
}
|
|
123
121
|
},
|
|
124
122
|
onChangePlace: (place) => {
|
|
125
|
-
Object.assign(centerPlace, { ...place });
|
|
126
123
|
if (centerSource.source !== "recomend") {
|
|
127
124
|
updateRecomandPlace();
|
|
128
125
|
}
|
|
@@ -131,11 +128,12 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
131
128
|
onChange: (place) => {
|
|
132
129
|
centerSource.source = "recomend";
|
|
133
130
|
Object.assign(centerPlace, { ...place });
|
|
134
|
-
updatePlace();
|
|
135
131
|
emit("changeRecomandPlace", place);
|
|
136
132
|
},
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
onChangeCity: (value) => {
|
|
134
|
+
emit("changeCity", value);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
139
137
|
watchEffect(() => {
|
|
140
138
|
mapContext.onChangeCenterPlace({ ...centerPlace });
|
|
141
139
|
});
|
|
@@ -143,6 +141,11 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
143
141
|
mapContext.onChangeRecomendPlaces([...placeCandidates.value]);
|
|
144
142
|
});
|
|
145
143
|
return () => {
|
|
144
|
+
const title = geoLoading.value
|
|
145
|
+
? props.geoLoadingTitle
|
|
146
|
+
: availableRef.value
|
|
147
|
+
? centerPlace.name
|
|
148
|
+
: props.unavailableTitle;
|
|
146
149
|
const description = !availableRef.value
|
|
147
150
|
? undefined
|
|
148
151
|
: placeCandidates.value.length > 0
|
|
@@ -153,7 +156,7 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
153
156
|
<PassengerCircle position={geoPosition.value} />
|
|
154
157
|
<PickupPoints places={placeCandidates.value} onClick={setCenterByPlace} log={props.log} />
|
|
155
158
|
<AbsoluteAddressBox
|
|
156
|
-
title={
|
|
159
|
+
title={title}
|
|
157
160
|
description={description}
|
|
158
161
|
type={isDragging.value ? "locator" : "box"}
|
|
159
162
|
log={props.log}
|
|
@@ -165,6 +168,7 @@ export const BusinessRecomendPlaceMap = defineLagecySetup(
|
|
|
165
168
|
}
|
|
166
169
|
).props([
|
|
167
170
|
"log",
|
|
171
|
+
"geoLoadingTitle",
|
|
168
172
|
"unavailableTitle",
|
|
169
173
|
"recomendDescription",
|
|
170
174
|
"noRecomendDescription",
|
|
@@ -10,6 +10,7 @@ export interface UseGeoLocationProps {
|
|
|
10
10
|
}
|
|
11
11
|
export const useGeoLocation = (props?: UseGeoLocationProps) => {
|
|
12
12
|
const { onChange, onLoad, onLoadDefault, onError, geoDefaultPosition } = props ?? {};
|
|
13
|
+
let isOnLoadDefaultTriggered = false;
|
|
13
14
|
const loading = ref(false);
|
|
14
15
|
const readyRef = ref(false);
|
|
15
16
|
const errorRef = ref<GeolocationPositionError>();
|
|
@@ -44,12 +45,15 @@ export const useGeoLocation = (props?: UseGeoLocationProps) => {
|
|
|
44
45
|
loading.value = false;
|
|
45
46
|
errorRef.value = error;
|
|
46
47
|
const position = props?.geoDefaultPosition;
|
|
47
|
-
if (position)
|
|
48
|
+
if (position && !isOnLoadDefaultTriggered) {
|
|
49
|
+
isOnLoadDefaultTriggered = true;
|
|
50
|
+
onLoadDefault?.({ position });
|
|
51
|
+
}
|
|
48
52
|
onError?.(error);
|
|
49
53
|
console.log("errorRef = ", errorRef);
|
|
50
54
|
},
|
|
51
55
|
// todo 要不要 timeout
|
|
52
|
-
{ timeout:
|
|
56
|
+
{ timeout: 3000, maximumAge: 0, enableHighAccuracy: false }
|
|
53
57
|
);
|
|
54
58
|
onCleanup(() => navigator.geolocation.clearWatch(watchId));
|
|
55
59
|
},
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { ref, watch } from "vue-demi";
|
|
2
|
-
import type { AutoCompletePlace,
|
|
2
|
+
import type { AutoCompletePlace, Region } 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
|
-
city:
|
|
7
|
+
export interface UseMapAutoCompleteProps extends MapLogProps {
|
|
8
|
+
city: Region;
|
|
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[]>([]);
|
|
16
18
|
const { update, idx: updateKey } = useUpdate();
|
|
17
|
-
const setCity = (value:
|
|
19
|
+
const setCity = (value: Region) => {
|
|
18
20
|
cityRef.value = value;
|
|
19
21
|
update();
|
|
20
22
|
};
|
|
@@ -63,7 +65,7 @@ export const useGmapAutoComplete = (props: UseMapAutoCompleteProps) => {
|
|
|
63
65
|
const keywordRef = ref("");
|
|
64
66
|
const autoCompletePlacesRef = ref<AutoCompletePlace[]>([]);
|
|
65
67
|
const { update, idx: updateKey } = useUpdate();
|
|
66
|
-
const setCity = (value:
|
|
68
|
+
const setCity = (value: Region) => {
|
|
67
69
|
cityRef.value = value;
|
|
68
70
|
update();
|
|
69
71
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { reactive, Ref, watch, watchEffect } from "vue-demi";
|
|
2
2
|
import { LANGUAGE } from "../types/helper";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Region } from "../types/interface";
|
|
4
4
|
import { useMapSupplier } from "./useMapSupplier";
|
|
5
5
|
|
|
6
6
|
export interface UseMapCityBoundProps {
|
|
7
7
|
cityNameRef: Ref<string | undefined>;
|
|
8
|
-
onChange?: (value:
|
|
8
|
+
onChange?: (value: Region) => any;
|
|
9
9
|
}
|
|
10
|
-
export const useAmapBoundCity = (props: UseMapCityBoundProps):
|
|
10
|
+
export const useAmapBoundCity = (props: UseMapCityBoundProps): Region => {
|
|
11
11
|
const { cityNameRef, onChange } = props;
|
|
12
12
|
const city = reactive({ name: cityNameRef.value ?? "" });
|
|
13
13
|
watch(
|
|
@@ -21,10 +21,10 @@ export const useAmapBoundCity = (props: UseMapCityBoundProps): City => {
|
|
|
21
21
|
return city;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export const useGmapBoundCity = (props: UseMapCityBoundProps):
|
|
24
|
+
export const useGmapBoundCity = (props: UseMapCityBoundProps): Region => {
|
|
25
25
|
const { cityNameRef, onChange } = props;
|
|
26
26
|
const { readyPromise } = useMapSupplier();
|
|
27
|
-
const city = reactive<
|
|
27
|
+
const city = reactive<Region>({
|
|
28
28
|
name: cityNameRef.value ?? "",
|
|
29
29
|
bound: {
|
|
30
30
|
east: 0,
|
package/src/hooks/useMapDrag.ts
CHANGED
|
@@ -18,9 +18,12 @@ export const useAmapDrag = (props: UseMapDragProps<AMap.Map>) => {
|
|
|
18
18
|
const centerRef = ref<Point>([0, 0]);
|
|
19
19
|
const isDragging = ref(false);
|
|
20
20
|
const emitDragStart: SetupContextEmitHandler<Pick<AmapProps, "onDragStart">> = () => {
|
|
21
|
-
|
|
21
|
+
pipeAsync(() => {
|
|
22
|
+
isDragging.value = true;
|
|
23
|
+
});
|
|
22
24
|
};
|
|
23
25
|
const emitDragEnd: SetupContextEmitHandler<Pick<AmapProps, "onDragEnd">> = (_, { target }) => {
|
|
26
|
+
console.log("on DragEnd ------");
|
|
24
27
|
isDragging.value = false;
|
|
25
28
|
const { lng, lat } = target.getCenter();
|
|
26
29
|
centerRef.value = [lng, lat];
|
|
@@ -40,7 +43,9 @@ export const useGmapDrag = (props: UseMapDragProps<google.maps.Map>) => {
|
|
|
40
43
|
const centerRef = ref<Point>([0, 0]);
|
|
41
44
|
const isDragging = ref(false);
|
|
42
45
|
const emitDragStart: SetupContextEmitHandler<Pick<GmapProps, "onDragStart">> = () => {
|
|
43
|
-
|
|
46
|
+
pipeAsync(() => {
|
|
47
|
+
isDragging.value = true;
|
|
48
|
+
});
|
|
44
49
|
};
|
|
45
50
|
const emitDragEnd: SetupContextEmitHandler<Pick<GmapProps, "onDragEnd">> = async () => {
|
|
46
51
|
isDragging.value = false;
|
package/src/hooks/useMapLog.ts
CHANGED
|
@@ -4,9 +4,21 @@ export interface MapLogProps {
|
|
|
4
4
|
log?: boolean;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export const useMapLog = <P extends MapLogProps>(props: P,
|
|
7
|
+
export const useMapLog = <P extends MapLogProps>(props: P, prefix: string) => {
|
|
8
8
|
watchEffect(() => {
|
|
9
9
|
if (!props.log) return;
|
|
10
|
-
console.log(`log ${
|
|
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
|
};
|
package/src/hooks/useMapPlace.ts
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
|
-
import { reactive, Ref, watch } from "vue-demi";
|
|
1
|
+
import { reactive, ref, Ref, watch } from "vue-demi";
|
|
2
2
|
import { LANGUAGE } from "../types/helper";
|
|
3
3
|
import type { Place, Point } from "../types/interface";
|
|
4
4
|
import { geocoderResult2cityName } from "../utils/transform";
|
|
5
5
|
import { useMapSupplier } from "./useMapSupplier";
|
|
6
6
|
import { useUpdate } from "./useUdate";
|
|
7
7
|
|
|
8
|
+
export interface UseMapPlaceOnChangeCityProps {
|
|
9
|
+
cityName?: string;
|
|
10
|
+
cityParentName?: string;
|
|
11
|
+
}
|
|
8
12
|
export interface UseMapPlaceProps {
|
|
9
13
|
pointRef: Ref<Point>;
|
|
10
14
|
onChange?: (value: Place) => any;
|
|
15
|
+
onChangeCity?: (value: UseMapPlaceOnChangeCityProps) => any;
|
|
11
16
|
}
|
|
12
17
|
export const useAmapPlace = (props: UseMapPlaceProps) => {
|
|
13
|
-
const {
|
|
18
|
+
const { onChange, onChangeCity } = props;
|
|
19
|
+
const defaultPoint: Point = [...props.pointRef.value];
|
|
20
|
+
const pointRef = ref<Point>(defaultPoint);
|
|
14
21
|
const { readyPromise } = useMapSupplier();
|
|
15
|
-
const { idx: placeKey, update: updatePlace } = useUpdate();
|
|
16
22
|
const place = reactive<Place>({
|
|
17
23
|
lng: pointRef.value[0],
|
|
18
24
|
lat: pointRef.value[1],
|
|
19
25
|
name: "",
|
|
20
|
-
cityName: undefined,
|
|
21
26
|
});
|
|
27
|
+
const { idx: placeKey, update } = useUpdate();
|
|
28
|
+
const updatePlace = (value: Point) => {
|
|
29
|
+
pointRef.value = value;
|
|
30
|
+
update();
|
|
31
|
+
};
|
|
32
|
+
const setPlace = (value: Place) => {
|
|
33
|
+
place.lng = value.lng;
|
|
34
|
+
place.lat = value.lat;
|
|
35
|
+
place.name = value.name;
|
|
36
|
+
};
|
|
22
37
|
watch(
|
|
23
38
|
() => placeKey.value,
|
|
24
39
|
async () => {
|
|
@@ -33,13 +48,12 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
|
|
|
33
48
|
const cityName = addressComponent.city
|
|
34
49
|
? addressComponent.city
|
|
35
50
|
: addressComponent.province;
|
|
36
|
-
const
|
|
51
|
+
const cityParentName = addressComponent.province;
|
|
37
52
|
place.name = name;
|
|
38
53
|
place.lng = lng;
|
|
39
54
|
place.lat = lat;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
onChange?.({ lng, lat, name, cityName, countryName });
|
|
55
|
+
onChange?.({ lng, lat, name });
|
|
56
|
+
onChangeCity?.({ cityName, cityParentName });
|
|
43
57
|
return;
|
|
44
58
|
}
|
|
45
59
|
|
|
@@ -53,14 +67,23 @@ export const useAmapPlace = (props: UseMapPlaceProps) => {
|
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
);
|
|
56
|
-
return { place, updatePlace };
|
|
70
|
+
return { place, updatePlace, setPlace };
|
|
57
71
|
};
|
|
58
72
|
|
|
59
73
|
export const useGmapPlace = (props: UseMapPlaceProps) => {
|
|
60
|
-
const { pointRef, onChange } = props;
|
|
74
|
+
const { pointRef, onChange, onChangeCity } = props;
|
|
61
75
|
const { readyPromise } = useMapSupplier();
|
|
62
76
|
const { idx: placeKey, update: updatePlace } = useUpdate();
|
|
63
|
-
const place = reactive<Place>({
|
|
77
|
+
const place = reactive<Place>({
|
|
78
|
+
lng: pointRef.value[0],
|
|
79
|
+
lat: pointRef.value[1],
|
|
80
|
+
name: "",
|
|
81
|
+
});
|
|
82
|
+
const setPlace = (value: Place) => {
|
|
83
|
+
place.lng = value.lng;
|
|
84
|
+
place.lat = value.lat;
|
|
85
|
+
place.name = value.name;
|
|
86
|
+
};
|
|
64
87
|
watch(
|
|
65
88
|
() => placeKey.value,
|
|
66
89
|
async () => {
|
|
@@ -70,16 +93,16 @@ export const useGmapPlace = (props: UseMapPlaceProps) => {
|
|
|
70
93
|
const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
|
|
71
94
|
const name = results[0].formatted_address;
|
|
72
95
|
const cityName = geocoderResult2cityName(results[0]);
|
|
73
|
-
const
|
|
96
|
+
const cityParentName = results.slice(-2)[0].address_components[0].long_name;
|
|
97
|
+
// const countryName = results.slice(-1)[0].address_components[0].long_name;
|
|
74
98
|
place.lng = lng;
|
|
75
99
|
place.lat = lat;
|
|
76
100
|
place.name = name;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onChange?.({ lng, lat, name, cityName, countryName });
|
|
101
|
+
onChange?.({ lng, lat, name });
|
|
102
|
+
onChangeCity?.({ cityName, cityParentName });
|
|
80
103
|
}
|
|
81
104
|
);
|
|
82
|
-
return { place, updatePlace };
|
|
105
|
+
return { place, updatePlace, setPlace };
|
|
83
106
|
};
|
|
84
107
|
|
|
85
108
|
export const useMapPlace = (props: UseMapPlaceProps) => {
|
|
@@ -35,16 +35,22 @@ export interface UseMapRecomendPlaceProps<C = Record<string, any>> {
|
|
|
35
35
|
getLimit: (context?: C) => number;
|
|
36
36
|
// 如果返回 undefined, 表示当前位置无服务可提供
|
|
37
37
|
getRecomendPlace: (place: Place, context?: C) => Promise<Place[] | undefined>;
|
|
38
|
+
onChangeCity?: UseMapPlaceProps["onChangeCity"];
|
|
38
39
|
onChangePlace?: UseMapPlaceProps["onChange"];
|
|
39
40
|
onChange?: (place: Place) => any;
|
|
40
41
|
}
|
|
41
42
|
export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
42
|
-
const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace } =
|
|
43
|
+
const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace, onChangeCity } =
|
|
44
|
+
props;
|
|
43
45
|
const availableRef = ref(true);
|
|
44
46
|
const placeCandidatesRef = ref<Place[]>([]);
|
|
45
47
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
46
48
|
const { readyPromise } = useMapSupplier();
|
|
47
|
-
const { place, updatePlace } = useAmapPlace({
|
|
49
|
+
const { place, updatePlace, setPlace } = useAmapPlace({
|
|
50
|
+
pointRef,
|
|
51
|
+
onChange: onChangePlace,
|
|
52
|
+
onChangeCity,
|
|
53
|
+
});
|
|
48
54
|
const recomendPlace = reactive<Place>({ ...place });
|
|
49
55
|
watch(
|
|
50
56
|
() => recomendPlaceKey.value,
|
|
@@ -73,16 +79,22 @@ export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
73
79
|
availableRef,
|
|
74
80
|
updateRecomandPlace,
|
|
75
81
|
updatePlace,
|
|
82
|
+
setPlace,
|
|
76
83
|
};
|
|
77
84
|
};
|
|
78
85
|
|
|
79
86
|
export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
80
|
-
const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace } =
|
|
87
|
+
const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace, onChangeCity } =
|
|
88
|
+
props;
|
|
81
89
|
const availableRef = ref(true);
|
|
82
90
|
const placeCandidatesRef = ref<Place[]>([]);
|
|
83
91
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
84
92
|
const { readyPromise } = useMapSupplier();
|
|
85
|
-
const { place, updatePlace } = useGmapPlace({
|
|
93
|
+
const { place, updatePlace, setPlace } = useGmapPlace({
|
|
94
|
+
pointRef,
|
|
95
|
+
onChange: onChangePlace,
|
|
96
|
+
onChangeCity,
|
|
97
|
+
});
|
|
86
98
|
const recomendPlace = reactive<Place>({ ...place });
|
|
87
99
|
watch(
|
|
88
100
|
() => recomendPlaceKey.value,
|
|
@@ -111,6 +123,7 @@ export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
|
|
|
111
123
|
availableRef,
|
|
112
124
|
updateRecomandPlace,
|
|
113
125
|
updatePlace,
|
|
126
|
+
setPlace,
|
|
114
127
|
};
|
|
115
128
|
};
|
|
116
129
|
|
|
@@ -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);
|
|
@@ -4,7 +4,7 @@ import type { Place, Point } from "../types/interface";
|
|
|
4
4
|
|
|
5
5
|
export interface BusinessRecomendPlaceContext {
|
|
6
6
|
panToGeoPositionByRecomend: (value: Point) => void;
|
|
7
|
-
|
|
7
|
+
setCenterPlaceByUserSpecified: (value: Place) => void;
|
|
8
8
|
onChangeCenterPlace: (value: Place) => void;
|
|
9
9
|
onChangeRecomendPlaces: (value: Place[]) => void;
|
|
10
10
|
}
|
|
@@ -14,17 +14,17 @@ export const useBusinessRecomendPlaceMap = () => {
|
|
|
14
14
|
lng: 0,
|
|
15
15
|
lat: 0,
|
|
16
16
|
name: "",
|
|
17
|
-
cityName: undefined,
|
|
18
17
|
});
|
|
19
18
|
const placeCandidates = ref<Place[]>([]);
|
|
20
19
|
const { apiMapDistance } = useMapGeometry();
|
|
21
20
|
const panToGeoPositionByRecomend = (value: Point) => mapContext.panToGeoPositionByRecomend(value);
|
|
22
|
-
const
|
|
21
|
+
const setCenterPlaceByUserSpecified = (value: Place) =>
|
|
22
|
+
mapContext.setCenterPlaceByUserSpecified(value);
|
|
23
23
|
const mapContext: BusinessRecomendPlaceContext = {
|
|
24
24
|
panToGeoPositionByRecomend: () => {
|
|
25
25
|
throw new Error("MyError: panToGeoPositionByRecomend used before assigned");
|
|
26
26
|
},
|
|
27
|
-
|
|
27
|
+
setCenterPlaceByUserSpecified: () => {
|
|
28
28
|
throw new Error("MyError: setCenterPlaceByRecomand used before assigned");
|
|
29
29
|
},
|
|
30
30
|
onChangeCenterPlace: (place: Place) => {
|
|
@@ -39,7 +39,7 @@ export const useBusinessRecomendPlaceMap = () => {
|
|
|
39
39
|
centerPlace,
|
|
40
40
|
placeCandidates,
|
|
41
41
|
panToGeoPositionByRecomend,
|
|
42
|
-
|
|
42
|
+
setCenterPlaceByUserSpecified,
|
|
43
43
|
apiMapDistance,
|
|
44
44
|
};
|
|
45
45
|
};
|
package/src/types/interface.ts
CHANGED
|
@@ -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
|
|
|
@@ -15,7 +16,7 @@ export interface AutoCompletePlace extends Place {
|
|
|
15
16
|
description: string;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export type
|
|
19
|
+
export type Region = {
|
|
19
20
|
bound?: {
|
|
20
21
|
east: number;
|
|
21
22
|
north: number;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { UseGeoLocationProps } from "../hooks/useGeoLocation";
|
|
2
|
-
import { UseMapDragProps } from "../hooks/useMapDrag";
|
|
3
|
-
import type { UseMapPlaceProps } from "../hooks/useMapPlace";
|
|
4
|
-
import { UseMapRecomendPlaceProps } from "../hooks/useMapRecomendPlace";
|
|
5
|
-
import type { MapShallowRef, Place, Point } from "../types/interface";
|
|
6
|
-
interface CenterPlaceSource {
|
|
7
|
-
source: "default" | "geo" | "drag" | "recomend" | "api";
|
|
8
|
-
}
|
|
9
|
-
export interface UseLagecyMapRecomendPlace extends Pick<UseMapRecomendPlaceProps<CenterPlaceSource>, "getRecomendPlace"> {
|
|
10
|
-
mapRef: MapShallowRef;
|
|
11
|
-
defaultCenterPoint?: Point;
|
|
12
|
-
geoDefaultPosition?: Point;
|
|
13
|
-
recomendPlaceGeoLimit: number;
|
|
14
|
-
recomendPlaceDragLimit: number;
|
|
15
|
-
onLoadGeoLocation?: UseGeoLocationProps["onLoad"];
|
|
16
|
-
onLoadDefaultGeoLocation?: UseGeoLocationProps["onLoadDefault"];
|
|
17
|
-
onChangeByDrag?: UseMapDragProps["onChange"];
|
|
18
|
-
onChangeGeoLocation?: UseGeoLocationProps["onChange"];
|
|
19
|
-
onChangePlace?: UseMapPlaceProps["onChange"];
|
|
20
|
-
onChangeRecomandPlace?: UseMapRecomendPlaceProps["onChange"];
|
|
21
|
-
}
|
|
22
|
-
export declare const useLagecyMapRecomendPlace: (props: UseLagecyMapRecomendPlace) => {
|
|
23
|
-
isDragging: import("vue-demi").Ref<boolean>;
|
|
24
|
-
geoLoading: import("vue-demi").Ref<boolean>;
|
|
25
|
-
geoError: import("vue-demi").Ref<GeolocationPositionError | undefined>;
|
|
26
|
-
geoPosition: import("vue-demi").Ref<[number, number]>;
|
|
27
|
-
geoCoordinate: import("vue-demi").Ref<{
|
|
28
|
-
readonly accuracy: number;
|
|
29
|
-
readonly altitude: number | null;
|
|
30
|
-
readonly altitudeAccuracy: number | null;
|
|
31
|
-
readonly heading: number | null;
|
|
32
|
-
readonly latitude: number;
|
|
33
|
-
readonly longitude: number;
|
|
34
|
-
readonly speed: number | null;
|
|
35
|
-
}>;
|
|
36
|
-
geoReady: import("vue-demi").Ref<boolean>;
|
|
37
|
-
centerPlace: {
|
|
38
|
-
lng: number;
|
|
39
|
-
lat: number;
|
|
40
|
-
name: string;
|
|
41
|
-
cityName?: string | undefined;
|
|
42
|
-
countryName?: string | undefined;
|
|
43
|
-
};
|
|
44
|
-
centerPoint: import("vue-demi").ComputedRef<Point>;
|
|
45
|
-
placeCandidates: import("vue-demi").Ref<{
|
|
46
|
-
lng: number;
|
|
47
|
-
lat: number;
|
|
48
|
-
name: string;
|
|
49
|
-
cityName?: string | undefined;
|
|
50
|
-
countryName?: string | undefined;
|
|
51
|
-
}[]>;
|
|
52
|
-
setCenterPlaceByRecomand: (point: Point) => void;
|
|
53
|
-
setCenterByPlace: (place: Place) => void;
|
|
54
|
-
};
|
|
55
|
-
export {};
|