@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.
- package/.eslintrc.json +15 -0
- package/README.md +18 -0
- package/dist/App.d.ts +1 -0
- package/dist/api/driving.d.ts +12 -0
- package/dist/api/geocoder.d.ts +16 -0
- package/dist/api/geometry.d.ts +20 -0
- package/dist/api/place.d.ts +16 -0
- package/dist/business-components/AddressBox/AddressBox.css.d.ts +7 -0
- package/dist/business-components/AddressBox/AddressBox.d.ts +10 -0
- package/dist/business-components/AddressBox/index.d.ts +1 -0
- package/dist/business-components/AddressLocator/AddressLocator.css.d.ts +1 -0
- package/dist/business-components/AddressLocator/AddressLocator.d.ts +7 -0
- package/dist/business-components/AddressLocator/index.d.ts +1 -0
- package/dist/business-components/DrivingLine/DrivingLine.css.d.ts +1 -0
- package/dist/business-components/DrivingLine/DrivingLine.d.ts +6 -0
- package/dist/business-components/DrivingLine/index.d.ts +1 -0
- package/dist/business-components/PassengerCircle/PassengerCircle.css.d.ts +1 -0
- package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +7 -0
- package/dist/business-components/PassengerCircle/index.d.ts +1 -0
- package/dist/business-components/PlaceCircle/PlaceCircle.css.d.ts +5 -0
- package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +8 -0
- package/dist/business-components/PlaceCircle/index.d.ts +1 -0
- package/dist/business-components/StartEndPoint/StartEndPoint.css.d.ts +20 -0
- package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +9 -0
- package/dist/business-components/StartEndPoint/index.d.ts +1 -0
- package/dist/business-components/TaxiCar/TaxiCar.css.d.ts +3 -0
- package/dist/business-components/TaxiCar/TaxiCar.d.ts +8 -0
- package/dist/business-components/TaxiCar/index.d.ts +1 -0
- package/dist/business-components/WalkingLine/WalkingLine.d.ts +6 -0
- package/dist/business-components/WalkingLine/index.d.ts +1 -0
- package/dist/business-components/WaveCircle/WaveCircle.css.d.ts +4 -0
- package/dist/business-components/WaveCircle/WaveCircle.d.ts +6 -0
- package/dist/business-components/WaveCircle/index.d.ts +1 -0
- package/dist/components/Amap/Amap.css.d.ts +1 -0
- package/dist/components/Amap/Amap.d.ts +7 -0
- package/dist/components/Amap/index.d.ts +1 -0
- package/dist/components/Amap/useAmap.d.ts +399 -0
- package/dist/components/AmapInfoWindow/AmapInfoWindow.d.ts +4 -0
- package/dist/components/AmapInfoWindow/index.d.ts +1 -0
- package/dist/components/AmapLoader/AmapLoader.d.ts +20 -0
- package/dist/components/AmapLoader/index.d.ts +1 -0
- package/dist/components/AmapMarker/AmapMarker.d.ts +2 -0
- package/dist/components/AmapMarker/index.d.ts +1 -0
- package/dist/components/AmapPolygon/AmapPolygon.d.ts +2 -0
- package/dist/components/AmapPolygon/index.d.ts +1 -0
- package/dist/components/AmapPolyline/AmapPolyline.d.ts +2 -0
- package/dist/components/AmapPolyline/index.d.ts +1 -0
- package/dist/components/AmapText/AmapText.d.ts +2 -0
- package/dist/components/AmapText/index.d.ts +1 -0
- package/dist/components/Demo/BusinessDemo.d.ts +2 -0
- package/dist/components/Demo/Demo.css.d.ts +1 -0
- package/dist/components/Demo/Demo.d.ts +2 -0
- package/dist/components/Demo/Hello.d.ts +17 -0
- package/dist/components/Demo/HeycarDemo.d.ts +1 -0
- package/dist/components/Demo/index.d.ts +1 -0
- package/dist/components/Gmap/Gmap.d.ts +5 -0
- package/dist/components/Gmap/index.d.ts +1 -0
- package/dist/components/Gmap/useGmap.d.ts +5 -0
- package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +3 -0
- package/dist/components/GmapAdvancedMarkerView/index.d.ts +1 -0
- package/dist/components/GmapInfoWindow/GmapInfoWindow.d.ts +5 -0
- package/dist/components/GmapInfoWindow/index.d.ts +1 -0
- package/dist/components/GmapLoader/GmapLoader.d.ts +37 -0
- package/dist/components/GmapLoader/index.d.ts +1 -0
- package/dist/components/GmapMarker/GmapMarker.d.ts +3 -0
- package/dist/components/GmapMarker/index.d.ts +1 -0
- package/dist/components/GmapPolygon/GmapPolygon.d.ts +3 -0
- package/dist/components/GmapPolygon/index.d.ts +1 -0
- package/dist/components/GmapPolyline/GmapPolyline.d.ts +3 -0
- package/dist/components/GmapPolyline/index.d.ts +1 -0
- package/dist/components/MapProvider/MapProvider.d.ts +7 -0
- package/dist/components/MapProvider/index.d.ts +1 -0
- package/dist/components/MapProvider/useMapSupplier.d.ts +11 -0
- package/dist/index.cjs +70 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1498 -0
- package/dist/main.d.ts +1 -0
- package/dist/style.css +1 -0
- package/dist/types/amap/marker.d.ts +11 -0
- package/dist/types/helper.d.ts +30 -0
- package/dist/types/interface.d.ts +1 -0
- package/dist/utils/compare.d.ts +21 -0
- package/dist/utils/dom.d.ts +2 -0
- package/dist/utils/transform.d.ts +9 -0
- package/dist/vite.svg +1 -0
- package/esbuild.mjs +40 -0
- package/index.html +13 -0
- package/package.json +94 -0
- package/public/vite.svg +1 -0
- package/src/App.tsx +10 -0
- package/src/api/driving.ts +87 -0
- package/src/api/geocoder.ts +88 -0
- package/src/api/geometry.ts +44 -0
- package/src/api/place.ts +107 -0
- package/src/assets/icons/svg/address-locator.svg +1 -0
- package/src/assets/icons/svg/arrow-right.svg +1 -0
- package/src/assets/icons/svg/end-point.svg +1 -0
- package/src/assets/icons/svg/passenger-circle.svg +1 -0
- package/src/assets/icons/svg/place-circle.svg +22 -0
- package/src/assets/icons/svg/start-point.svg +1 -0
- package/src/assets/icons/svg/taxi-car.svg +1 -0
- package/src/assets/icons/svg/wave-circle.svg +1 -0
- package/src/business-components/AddressBox/AddressBox.css.ts +55 -0
- package/src/business-components/AddressBox/AddressBox.tsx +69 -0
- package/src/business-components/AddressBox/index.ts +1 -0
- package/src/business-components/AddressLocator/AddressLocator.css.ts +7 -0
- package/src/business-components/AddressLocator/AddressLocator.tsx +40 -0
- package/src/business-components/AddressLocator/index.ts +1 -0
- package/src/business-components/DrivingLine/DrivingLine.css.ts +10 -0
- package/src/business-components/DrivingLine/DrivingLine.tsx +124 -0
- package/src/business-components/DrivingLine/index.ts +1 -0
- package/src/business-components/PassengerCircle/PassengerCircle.css.ts +8 -0
- package/src/business-components/PassengerCircle/PassengerCircle.tsx +42 -0
- package/src/business-components/PassengerCircle/index.ts +1 -0
- package/src/business-components/PlaceCircle/PlaceCircle.css.ts +30 -0
- package/src/business-components/PlaceCircle/PlaceCircle.tsx +66 -0
- package/src/business-components/PlaceCircle/index.ts +1 -0
- package/src/business-components/StartEndPoint/StartEndPoint.css.ts +70 -0
- package/src/business-components/StartEndPoint/StartEndPoint.tsx +103 -0
- package/src/business-components/StartEndPoint/index.ts +1 -0
- package/src/business-components/TaxiCar/TaxiCar.css.ts +16 -0
- package/src/business-components/TaxiCar/TaxiCar.tsx +77 -0
- package/src/business-components/TaxiCar/index.ts +1 -0
- package/src/business-components/WalkingLine/WalkingLine.tsx +73 -0
- package/src/business-components/WalkingLine/index.ts +1 -0
- package/src/business-components/WaveCircle/WaveCircle.css.ts +54 -0
- package/src/business-components/WaveCircle/WaveCircle.tsx +56 -0
- package/src/business-components/WaveCircle/index.ts +1 -0
- package/src/components/Amap/Amap.css.ts +3 -0
- package/src/components/Amap/Amap.ts +58 -0
- package/src/components/Amap/index.ts +1 -0
- package/src/components/Amap/useAmap.ts +9 -0
- package/src/components/AmapInfoWindow/AmapInfoWindow.ts +45 -0
- package/src/components/AmapInfoWindow/index.ts +1 -0
- package/src/components/AmapLoader/AmapLoader.ts +68 -0
- package/src/components/AmapLoader/index.ts +1 -0
- package/src/components/AmapMarker/AmapMarker.ts +38 -0
- package/src/components/AmapMarker/index.ts +1 -0
- package/src/components/AmapPolygon/AmapPolygon.ts +41 -0
- package/src/components/AmapPolygon/index.ts +1 -0
- package/src/components/AmapPolyline/AmapPolyline.ts +40 -0
- package/src/components/AmapPolyline/index.ts +1 -0
- package/src/components/AmapText/AmapText.ts +39 -0
- package/src/components/AmapText/index.ts +1 -0
- package/src/components/Demo/BusinessDemo.tsx +117 -0
- package/src/components/Demo/Demo.css.ts +6 -0
- package/src/components/Demo/Demo.tsx +97 -0
- package/src/components/Demo/Hello.tsx +15 -0
- package/src/components/Demo/HeycarDemo.tsx +31 -0
- package/src/components/Demo/TemplateDemo.vue +11 -0
- package/src/components/Demo/index.ts +1 -0
- package/src/components/Gmap/Gmap.ts +34 -0
- package/src/components/Gmap/index.ts +1 -0
- package/src/components/Gmap/useGmap.ts +7 -0
- package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +48 -0
- package/src/components/GmapAdvancedMarkerView/index.ts +1 -0
- package/src/components/GmapInfoWindow/GmapInfoWindow.ts +38 -0
- package/src/components/GmapInfoWindow/index.ts +1 -0
- package/src/components/GmapLoader/GmapLoader.ts +79 -0
- package/src/components/GmapLoader/index.ts +1 -0
- package/src/components/GmapMarker/GmapMarker.ts +31 -0
- package/src/components/GmapMarker/index.ts +1 -0
- package/src/components/GmapPolygon/GmapPolygon.ts +29 -0
- package/src/components/GmapPolygon/index.ts +1 -0
- package/src/components/GmapPolyline/GmapPolyline.ts +29 -0
- package/src/components/GmapPolyline/index.ts +1 -0
- package/src/components/MapProvider/MapProvider.tsx +64 -0
- package/src/components/MapProvider/index.ts +1 -0
- package/src/components/MapProvider/useMapSupplier.ts +19 -0
- package/src/index.ts +14 -0
- package/src/main.ts +6 -0
- package/src/style.css +0 -0
- package/src/types/amap/autocomplete.d.ts +64 -0
- package/src/types/amap/driving.d.ts +168 -0
- package/src/types/amap/geocoder.d.ts +214 -0
- package/src/types/amap/marker.ts +11 -0
- package/src/types/amap/place.d.ts +114 -0
- package/src/types/amap/plugin.d.ts +27 -0
- package/src/types/amap/walking.d.ts +76 -0
- package/src/types/global.d.ts +10 -0
- package/src/types/helper.ts +139 -0
- package/src/types/interface.ts +1 -0
- package/src/utils/compare.ts +174 -0
- package/src/utils/dom.ts +14 -0
- package/src/utils/transform.ts +27 -0
- package/src/vite-env.d.ts +12 -0
- package/todo.md +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +9 -0
- package/vite.config.dev.ts +17 -0
- 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,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 @@
|
|
|
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";
|