@heycar/heycars-map 0.3.7 → 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 (174) 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.d.ts +0 -2
  18. package/dist/components/MapProvider/MapProvider.d.ts +1 -4
  19. package/dist/hooks/useMapAutoComplete.d.ts +1 -2
  20. package/dist/hooks-business/useBusinessMapAutoComplete.d.ts +1 -2
  21. package/dist/index.cjs +55 -55
  22. package/dist/index.js +1966 -2061
  23. package/package.json +1 -1
  24. package/todo.md +16 -4
  25. package/dist/Demo/CityBound/SearchDemo.d.ts +0 -1
  26. package/dist/Demo/CityBound/country.d.ts +0 -5
  27. package/dist/Demo/CityBound/searchResult.d.ts +0 -8
  28. package/dist/hooks/useMapLog.d.ts +0 -5
  29. package/src/App.tsx +0 -27
  30. package/src/Demo/CityBound/SearchDemo.tsx +0 -142
  31. package/src/Demo/CityBound/country.ts +0 -4179
  32. package/src/Demo/CityBound/searchResult.ts +0 -21122
  33. package/src/Demo/Demo.css.ts +0 -6
  34. package/src/Demo/Demo.tsx +0 -97
  35. package/src/Demo/DemoBusinessQuoting.tsx +0 -18
  36. package/src/Demo/DemoBusinessRecomendPlace.tsx +0 -89
  37. package/src/Demo/DemoBusinessTaxiEnd.tsx +0 -38
  38. package/src/Demo/DemoBusinessTaxiService.tsx +0 -58
  39. package/src/Demo/sample.json +0 -793
  40. package/src/api/contants.ts +0 -3
  41. package/src/api/driving.ts +0 -87
  42. package/src/api/geocoder.ts +0 -88
  43. package/src/api/geometry.ts +0 -44
  44. package/src/api/place.ts +0 -105
  45. package/src/assets/icons/svg/address-locator.svg +0 -1
  46. package/src/assets/icons/svg/arrow-right.svg +0 -1
  47. package/src/assets/icons/svg/end-point.svg +0 -1
  48. package/src/assets/icons/svg/passenger-circle.svg +0 -1
  49. package/src/assets/icons/svg/place-circle.svg +0 -22
  50. package/src/assets/icons/svg/start-point.svg +0 -1
  51. package/src/assets/icons/svg/taxi-car.svg +0 -1
  52. package/src/assets/icons/svg/wave-circle.svg +0 -1
  53. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.css.ts +0 -68
  54. package/src/business-components/AbsoluteAddressBox/AbsoluteAddressBox.tsx +0 -50
  55. package/src/business-components/AbsoluteAddressBox/index.ts +0 -1
  56. package/src/business-components/AddressBox/AddressBox.css.ts +0 -55
  57. package/src/business-components/AddressBox/AddressBox.tsx +0 -76
  58. package/src/business-components/AddressBox/index.ts +0 -1
  59. package/src/business-components/AddressLocator/AddressLocator.css.ts +0 -7
  60. package/src/business-components/AddressLocator/AddressLocator.tsx +0 -40
  61. package/src/business-components/AddressLocator/index.ts +0 -1
  62. package/src/business-components/BusinessQuotingMap/BusinessQuotingMap.tsx +0 -49
  63. package/src/business-components/BusinessQuotingMap/index.ts +0 -1
  64. package/src/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.tsx +0 -218
  65. package/src/business-components/BusinessRecomendPlaceMap/index.ts +0 -1
  66. package/src/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.tsx +0 -43
  67. package/src/business-components/BusinessTaxiEndMap/index.ts +0 -1
  68. package/src/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.tsx +0 -453
  69. package/src/business-components/BusinessTaxiServiceMap/index.ts +0 -1
  70. package/src/business-components/DrivingLine/DrivingLine.css.ts +0 -10
  71. package/src/business-components/DrivingLine/DrivingLine.tsx +0 -135
  72. package/src/business-components/DrivingLine/index.ts +0 -1
  73. package/src/business-components/DrivingRoute/DrivingRoute.tsx +0 -52
  74. package/src/business-components/DrivingRoute/index.ts +0 -1
  75. package/src/business-components/FitView/FitView.tsx +0 -22
  76. package/src/business-components/FitView/index.ts +0 -1
  77. package/src/business-components/PassengerCircle/PassengerCircle.css.ts +0 -21
  78. package/src/business-components/PassengerCircle/PassengerCircle.tsx +0 -69
  79. package/src/business-components/PassengerCircle/index.ts +0 -1
  80. package/src/business-components/PickupPoints/PickupPoints.tsx +0 -38
  81. package/src/business-components/PickupPoints/index.ts +0 -1
  82. package/src/business-components/PlaceCircle/PlaceCircle.css.ts +0 -76
  83. package/src/business-components/PlaceCircle/PlaceCircle.tsx +0 -110
  84. package/src/business-components/PlaceCircle/index.ts +0 -1
  85. package/src/business-components/StartEndPoint/StartEndPoint.css.ts +0 -70
  86. package/src/business-components/StartEndPoint/StartEndPoint.tsx +0 -122
  87. package/src/business-components/StartEndPoint/index.ts +0 -1
  88. package/src/business-components/TaxiCar/TaxiCar.css.ts +0 -16
  89. package/src/business-components/TaxiCar/TaxiCar.tsx +0 -93
  90. package/src/business-components/TaxiCar/index.ts +0 -1
  91. package/src/business-components/WalkingLine/WalkingLine.tsx +0 -80
  92. package/src/business-components/WalkingLine/index.ts +0 -1
  93. package/src/business-components/WalkingRoute/WalkingRoute.tsx +0 -43
  94. package/src/business-components/WalkingRoute/index.ts +0 -1
  95. package/src/business-components/WaveCircle/WaveCircle.css.ts +0 -54
  96. package/src/business-components/WaveCircle/WaveCircle.tsx +0 -59
  97. package/src/business-components/WaveCircle/index.ts +0 -1
  98. package/src/components/Amap/Amap.css.ts +0 -5
  99. package/src/components/Amap/Amap.ts +0 -76
  100. package/src/components/Amap/index.ts +0 -1
  101. package/src/components/AmapInfoWindow/AmapInfoWindow.ts +0 -45
  102. package/src/components/AmapInfoWindow/index.ts +0 -1
  103. package/src/components/AmapLoader/AmapLoader.ts +0 -20
  104. package/src/components/AmapLoader/index.ts +0 -1
  105. package/src/components/AmapMarker/AmapMarker.ts +0 -48
  106. package/src/components/AmapMarker/index.ts +0 -1
  107. package/src/components/AmapPolygon/AmapPolygon.ts +0 -41
  108. package/src/components/AmapPolygon/index.ts +0 -1
  109. package/src/components/AmapPolyline/AmapPolyline.ts +0 -40
  110. package/src/components/AmapPolyline/index.ts +0 -1
  111. package/src/components/AmapText/AmapText.ts +0 -39
  112. package/src/components/AmapText/index.ts +0 -1
  113. package/src/components/Gmap/Gmap.css.ts +0 -10
  114. package/src/components/Gmap/Gmap.ts +0 -54
  115. package/src/components/Gmap/index.ts +0 -1
  116. package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +0 -63
  117. package/src/components/GmapAdvancedMarkerView/index.ts +0 -1
  118. package/src/components/GmapInfoWindow/GmapInfoWindow.ts +0 -38
  119. package/src/components/GmapInfoWindow/index.ts +0 -1
  120. package/src/components/GmapLoader/GmapLoader.ts +0 -21
  121. package/src/components/GmapLoader/index.ts +0 -1
  122. package/src/components/GmapMarker/GmapMarker.ts +0 -34
  123. package/src/components/GmapMarker/index.ts +0 -1
  124. package/src/components/GmapPolygon/GmapPolygon.ts +0 -29
  125. package/src/components/GmapPolygon/index.ts +0 -1
  126. package/src/components/GmapPolyline/GmapPolyline.ts +0 -29
  127. package/src/components/GmapPolyline/index.ts +0 -1
  128. package/src/components/MapProvider/MapProvider.tsx +0 -83
  129. package/src/components/MapProvider/index.ts +0 -1
  130. package/src/hooks/useDrivingRoute.ts +0 -106
  131. package/src/hooks/useGeoLocation.ts +0 -70
  132. package/src/hooks/useHeycarMap.ts +0 -28
  133. package/src/hooks/useMap.ts +0 -43
  134. package/src/hooks/useMapAngle.ts +0 -42
  135. package/src/hooks/useMapAutoComplete.ts +0 -130
  136. package/src/hooks/useMapCityBound.ts +0 -64
  137. package/src/hooks/useMapDrag.ts +0 -72
  138. package/src/hooks/useMapEventSource.ts +0 -20
  139. package/src/hooks/useMapFitView.ts +0 -135
  140. package/src/hooks/useMapGeometry.ts +0 -27
  141. package/src/hooks/useMapLngLatToVw.ts +0 -31
  142. package/src/hooks/useMapLoader.ts +0 -164
  143. package/src/hooks/useMapLog.ts +0 -24
  144. package/src/hooks/useMapPlace.ts +0 -138
  145. package/src/hooks/useMapRecomendPlace.ts +0 -150
  146. package/src/hooks/useMapSupplier.ts +0 -16
  147. package/src/hooks/useOverlay.ts +0 -23
  148. package/src/hooks/usePlacesLabelDirection.ts +0 -61
  149. package/src/hooks/useUdate.ts +0 -9
  150. package/src/hooks/useWaitTimer.ts +0 -25
  151. package/src/hooks/useWalkingRoute.ts +0 -87
  152. package/src/hooks-business/useBusinessMapAutoComplete.ts +0 -22
  153. package/src/hooks-business/useBusinessQuotingMap.ts +0 -11
  154. package/src/hooks-business/useBusinessRecomendPlaceMap.ts +0 -45
  155. package/src/hooks-business/useBusinessTaxiServiceMap.ts +0 -12
  156. package/src/index.ts +0 -33
  157. package/src/main.ts +0 -6
  158. package/src/style.css +0 -0
  159. package/src/types/amap/autocomplete.d.ts +0 -64
  160. package/src/types/amap/driving.d.ts +0 -170
  161. package/src/types/amap/geocoder.d.ts +0 -217
  162. package/src/types/amap/marker.ts +0 -11
  163. package/src/types/amap/place.d.ts +0 -114
  164. package/src/types/amap/plugin.d.ts +0 -27
  165. package/src/types/amap/walking.d.ts +0 -78
  166. package/src/types/global.d.ts +0 -10
  167. package/src/types/helper.ts +0 -172
  168. package/src/types/interface.ts +0 -62
  169. package/src/types/mapHelper.ts +0 -1
  170. package/src/utils/compare.ts +0 -189
  171. package/src/utils/dom.ts +0 -14
  172. package/src/utils/helper.ts +0 -5
  173. package/src/utils/transform.ts +0 -68
  174. package/src/vite-env.d.ts +0 -12
@@ -1,63 +0,0 @@
1
- import { onMounted, onUnmounted, shallowRef, watch, watchPostEffect } from "vue-demi";
2
- import { useGmap } from "../../hooks/useMap";
3
- import { GmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
4
- import { defineSetup } from "../../types/helper";
5
- import type { MapEventHandler } from "../../types/mapHelper";
6
- import {
7
- watchNoneImmediatePostEffectForDeepOption,
8
- watchPostEffectForGMapEvent,
9
- } from "../../utils/compare";
10
-
11
- export interface GmapAdvancedMarkerViewProps
12
- extends google.maps.marker.AdvancedMarkerViewOptions,
13
- MapRegisterOverlayProps<GmapOverlay> {
14
- onClick?: MapEventHandler<google.maps.marker.AdvancedMarkerView>;
15
- }
16
-
17
- export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerView(
18
- props: GmapAdvancedMarkerViewProps,
19
- { emit }
20
- ) {
21
- const { registerOverlay } = props;
22
- const markerRef = shallowRef<google.maps.marker.AdvancedMarkerView>();
23
- const mapRef = useGmap();
24
- const handleClick: typeof emit = (name) => emit(name as any, { target: markerRef.value! });
25
- useMapOverlay({ registerOverlay, overlayRef: markerRef });
26
- onMounted(() => {
27
- const { registerOverlay, ...markerViewProps } = props;
28
- markerRef.value = new google.maps.marker.AdvancedMarkerView({ ...markerViewProps });
29
- markerRef.value.addListener;
30
- });
31
- onUnmounted(() => {
32
- if (!markerRef.value) return;
33
- markerRef.value.map = null;
34
- });
35
- watchPostEffect(() => {
36
- const map = mapRef?.value;
37
- if (!map || !markerRef.value) return;
38
- markerRef.value.map = map;
39
- });
40
- watchNoneImmediatePostEffectForDeepOption(
41
- () => {
42
- const { content, registerOverlay, ...restProps } = props;
43
- return restProps;
44
- },
45
- (props) => {
46
- if (!markerRef.value) return;
47
- Object.assign(markerRef.value, props);
48
- }
49
- );
50
- // content 通过 createDom 会新建,只需要 shallowCompare
51
- watch(
52
- () => props.content,
53
- (content) => {
54
- if (!markerRef.value) return;
55
- markerRef.value.content = content;
56
- },
57
- {
58
- flush: "post",
59
- }
60
- );
61
- watchPostEffectForGMapEvent(markerRef, props, handleClick, ["onClick"]);
62
- return () => null;
63
- });
@@ -1 +0,0 @@
1
- export * from "./GmapAdvancedMarkerView";
@@ -1,38 +0,0 @@
1
- import { computed, onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
- import { useGmap } from "../../hooks/useMap";
3
- import { defineSetup } from "../../types/helper";
4
- import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
5
-
6
- export interface GmapInfoWindowProps extends google.maps.InfoWindowOptions {
7
- visible: boolean;
8
- }
9
-
10
- export const GmapInfoWindow = defineSetup(function GmapInfoWindow(props: GmapInfoWindowProps) {
11
- const options = computed(() => {
12
- const { visible, ...options } = props;
13
- return options;
14
- });
15
- const defaultOptions = options.value;
16
- const infoWindowRef = shallowRef<google.maps.InfoWindow>();
17
- const mapRef = useGmap();
18
- onMounted(() => {
19
- infoWindowRef.value = new google.maps.InfoWindow({ ...defaultOptions });
20
- });
21
- onUnmounted(() => {
22
- infoWindowRef.value?.close();
23
- });
24
- watchPostEffect(() => {
25
- const { visible } = props;
26
- const infoWindow = infoWindowRef.value;
27
- const map = mapRef?.value;
28
- if (!map || !infoWindow) return;
29
- visible ? infoWindow.open({ map }) : infoWindow.close();
30
- });
31
- watchNoneImmediatePostEffectForDeepOption(
32
- () => options.value,
33
- (options) => {
34
- infoWindowRef.value?.setOptions({ ...options });
35
- }
36
- );
37
- return () => null;
38
- });
@@ -1 +0,0 @@
1
- export * from "./GmapInfoWindow";
@@ -1,21 +0,0 @@
1
- import { GmapLoaderProps, Status, useGmapLoader } from "../../hooks/useMapLoader";
2
- import { defineSetup, VueNode } from "../../types/helper";
3
-
4
- /**
5
- * Deprecated
6
- */
7
- export const GmapLoader = defineSetup(function GmapLoader(props: GmapLoaderProps, { slots }) {
8
- const { statusRef } = useGmapLoader(props);
9
- return () => {
10
- switch (statusRef.value) {
11
- case Status.SUCCESS:
12
- return slots.default?.() as VueNode;
13
- case Status.LOADING:
14
- return slots.loading?.();
15
- case Status.FAILURE:
16
- return slots.fallback?.();
17
- default:
18
- throw new Error("MyError: unknown loader status");
19
- }
20
- };
21
- });
@@ -1 +0,0 @@
1
- export * from "./GmapLoader";
@@ -1,34 +0,0 @@
1
- import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
- import { useGmap } from "../../hooks/useMap";
3
- import { GmapOverlay, MapRegisterOverlayProps, useMapOverlay } from "../../hooks/useOverlay";
4
- import { defineSetup } from "../../types/helper";
5
- import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
6
-
7
- export type GmapMarkerProps = google.maps.MarkerOptions & MapRegisterOverlayProps<GmapOverlay>;
8
-
9
- export const GmapMarker = defineSetup(function GmapMarker(props: GmapMarkerProps) {
10
- const { registerOverlay } = props;
11
- const markerRef = shallowRef<google.maps.Marker>();
12
- const mapRef = useGmap();
13
- onMounted(() => {
14
- markerRef.value = new google.maps.Marker({ ...props });
15
- });
16
- onUnmounted(() => {
17
- markerRef.value?.setMap(null);
18
- });
19
- useMapOverlay({ registerOverlay, overlayRef: markerRef });
20
- watchPostEffect(() => {
21
- const map = mapRef?.value;
22
- if (!map) return;
23
- markerRef.value?.setMap(map);
24
- });
25
- watchNoneImmediatePostEffectForDeepOption(
26
- () => {
27
- return { ...props };
28
- },
29
- (props) => {
30
- markerRef.value?.setOptions({ ...props });
31
- }
32
- );
33
- return () => null;
34
- });
@@ -1 +0,0 @@
1
- export * from "./GmapMarker";
@@ -1,29 +0,0 @@
1
- import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
- import { useGmap } from "../../hooks/useMap";
3
- import { defineSetup } from "../../types/helper";
4
- import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
5
-
6
- export type GmapPolygonProps = google.maps.PolygonOptions;
7
-
8
- export const GmapPolygon = defineSetup(function GmapPolygon(props: GmapPolygonProps) {
9
- const polygonRef = shallowRef<google.maps.Polygon>();
10
- const mapRef = useGmap();
11
- onMounted(() => {
12
- polygonRef.value = new google.maps.Polygon({ ...props });
13
- });
14
- onUnmounted(() => {
15
- polygonRef.value?.setMap(null);
16
- });
17
- watchPostEffect(() => {
18
- const map = mapRef?.value;
19
- if (!map) return;
20
- polygonRef.value?.setMap(map);
21
- });
22
- watchNoneImmediatePostEffectForDeepOption(
23
- () => ({ ...props }),
24
- (props) => {
25
- polygonRef.value?.setOptions({ ...props });
26
- }
27
- );
28
- return () => null;
29
- });
@@ -1 +0,0 @@
1
- export * from "./GmapPolygon";
@@ -1,29 +0,0 @@
1
- import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
- import { useGmap } from "../../hooks/useMap";
3
- import { defineSetup } from "../../types/helper";
4
- import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
5
-
6
- export type GmapPolylineProps = google.maps.PolylineOptions;
7
-
8
- export const GmapPolyline = defineSetup(function GmapPolyline(props: GmapPolylineProps) {
9
- const polylineRef = shallowRef<google.maps.Polyline>();
10
- const mapRef = useGmap();
11
- onMounted(() => {
12
- polylineRef.value = new google.maps.Polyline({ ...props });
13
- });
14
- onUnmounted(() => {
15
- polylineRef.value?.setMap(null);
16
- });
17
- watchPostEffect(() => {
18
- const map = mapRef?.value;
19
- if (!map) return;
20
- polylineRef.value?.setMap(map);
21
- });
22
- watchNoneImmediatePostEffectForDeepOption(
23
- () => ({ ...props }),
24
- (props) => {
25
- polylineRef.value?.setOptions({ ...props });
26
- }
27
- );
28
- return () => null;
29
- });
@@ -1 +0,0 @@
1
- export * from "./GmapPolyline";
@@ -1,83 +0,0 @@
1
- import type { SetMap } from "../../hooks/useHeycarMap";
2
- import { GmapLoaderProps, Status, useMapLoader, UseMapLoaderProps } from "../../hooks/useMapLoader";
3
- import { MapLogProps, useMapLog } from "../../hooks/useMapLog";
4
- import { MapSupplierPayolad, provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier";
5
- import { defineLagecySetup } from "../../types/helper";
6
- import { language2vectorMapForeign, vec2lnglat } from "../../utils/transform";
7
- import { Amap, AmapProps } from "../Amap";
8
- import { Gmap, GmapProps } from "../Gmap";
9
-
10
- export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId">;
11
- export const MapProvider = defineLagecySetup(function MapProvider(
12
- props: MapProviderProps,
13
- { slots }
14
- ) {
15
- const { statusRef, readyPromise } = useMapLoader(props);
16
- const context = new Proxy<MapSupplierPayolad>(props as MapSupplierPayolad, {
17
- get(target, name, receiver) {
18
- if (name === "status") return statusRef.value;
19
- if (name === "readyPromise") return readyPromise;
20
- return Reflect.get(target, name, receiver);
21
- },
22
- });
23
- provideMapSupplier(context);
24
- return () => <div>{slots.default?.()}</div>;
25
- }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapKey", "supplier", "language"]);
26
-
27
- export interface HeycarMapProps
28
- extends Pick<GmapLoaderProps, "fallback" | "loading">,
29
- Pick<AmapProps, "center" | "zoom">,
30
- MapLogProps {
31
- mapRef?: SetMap<AMap.Map> | SetMap<google.maps.Map>;
32
- renderOverlay?: GmapProps["renderOverlay"];
33
- onDragEnd?: (value: [number, number]) => any;
34
- }
35
- export const HeycarMap = defineLagecySetup(function HeycarMap(
36
- props: HeycarMapProps,
37
- { slots, emit }
38
- ) {
39
- useMapLog(props, "HeycarMap");
40
- const payload = useMapSupplier();
41
- const gmapDebouncedEmit: GmapProps["onDragEnd"] = ({ target }) => {
42
- const { lng, lat } = target.getCenter() as google.maps.LatLng;
43
- emit("dragEnd", [lng(), lat()]);
44
- };
45
- const amapDebounceEmit: AmapProps["onDragEnd"] = ({ target }) => {
46
- const { lng, lat } = target.getCenter();
47
- emit("dragEnd", [lng, lat]);
48
- };
49
- return () => {
50
- const { supplier, gmapId, language = "zh", status } = payload;
51
- const { mapRef: setMap, center, zoom, renderOverlay } = props;
52
- if (status === Status.LOADING) return slots.loading?.();
53
- if (status === Status.FAILURE) return slots.fallback?.();
54
- const children = slots.default?.();
55
- switch (supplier) {
56
- case "gmap":
57
- return (
58
- <Gmap
59
- mapRef={setMap as SetMap<google.maps.Map>}
60
- mapId={gmapId}
61
- center={center ? vec2lnglat(center) : undefined}
62
- zoom={zoom}
63
- renderOverlay={renderOverlay}
64
- onDragEnd={gmapDebouncedEmit}
65
- >
66
- {children}
67
- </Gmap>
68
- );
69
- default:
70
- return (
71
- <Amap
72
- mapRef={setMap as SetMap<AMap.Map>}
73
- vectorMapForeign={language2vectorMapForeign(language)}
74
- center={center}
75
- zoom={zoom}
76
- onDragEnd={amapDebounceEmit}
77
- >
78
- {children}
79
- </Amap>
80
- );
81
- }
82
- };
83
- }).props(["center", "fallback", "loading", "mapRef", "zoom", "renderOverlay"]);
@@ -1 +0,0 @@
1
- export * from "./MapProvider";
@@ -1,106 +0,0 @@
1
- import { reactive } from "vue-demi";
2
- import type { Point, Route } from "../types/interface";
3
- import { watchPostEffectForDeepOption } from "../utils/compare";
4
- import { useMapSupplier } from "./useMapSupplier";
5
-
6
- export interface UseDrivingRouteProps {
7
- from: Point;
8
- to: Point;
9
- }
10
-
11
- export const useADrivingRoute = (props: UseDrivingRouteProps) => {
12
- const outputRoute = reactive<Route>({ path: [], distance: 0, duration: 0 });
13
- const amapDriving = new AMap.Driving({});
14
- watchPostEffectForDeepOption(
15
- () => ({ ...props }),
16
- ({ from, to }) => {
17
- amapDriving.search(
18
- AMap.LngLat.from(from),
19
- AMap.LngLat.from(to),
20
- { waypoints: [] },
21
- (status, result) => {
22
- switch (status) {
23
- case "complete": {
24
- let path: Point[] = [];
25
- const drivingResult = result as AMap.DrivingResult;
26
- // todo 多条导航路线的情况
27
- const firstRoute = drivingResult.routes[0];
28
- for (const step of firstRoute.steps) {
29
- const basicStep = step as AMap.DriveStepBasic;
30
- const stepPath = basicStep.path.map<Point>(({ lng, lat }) => [lng, lat]);
31
- path = path.concat(stepPath);
32
- }
33
- outputRoute.path = path;
34
- outputRoute.distance = firstRoute.distance;
35
- outputRoute.duration = firstRoute.time;
36
- return;
37
- }
38
- case "no_data":
39
- outputRoute.path = [];
40
- outputRoute.distance = 0;
41
- outputRoute.duration = 0;
42
- return;
43
- default:
44
- throw result;
45
- }
46
- }
47
- );
48
- }
49
- );
50
- return outputRoute;
51
- };
52
-
53
- export const useGDrivingRoute = (props: UseDrivingRouteProps) => {
54
- const outputRoute = reactive<Route>({ path: [], distance: 0, duration: 0 });
55
- const gmapDirectionsService = new google.maps.DirectionsService();
56
- watchPostEffectForDeepOption(
57
- () => ({ ...props }),
58
- ({ from, to }) => {
59
- gmapDirectionsService.route(
60
- {
61
- origin: { lng: from[0], lat: from[1] },
62
- destination: { lng: to[0], lat: to[1] },
63
- travelMode: google.maps.TravelMode.DRIVING,
64
- },
65
- (result, status) => {
66
- switch (status) {
67
- case google.maps.DirectionsStatus.OK: {
68
- let path: Point[] = [];
69
- let distance = 0;
70
- let duration = 0;
71
- const firstRoute = result!.routes[0];
72
- const stepPath = firstRoute.overview_path.map<Point>((item) => [
73
- item.lng(),
74
- item.lat(),
75
- ]);
76
- path = path.concat(stepPath);
77
- for (const leg of firstRoute.legs) {
78
- distance += leg.distance?.value ?? 0;
79
- // todo 考虑用 duration_in_traffic 但这个字段上有条件的
80
- duration += leg.duration?.value ?? 0;
81
- }
82
- outputRoute.path = path;
83
- outputRoute.distance = distance;
84
- outputRoute.duration = duration;
85
- return;
86
- }
87
- case google.maps.DirectionsStatus.ZERO_RESULTS:
88
- case google.maps.DirectionsStatus.NOT_FOUND:
89
- outputRoute.path = [];
90
- outputRoute.distance = 0;
91
- outputRoute.duration = 0;
92
- return;
93
- default:
94
- throw new Error(status);
95
- }
96
- }
97
- );
98
- }
99
- );
100
- return outputRoute;
101
- };
102
-
103
- export const useDrivingRoute = (props: UseDrivingRouteProps): Route => {
104
- const { supplier } = useMapSupplier();
105
- return supplier === "gmap" ? useGDrivingRoute(props) : useADrivingRoute(props);
106
- };
@@ -1,70 +0,0 @@
1
- import { ref, watch } from "vue-demi";
2
- import type { Point } from "../types/interface";
3
-
4
- const GEO_TIMEOUT = 5000;
5
-
6
- export interface UseGeoLocationProps {
7
- geoDefaultPosition?: Point;
8
- onChange?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
9
- onLoad?: (value: { position: Point; coordinate: GeolocationCoordinates }) => any;
10
- onLoadDefault?: (value: { position: Point }) => any;
11
- onError?: (error: GeolocationPositionError) => any;
12
- }
13
- export const useGeoLocation = (props?: UseGeoLocationProps) => {
14
- const { onChange, onLoad, onLoadDefault, onError, geoDefaultPosition } = props ?? {};
15
- let isOnLoadDefaultTriggered = false;
16
- const loading = ref(false);
17
- const readyRef = ref(false);
18
- const errorRef = ref<GeolocationPositionError>();
19
- const coordinateRef = ref<GeolocationCoordinates>({
20
- accuracy: 0,
21
- altitude: 0,
22
- altitudeAccuracy: 0,
23
- heading: 0,
24
- latitude: geoDefaultPosition?.[1] ?? 0,
25
- longitude: geoDefaultPosition?.[0] ?? 0,
26
- speed: 0,
27
- });
28
- const positionRef = ref<Point>([coordinateRef.value.longitude, coordinateRef.value.latitude]);
29
- watch(
30
- () => true,
31
- (_1, _2, onCleanup) => {
32
- loading.value = true;
33
- const watchId = navigator.geolocation.watchPosition(
34
- (position) => {
35
- const coordinate = position.coords;
36
- const point: Point = [position.coords.longitude, position.coords.latitude];
37
- coordinateRef.value = coordinate;
38
- positionRef.value = point;
39
- if (loading.value) {
40
- loading.value = false;
41
- readyRef.value = true;
42
- onLoad?.({ position: point, coordinate });
43
- }
44
- onChange?.({ position: point, coordinate });
45
- },
46
- (error) => {
47
- loading.value = false;
48
- errorRef.value = error;
49
- const position = props?.geoDefaultPosition;
50
- if (position && !isOnLoadDefaultTriggered) {
51
- isOnLoadDefaultTriggered = true;
52
- onLoadDefault?.({ position });
53
- }
54
- onError?.(error);
55
- console.log("errorRef = ", errorRef);
56
- },
57
- { timeout: GEO_TIMEOUT, maximumAge: 0, enableHighAccuracy: false }
58
- );
59
- onCleanup(() => navigator.geolocation.clearWatch(watchId));
60
- },
61
- { immediate: true }
62
- );
63
- return {
64
- geoError: errorRef,
65
- geoPosition: positionRef,
66
- geoCoordinate: coordinateRef,
67
- geoLoading: loading,
68
- geoReady: readyRef,
69
- };
70
- };
@@ -1,28 +0,0 @@
1
- import { shallowRef } from "vue-demi";
2
- import { vec2lnglat } from "../utils/transform";
3
- import { useMapSupplier } from "./useMapSupplier";
4
-
5
- export type SetMap<M> = (map: M) => void;
6
-
7
- export const useHeycarAmap = () => {
8
- const amapRef = shallowRef<AMap.Map>();
9
- const setMap: SetMap<AMap.Map> = (map) => {
10
- amapRef.value = map;
11
- };
12
- const panTo = (value: [number, number]) => amapRef?.value?.panTo(value);
13
- return { mapRef: amapRef, panTo, setMap };
14
- };
15
-
16
- export const useHeycarGamp = () => {
17
- const gmapRef = shallowRef<google.maps.Map>();
18
- const setMap: SetMap<google.maps.Map> = (map) => {
19
- gmapRef.value = map;
20
- };
21
- const panTo = (value: [number, number]) => gmapRef?.value?.panTo(vec2lnglat(value));
22
- return { mapRef: gmapRef, panTo, setMap };
23
- };
24
-
25
- export const useHeycarMap = () => {
26
- const { supplier } = useMapSupplier();
27
- return supplier === "gmap" ? useHeycarGamp() : useHeycarAmap();
28
- };
@@ -1,43 +0,0 @@
1
- import { inject, provide, ShallowRef, watch } from "vue-demi";
2
- import type { MapShallowRef } from "../types/interface";
3
- import { useMapSupplier } from "./useMapSupplier";
4
-
5
- export const amapContext = Symbol("amap");
6
-
7
- export const useAmap = () => {
8
- return inject<ShallowRef<AMap.Map | undefined>>(amapContext);
9
- };
10
- export const provideAmap = (mapRef: ShallowRef<AMap.Map | undefined>) =>
11
- provide(amapContext, mapRef);
12
-
13
- export const gmapContext = Symbol("gmap");
14
-
15
- export const useGmap = () => inject<ShallowRef<google.maps.Map | undefined>>(gmapContext);
16
- export const provideGmap = (mapRef: ShallowRef<google.maps.Map | undefined>) =>
17
- provide(gmapContext, mapRef);
18
-
19
- export const useMap = () => {
20
- const { supplier } = useMapSupplier();
21
- const result = supplier === "gmap" ? useGmap() : useAmap();
22
- return result as MapShallowRef;
23
- };
24
- export const provideMap = (mapRef: MapShallowRef) => {
25
- const { supplier } = useMapSupplier();
26
- return supplier === "gmap"
27
- ? provideGmap(mapRef as MapShallowRef<google.maps.Map>)
28
- : provideAmap(mapRef as MapShallowRef<AMap.Map>);
29
- };
30
-
31
- export interface MapMountedProps {
32
- onMapMounted?: () => any;
33
- }
34
- export const onMapMounted = (callback: (...args: any) => any) => {
35
- const mapRef = useMap();
36
- watch(
37
- () => mapRef.value,
38
- (map) => {
39
- if (!map) return;
40
- Promise.resolve().then(callback);
41
- }
42
- );
43
- };
@@ -1,42 +0,0 @@
1
- import { computed } from "vue-demi";
2
- import type { Point } from "../types/interface";
3
- import { vec2lnglat } from "../utils/transform";
4
- import { useMapSupplier } from "./useMapSupplier";
5
-
6
- const amapComputeHeading = (from: Point, to: Point, map?: AMap.Map) => {
7
- if (!map) return 0;
8
- const { x: xFrom, y: yFrom } = map.lngLatToContainer(from);
9
- const { x: xTo, y: yTo } = map.lngLatToContainer(to);
10
- const theta = Math.atan2(yFrom - yTo, xTo - xFrom);
11
- return ((Math.PI / 2 - theta) / Math.PI) * 180;
12
- };
13
-
14
- export type UseMapAngleProps<M = AMap.Map | google.maps.Map> = {
15
- path: Point[];
16
- map?: M;
17
- };
18
-
19
- export const useAmapAngle = (props: UseMapAngleProps<AMap.Map>) => {
20
- return computed(() => {
21
- const { map, path } = props;
22
- const [from, to] = path;
23
- if (!from || !to || !map) return undefined;
24
- return amapComputeHeading(from, to, map);
25
- });
26
- };
27
-
28
- export const useGmapAngle = (props: UseMapAngleProps<google.maps.Map>) => {
29
- return computed(() => {
30
- const { path } = props;
31
- const [from, to] = path;
32
- if (!from || !to) return undefined;
33
- return google.maps.geometry.spherical.computeHeading(vec2lnglat(from), vec2lnglat(to));
34
- });
35
- };
36
-
37
- export const useMapAngle = (props: UseMapAngleProps) => {
38
- const { supplier } = useMapSupplier();
39
- return supplier === "gmap"
40
- ? useGmapAngle(props as UseMapAngleProps<google.maps.Map>)
41
- : useAmapAngle(props as UseMapAngleProps<AMap.Map>);
42
- };