@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",
@@ -91,4 +91,4 @@
91
91
  "engines": {
92
92
  "node": ">=16.0.0"
93
93
  }
94
- }
94
+ }
@@ -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
- positions: [number, number][];
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.positions.map((position, idx) => (
12
- <PlaceCircle position={position} label={props.labels[idx]} textAlign="left" />
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 } = useBusinessMapRecomendPlace({
44
- mapRef,
45
- recomendPlaceGeoLimit: 300,
46
- recomendPlaceDragLimit: 30,
47
- getRecomendPlace,
48
- onChangeGeoLocation: (v) => console.log("onChangeGeoLocation: ", v),
49
- onChangePlace: (v) => console.log("onChangePlace: ", v),
50
- onChangeRecomandPlace: (v) => console.log("onChangeRecomandPlace: ", v),
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}
@@ -29,7 +29,6 @@ export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerVie
29
29
  },
30
30
  (props) => {
31
31
  if (!markerRef.value) return;
32
- debugger;
33
32
  Object.assign(markerRef.value, props);
34
33
  }
35
34
  );
@@ -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
- debugger;
25
- mapRef.value;
26
- loading.value = true;
27
- navigator.geolocation.getCurrentPosition(
28
- (position) => {
29
- loading.value = false;
30
- const coordinate = position.coords;
31
- const point: Point = [position.coords.longitude, position.coords.latitude];
32
- coordinateRef.value = coordinate;
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
  };
@@ -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
  };