@heycar/heycars-map 0.1.6 → 0.1.7
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/dist/business-components/PickupPoints/PickupPoints.d.ts +2 -2
- package/dist/hooks/useMapRecomendPlace.d.ts +15 -0
- package/dist/hooks-business/useBusinessMapRecomendPlace.d.ts +5 -0
- package/dist/index.cjs +19 -19
- package/dist/index.js +371 -394
- package/package.json +2 -2
- package/src/business-components/PickupPoints/PickupPoints.tsx +5 -4
- package/src/components/Demo/HeycarDemo.tsx +12 -9
- package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +0 -1
- package/src/hooks/useGeoLocation.ts +20 -29
- package/src/hooks/useMapPlace.ts +0 -6
- package/src/hooks/useMapRecomendPlace.ts +7 -9
- package/src/hooks-business/useBusinessMapRecomendPlace.ts +2 -1
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { defineSetup } from "../../types/helper";
|
|
2
|
+
import type { Place } from "../../types/interface";
|
|
3
|
+
import { place2point } from "../../utils/transform";
|
|
2
4
|
import { PlaceCircle } from "../PlaceCircle";
|
|
3
5
|
|
|
4
6
|
export interface PickupPointsProps {
|
|
5
|
-
|
|
6
|
-
labels: string[];
|
|
7
|
+
places: Place[];
|
|
7
8
|
}
|
|
8
9
|
export const PickupPoints = defineSetup(function PickupPoints(props: PickupPointsProps) {
|
|
9
10
|
return () => (
|
|
10
11
|
<div>
|
|
11
|
-
{props.
|
|
12
|
-
<PlaceCircle position={
|
|
12
|
+
{props.places.map((place) => (
|
|
13
|
+
<PlaceCircle position={place2point(place)} label={place.name} textAlign="left" />
|
|
13
14
|
))}
|
|
14
15
|
</div>
|
|
15
16
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AddressBox } from "../../business-components/AddressBox";
|
|
2
2
|
import { DrivingLine } from "../../business-components/DrivingLine";
|
|
3
3
|
import { DrivingRoute } from "../../business-components/DrivingRoute";
|
|
4
|
+
import { PickupPoints } from "../../business-components/PickupPoints";
|
|
4
5
|
import { TaxiCar } from "../../business-components/TaxiCar";
|
|
5
6
|
import {
|
|
6
7
|
useBusinessMapRecomendPlace,
|
|
@@ -40,15 +41,16 @@ export const SomePage = defineSetup(function Hello() {
|
|
|
40
41
|
console.log("getRecomendPlace context?.source = ", context?.source);
|
|
41
42
|
return [{ lat: lat + 0.0001, lng: lng + 0.0001, name: "place name 1" }];
|
|
42
43
|
};
|
|
43
|
-
const { centerPlace, centerPoint, isDragging, isGeoLoading } =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
const { centerPlace, centerPoint, placeCandidates, isDragging, isGeoLoading } =
|
|
45
|
+
useBusinessMapRecomendPlace({
|
|
46
|
+
mapRef,
|
|
47
|
+
recomendPlaceGeoLimit: 300,
|
|
48
|
+
recomendPlaceDragLimit: 30,
|
|
49
|
+
getRecomendPlace,
|
|
50
|
+
onChangeGeoLocation: (v) => console.log("onChangeGeoLocation: ", v),
|
|
51
|
+
onChangePlace: (v) => console.log("onChangePlace: ", v),
|
|
52
|
+
onChangeRecomandPlace: (v) => console.log("onChangeRecomandPlace: ", v),
|
|
53
|
+
});
|
|
52
54
|
(window as any).panTo = panTo;
|
|
53
55
|
return () => {
|
|
54
56
|
return (
|
|
@@ -64,6 +66,7 @@ export const SomePage = defineSetup(function Hello() {
|
|
|
64
66
|
zoom={15}
|
|
65
67
|
mapRef={setMap}
|
|
66
68
|
>
|
|
69
|
+
<PickupPoints places={placeCandidates.value} />
|
|
67
70
|
<AddressBox
|
|
68
71
|
type="box"
|
|
69
72
|
position={centerPoint.value}
|
|
@@ -19,35 +19,26 @@ export const useGeoLocation = (props: UseGeoLocationProps) => {
|
|
|
19
19
|
speed: 0,
|
|
20
20
|
});
|
|
21
21
|
const positionRef = ref<Point>([coordinateRef.value.longitude, coordinateRef.value.latitude]);
|
|
22
|
-
watchEffect(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
positionRef.value = point;
|
|
34
|
-
onChange?.({ position: point, coordinate });
|
|
35
|
-
},
|
|
36
|
-
(error) => {
|
|
37
|
-
loading.value = false;
|
|
38
|
-
errorRef.value = error;
|
|
39
|
-
console.log("errorRef = ", errorRef);
|
|
40
|
-
},
|
|
41
|
-
// debug
|
|
42
|
-
{ timeout: 5000 * 1000 }
|
|
43
|
-
// { timeout: 5000 }
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
onTrigger(e) {
|
|
48
|
-
console.log("useGeoLocation onTrigger: ", e.key, e.newValue, e.oldValue);
|
|
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 });
|
|
49
33
|
},
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
});
|
|
52
43
|
return { errorRef, positionRef, coordinateRef, loading };
|
|
53
44
|
};
|
package/src/hooks/useMapPlace.ts
CHANGED
|
@@ -19,7 +19,6 @@ export const useAmapPlace = (props: UseMapPlaceProps<AMap.Map>) => {
|
|
|
19
19
|
watch(
|
|
20
20
|
() => placeKey.value,
|
|
21
21
|
() => {
|
|
22
|
-
debugger;
|
|
23
22
|
if (!readyRef.value) return;
|
|
24
23
|
const geocoder = new AMap.Geocoder({ lang: LANGUAGE });
|
|
25
24
|
const [lng, lat] = pointRef.value;
|
|
@@ -42,11 +41,6 @@ export const useAmapPlace = (props: UseMapPlaceProps<AMap.Map>) => {
|
|
|
42
41
|
throw result;
|
|
43
42
|
}
|
|
44
43
|
});
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
onTrigger(e) {
|
|
48
|
-
console.log("useAmapPlace onTrigger: ", e.key, e.newValue, e.oldValue);
|
|
49
|
-
},
|
|
50
44
|
}
|
|
51
45
|
);
|
|
52
46
|
return { place, updatePlace };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { reactive, Ref, watch } from "vue-demi";
|
|
1
|
+
import { reactive, ref, Ref, watch } from "vue-demi";
|
|
2
2
|
import { useMapSupplier } from "../components/MapProvider/useMapSupplier";
|
|
3
3
|
import type { MapShallowRef, Place, Point } from "../types/interface";
|
|
4
4
|
import { pipeAsync, place2point } from "../utils/transform";
|
|
@@ -41,6 +41,7 @@ export interface UseMapRecomendPlaceProps<M = AMap.Map | google.maps.Map, C = Re
|
|
|
41
41
|
}
|
|
42
42
|
export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<AMap.Map, C>) => {
|
|
43
43
|
const { pointRef, mapRef, getRecomendPlace, getLimit, context, onChange, onChangePlace } = props;
|
|
44
|
+
const placeCandidatesRef = ref<Place[]>([]);
|
|
44
45
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
45
46
|
const { readyRef } = useMapReady(mapRef);
|
|
46
47
|
const { place, updatePlace } = useAmapPlace({ pointRef, mapRef, onChange: onChangePlace });
|
|
@@ -48,27 +49,23 @@ export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<AMap.Map
|
|
|
48
49
|
watch(
|
|
49
50
|
() => recomendPlaceKey.value,
|
|
50
51
|
async () => {
|
|
51
|
-
debugger;
|
|
52
52
|
if (!readyRef.value) return;
|
|
53
53
|
const placeCandidates = await getRecomendPlace({ ...place }, context);
|
|
54
54
|
const { shortestPlace, shortestDistance } = findAmapNearestPlace(place, placeCandidates);
|
|
55
55
|
console.log("shortestPlace, shortestDistance = ", shortestPlace, shortestDistance);
|
|
56
56
|
const limit = getLimit(context);
|
|
57
57
|
const resultPlace = shortestDistance > limit ? place : shortestPlace;
|
|
58
|
+
placeCandidatesRef.value = placeCandidates;
|
|
58
59
|
Object.assign(recomendPlace, { ...resultPlace });
|
|
59
60
|
pipeAsync(onChange)?.({ ...resultPlace });
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
onTrigger(e) {
|
|
63
|
-
console.log("UseMapRecomendPlaceProps onTrigger: ", e.key, e.newValue, e.oldValue);
|
|
64
|
-
},
|
|
65
61
|
}
|
|
66
62
|
);
|
|
67
|
-
return { recomendPlace, updateRecomandPlace, updatePlace };
|
|
63
|
+
return { recomendPlace, placeCandidates: placeCandidatesRef, updateRecomandPlace, updatePlace };
|
|
68
64
|
};
|
|
69
65
|
|
|
70
66
|
export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<google.maps.Map, C>) => {
|
|
71
67
|
const { pointRef, mapRef, getRecomendPlace, getLimit, context, onChange, onChangePlace } = props;
|
|
68
|
+
const placeCandidatesRef = ref<Place[]>([]);
|
|
72
69
|
const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
|
|
73
70
|
const { readyRef } = useMapReady(mapRef);
|
|
74
71
|
const { place, updatePlace } = useGmapPlace({ pointRef, mapRef, onChange: onChangePlace });
|
|
@@ -81,11 +78,12 @@ export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<google.m
|
|
|
81
78
|
const { shortestPlace, shortestDistance } = findGmapNearestPlace(place, placeCandidates);
|
|
82
79
|
const limit = getLimit(context);
|
|
83
80
|
const resultPlace = shortestDistance > limit ? place : shortestPlace;
|
|
81
|
+
placeCandidatesRef.value = placeCandidates;
|
|
84
82
|
Object.assign(recomendPlace, { ...resultPlace });
|
|
85
83
|
pipeAsync(onChange)?.({ ...resultPlace });
|
|
86
84
|
}
|
|
87
85
|
);
|
|
88
|
-
return { recomendPlace, updateRecomandPlace, updatePlace };
|
|
86
|
+
return { recomendPlace, placeCandidates: placeCandidatesRef, updateRecomandPlace, updatePlace };
|
|
89
87
|
};
|
|
90
88
|
|
|
91
89
|
export const useMapRecomendPlace = <C>(
|
|
@@ -54,7 +54,7 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
|
|
|
54
54
|
onChangeByDrag?.(point);
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
|
-
const { updatePlace, updateRecomandPlace } = useMapRecomendPlace({
|
|
57
|
+
const { updatePlace, updateRecomandPlace, placeCandidates } = useMapRecomendPlace({
|
|
58
58
|
pointRef: centerPoint,
|
|
59
59
|
context: centerSource,
|
|
60
60
|
getRecomendPlace,
|
|
@@ -90,5 +90,6 @@ export const useBusinessMapRecomendPlace = (props: UseBusinessMapRecomendPlacePr
|
|
|
90
90
|
geoError: errorRef,
|
|
91
91
|
centerPlace,
|
|
92
92
|
centerPoint,
|
|
93
|
+
placeCandidates,
|
|
93
94
|
};
|
|
94
95
|
};
|