@heycar/heycars-map 0.3.6 → 0.3.8

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 (177) hide show
  1. package/dist/business-components/AbsoluteAddressBox/AbsoluteAddressBox.d.ts +1 -2
  2. package/dist/business-components/AddressBox/AddressBox.d.ts +1 -2
  3. package/dist/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +1 -0
  4. package/dist/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +1 -2
  5. package/dist/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.d.ts +1 -2
  6. package/dist/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +2 -3
  7. package/dist/business-components/DrivingLine/DrivingLine.d.ts +1 -2
  8. package/dist/business-components/DrivingRoute/DrivingRoute.d.ts +1 -2
  9. package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +1 -2
  10. package/dist/business-components/PickupPoints/PickupPoints.d.ts +1 -2
  11. package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +1 -2
  12. package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +1 -2
  13. package/dist/business-components/TaxiCar/TaxiCar.d.ts +1 -2
  14. package/dist/business-components/WalkingLine/WalkingLine.d.ts +1 -2
  15. package/dist/business-components/WalkingRoute/WalkingRoute.d.ts +1 -2
  16. package/dist/business-components/WaveCircle/WaveCircle.d.ts +1 -2
  17. package/dist/components/Gmap/Gmap.css.d.ts +1 -0
  18. package/dist/components/MapProvider/MapProvider.d.ts +1 -2
  19. package/dist/hooks/useMapAutoComplete.d.ts +1 -2
  20. package/dist/hooks/useMapPlace.d.ts +2 -1
  21. package/dist/hooks/useMapRecomendPlace.d.ts +1 -1
  22. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -2
  23. package/dist/index.cjs +55 -55
  24. package/dist/index.js +1923 -1999
  25. package/dist/style.css +1 -1
  26. package/package.json +1 -1
  27. package/todo.md +16 -4
  28. package/dist/Demo/CityBound/SearchDemo.d.ts +0 -1
  29. package/dist/Demo/CityBound/country.d.ts +0 -5
  30. package/dist/Demo/CityBound/searchResult.d.ts +0 -8
  31. package/dist/hooks/useMapLog.d.ts +0 -5
  32. package/src/App.tsx +0 -27
  33. package/src/Demo/CityBound/SearchDemo.tsx +0 -142
  34. package/src/Demo/CityBound/country.ts +0 -4179
  35. package/src/Demo/CityBound/searchResult.ts +0 -21122
  36. package/src/Demo/Demo.css.ts +0 -6
  37. package/src/Demo/Demo.tsx +0 -97
  38. package/src/Demo/DemoBusinessQuoting.tsx +0 -18
  39. package/src/Demo/DemoBusinessRecomendPlace.tsx +0 -89
  40. package/src/Demo/DemoBusinessTaxiEnd.tsx +0 -38
  41. package/src/Demo/DemoBusinessTaxiService.tsx +0 -58
  42. package/src/Demo/sample.json +0 -793
  43. package/src/api/contants.ts +0 -3
  44. package/src/api/driving.ts +0 -87
  45. package/src/api/geocoder.ts +0 -88
  46. package/src/api/geometry.ts +0 -44
  47. package/src/api/place.ts +0 -105
  48. package/src/assets/icons/svg/address-locator.svg +0 -1
  49. package/src/assets/icons/svg/arrow-right.svg +0 -1
  50. package/src/assets/icons/svg/end-point.svg +0 -1
  51. package/src/assets/icons/svg/passenger-circle.svg +0 -1
  52. package/src/assets/icons/svg/place-circle.svg +0 -22
  53. package/src/assets/icons/svg/start-point.svg +0 -1
  54. package/src/assets/icons/svg/taxi-car.svg +0 -1
  55. package/src/assets/icons/svg/wave-circle.svg +0 -1
  56. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.css.ts +0 -68
  57. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +0 -50
  58. package/src/business-components/AbsoluteAddressBox/index.ts +0 -1
  59. package/src/business-components/AddressBox/AddressBox.css.ts +0 -55
  60. package/src/business-components/AddressBox/AddressBox.tsx +0 -76
  61. package/src/business-components/AddressBox/index.ts +0 -1
  62. package/src/business-components/AddressLocator/AddressLocator.css.ts +0 -7
  63. package/src/business-components/AddressLocator/AddressLocator.tsx +0 -40
  64. package/src/business-components/AddressLocator/index.ts +0 -1
  65. package/src/business-components/BusinessQuotingMap/BusinessQuotingMap.tsx +0 -49
  66. package/src/business-components/BusinessQuotingMap/index.ts +0 -1
  67. package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +0 -200
  68. package/src/business-components/BusinessRecomendPlaceMap/index.ts +0 -1
  69. package/src/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.tsx +0 -43
  70. package/src/business-components/BusinessTaxiEndMap/index.ts +0 -1
  71. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +0 -453
  72. package/src/business-components/BusinessTaxiServiceMap/index.ts +0 -1
  73. package/src/business-components/DrivingLine/DrivingLine.css.ts +0 -10
  74. package/src/business-components/DrivingLine/DrivingLine.tsx +0 -135
  75. package/src/business-components/DrivingLine/index.ts +0 -1
  76. package/src/business-components/DrivingRoute/DrivingRoute.tsx +0 -52
  77. package/src/business-components/DrivingRoute/index.ts +0 -1
  78. package/src/business-components/FitView/FitView.tsx +0 -22
  79. package/src/business-components/FitView/index.ts +0 -1
  80. package/src/business-components/PassengerCircle/PassengerCircle.css.ts +0 -21
  81. package/src/business-components/PassengerCircle/PassengerCircle.tsx +0 -69
  82. package/src/business-components/PassengerCircle/index.ts +0 -1
  83. package/src/business-components/PickupPoints/PickupPoints.tsx +0 -38
  84. package/src/business-components/PickupPoints/index.ts +0 -1
  85. package/src/business-components/PlaceCircle/PlaceCircle.css.ts +0 -76
  86. package/src/business-components/PlaceCircle/PlaceCircle.tsx +0 -110
  87. package/src/business-components/PlaceCircle/index.ts +0 -1
  88. package/src/business-components/StartEndPoint/StartEndPoint.css.ts +0 -70
  89. package/src/business-components/StartEndPoint/StartEndPoint.tsx +0 -122
  90. package/src/business-components/StartEndPoint/index.ts +0 -1
  91. package/src/business-components/TaxiCar/TaxiCar.css.ts +0 -16
  92. package/src/business-components/TaxiCar/TaxiCar.tsx +0 -93
  93. package/src/business-components/TaxiCar/index.ts +0 -1
  94. package/src/business-components/WalkingLine/WalkingLine.tsx +0 -80
  95. package/src/business-components/WalkingLine/index.ts +0 -1
  96. package/src/business-components/WalkingRoute/WalkingRoute.tsx +0 -43
  97. package/src/business-components/WalkingRoute/index.ts +0 -1
  98. package/src/business-components/WaveCircle/WaveCircle.css.ts +0 -54
  99. package/src/business-components/WaveCircle/WaveCircle.tsx +0 -59
  100. package/src/business-components/WaveCircle/index.ts +0 -1
  101. package/src/components/Amap/Amap.css.ts +0 -5
  102. package/src/components/Amap/Amap.ts +0 -76
  103. package/src/components/Amap/index.ts +0 -1
  104. package/src/components/AmapInfoWindow/AmapInfoWindow.ts +0 -45
  105. package/src/components/AmapInfoWindow/index.ts +0 -1
  106. package/src/components/AmapLoader/AmapLoader.ts +0 -20
  107. package/src/components/AmapLoader/index.ts +0 -1
  108. package/src/components/AmapMarker/AmapMarker.ts +0 -48
  109. package/src/components/AmapMarker/index.ts +0 -1
  110. package/src/components/AmapPolygon/AmapPolygon.ts +0 -41
  111. package/src/components/AmapPolygon/index.ts +0 -1
  112. package/src/components/AmapPolyline/AmapPolyline.ts +0 -40
  113. package/src/components/AmapPolyline/index.ts +0 -1
  114. package/src/components/AmapText/AmapText.ts +0 -39
  115. package/src/components/AmapText/index.ts +0 -1
  116. package/src/components/Gmap/Gmap.css.ts +0 -5
  117. package/src/components/Gmap/Gmap.ts +0 -56
  118. package/src/components/Gmap/index.ts +0 -1
  119. package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +0 -63
  120. package/src/components/GmapAdvancedMarkerView/index.ts +0 -1
  121. package/src/components/GmapInfoWindow/GmapInfoWindow.ts +0 -38
  122. package/src/components/GmapInfoWindow/index.ts +0 -1
  123. package/src/components/GmapLoader/GmapLoader.ts +0 -21
  124. package/src/components/GmapLoader/index.ts +0 -1
  125. package/src/components/GmapMarker/GmapMarker.ts +0 -34
  126. package/src/components/GmapMarker/index.ts +0 -1
  127. package/src/components/GmapPolygon/GmapPolygon.ts +0 -29
  128. package/src/components/GmapPolygon/index.ts +0 -1
  129. package/src/components/GmapPolyline/GmapPolyline.ts +0 -29
  130. package/src/components/GmapPolyline/index.ts +0 -1
  131. package/src/components/MapProvider/MapProvider.tsx +0 -81
  132. package/src/components/MapProvider/index.ts +0 -1
  133. package/src/hooks/useDrivingRoute.ts +0 -106
  134. package/src/hooks/useGeoLocation.ts +0 -70
  135. package/src/hooks/useHeycarMap.ts +0 -28
  136. package/src/hooks/useMap.ts +0 -43
  137. package/src/hooks/useMapAngle.ts +0 -42
  138. package/src/hooks/useMapAutoComplete.ts +0 -130
  139. package/src/hooks/useMapCityBound.ts +0 -64
  140. package/src/hooks/useMapDrag.ts +0 -72
  141. package/src/hooks/useMapEventSource.ts +0 -20
  142. package/src/hooks/useMapFitView.ts +0 -135
  143. package/src/hooks/useMapGeometry.ts +0 -27
  144. package/src/hooks/useMapLngLatToVw.ts +0 -31
  145. package/src/hooks/useMapLoader.ts +0 -164
  146. package/src/hooks/useMapLog.ts +0 -24
  147. package/src/hooks/useMapPlace.ts +0 -130
  148. package/src/hooks/useMapRecomendPlace.ts +0 -150
  149. package/src/hooks/useMapSupplier.ts +0 -16
  150. package/src/hooks/useOverlay.ts +0 -23
  151. package/src/hooks/usePlacesLabelDirection.ts +0 -61
  152. package/src/hooks/useUdate.ts +0 -9
  153. package/src/hooks/useWaitTimer.ts +0 -25
  154. package/src/hooks/useWalkingRoute.ts +0 -87
  155. package/src/hooks-business/useBusinessMapAutoComplete.ts +0 -22
  156. package/src/hooks-business/useBusinessQuotingMap.ts +0 -11
  157. package/src/hooks-business/useBusinessRecomendPlaceMap.ts +0 -45
  158. package/src/hooks-business/useBusinessTaxiServiceMap.ts +0 -12
  159. package/src/index.ts +0 -33
  160. package/src/main.ts +0 -6
  161. package/src/style.css +0 -0
  162. package/src/types/amap/autocomplete.d.ts +0 -64
  163. package/src/types/amap/driving.d.ts +0 -170
  164. package/src/types/amap/geocoder.d.ts +0 -217
  165. package/src/types/amap/marker.ts +0 -11
  166. package/src/types/amap/place.d.ts +0 -114
  167. package/src/types/amap/plugin.d.ts +0 -27
  168. package/src/types/amap/walking.d.ts +0 -78
  169. package/src/types/global.d.ts +0 -10
  170. package/src/types/helper.ts +0 -172
  171. package/src/types/interface.ts +0 -62
  172. package/src/types/mapHelper.ts +0 -1
  173. package/src/utils/compare.ts +0 -189
  174. package/src/utils/dom.ts +0 -14
  175. package/src/utils/helper.ts +0 -5
  176. package/src/utils/transform.ts +0 -68
  177. package/src/vite-env.d.ts +0 -12
@@ -1,130 +0,0 @@
1
- import { reactive, ref, Ref, watch } from "vue-demi";
2
- import { LANGUAGE } from "../types/helper";
3
- import type { Place, Point } from "../types/interface";
4
- import { geocoderResult2cityName } from "../utils/transform";
5
- import { useMapSupplier } from "./useMapSupplier";
6
- import { useUpdate } from "./useUdate";
7
-
8
- export interface UseMapPlaceOnChangeCityProps {
9
- cityName?: string;
10
- cityParentName?: string;
11
- }
12
- export interface UseMapPlaceProps {
13
- pointRef: Ref<Point>;
14
- onChange?: (value: Place) => any;
15
- onChangeCity?: (value: UseMapPlaceOnChangeCityProps) => any;
16
- }
17
- export const useAmapPlace = (props: UseMapPlaceProps) => {
18
- const { onChange, onChangeCity } = props;
19
- const defaultPoint: Point = [...props.pointRef.value];
20
- const pointRef = ref<Point>(defaultPoint);
21
- const { readyPromise } = useMapSupplier();
22
- const place = reactive<Place>({
23
- lng: pointRef.value[0],
24
- lat: pointRef.value[1],
25
- name: "",
26
- });
27
- const { idx: placeKey, update } = useUpdate();
28
- const updateCity = (value: Place) => {
29
- const geocoder = new AMap.Geocoder({ lang: LANGUAGE });
30
- const { lng, lat } = value;
31
- geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
32
- if (status !== "complete") return;
33
- const { addressComponent } = (result as AMap.ReGeocoderResult).regeocode;
34
- const cityName = addressComponent.city ? addressComponent.city : addressComponent.province;
35
- const cityParentName = addressComponent.province;
36
- onChangeCity?.({ cityName, cityParentName });
37
- });
38
- };
39
- const updatePlace = (value: Point) => {
40
- pointRef.value = value;
41
- update();
42
- };
43
- const setPlace = (value: Place) => {
44
- place.lng = value.lng;
45
- place.lat = value.lat;
46
- place.name = value.name;
47
- };
48
- watch(
49
- () => placeKey.value,
50
- async () => {
51
- await readyPromise;
52
- const geocoder = new AMap.Geocoder({ lang: LANGUAGE });
53
- const [lng, lat] = pointRef.value;
54
- geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
55
- switch (status) {
56
- case "complete": {
57
- const { formattedAddress: name, addressComponent } = (result as AMap.ReGeocoderResult)
58
- .regeocode;
59
- const cityName = addressComponent.city
60
- ? addressComponent.city
61
- : addressComponent.province;
62
- const cityParentName = addressComponent.province;
63
- place.name = name;
64
- place.lng = lng;
65
- place.lat = lat;
66
- onChange?.({ lng, lat, name });
67
- onChangeCity?.({ cityName, cityParentName });
68
- return;
69
- }
70
-
71
- case "no_data":
72
- place.name = "";
73
- onChange?.({ lng, lat, name: "" });
74
- return;
75
- case "error":
76
- throw result;
77
- }
78
- });
79
- }
80
- );
81
- return { place, updatePlace, setPlace, updateCity };
82
- };
83
-
84
- export const useGmapPlace = (props: UseMapPlaceProps) => {
85
- const { pointRef, onChange, onChangeCity } = props;
86
- const { readyPromise } = useMapSupplier();
87
- const { idx: placeKey, update: updatePlace } = useUpdate();
88
- const place = reactive<Place>({
89
- lng: pointRef.value[0],
90
- lat: pointRef.value[1],
91
- name: "",
92
- });
93
- const setPlace = (value: Place) => {
94
- place.lng = value.lng;
95
- place.lat = value.lat;
96
- place.name = value.name;
97
- };
98
- const updateCity = async (value: Place) => {
99
- const geocoder = new google.maps.Geocoder();
100
- const { lng, lat } = value;
101
- const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
102
- const cityName = geocoderResult2cityName(results[0]);
103
- const cityParentName = results.slice(-2)[0].address_components[0].long_name;
104
- onChangeCity?.({ cityName, cityParentName });
105
- };
106
- watch(
107
- () => placeKey.value,
108
- async () => {
109
- await readyPromise;
110
- const geocoder = new google.maps.Geocoder();
111
- const [lng, lat] = pointRef.value;
112
- const { results } = await geocoder.geocode({ language: LANGUAGE, location: { lng, lat } });
113
- const name = results[0].formatted_address;
114
- const cityName = geocoderResult2cityName(results[0]);
115
- const cityParentName = results.slice(-2)[0].address_components[0].long_name;
116
- // const countryName = results.slice(-1)[0].address_components[0].long_name;
117
- place.lng = lng;
118
- place.lat = lat;
119
- place.name = name;
120
- onChange?.({ lng, lat, name });
121
- onChangeCity?.({ cityName, cityParentName });
122
- }
123
- );
124
- return { place, updatePlace, setPlace, updateCity };
125
- };
126
-
127
- export const useMapPlace = (props: UseMapPlaceProps) => {
128
- const { supplier } = useMapSupplier();
129
- return supplier === "gmap" ? useGmapPlace(props) : useAmapPlace(props);
130
- };
@@ -1,150 +0,0 @@
1
- import { computed, reactive, ref, Ref, watch } from "vue-demi";
2
- import type { Place, Point } from "../types/interface";
3
-
4
- import { isPointEqual, place2point } from "../utils/transform";
5
- import { useAmapPlace, useGmapPlace, UseMapPlaceProps } from "./useMapPlace";
6
- import { useMapSupplier } from "./useMapSupplier";
7
- import { useUpdate } from "./useUdate";
8
-
9
- const findAmapNearestPlace = (place: Place, candidates: Place[]) => {
10
- let shortestDistance = Infinity;
11
- let shortestPlace = place;
12
- for (const candidate of candidates) {
13
- const distance = AMap.GeometryUtil.distance(place2point(place), place2point(candidate));
14
- if (distance >= shortestDistance) continue;
15
- shortestPlace = candidate;
16
- shortestDistance = distance;
17
- }
18
- return { shortestPlace, shortestDistance };
19
- };
20
-
21
- const findGmapNearestPlace = (place: Place, candidates: Place[]) => {
22
- let shortestDistance = Infinity;
23
- let shortestPlace = place;
24
- for (const candidate of candidates) {
25
- const distance = google.maps.geometry.spherical.computeDistanceBetween(place, candidate);
26
- if (distance >= shortestDistance) continue;
27
- shortestPlace = candidate;
28
- shortestDistance = distance;
29
- }
30
- return { shortestPlace, shortestDistance };
31
- };
32
-
33
- export interface UseMapRecomendPlaceProps<C = Record<string, any>> {
34
- pointRef: Ref<Point>;
35
- context?: C;
36
- getLimit: (context?: C) => number;
37
- // 如果返回 undefined, 表示当前位置无服务可提供
38
- getRecomendPlace: (place: Place, context?: C) => Promise<Place[] | undefined>;
39
- onChangeCity?: UseMapPlaceProps["onChangeCity"];
40
- onChangePlace?: UseMapPlaceProps["onChange"];
41
- onChange?: (place: Place) => any;
42
- }
43
- export const useAmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
44
- const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace, onChangeCity } =
45
- props;
46
- const availableRef = ref(true);
47
- const placeCandidatesRef = ref<Place[]>([]);
48
- const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
49
- const { readyPromise } = useMapSupplier();
50
- const { place, updatePlace, setPlace, updateCity } = useAmapPlace({
51
- pointRef,
52
- onChange: onChangePlace,
53
- onChangeCity,
54
- });
55
- const recomendPlace = reactive<Place>({ ...place });
56
- const isElectedRef = computed(() => {
57
- const point = pointRef.value;
58
- return placeCandidatesRef.value.some((candidate) =>
59
- isPointEqual(place2point(candidate), point)
60
- );
61
- });
62
- watch(
63
- () => recomendPlaceKey.value,
64
- async () => {
65
- await readyPromise;
66
- const placeCandidates = await getRecomendPlace({ ...place }, context);
67
- if (placeCandidates === undefined) {
68
- availableRef.value = false;
69
- placeCandidatesRef.value = [];
70
- Object.assign(recomendPlace, { ...place });
71
- onChange?.({ ...place });
72
- return;
73
- }
74
- const { shortestPlace, shortestDistance } = findAmapNearestPlace(place, placeCandidates);
75
- const limit = getLimit(context);
76
- const resultPlace = shortestDistance > limit ? place : shortestPlace;
77
- availableRef.value = true;
78
- placeCandidatesRef.value = placeCandidates;
79
- Object.assign(recomendPlace, { ...resultPlace });
80
- onChange?.({ ...resultPlace });
81
- }
82
- );
83
- return {
84
- recomendPlace,
85
- placeCandidates: placeCandidatesRef,
86
- availableRef,
87
- isElectedRef,
88
- updateRecomandPlace,
89
- updatePlace,
90
- setPlace,
91
- updateCity,
92
- };
93
- };
94
-
95
- export const useGmapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
96
- const { pointRef, getRecomendPlace, getLimit, context, onChange, onChangePlace, onChangeCity } =
97
- props;
98
- const availableRef = ref(true);
99
- const placeCandidatesRef = ref<Place[]>([]);
100
- const { idx: recomendPlaceKey, update: updateRecomandPlace } = useUpdate();
101
- const { readyPromise } = useMapSupplier();
102
- const { place, updatePlace, setPlace, updateCity } = useGmapPlace({
103
- pointRef,
104
- onChange: onChangePlace,
105
- onChangeCity,
106
- });
107
- const recomendPlace = reactive<Place>({ ...place });
108
- const isElectedRef = computed(() => {
109
- const point = pointRef.value;
110
- return placeCandidatesRef.value.some((candidate) =>
111
- isPointEqual(place2point(candidate), point)
112
- );
113
- });
114
- watch(
115
- () => recomendPlaceKey.value,
116
- async () => {
117
- await readyPromise;
118
- const placeCandidates = await getRecomendPlace({ ...place }, context);
119
- if (placeCandidates === undefined) {
120
- availableRef.value = false;
121
- placeCandidatesRef.value = [];
122
- Object.assign(recomendPlace, { ...place });
123
- onChange?.({ ...place });
124
- return;
125
- }
126
- const { shortestPlace, shortestDistance } = findGmapNearestPlace(place, placeCandidates);
127
- const limit = getLimit(context);
128
- const resultPlace = shortestDistance > limit ? place : shortestPlace;
129
- availableRef.value = true;
130
- placeCandidatesRef.value = placeCandidates;
131
- Object.assign(recomendPlace, { ...resultPlace });
132
- onChange?.({ ...resultPlace });
133
- }
134
- );
135
- return {
136
- recomendPlace,
137
- placeCandidates: placeCandidatesRef,
138
- availableRef,
139
- isElectedRef,
140
- updateRecomandPlace,
141
- updatePlace,
142
- setPlace,
143
- updateCity,
144
- };
145
- };
146
-
147
- export const useMapRecomendPlace = <C>(props: UseMapRecomendPlaceProps<C>) => {
148
- const { supplier } = useMapSupplier();
149
- return supplier === "gmap" ? useGmapRecomendPlace(props) : useAmapRecomendPlace(props);
150
- };
@@ -1,16 +0,0 @@
1
- import { inject, provide } from "vue-demi";
2
- import type { Status, UseMapLoaderOutput, UseMapLoaderProps } from "./useMapLoader";
3
-
4
- export interface MapSupplierPayolad extends UseMapLoaderProps {
5
- gmapId: string;
6
- readyPromise: UseMapLoaderOutput["readyPromise"];
7
- status: Status;
8
- }
9
- const context = Symbol();
10
-
11
- export const useMapSupplier = () => {
12
- const payload = inject<MapSupplierPayolad>(context);
13
- if (!payload) throw new Error("MyError: useMapSupplier should be under MapProvider");
14
- return payload;
15
- };
16
- export const provideMapSupplier = (payload: MapSupplierPayolad) => provide(context, payload);
@@ -1,23 +0,0 @@
1
- import { ShallowRef, watch } from "vue-demi";
2
- import type { RegisterOverlay } from "../types/interface";
3
-
4
- export type MROP = MapRegisterOverlayProps<AmapOverlay> | MapRegisterOverlayProps<GmapOverlay>;
5
- export interface MapRegisterOverlayProps<T> {
6
- registerOverlay?: RegisterOverlay<T>;
7
- }
8
- export type AmapOverlay = Parameters<AMap.OverlayGroup["addOverlay"]>[0];
9
- export type GmapOverlay = google.maps.Marker | google.maps.marker.AdvancedMarkerView;
10
- export interface UseMapOverlayProps<T> extends MapRegisterOverlayProps<T> {
11
- overlayRef: ShallowRef<T | undefined>;
12
- }
13
- export const useMapOverlay = <T>(props: UseMapOverlayProps<T>) => {
14
- const { registerOverlay, overlayRef } = props;
15
- watch(
16
- () => overlayRef.value,
17
- (overlay, prevOverlay) => {
18
- if (!registerOverlay) return;
19
- if (prevOverlay) registerOverlay.remove(prevOverlay);
20
- if (overlay) registerOverlay.add(overlay);
21
- }
22
- );
23
- };
@@ -1,61 +0,0 @@
1
- import { ref } from "vue-demi";
2
- import type { Place, Point } from "../types/interface";
3
- import { watchEffectForDeepOption } from "../utils/compare";
4
- import { place2point } from "../utils/transform";
5
- import { useMapLngLatToVw } from "./useMapLngLatToVw";
6
-
7
- type LabelDirection = "left" | "right";
8
- const reverse = (direction: LabelDirection) => (direction === "left" ? "right" : "left");
9
-
10
- export interface UsePointsLabelDirectionProps {
11
- places: Place[];
12
- widthLimit: number;
13
- heightLimit: number;
14
- }
15
- export const usePointsLabelDirection = (props: UsePointsLabelDirectionProps) => {
16
- const { widthLimit, heightLimit } = props;
17
- const { apiMapLngLatToVw } = useMapLngLatToVw();
18
- const diffVw = (from: Point, to: Point) => {
19
- const vw = 100 / window.innerWidth;
20
- const [x1, y1] = apiMapLngLatToVw(from);
21
- const [x2, y2] = apiMapLngLatToVw(to);
22
- return [(x2 - x1) * vw, (y2 - y1) * vw];
23
- };
24
- const directionsRef = ref<LabelDirection[]>(Array(props.places.length).fill("right"));
25
- watchEffectForDeepOption(
26
- () => props.places.map(place2point),
27
- (points) => {
28
- const sortedPoints = points
29
- .map((point, index) => ({ point, index }))
30
- .sort(({ point: [, lat1] }, { point: [, lat2] }) =>
31
- lat1 < lat2 ? 1 : lat1 > lat2 ? -1 : 0
32
- );
33
- const len = points.length;
34
- const result: LabelDirection[] = Array(len);
35
- let prevDirection: LabelDirection = "right";
36
- let isLimited = false;
37
- for (let idx = 0; idx < len; idx++) {
38
- const { index } = sortedPoints[idx];
39
- if (idx === len - 1) {
40
- result[index] = isLimited ? reverse(prevDirection) : "right";
41
- continue;
42
- }
43
- if (idx === 0) {
44
- const [dx, dy] = diffVw(sortedPoints[idx].point, sortedPoints[idx + 1].point);
45
- isLimited = dx > -widthLimit && dx < widthLimit && dy > -heightLimit && dy < heightLimit;
46
- const direction: LabelDirection = !isLimited ? "right" : dx > 0 ? "left" : "right";
47
- result[index] = direction;
48
- prevDirection = direction;
49
- continue;
50
- }
51
- const [dx, dy] = diffVw(sortedPoints[idx].point, sortedPoints[idx + 1].point);
52
- const direction: LabelDirection = isLimited ? reverse(prevDirection) : "right";
53
- result[index] = direction;
54
- prevDirection = direction;
55
- isLimited = dx > -widthLimit && dx < widthLimit && dy > -heightLimit && dy < heightLimit;
56
- }
57
- directionsRef.value = result;
58
- }
59
- );
60
- return directionsRef;
61
- };
@@ -1,9 +0,0 @@
1
- import { ref } from "vue-demi";
2
-
3
- export const useUpdate = () => {
4
- const idx = ref(0);
5
- const update = () => {
6
- idx.value += 1;
7
- };
8
- return { idx, update };
9
- };
@@ -1,25 +0,0 @@
1
- interface TimerStop {
2
- promise: Promise<void>;
3
- resolve?: () => void;
4
- }
5
-
6
- export interface UseWaitTimerProps {
7
- interval: number;
8
- }
9
- export const useWaitTimer = (props: UseWaitTimerProps) => {
10
- const { interval } = props;
11
- let timer: number | undefined = undefined;
12
- const timerStop: TimerStop = {
13
- promise: Promise.resolve(),
14
- resolve: undefined,
15
- };
16
- const timerStart = () => {
17
- if (timer) clearTimeout(timer);
18
- timerStop.resolve?.();
19
- timerStop.promise = new Promise((resolve) => {
20
- timerStop.resolve = resolve;
21
- timer = setTimeout(resolve, interval);
22
- });
23
- };
24
- return { timerStart, timerStop };
25
- };
@@ -1,87 +0,0 @@
1
- import { ShallowRef, shallowRef } from "vue-demi";
2
- import type { Point } from "../types/interface";
3
- import { watchPostEffectForDeepOption } from "../utils/compare";
4
- import { useMapSupplier } from "./useMapSupplier";
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
- if (!walkingResult.routes) {
23
- return;
24
- }
25
- const firstRoute = walkingResult.routes[0];
26
- for (const step of firstRoute.steps) {
27
- const stepPath = step.path.map<Point>(({ lng, lat }) => [lng, lat]);
28
- path = path.concat(stepPath);
29
- }
30
- pathRef.value = path;
31
- return;
32
- }
33
- case "no_data":
34
- pathRef.value = [];
35
- return;
36
- default:
37
- throw result;
38
- }
39
- });
40
- }
41
- );
42
- return pathRef;
43
- };
44
-
45
- export const useGWalkingRoute = (props: UseWalkingRouteProps) => {
46
- const pathRef = shallowRef<Point[]>([]);
47
- const gmapDirectionsService = new google.maps.DirectionsService();
48
- watchPostEffectForDeepOption(
49
- () => ({ ...props }),
50
- ({ from, to }) => {
51
- gmapDirectionsService.route(
52
- {
53
- origin: { lng: from[0], lat: from[1] },
54
- destination: { lng: to[0], lat: to[1] },
55
- travelMode: google.maps.TravelMode.WALKING,
56
- },
57
- (result, status) => {
58
- switch (status) {
59
- case google.maps.DirectionsStatus.OK: {
60
- let path: Point[] = [];
61
- const firstRoute = result!.routes[0];
62
- const stepPath = firstRoute.overview_path.map<Point>((item) => [
63
- item.lng(),
64
- item.lat(),
65
- ]);
66
- path = path.concat(stepPath);
67
- pathRef.value = path;
68
- return;
69
- }
70
- case google.maps.DirectionsStatus.ZERO_RESULTS:
71
- case google.maps.DirectionsStatus.NOT_FOUND:
72
- pathRef.value = [];
73
- return;
74
- default:
75
- throw new Error(status);
76
- }
77
- }
78
- );
79
- }
80
- );
81
- return pathRef;
82
- };
83
-
84
- export const useWalkingRoute = (props: UseWalkingRouteProps): ShallowRef<Point[]> => {
85
- const { supplier } = useMapSupplier();
86
- return supplier === "gmap" ? useGWalkingRoute(props) : useAWalkingRoute(props);
87
- };
@@ -1,22 +0,0 @@
1
- import type { Ref } from "vue-demi";
2
- import { useMapAutoComplete } from "../hooks/useMapAutoComplete";
3
- import { useMapBoundCity } from "../hooks/useMapCityBound";
4
- import type { MapLogProps } from "../hooks/useMapLog";
5
-
6
- export interface UseBusinessMapAutoCompleteProps extends MapLogProps {
7
- cityNameRef: Ref<string>;
8
- }
9
-
10
- export const useBusinessMapAutoComplete = (props: UseBusinessMapAutoCompleteProps) => {
11
- const { cityNameRef } = props;
12
- const city = useMapBoundCity({
13
- cityNameRef,
14
- onChange: (v) => setCity(v),
15
- });
16
- const { autoCompletePlaces, setKeyword, setCity } = useMapAutoComplete({ city, log: props.log });
17
- const handleKeywordInput = (e: Event) => {
18
- const target = e.target as HTMLInputElement;
19
- setKeyword(target.value);
20
- };
21
- return { autoCompletePlaces, setKeyword, setCity, handleKeywordInput };
22
- };
@@ -1,11 +0,0 @@
1
- import { useHeycarMap } from "../hooks/useHeycarMap";
2
- import { useMapFitView } from "../hooks/useMapFitView";
3
-
4
- export const useBusinessQuotingMap = () => {
5
- const { setMap, mapRef } = useHeycarMap();
6
- const { registerFitVeiw, setFitView } = useMapFitView({
7
- mapRef,
8
- padding: [25, 20, 15, 15],
9
- });
10
- return { setMap, registerFitVeiw, setFitView };
11
- };
@@ -1,45 +0,0 @@
1
- import { reactive, ref } from "vue-demi";
2
- import { useMapGeometry } from "../hooks/useMapGeometry";
3
- import type { Place, Point } from "../types/interface";
4
-
5
- export interface BusinessRecomendPlaceContext {
6
- panToGeoPositionByRecomend: (value: Point) => void;
7
- setCenterPlaceByUserSpecified: (value: Place) => void;
8
- onChangeCenterPlace: (value: Place) => void;
9
- onChangeRecomendPlaces: (value: Place[]) => void;
10
- }
11
-
12
- export const useBusinessRecomendPlaceMap = () => {
13
- const centerPlace = reactive<Place>({
14
- lng: 0,
15
- lat: 0,
16
- name: "",
17
- });
18
- const placeCandidates = ref<Place[]>([]);
19
- const { apiMapDistance } = useMapGeometry();
20
- const panToGeoPositionByRecomend = (value: Point) => mapContext.panToGeoPositionByRecomend(value);
21
- const setCenterPlaceByUserSpecified = (value: Place) =>
22
- mapContext.setCenterPlaceByUserSpecified(value);
23
- const mapContext: BusinessRecomendPlaceContext = {
24
- panToGeoPositionByRecomend: () => {
25
- throw new Error("MyError: panToGeoPositionByRecomend used before assigned");
26
- },
27
- setCenterPlaceByUserSpecified: () => {
28
- throw new Error("MyError: setCenterPlaceByRecomand used before assigned");
29
- },
30
- onChangeCenterPlace: (place: Place) => {
31
- Object.assign(centerPlace, { ...place });
32
- },
33
- onChangeRecomendPlaces: (places: Place[]) => {
34
- placeCandidates.value = [...places];
35
- },
36
- };
37
- return {
38
- mapContext,
39
- centerPlace,
40
- placeCandidates,
41
- panToGeoPositionByRecomend,
42
- setCenterPlaceByUserSpecified,
43
- apiMapDistance,
44
- };
45
- };
@@ -1,12 +0,0 @@
1
- import { useHeycarMap } from "../hooks/useHeycarMap";
2
- import { useMapFitView } from "../hooks/useMapFitView";
3
-
4
- export const useBusinessTaxiServiceMap = () => {
5
- const { mapRef, setMap } = useHeycarMap();
6
- const { registerFitVeiw, setFitView } = useMapFitView({
7
- mapRef,
8
- autoFitTimeout: 5000,
9
- padding: [25, 20, 15, 15],
10
- });
11
- return { setMap, registerFitVeiw, setFitView };
12
- };
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- import "./style.css";
2
- export { AbsoluteAddressBox } from "./business-components/AbsoluteAddressBox";
3
- export { AddressBox } from "./business-components/AddressBox";
4
- export { BusinessQuotingMap } from "./business-components/BusinessQuotingMap";
5
- export { BusinessRecomendPlaceMap } from "./business-components/BusinessRecomendPlaceMap";
6
- export { BusinessTaxiEndMap } from "./business-components/BusinessTaxiEndMap";
7
- export { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap";
8
- export { DrivingLine } from "./business-components/DrivingLine";
9
- export { DrivingRoute } from "./business-components/DrivingRoute";
10
- export { PassengerCircle } from "./business-components/PassengerCircle";
11
- export { PickupPoints } from "./business-components/PickupPoints";
12
- export { PlaceCircle } from "./business-components/PlaceCircle";
13
- export { StartEndPoint } from "./business-components/StartEndPoint";
14
- export { TaxiCar } from "./business-components/TaxiCar";
15
- export { WalkingLine } from "./business-components/WalkingLine";
16
- export { WalkingRoute } from "./business-components/WalkingRoute";
17
- export { WaveCircle } from "./business-components/WaveCircle";
18
- export * from "./components/MapProvider";
19
- export * from "./hooks-business/useBusinessMapAutoComplete";
20
- export * from "./hooks-business/useBusinessQuotingMap";
21
- export * from "./hooks-business/useBusinessRecomendPlaceMap";
22
- export * from "./hooks-business/useBusinessTaxiServiceMap";
23
- export { useDrivingRoute } from "./hooks/useDrivingRoute";
24
- export { useGeoLocation } from "./hooks/useGeoLocation";
25
- export { useHeycarMap } from "./hooks/useHeycarMap";
26
- export { useMapAngle } from "./hooks/useMapAngle";
27
- export { useMapDrag } from "./hooks/useMapDrag";
28
- export { useMapFitView } from "./hooks/useMapFitView";
29
- export { useMapGeometry } from "./hooks/useMapGeometry";
30
- export { useMapPlace } from "./hooks/useMapPlace";
31
- export { useMapRecomendPlace } from "./hooks/useMapRecomendPlace";
32
- export { useWalkingRoute } from "./hooks/useWalkingRoute";
33
- export * from "./types/interface";
package/src/main.ts DELETED
@@ -1,6 +0,0 @@
1
- import { createApp } from "vue-demi";
2
-
3
- import { App } from "./App";
4
- import "./style.css";
5
-
6
- createApp(App).mount("#app");
package/src/style.css DELETED
File without changes