@heycar/heycars-map 0.1.0

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 (191) hide show
  1. package/.eslintrc.json +15 -0
  2. package/README.md +18 -0
  3. package/dist/App.d.ts +1 -0
  4. package/dist/api/driving.d.ts +12 -0
  5. package/dist/api/geocoder.d.ts +16 -0
  6. package/dist/api/geometry.d.ts +20 -0
  7. package/dist/api/place.d.ts +16 -0
  8. package/dist/business-components/AddressBox/AddressBox.css.d.ts +7 -0
  9. package/dist/business-components/AddressBox/AddressBox.d.ts +10 -0
  10. package/dist/business-components/AddressBox/index.d.ts +1 -0
  11. package/dist/business-components/AddressLocator/AddressLocator.css.d.ts +1 -0
  12. package/dist/business-components/AddressLocator/AddressLocator.d.ts +7 -0
  13. package/dist/business-components/AddressLocator/index.d.ts +1 -0
  14. package/dist/business-components/DrivingLine/DrivingLine.css.d.ts +1 -0
  15. package/dist/business-components/DrivingLine/DrivingLine.d.ts +6 -0
  16. package/dist/business-components/DrivingLine/index.d.ts +1 -0
  17. package/dist/business-components/PassengerCircle/PassengerCircle.css.d.ts +1 -0
  18. package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +7 -0
  19. package/dist/business-components/PassengerCircle/index.d.ts +1 -0
  20. package/dist/business-components/PlaceCircle/PlaceCircle.css.d.ts +5 -0
  21. package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +8 -0
  22. package/dist/business-components/PlaceCircle/index.d.ts +1 -0
  23. package/dist/business-components/StartEndPoint/StartEndPoint.css.d.ts +20 -0
  24. package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +9 -0
  25. package/dist/business-components/StartEndPoint/index.d.ts +1 -0
  26. package/dist/business-components/TaxiCar/TaxiCar.css.d.ts +3 -0
  27. package/dist/business-components/TaxiCar/TaxiCar.d.ts +8 -0
  28. package/dist/business-components/TaxiCar/index.d.ts +1 -0
  29. package/dist/business-components/WalkingLine/WalkingLine.d.ts +6 -0
  30. package/dist/business-components/WalkingLine/index.d.ts +1 -0
  31. package/dist/business-components/WaveCircle/WaveCircle.css.d.ts +4 -0
  32. package/dist/business-components/WaveCircle/WaveCircle.d.ts +6 -0
  33. package/dist/business-components/WaveCircle/index.d.ts +1 -0
  34. package/dist/components/Amap/Amap.css.d.ts +1 -0
  35. package/dist/components/Amap/Amap.d.ts +7 -0
  36. package/dist/components/Amap/index.d.ts +1 -0
  37. package/dist/components/Amap/useAmap.d.ts +399 -0
  38. package/dist/components/AmapInfoWindow/AmapInfoWindow.d.ts +4 -0
  39. package/dist/components/AmapInfoWindow/index.d.ts +1 -0
  40. package/dist/components/AmapLoader/AmapLoader.d.ts +20 -0
  41. package/dist/components/AmapLoader/index.d.ts +1 -0
  42. package/dist/components/AmapMarker/AmapMarker.d.ts +2 -0
  43. package/dist/components/AmapMarker/index.d.ts +1 -0
  44. package/dist/components/AmapPolygon/AmapPolygon.d.ts +2 -0
  45. package/dist/components/AmapPolygon/index.d.ts +1 -0
  46. package/dist/components/AmapPolyline/AmapPolyline.d.ts +2 -0
  47. package/dist/components/AmapPolyline/index.d.ts +1 -0
  48. package/dist/components/AmapText/AmapText.d.ts +2 -0
  49. package/dist/components/AmapText/index.d.ts +1 -0
  50. package/dist/components/Demo/BusinessDemo.d.ts +2 -0
  51. package/dist/components/Demo/Demo.css.d.ts +1 -0
  52. package/dist/components/Demo/Demo.d.ts +2 -0
  53. package/dist/components/Demo/Hello.d.ts +17 -0
  54. package/dist/components/Demo/HeycarDemo.d.ts +1 -0
  55. package/dist/components/Demo/index.d.ts +1 -0
  56. package/dist/components/Gmap/Gmap.d.ts +5 -0
  57. package/dist/components/Gmap/index.d.ts +1 -0
  58. package/dist/components/Gmap/useGmap.d.ts +5 -0
  59. package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +3 -0
  60. package/dist/components/GmapAdvancedMarkerView/index.d.ts +1 -0
  61. package/dist/components/GmapInfoWindow/GmapInfoWindow.d.ts +5 -0
  62. package/dist/components/GmapInfoWindow/index.d.ts +1 -0
  63. package/dist/components/GmapLoader/GmapLoader.d.ts +37 -0
  64. package/dist/components/GmapLoader/index.d.ts +1 -0
  65. package/dist/components/GmapMarker/GmapMarker.d.ts +3 -0
  66. package/dist/components/GmapMarker/index.d.ts +1 -0
  67. package/dist/components/GmapPolygon/GmapPolygon.d.ts +3 -0
  68. package/dist/components/GmapPolygon/index.d.ts +1 -0
  69. package/dist/components/GmapPolyline/GmapPolyline.d.ts +3 -0
  70. package/dist/components/GmapPolyline/index.d.ts +1 -0
  71. package/dist/components/MapProvider/MapProvider.d.ts +7 -0
  72. package/dist/components/MapProvider/index.d.ts +1 -0
  73. package/dist/components/MapProvider/useMapSupplier.d.ts +11 -0
  74. package/dist/index.cjs +70 -0
  75. package/dist/index.d.ts +14 -0
  76. package/dist/index.js +1498 -0
  77. package/dist/main.d.ts +1 -0
  78. package/dist/style.css +1 -0
  79. package/dist/types/amap/marker.d.ts +11 -0
  80. package/dist/types/helper.d.ts +30 -0
  81. package/dist/types/interface.d.ts +1 -0
  82. package/dist/utils/compare.d.ts +21 -0
  83. package/dist/utils/dom.d.ts +2 -0
  84. package/dist/utils/transform.d.ts +9 -0
  85. package/dist/vite.svg +1 -0
  86. package/esbuild.mjs +40 -0
  87. package/index.html +13 -0
  88. package/package.json +94 -0
  89. package/public/vite.svg +1 -0
  90. package/src/App.tsx +10 -0
  91. package/src/api/driving.ts +87 -0
  92. package/src/api/geocoder.ts +88 -0
  93. package/src/api/geometry.ts +44 -0
  94. package/src/api/place.ts +107 -0
  95. package/src/assets/icons/svg/address-locator.svg +1 -0
  96. package/src/assets/icons/svg/arrow-right.svg +1 -0
  97. package/src/assets/icons/svg/end-point.svg +1 -0
  98. package/src/assets/icons/svg/passenger-circle.svg +1 -0
  99. package/src/assets/icons/svg/place-circle.svg +22 -0
  100. package/src/assets/icons/svg/start-point.svg +1 -0
  101. package/src/assets/icons/svg/taxi-car.svg +1 -0
  102. package/src/assets/icons/svg/wave-circle.svg +1 -0
  103. package/src/business-components/AddressBox/AddressBox.css.ts +55 -0
  104. package/src/business-components/AddressBox/AddressBox.tsx +69 -0
  105. package/src/business-components/AddressBox/index.ts +1 -0
  106. package/src/business-components/AddressLocator/AddressLocator.css.ts +7 -0
  107. package/src/business-components/AddressLocator/AddressLocator.tsx +40 -0
  108. package/src/business-components/AddressLocator/index.ts +1 -0
  109. package/src/business-components/DrivingLine/DrivingLine.css.ts +10 -0
  110. package/src/business-components/DrivingLine/DrivingLine.tsx +124 -0
  111. package/src/business-components/DrivingLine/index.ts +1 -0
  112. package/src/business-components/PassengerCircle/PassengerCircle.css.ts +8 -0
  113. package/src/business-components/PassengerCircle/PassengerCircle.tsx +42 -0
  114. package/src/business-components/PassengerCircle/index.ts +1 -0
  115. package/src/business-components/PlaceCircle/PlaceCircle.css.ts +30 -0
  116. package/src/business-components/PlaceCircle/PlaceCircle.tsx +66 -0
  117. package/src/business-components/PlaceCircle/index.ts +1 -0
  118. package/src/business-components/StartEndPoint/StartEndPoint.css.ts +70 -0
  119. package/src/business-components/StartEndPoint/StartEndPoint.tsx +103 -0
  120. package/src/business-components/StartEndPoint/index.ts +1 -0
  121. package/src/business-components/TaxiCar/TaxiCar.css.ts +16 -0
  122. package/src/business-components/TaxiCar/TaxiCar.tsx +77 -0
  123. package/src/business-components/TaxiCar/index.ts +1 -0
  124. package/src/business-components/WalkingLine/WalkingLine.tsx +73 -0
  125. package/src/business-components/WalkingLine/index.ts +1 -0
  126. package/src/business-components/WaveCircle/WaveCircle.css.ts +54 -0
  127. package/src/business-components/WaveCircle/WaveCircle.tsx +56 -0
  128. package/src/business-components/WaveCircle/index.ts +1 -0
  129. package/src/components/Amap/Amap.css.ts +3 -0
  130. package/src/components/Amap/Amap.ts +58 -0
  131. package/src/components/Amap/index.ts +1 -0
  132. package/src/components/Amap/useAmap.ts +9 -0
  133. package/src/components/AmapInfoWindow/AmapInfoWindow.ts +45 -0
  134. package/src/components/AmapInfoWindow/index.ts +1 -0
  135. package/src/components/AmapLoader/AmapLoader.ts +68 -0
  136. package/src/components/AmapLoader/index.ts +1 -0
  137. package/src/components/AmapMarker/AmapMarker.ts +38 -0
  138. package/src/components/AmapMarker/index.ts +1 -0
  139. package/src/components/AmapPolygon/AmapPolygon.ts +41 -0
  140. package/src/components/AmapPolygon/index.ts +1 -0
  141. package/src/components/AmapPolyline/AmapPolyline.ts +40 -0
  142. package/src/components/AmapPolyline/index.ts +1 -0
  143. package/src/components/AmapText/AmapText.ts +39 -0
  144. package/src/components/AmapText/index.ts +1 -0
  145. package/src/components/Demo/BusinessDemo.tsx +117 -0
  146. package/src/components/Demo/Demo.css.ts +6 -0
  147. package/src/components/Demo/Demo.tsx +97 -0
  148. package/src/components/Demo/Hello.tsx +15 -0
  149. package/src/components/Demo/HeycarDemo.tsx +31 -0
  150. package/src/components/Demo/TemplateDemo.vue +11 -0
  151. package/src/components/Demo/index.ts +1 -0
  152. package/src/components/Gmap/Gmap.ts +34 -0
  153. package/src/components/Gmap/index.ts +1 -0
  154. package/src/components/Gmap/useGmap.ts +7 -0
  155. package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +48 -0
  156. package/src/components/GmapAdvancedMarkerView/index.ts +1 -0
  157. package/src/components/GmapInfoWindow/GmapInfoWindow.ts +38 -0
  158. package/src/components/GmapInfoWindow/index.ts +1 -0
  159. package/src/components/GmapLoader/GmapLoader.ts +79 -0
  160. package/src/components/GmapLoader/index.ts +1 -0
  161. package/src/components/GmapMarker/GmapMarker.ts +31 -0
  162. package/src/components/GmapMarker/index.ts +1 -0
  163. package/src/components/GmapPolygon/GmapPolygon.ts +29 -0
  164. package/src/components/GmapPolygon/index.ts +1 -0
  165. package/src/components/GmapPolyline/GmapPolyline.ts +29 -0
  166. package/src/components/GmapPolyline/index.ts +1 -0
  167. package/src/components/MapProvider/MapProvider.tsx +64 -0
  168. package/src/components/MapProvider/index.ts +1 -0
  169. package/src/components/MapProvider/useMapSupplier.ts +19 -0
  170. package/src/index.ts +14 -0
  171. package/src/main.ts +6 -0
  172. package/src/style.css +0 -0
  173. package/src/types/amap/autocomplete.d.ts +64 -0
  174. package/src/types/amap/driving.d.ts +168 -0
  175. package/src/types/amap/geocoder.d.ts +214 -0
  176. package/src/types/amap/marker.ts +11 -0
  177. package/src/types/amap/place.d.ts +114 -0
  178. package/src/types/amap/plugin.d.ts +27 -0
  179. package/src/types/amap/walking.d.ts +76 -0
  180. package/src/types/global.d.ts +10 -0
  181. package/src/types/helper.ts +139 -0
  182. package/src/types/interface.ts +1 -0
  183. package/src/utils/compare.ts +174 -0
  184. package/src/utils/dom.ts +14 -0
  185. package/src/utils/transform.ts +27 -0
  186. package/src/vite-env.d.ts +12 -0
  187. package/todo.md +1 -0
  188. package/tsconfig.json +25 -0
  189. package/tsconfig.node.json +9 -0
  190. package/vite.config.dev.ts +17 -0
  191. package/vite.config.ts +40 -0
@@ -0,0 +1,117 @@
1
+ import { APlaceCircle, GPlaceCircle } from "../../business-components/PlaceCircle";
2
+ import { GWaveCircle } from "../../business-components/WaveCircle";
3
+ import { defineSetup } from "../../types/helper";
4
+ import { Amap } from "../Amap";
5
+ import { AmapLoader } from "../AmapLoader";
6
+ import { Gmap } from "../Gmap";
7
+ import { GmapLoader } from "../GmapLoader";
8
+ import * as css from "./Demo.css";
9
+
10
+ const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
11
+ const gmapId = import.meta.env.VITE_GMAP_MAP_ID;
12
+ const amapApiKey = import.meta.env.VITE_AMAP_API_KEY;
13
+ const amapApiSecret = import.meta.env.VITE_AMAP_API_SECRET;
14
+
15
+ export const ABusinessDemo = defineSetup(function ABusinessDemo() {
16
+ return () => (
17
+ <AmapLoader
18
+ apiKey={amapApiKey}
19
+ apiSecret={amapApiSecret}
20
+ loading={() => <div>loading</div>}
21
+ fallback={() => <div>error</div>}
22
+ plugins={["AMap.AutoComplete"]}
23
+ >
24
+ <Amap class={css.demo} center={[0, 0]} zoom={3}>
25
+ {/* <APassengerCircle position={[0, 0]} /> */}
26
+ {/* <AAddressBox position={[0, 0]} title={"Martyrs Lawn"} description={"您将在此处上车"} /> */}
27
+ <APlaceCircle position={[0, 0]} label={"Kenkey Hut"} />
28
+ {/* <AAddressLocator position={[0, 0]} /> */}
29
+ {/* <AmapMarker position={[0, 0]} /> */}
30
+ {/* <AStartEndPoint
31
+ type="end"
32
+ position={[0, 0]}
33
+ title="2月14日 11:00 用车"
34
+ description={"全程 *4.12公里* 约行驶 *22分钟*"}
35
+ /> */}
36
+ {/* <ATaxiCar position={[0, 0]} angle={90} title="距离终点 *4.2公里* 预计 *25分钟*" /> */}
37
+ {/* <ADrivingLine
38
+ path={[
39
+ [-5, -5],
40
+ [-4, -3],
41
+ [-3, -4],
42
+ [-2, -1],
43
+ [-1, -2],
44
+ [0, 1],
45
+ [1, 0],
46
+ [2, 2],
47
+ ]}
48
+ /> */}
49
+ {/* <AWalkingLine
50
+ path={[
51
+ [-5, -5],
52
+ [-4, -3],
53
+ [-3, -4],
54
+ [-2, -1],
55
+ [-1, -2],
56
+ [0, 1],
57
+ [1, 0],
58
+ [2, 2],
59
+ ]}
60
+ /> */}
61
+ {/* <AWaveCircle position={[0, 0]} /> */}
62
+ </Amap>
63
+ </AmapLoader>
64
+ );
65
+ });
66
+
67
+ export const GBusinessDemo = defineSetup(function GBusinessDemo() {
68
+ return () => (
69
+ <GmapLoader
70
+ version="beta"
71
+ apiKey={gmapApiKey}
72
+ loading={() => <div>loading</div>}
73
+ fallback={() => <div>error</div>}
74
+ libraries={["places", "marker"]}
75
+ >
76
+ <Gmap class={css.demo} center={{ lat: 0, lng: 0 }} zoom={3} mapId={gmapId}>
77
+ {/* {/* <GmapMarker position={{ lat: 0, lng: 0 }} /> */}
78
+ {/* <GPassengerCircle position={[0, 0]} /> */}
79
+ {/* <GAddressLocator position={[0, 0]} /> */}
80
+ <GPlaceCircle position={[0, 0]} />
81
+ {/* <GAddressBox position={[0, 0]} title={"当前区域暂未开通服务"} /> */}
82
+ {/* <GStartEndPoint
83
+ type="start"
84
+ position={[0, 0]}
85
+ title="Webster Dental Plaza"
86
+ description={"全程 *4.12公里* 约行驶 *22分钟*"}
87
+ /> */}
88
+ {/* <GTaxiCar position={[0, 0]} /> */}
89
+ {/* <GDrivingLine
90
+ path={[
91
+ [-5, -5],
92
+ [-4, -3],
93
+ [-3, -4],
94
+ [-2, -1],
95
+ [-1, -2],
96
+ [0, 1],
97
+ [1, 0],
98
+ [2, 2],
99
+ ]}
100
+ /> */}
101
+ {/* <GWalkingLine
102
+ path={[
103
+ [-5, -5],
104
+ [-4, -3],
105
+ [-3, -4],
106
+ [-2, -1],
107
+ [-1, -2],
108
+ [0, 1],
109
+ [1, 0],
110
+ [2, 2],
111
+ ]}
112
+ /> */}
113
+ <GWaveCircle position={[0, 0]} />
114
+ </Gmap>
115
+ </GmapLoader>
116
+ );
117
+ });
@@ -0,0 +1,6 @@
1
+ import { style } from "@vanilla-extract/css";
2
+
3
+ export const demo = style({
4
+ width: "100vw",
5
+ height: "100vh",
6
+ });
@@ -0,0 +1,97 @@
1
+ import { ref } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { Amap } from "../Amap";
4
+ import { AmapInfoWindow } from "../AmapInfoWindow";
5
+ import { AmapLoader } from "../AmapLoader";
6
+ import { AmapMarker } from "../AmapMarker";
7
+ import { AmapPolygon } from "../AmapPolygon";
8
+ import { AmapPolyline } from "../AmapPolyline";
9
+ import { Gmap } from "../Gmap";
10
+ import { GmapInfoWindow } from "../GmapInfoWindow";
11
+ import { GmapLoader } from "../GmapLoader";
12
+ import { GmapMarker } from "../GmapMarker";
13
+ import { GmapPolygon } from "../GmapPolygon";
14
+ import { GmapPolyline } from "../GmapPolyline";
15
+
16
+ import * as css from "./Demo.css";
17
+ const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
18
+ const amapApiKey = import.meta.env.VITE_AMAP_API_KEY;
19
+ const amapApiSecret = import.meta.env.VITE_AMAP_API_SECRET;
20
+
21
+ export const DemoGmap = defineSetup(function DemoGmap() {
22
+ const latRef = ref(0);
23
+ const visibleRef = ref(false);
24
+ return () => (
25
+ <GmapLoader
26
+ apiKey={gmapApiKey}
27
+ loading={() => <div>loading</div>}
28
+ fallback={() => <div>error</div>}
29
+ libraries={["places"]}
30
+ >
31
+ <div>gmap {latRef.value}</div>
32
+ <Gmap class={css.demo} center={{ lat: 0, lng: 0 }} zoom={3}>
33
+ <GmapMarker position={{ lat: 0, lng: 0 }} label="hello" />
34
+ <GmapPolyline
35
+ path={[
36
+ { lng: -5, lat: -5 },
37
+ { lng: 3, lat: 0 },
38
+ { lng: 5, lat: 5 },
39
+ ]}
40
+ />
41
+ <GmapPolygon
42
+ paths={[
43
+ { lng: -10, lat: -10 },
44
+ { lng: -20, lat: -5 },
45
+ { lng: -15, lat: -10 },
46
+ { lng: -20, lat: -20 },
47
+ { lng: -10, lat: -10 },
48
+ ]}
49
+ />
50
+ <GmapInfoWindow
51
+ visible={visibleRef.value}
52
+ content={"info window content"}
53
+ position={{ lng: 0, lat: 0 }}
54
+ />
55
+ </Gmap>
56
+ </GmapLoader>
57
+ );
58
+ });
59
+
60
+ export const DemoAmap = defineSetup(function DemoAmap() {
61
+ const latRef = ref(0);
62
+ return () => (
63
+ <AmapLoader
64
+ apiKey={amapApiKey}
65
+ apiSecret={amapApiSecret}
66
+ loading={() => <div>loading</div>}
67
+ fallback={() => <div>error</div>}
68
+ plugins={["AMap.AutoComplete"]}
69
+ >
70
+ <div>amap {latRef.value}</div>
71
+ <Amap class={css.demo} center={[latRef.value, 0]} zoom={3}>
72
+ <AmapMarker
73
+ position={[0, 0]}
74
+ label={{ content: `haha ${latRef.value}`, offset: [0, 0], direction: "" }}
75
+ />
76
+ <AmapPolyline
77
+ path={[
78
+ [-5, -5],
79
+ [3, latRef.value],
80
+ [5, 5],
81
+ ]}
82
+ />
83
+ <AmapPolygon
84
+ path={[
85
+ [-10, -10],
86
+ [-10, latRef.value],
87
+ [-20, -5],
88
+ [-15, -10],
89
+ [-20, -20],
90
+ [-10, -10],
91
+ ]}
92
+ />
93
+ <AmapInfoWindow visible content={"info window content"} position={[0, 0]} />
94
+ </Amap>
95
+ </AmapLoader>
96
+ );
97
+ });
@@ -0,0 +1,15 @@
1
+ import { defineSetup } from "../../types/helper";
2
+
3
+ export const Hello = defineSetup(function Hello(props: {
4
+ className?: string;
5
+ qyc: number;
6
+ style: any;
7
+ }) {
8
+ return () => (
9
+ <section>
10
+ <span class={props.className} style={props.style}>
11
+ hello
12
+ </span>
13
+ </section>
14
+ );
15
+ });
@@ -0,0 +1,31 @@
1
+ import { AddressBox } from "../../business-components/AddressBox";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { HeycarMap, MapProvider } from "../MapProvider/MapProvider";
4
+ import * as css from "./Demo.css";
5
+
6
+ const gmapApiKey = import.meta.env.VITE_GMAP_API_KEY;
7
+ const gmapId = import.meta.env.VITE_GMAP_MAP_ID;
8
+ const amapApiKey = import.meta.env.VITE_AMAP_API_KEY;
9
+ const amapApiSecret = import.meta.env.VITE_AMAP_API_SECRET;
10
+
11
+ export const HeycarDemo = defineSetup(function HeycarDemo() {
12
+ return () => (
13
+ <MapProvider
14
+ amapKey={amapApiKey}
15
+ amapSecret={amapApiSecret}
16
+ gmapId={gmapId}
17
+ gmapKey={gmapApiKey}
18
+ supplier={"amap"}
19
+ >
20
+ <HeycarMap
21
+ class={css.demo}
22
+ fallback={() => <div>error</div>}
23
+ loading={() => <div>loading</div>}
24
+ center={[0, 0]}
25
+ zoom={3}
26
+ >
27
+ <AddressBox position={[0, 0]} title={"Martyrs Lawn"} description={"您将在此处上车"} />
28
+ </HeycarMap>
29
+ </MapProvider>
30
+ );
31
+ });
@@ -0,0 +1,11 @@
1
+ <script>
2
+ import { defineComponent } from "vue";
3
+ import { Hello } from "./Hello";
4
+
5
+ export default defineComponent({
6
+ components: { Hello },
7
+ });
8
+ </script>
9
+ <template>
10
+ <Hello class="hi3" qyc="3"></Hello>
11
+ </template>
@@ -0,0 +1 @@
1
+ export * from "./Demo";
@@ -0,0 +1,34 @@
1
+ import { computed, h, shallowRef, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import {
4
+ watchNoneImmediatePostEffectForDeepOption,
5
+ watchPostEffectForGMapEvent,
6
+ } from "../../utils/compare";
7
+ import { provideGmap } from "./useGmap";
8
+ export interface GampProps extends google.maps.MapOptions {
9
+ onCenter_changed?: () => void;
10
+ }
11
+
12
+ export const Gmap = defineSetup(function Gmap(props: GampProps, { slots, emit }) {
13
+ const options = computed(() => {
14
+ const { onCenter_changed, ...options } = props;
15
+ return options;
16
+ });
17
+ const defaultOptions = options.value;
18
+ const elementRef = shallowRef();
19
+ const mapRef = shallowRef<google.maps.Map>();
20
+ provideGmap(mapRef);
21
+ watchPostEffect(() => {
22
+ // todo 这里是否会因为 mapRef 的赋值导致不停运行?
23
+ if (mapRef.value || !elementRef.value) return;
24
+ mapRef.value = new google.maps.Map(elementRef.value, { ...defaultOptions });
25
+ });
26
+ watchNoneImmediatePostEffectForDeepOption(
27
+ () => options.value,
28
+ (options) => {
29
+ mapRef.value?.setOptions({ ...options });
30
+ }
31
+ );
32
+ watchPostEffectForGMapEvent(mapRef, props, emit, ["onCenter_changed"]);
33
+ return () => h("div", { ref: elementRef }, slots.default?.());
34
+ });
@@ -0,0 +1 @@
1
+ export * from "./Gmap";
@@ -0,0 +1,7 @@
1
+ import { inject, provide, ShallowRef } from "vue-demi";
2
+
3
+ export const gmapContext = Symbol();
4
+
5
+ export const useGmap = () => inject<ShallowRef<google.maps.Map | undefined>>(gmapContext);
6
+ export const provideGmap = (mapRef: ShallowRef<google.maps.Map | undefined>) =>
7
+ provide(gmapContext, mapRef);
@@ -0,0 +1,48 @@
1
+ import { onMounted, onUnmounted, shallowRef, watch, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
4
+ import { useGmap } from "../Gmap/useGmap";
5
+
6
+ export type GmapAdvancedMarkerViewProps = google.maps.marker.AdvancedMarkerViewOptions;
7
+
8
+ export const GmapAdvancedMarkerView = defineSetup(function GmapAdvancedMarkerView(
9
+ props: GmapAdvancedMarkerViewProps
10
+ ) {
11
+ const markerRef = shallowRef<google.maps.marker.AdvancedMarkerView>();
12
+ const mapRef = useGmap();
13
+ onMounted(() => {
14
+ markerRef.value = new google.maps.marker.AdvancedMarkerView({ ...props });
15
+ });
16
+ onUnmounted(() => {
17
+ if (!markerRef.value) return;
18
+ markerRef.value.map = null;
19
+ });
20
+ watchPostEffect(() => {
21
+ const map = mapRef?.value;
22
+ if (!map || !markerRef.value) return;
23
+ markerRef.value.map = map;
24
+ });
25
+ watchNoneImmediatePostEffectForDeepOption(
26
+ () => {
27
+ const { content, ...restProps } = props;
28
+ return restProps;
29
+ },
30
+ (props) => {
31
+ if (!markerRef.value) return;
32
+ debugger;
33
+ Object.assign(markerRef.value, props);
34
+ }
35
+ );
36
+ // content 通过 createDom 会新建,只需要 shallowCompare
37
+ watch(
38
+ () => props.content,
39
+ (content) => {
40
+ if (!markerRef.value) return;
41
+ markerRef.value.content = content;
42
+ },
43
+ {
44
+ flush: "post",
45
+ }
46
+ );
47
+ return () => null;
48
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapAdvancedMarkerView";
@@ -0,0 +1,38 @@
1
+ import { computed, onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
4
+ import { useGmap } from "../Gmap/useGmap";
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
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapInfoWindow";
@@ -0,0 +1,79 @@
1
+ import { Loader, LoaderOptions } from "@googlemaps/js-api-loader";
2
+ import { computed, shallowRef } from "vue-demi";
3
+ import { defineSetup, VueNode } from "../../types/helper";
4
+ import { watchPostEffectForDeepOption } from "../../utils/compare";
5
+
6
+ export enum Status {
7
+ LOADING = "LOADING",
8
+ FAILURE = "FAILURE",
9
+ SUCCESS = "SUCCESS",
10
+ }
11
+
12
+ export interface GmapLoaderProps extends LoaderOptions {
13
+ /**
14
+ * Render prop used to switch to loading component.
15
+ */
16
+ loading?: () => VueNode;
17
+ /**
18
+ * Render prop used to switch to error fallback component.
19
+ */
20
+ fallback?: () => VueNode;
21
+ /**
22
+ * Callback prop used to access `@googlemaps/js-api-loader` and `Status`.
23
+ *
24
+ * Note: The callback be executed multiple times in the lifecycle of the component.
25
+ */
26
+ onChange?: (status: Status) => void;
27
+ }
28
+
29
+ /**
30
+ * A component to wrap the loading of the Google Maps JavaScript API.
31
+ *
32
+ * ```
33
+ * const MyApp = () => (
34
+ * <GmapLoader apiKey={'YOUR_API_KEY'}>
35
+ * <MyMapComponent />
36
+ * </GmapLoader>
37
+ * );
38
+ * ```
39
+ *
40
+ * @param props
41
+ */
42
+ export const GmapLoader = defineSetup(function GmapLoader(props: GmapLoaderProps, { slots, emit }) {
43
+ const statusRef = shallowRef(Status.LOADING);
44
+ const options = computed(() => {
45
+ const { onChange, fallback, loading, ...options } = props;
46
+ return options;
47
+ });
48
+ watchPostEffectForDeepOption(
49
+ () => options.value,
50
+ (options) => {
51
+ const loader = new Loader(options);
52
+
53
+ const setStatusAndExecuteCallback = (status: Status) => {
54
+ emit("change", status);
55
+ statusRef.value = status;
56
+ };
57
+
58
+ setStatusAndExecuteCallback(Status.LOADING);
59
+
60
+ loader.load().then(
61
+ () => setStatusAndExecuteCallback(Status.SUCCESS),
62
+ () => setStatusAndExecuteCallback(Status.FAILURE)
63
+ );
64
+ }
65
+ );
66
+ return () => {
67
+ switch (statusRef.value) {
68
+ case Status.SUCCESS:
69
+ // todo: 由于 class 无法禁止传递,所以不用 div 包裹。目前 GmapLoader 只在 HeycarMap 内部使用,能确保 slot.default 是单节点, 如果将来要开放去处,这里需要做处理
70
+ return slots.default?.() as VueNode;
71
+ case Status.LOADING:
72
+ return slots.loading?.();
73
+ case Status.FAILURE:
74
+ return slots.fallback?.();
75
+ default:
76
+ throw new Error("MyError: unknown loader status");
77
+ }
78
+ };
79
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapLoader";
@@ -0,0 +1,31 @@
1
+ import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
4
+ import { useGmap } from "../Gmap/useGmap";
5
+
6
+ export type GmapMarkerProps = google.maps.MarkerOptions;
7
+
8
+ export const GmapMarker = defineSetup(function GmapMarker(props: GmapMarkerProps) {
9
+ const markerRef = shallowRef<google.maps.Marker>();
10
+ const mapRef = useGmap();
11
+ onMounted(() => {
12
+ markerRef.value = new google.maps.Marker({ ...props });
13
+ });
14
+ onUnmounted(() => {
15
+ markerRef.value?.setMap(null);
16
+ });
17
+ watchPostEffect(() => {
18
+ const map = mapRef?.value;
19
+ if (!map) return;
20
+ markerRef.value?.setMap(map);
21
+ });
22
+ watchNoneImmediatePostEffectForDeepOption(
23
+ () => {
24
+ return { ...props };
25
+ },
26
+ (props) => {
27
+ markerRef.value?.setOptions({ ...props });
28
+ }
29
+ );
30
+ return () => null;
31
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapMarker";
@@ -0,0 +1,29 @@
1
+ import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
4
+ import { useGmap } from "../Gmap/useGmap";
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
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapPolygon";
@@ -0,0 +1,29 @@
1
+ import { onMounted, onUnmounted, shallowRef, watchPostEffect } from "vue-demi";
2
+ import { defineSetup } from "../../types/helper";
3
+ import { watchNoneImmediatePostEffectForDeepOption } from "../../utils/compare";
4
+ import { useGmap } from "../Gmap/useGmap";
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
+ });
@@ -0,0 +1 @@
1
+ export * from "./GmapPolyline";
@@ -0,0 +1,64 @@
1
+ import { defineLagecySetup, defineSetup } from "../../types/helper";
2
+ import { vec2lnglat } from "../../utils/transform";
3
+ import { Amap, AmapProps } from "../Amap";
4
+ import { AmapLoader } from "../AmapLoader";
5
+ import { Gmap } from "../Gmap";
6
+ import { GmapLoader, GmapLoaderProps } from "../GmapLoader";
7
+ import { MapSupplierPayolad, provideMapSupplier, useMapSupplier } from "./useMapSupplier";
8
+
9
+ export type MapProviderProps = MapSupplierPayolad;
10
+ export const MapProvider = defineLagecySetup(function MapProvider(
11
+ props: MapProviderProps,
12
+ { slots }
13
+ ) {
14
+ provideMapSupplier(props);
15
+ return () => <div>{slots.default?.()}</div>;
16
+ }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapKey", "supplier"]);
17
+
18
+ export type HeycarMapProps = Pick<GmapLoaderProps, "fallback" | "loading"> &
19
+ Pick<AmapProps, "center" | "zoom">;
20
+ export const HeycarMap = defineSetup(function HeycarMap(props: HeycarMapProps, { slots }) {
21
+ const payload = useMapSupplier();
22
+ return () => {
23
+ const { gmapKey, amapKey, amapSecret, amapServiceHost, supplier, gmapId } = payload;
24
+ const { fallback, loading, center, zoom } = props;
25
+ const children = slots.default?.();
26
+ switch (supplier) {
27
+ case "gmap":
28
+ return (
29
+ <GmapLoader
30
+ apiKey={gmapKey}
31
+ version="beta"
32
+ libraries={["marker", "places", "geometry"]}
33
+ loading={loading}
34
+ fallback={fallback}
35
+ >
36
+ <Gmap mapId={gmapId} center={center ? vec2lnglat(center) : undefined} zoom={zoom}>
37
+ {children}
38
+ </Gmap>
39
+ </GmapLoader>
40
+ );
41
+ default:
42
+ return (
43
+ <AmapLoader
44
+ apiKey={amapKey}
45
+ apiSecret={amapSecret}
46
+ apiServiceHost={amapServiceHost}
47
+ plugins={[
48
+ "AMap.Geolocation",
49
+ "AMap.Geocoder",
50
+ "AMap.PlaceSearch",
51
+ "AMap.Driving",
52
+ "AMap.Walker",
53
+ ]}
54
+ loading={loading}
55
+ fallback={fallback}
56
+ >
57
+ <Amap center={center} zoom={zoom}>
58
+ {children}
59
+ </Amap>
60
+ </AmapLoader>
61
+ );
62
+ }
63
+ };
64
+ });
@@ -0,0 +1 @@
1
+ export * from "./MapProvider";