@heycar/heycars-map 1.0.0-coordinate7 → 2.0.0-switchMap10
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/README.md +45 -52
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/v2/App.js +8 -4
- package/dist/v2/Demo/DemoBusinessQuoting.js +6 -12
- package/dist/v2/Demo/DemoBusinessRecomendPlace.js +3 -8
- package/dist/v2/Demo/DemoBusinessReselectPlace.js +2 -7
- package/dist/v2/Demo/DemoBusinessTaxiEnd.d.ts +1 -3
- package/dist/v2/Demo/DemoBusinessTaxiEnd.js +2 -18
- package/dist/v2/Demo/DemoBusinessTaxiService.d.ts +1 -2392
- package/dist/v2/Demo/DemoBusinessTaxiService.js +6 -19
- package/dist/v2/api/cdn.d.ts +1 -0
- package/dist/v2/api/cdn.js +2 -0
- package/dist/v2/api/googleSnapRoad.js +7 -2
- package/dist/v2/api/pingConnection.d.ts +9 -0
- package/dist/v2/api/pingConnection.js +111 -0
- package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +5 -5
- package/dist/v2/business-components/BusinessQuotingMap/BusinessQuotingMap.js +46 -12
- package/dist/v2/business-components/BusinessQuotingMap/index.js +3 -2
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +2 -3
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +7 -4
- package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +4 -3
- package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +3 -2
- package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +60 -24
- package/dist/v2/business-components/BusinessReselectPlaceMap/index.js +3 -2
- package/dist/v2/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.d.ts +2 -3
- package/dist/v2/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js +22 -8
- package/dist/v2/business-components/BusinessTaxiEndMap/index.js +3 -2
- package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +5 -5
- package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +52 -21
- package/dist/v2/business-components/BusinessTaxiServiceMap/index.js +3 -2
- package/dist/v2/chunks/{BusinessRecomendPlaceMap.87ea3b2f.js → BusinessRecomendPlaceMap.b4d45108.js} +65 -30
- package/dist/v2/chunks/{Loading.fc6e75d0.js → Loading.492acbc2.js} +30 -2
- package/dist/v2/components/AmapMarker/AmapMarker.js +2 -1
- package/dist/v2/components/GmapAdvancedMarkerElement/GmapAdvancedMarkerElement.js +1 -1
- package/dist/v2/components/Loading/Loading.css.d.ts +5 -0
- package/dist/v2/components/Loading/Loading.d.ts +6 -0
- package/dist/v2/components/Loading/Loading.js +4 -2
- package/dist/v2/components/Loading/index.js +3 -2
- package/dist/v2/components/MapProvider/MapProvider.d.ts +2 -2
- package/dist/v2/components/MapProvider/MapProvider.js +24 -13
- package/dist/v2/css/Loading-49e58ced.css +46 -0
- package/dist/v2/demi-polyfill/demi-polyfill.d.ts +1 -0
- package/dist/v2/hooks/useDrivingRoute.js +4 -0
- package/dist/v2/hooks/useMapGCJ02.js +4 -37
- package/dist/v2/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v2/hooks/useMapGeometry.js +4 -4
- package/dist/v2/hooks/useMapGraspRoad.js +1 -2
- package/dist/v2/hooks/useMapInChina.d.ts +3 -15
- package/dist/v2/hooks/useMapInChina.js +11 -16
- package/dist/v2/hooks/useMapLoader.d.ts +18 -10
- package/dist/v2/hooks/useMapLoader.js +159 -82
- package/dist/v2/hooks/useMapPlace.d.ts +1 -0
- package/dist/v2/hooks/useMapPlace.js +52 -44
- package/dist/v2/hooks/useMapRecomendPlace.d.ts +1 -0
- package/dist/v2/hooks/useMapRecomendPlace.js +75 -67
- package/dist/v2/hooks/useMapSupplier.d.ts +8 -0
- package/dist/v2/hooks/useMapSupplier.js +17 -0
- package/dist/v2/hooks/usePingConnection.d.ts +10 -0
- package/dist/v2/hooks/usePingConnection.js +26 -0
- package/dist/v2/hooks-business/useBusinessAlarm.d.ts +3 -0
- package/dist/v2/hooks-business/useBusinessQuotingMap.d.ts +7 -2393
- package/dist/v2/hooks-business/useBusinessQuotingMap.js +10 -10
- package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.d.ts +8 -17
- package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +8 -34
- package/dist/v2/hooks-business/useBusinessReselectPlaceMap.d.ts +4 -13
- package/dist/v2/hooks-business/useBusinessTaxiServiceMap.d.ts +5 -2393
- package/dist/v2/hooks-business/useBusinessTaxiServiceMap.js +5 -10
- package/dist/v2/index.js +1 -1
- package/dist/v2/types/global.d.ts +3 -0
- package/dist/v2/types/interface.d.ts +1 -1
- package/dist/v2/utils/ManualAbortError.d.ts +3 -0
- package/dist/v2/utils/ManualAbortError.js +14 -0
- package/dist/v2/utils/compare.d.ts +4 -0
- package/dist/v2/utils/compare.js +6 -0
- package/dist/v2/utils/helper.d.ts +6 -0
- package/dist/v2/utils/helper.js +43 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v2/utils/patchGoogleMapLoader.d.ts +2 -0
- package/dist/v2/utils/patchGoogleMapLoader.js +64 -0
- package/dist/v3/App.js +8 -4
- package/dist/v3/Demo/DemoBusinessQuoting.js +7 -13
- package/dist/v3/Demo/DemoBusinessRecomendPlace.js +3 -8
- package/dist/v3/Demo/DemoBusinessReselectPlace.js +2 -7
- package/dist/v3/Demo/DemoBusinessTaxiEnd.d.ts +1 -3
- package/dist/v3/Demo/DemoBusinessTaxiEnd.js +3 -17
- package/dist/v3/Demo/DemoBusinessTaxiService.d.ts +1 -2392
- package/dist/v3/Demo/DemoBusinessTaxiService.js +6 -17
- package/dist/v3/api/cdn.d.ts +1 -0
- package/dist/v3/api/cdn.js +2 -0
- package/dist/v3/api/googleSnapRoad.js +7 -2
- package/dist/v3/api/pingConnection.d.ts +9 -0
- package/dist/v3/api/pingConnection.js +111 -0
- package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.d.ts +16 -7
- package/dist/v3/business-components/BusinessQuotingMap/BusinessQuotingMap.js +46 -12
- package/dist/v3/business-components/BusinessQuotingMap/index.js +3 -2
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.d.ts +10 -3
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +7 -4
- package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +4 -3
- package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.d.ts +10 -2
- package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +60 -24
- package/dist/v3/business-components/BusinessReselectPlaceMap/index.js +3 -2
- package/dist/v3/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.d.ts +4 -3
- package/dist/v3/business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js +22 -8
- package/dist/v3/business-components/BusinessTaxiEndMap/index.js +3 -2
- package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.d.ts +19 -7
- package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +52 -21
- package/dist/v3/business-components/BusinessTaxiServiceMap/index.js +3 -2
- package/dist/v3/chunks/{BusinessRecomendPlaceMap.57b15c64.js → BusinessRecomendPlaceMap.6ba5dbb1.js} +65 -30
- package/dist/v3/chunks/{Loading.a8e2f26a.js → Loading.21d8e759.js} +26 -2
- package/dist/v3/components/AmapMarker/AmapMarker.js +2 -1
- package/dist/v3/components/GmapAdvancedMarkerElement/GmapAdvancedMarkerElement.js +1 -1
- package/dist/v3/components/Loading/Loading.css.d.ts +5 -0
- package/dist/v3/components/Loading/Loading.d.ts +8 -0
- package/dist/v3/components/Loading/Loading.js +4 -2
- package/dist/v3/components/Loading/index.js +3 -2
- package/dist/v3/components/MapProvider/MapProvider.d.ts +6 -3
- package/dist/v3/components/MapProvider/MapProvider.js +22 -13
- package/dist/v3/css/Loading-49e58ced.css +46 -0
- package/dist/v3/demi-polyfill/demi-polyfill.d.ts +1 -0
- package/dist/v3/hooks/useDrivingRoute.js +4 -0
- package/dist/v3/hooks/useMapGCJ02.js +4 -37
- package/dist/v3/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v3/hooks/useMapGeometry.js +4 -4
- package/dist/v3/hooks/useMapGraspRoad.js +1 -2
- package/dist/v3/hooks/useMapInChina.d.ts +3 -15
- package/dist/v3/hooks/useMapInChina.js +11 -16
- package/dist/v3/hooks/useMapLoader.d.ts +18 -10
- package/dist/v3/hooks/useMapLoader.js +159 -82
- package/dist/v3/hooks/useMapPlace.d.ts +1 -0
- package/dist/v3/hooks/useMapPlace.js +52 -44
- package/dist/v3/hooks/useMapRecomendPlace.d.ts +1 -0
- package/dist/v3/hooks/useMapRecomendPlace.js +75 -67
- package/dist/v3/hooks/useMapSupplier.d.ts +8 -0
- package/dist/v3/hooks/useMapSupplier.js +17 -0
- package/dist/v3/hooks/usePingConnection.d.ts +10 -0
- package/dist/v3/hooks/usePingConnection.js +26 -0
- package/dist/v3/hooks-business/useBusinessAlarm.d.ts +3 -0
- package/dist/v3/hooks-business/useBusinessQuotingMap.d.ts +7 -2393
- package/dist/v3/hooks-business/useBusinessQuotingMap.js +10 -10
- package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.d.ts +8 -17
- package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +8 -34
- package/dist/v3/hooks-business/useBusinessReselectPlaceMap.d.ts +4 -13
- package/dist/v3/hooks-business/useBusinessTaxiServiceMap.d.ts +5 -2393
- package/dist/v3/hooks-business/useBusinessTaxiServiceMap.js +5 -10
- package/dist/v3/index.js +1 -1
- package/dist/v3/types/global.d.ts +3 -0
- package/dist/v3/types/interface.d.ts +1 -1
- package/dist/v3/utils/ManualAbortError.d.ts +3 -0
- package/dist/v3/utils/ManualAbortError.js +14 -0
- package/dist/v3/utils/compare.d.ts +4 -0
- package/dist/v3/utils/compare.js +6 -0
- package/dist/v3/utils/helper.d.ts +6 -0
- package/dist/v3/utils/helper.js +43 -0
- package/dist/v3/utils/log.js +1 -1
- package/dist/v3/utils/patchGoogleMapLoader.d.ts +2 -0
- package/dist/v3/utils/patchGoogleMapLoader.js +64 -0
- package/package.json +2 -2
- package/dist/v2/Demo/Demo.d.ts +0 -3
- package/dist/v2/Demo/Demo.js +0 -1634
- package/dist/v2/api/googleConnection.d.ts +0 -5
- package/dist/v2/api/googleConnection.js +0 -51
- package/dist/v2/components/AmapLoader/AmapLoader.d.ts +0 -5
- package/dist/v2/components/AmapLoader/AmapLoader.js +0 -21
- package/dist/v2/components/AmapLoader/index.d.ts +0 -1
- package/dist/v2/components/AmapLoader/index.js +0 -4
- package/dist/v2/components/GmapLoader/GmapLoader.d.ts +0 -5
- package/dist/v2/components/GmapLoader/GmapLoader.js +0 -21
- package/dist/v2/components/GmapLoader/index.d.ts +0 -1
- package/dist/v2/components/GmapLoader/index.js +0 -4
- package/dist/v2/css/Loading-523061b9.css +0 -9
- package/dist/v2/hooks/useGoogleConnection.d.ts +0 -7
- package/dist/v2/hooks/useGoogleConnection.js +0 -15
- package/dist/v2/hooks-business/useBusinessTaxiEndMap.d.ts +0 -3
- package/dist/v2/hooks-business/useBusinessTaxiEndMap.js +0 -7
- package/dist/v3/Demo/Demo.d.ts +0 -9
- package/dist/v3/Demo/Demo.js +0 -1612
- package/dist/v3/api/googleConnection.d.ts +0 -5
- package/dist/v3/api/googleConnection.js +0 -51
- package/dist/v3/components/AmapLoader/AmapLoader.d.ts +0 -10
- package/dist/v3/components/AmapLoader/AmapLoader.js +0 -21
- package/dist/v3/components/AmapLoader/index.d.ts +0 -1
- package/dist/v3/components/AmapLoader/index.js +0 -4
- package/dist/v3/components/GmapLoader/GmapLoader.d.ts +0 -10
- package/dist/v3/components/GmapLoader/GmapLoader.js +0 -21
- package/dist/v3/components/GmapLoader/index.d.ts +0 -1
- package/dist/v3/components/GmapLoader/index.js +0 -4
- package/dist/v3/css/Loading-523061b9.css +0 -9
- package/dist/v3/hooks/useGoogleConnection.d.ts +0 -7
- package/dist/v3/hooks/useGoogleConnection.js +0 -15
- package/dist/v3/hooks-business/useBusinessTaxiEndMap.d.ts +0 -3
- package/dist/v3/hooks-business/useBusinessTaxiEndMap.js +0 -7
|
@@ -3,7 +3,7 @@ import { apiGoogleSnapRoad } from "../api/googleSnapRoad.js";
|
|
|
3
3
|
import { watchEffectForDeepOption } from "../utils/compare.js";
|
|
4
4
|
import { lnglat2point, trackPoints2amapGraspRoadPoints } from "../utils/transform.js";
|
|
5
5
|
import { useMapAngle } from "./useMapAngle.js";
|
|
6
|
-
import {
|
|
6
|
+
import { inChina } from "./useMapInChina.js";
|
|
7
7
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
8
8
|
const GRASP_ROAD_INPUT_MIN_AMOUNT = 2;
|
|
9
9
|
const GRASP_ROAD_INPUT_MAX_AMOUNT = 500;
|
|
@@ -12,7 +12,6 @@ const useAmapGraspRoad = (props) => {
|
|
|
12
12
|
const pathRef = ref([]);
|
|
13
13
|
const angleRef = ref(0);
|
|
14
14
|
const { apiMapComputeHeading } = useMapAngle();
|
|
15
|
-
const { inChina } = useMapInChina();
|
|
16
15
|
const apiMapToGraspRoadPath = (tracks) => {
|
|
17
16
|
return new Promise((resolve) => {
|
|
18
17
|
var _a, _b, _c;
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import { type Point } from "../types/interface";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
inMacau: (point: Point) => boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare const useAmapInChina: () => {
|
|
8
|
-
inChina: (point: Point) => boolean;
|
|
9
|
-
inHongkong: (point: Point) => boolean;
|
|
10
|
-
inMacau: (point: Point) => boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare const useGmapInChina: () => {
|
|
13
|
-
inChina: (point: Point) => boolean;
|
|
14
|
-
inHongkong: (point: Point) => boolean;
|
|
15
|
-
inMacau: (point: Point) => boolean;
|
|
16
|
-
};
|
|
2
|
+
export declare const inChina: (point: Point) => boolean;
|
|
3
|
+
export declare const inHongkong: (point: Point) => boolean;
|
|
4
|
+
export declare const inMacau: (point: Point) => boolean;
|
|
@@ -2593,22 +2593,17 @@ const macauBounds = [
|
|
|
2593
2593
|
22.19885
|
|
2594
2594
|
]
|
|
2595
2595
|
];
|
|
2596
|
-
const
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
return pointInPolygon(point, macauBounds) >= 0;
|
|
2605
|
-
};
|
|
2606
|
-
return { inChina, inHongkong, inMacau };
|
|
2596
|
+
const inChina = (point) => {
|
|
2597
|
+
return pointInPolygon(point, chinaBounds) >= 0;
|
|
2598
|
+
};
|
|
2599
|
+
const inHongkong = (point) => {
|
|
2600
|
+
return pointInPolygon(point, hongkongBounds) >= 0;
|
|
2601
|
+
};
|
|
2602
|
+
const inMacau = (point) => {
|
|
2603
|
+
return pointInPolygon(point, macauBounds) >= 0;
|
|
2607
2604
|
};
|
|
2608
|
-
const useAmapInChina = useMapInChina;
|
|
2609
|
-
const useGmapInChina = useMapInChina;
|
|
2610
2605
|
export {
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2606
|
+
inChina,
|
|
2607
|
+
inHongkong,
|
|
2608
|
+
inMacau
|
|
2614
2609
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { load as loadAmap } from "@amap/amap-jsapi-loader";
|
|
2
2
|
import { type LoaderOptions } from "@googlemaps/js-api-loader";
|
|
3
3
|
import { type Ref } from "vue-demi";
|
|
4
|
-
import type {
|
|
5
|
-
import type { Language } from "../types/interface";
|
|
4
|
+
import type { VNodeChild } from "../demi-polyfill";
|
|
5
|
+
import type { ConnectionStatus, Language } from "../types/interface";
|
|
6
6
|
export declare const DEFAULT_AMAP_PLUGINS: AmapLoaderProps["plugins"];
|
|
7
7
|
export declare const DEFAULT_GMAP_LIBRARIES: LoaderOptions["libraries"];
|
|
8
8
|
export declare enum Status {
|
|
@@ -19,40 +19,47 @@ declare global {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loading" | "
|
|
22
|
+
export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loading" | "onSuccess" | "onFail">, Omit<AMapLoaderOptions, "key" | "version" | "plugins"> {
|
|
23
23
|
apiKey: string;
|
|
24
24
|
apiSecret?: string;
|
|
25
25
|
apiServiceHost?: string;
|
|
26
26
|
version?: string;
|
|
27
27
|
plugins?: `AMap.${AMap.PluginName}`[];
|
|
28
|
+
disableRef?: Ref<boolean>;
|
|
28
29
|
}
|
|
29
30
|
export declare const useAmapLoader: (props: AmapLoaderProps) => {
|
|
30
31
|
statusRef: import("vue-demi").ShallowRef<Status>;
|
|
32
|
+
pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
|
|
31
33
|
readyPromise: Promise<undefined>;
|
|
32
34
|
};
|
|
33
35
|
export interface GmapLoaderProps extends LoaderOptions {
|
|
36
|
+
disableRef?: Ref<boolean>;
|
|
34
37
|
/**
|
|
35
38
|
* Render prop used to switch to loading component.
|
|
36
39
|
*/
|
|
37
|
-
loading?: () =>
|
|
40
|
+
loading?: () => VNodeChild;
|
|
38
41
|
/**
|
|
39
42
|
* Render prop used to switch to error fallback component.
|
|
40
43
|
*/
|
|
41
|
-
fallback?: () =>
|
|
44
|
+
fallback?: () => VNodeChild;
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* Note: The callback be executed multiple times in the lifecycle of the component.
|
|
46
|
+
* 成功回调只会触发一次
|
|
46
47
|
*/
|
|
47
|
-
|
|
48
|
+
onSuccess?: () => void;
|
|
49
|
+
/**
|
|
50
|
+
* 失败回调可能会触发多次
|
|
51
|
+
*/
|
|
52
|
+
onFail?: () => void;
|
|
48
53
|
}
|
|
49
54
|
export declare const useGmapLoader: (props: GmapLoaderProps) => {
|
|
50
55
|
statusRef: import("vue-demi").ShallowRef<Status>;
|
|
56
|
+
pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
|
|
51
57
|
readyPromise: Promise<undefined>;
|
|
52
58
|
};
|
|
53
59
|
export type MapSupplier = "gmap" | "amap";
|
|
54
60
|
export interface UseMapLoaderOutput {
|
|
55
61
|
statusRef: Ref<Status>;
|
|
62
|
+
pingStatusRef: Ref<ConnectionStatus>;
|
|
56
63
|
readyPromise: Promise<undefined>;
|
|
57
64
|
}
|
|
58
65
|
export interface UseMapLoaderProps {
|
|
@@ -62,7 +69,8 @@ export interface UseMapLoaderProps {
|
|
|
62
69
|
amapServiceHost?: string;
|
|
63
70
|
supplier: MapSupplier;
|
|
64
71
|
language: Language;
|
|
65
|
-
|
|
72
|
+
onSuccess?: () => void;
|
|
73
|
+
onFail?: () => void;
|
|
66
74
|
}
|
|
67
75
|
export declare const useMapLoader: (props: UseMapLoaderProps) => UseMapLoaderOutput;
|
|
68
76
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { shallowRef, computed } from "vue-demi";
|
|
2
|
+
import { apiPingAmap, apiPingGmap } from "../api/pingConnection.js";
|
|
2
3
|
import { watchPostEffectForDeepOption } from "../utils/compare.js";
|
|
3
|
-
import { createRunOnce } from "../utils/helper.js";
|
|
4
|
+
import { createOneConcurrent, sleep, createRunOnce } from "../utils/helper.js";
|
|
5
|
+
import { patchGoogleMapLoader } from "../utils/patchGoogleMapLoader.js";
|
|
4
6
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
5
7
|
var distExports = {};
|
|
6
8
|
var dist = {
|
|
@@ -537,6 +539,7 @@ class Loader {
|
|
|
537
539
|
}
|
|
538
540
|
}
|
|
539
541
|
}
|
|
542
|
+
const MIN_MAP_RELOAD_INTERVAL = 5e3;
|
|
540
543
|
const DEFAULT_AMAP_PLUGINS = [
|
|
541
544
|
"AMap.Geocoder",
|
|
542
545
|
"AMap.Driving",
|
|
@@ -551,120 +554,194 @@ var Status = /* @__PURE__ */ ((Status2) => {
|
|
|
551
554
|
return Status2;
|
|
552
555
|
})(Status || {});
|
|
553
556
|
const useAmapLoader = (props) => {
|
|
554
|
-
const {
|
|
557
|
+
const { disableRef, onSuccess, onFail } = props;
|
|
555
558
|
let resolveLoader;
|
|
556
|
-
|
|
557
|
-
const readyPromise = new Promise((resolve, reject) => {
|
|
559
|
+
const readyPromise = new Promise((resolve) => {
|
|
558
560
|
resolveLoader = resolve;
|
|
559
|
-
rejectLoader = reject;
|
|
560
561
|
});
|
|
561
562
|
const statusRef = shallowRef(
|
|
562
563
|
"LOADING"
|
|
563
564
|
/* LOADING */
|
|
564
565
|
);
|
|
566
|
+
const pingStatusRef = shallowRef("connected");
|
|
565
567
|
const optionsRef = computed(() => {
|
|
566
|
-
const {
|
|
568
|
+
const {
|
|
569
|
+
onSuccess: onSuccess2,
|
|
570
|
+
onFail: onFail2,
|
|
571
|
+
loading,
|
|
572
|
+
fallback,
|
|
573
|
+
apiKey,
|
|
574
|
+
apiSecret,
|
|
575
|
+
apiServiceHost,
|
|
576
|
+
version,
|
|
577
|
+
...options
|
|
578
|
+
} = props;
|
|
567
579
|
return { ...options, key: apiKey, version: version != null ? version : "2.0" };
|
|
568
580
|
});
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
581
|
+
const defineSecurityOnce = createRunOnce(() => {
|
|
582
|
+
window._AMapSecurityConfig = props.apiServiceHost ? {
|
|
583
|
+
serviceHost: props.apiServiceHost
|
|
584
|
+
} : { securityJsCode: props.apiSecret };
|
|
585
|
+
});
|
|
586
|
+
const reload = createOneConcurrent((options) => {
|
|
587
|
+
if (statusRef.value === "SUCCESS")
|
|
588
|
+
return Promise.resolve();
|
|
589
|
+
defineSecurityOnce();
|
|
590
|
+
distExports.reset();
|
|
591
|
+
statusRef.value = "LOADING";
|
|
592
|
+
return distExports.load(options).then(
|
|
593
|
+
() => {
|
|
594
|
+
statusRef.value = "SUCCESS";
|
|
595
|
+
resolveLoader();
|
|
596
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
597
|
+
},
|
|
598
|
+
() => {
|
|
599
|
+
statusRef.value = "FAILURE";
|
|
600
|
+
onFail == null ? void 0 : onFail();
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
});
|
|
604
|
+
const keepRetry = createOneConcurrent(async () => {
|
|
605
|
+
if (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value === "SUCCESS") {
|
|
606
|
+
pingStatusRef.value = "pending";
|
|
607
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && pingStatusRef.value !== "connected") {
|
|
608
|
+
if (pingStatusRef.value === "unconnected")
|
|
609
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
610
|
+
pingStatusRef.value = await apiPingAmap();
|
|
611
|
+
}
|
|
597
612
|
}
|
|
598
|
-
|
|
599
|
-
|
|
613
|
+
const options = optionsRef.value;
|
|
614
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
|
|
615
|
+
if (statusRef.value === "LOADING") {
|
|
616
|
+
await reload(options);
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
620
|
+
const pingStatus = await apiPingAmap();
|
|
621
|
+
if (pingStatus === "unconnected")
|
|
622
|
+
continue;
|
|
623
|
+
await reload(options);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
|
|
627
|
+
return { statusRef, pingStatusRef, readyPromise };
|
|
600
628
|
};
|
|
601
|
-
const loadGmapOnce = createRunOnce((opts) => {
|
|
602
|
-
const loader = new Loader(opts);
|
|
603
|
-
return loader.load();
|
|
604
|
-
});
|
|
605
629
|
const useGmapLoader = (props) => {
|
|
606
|
-
const {
|
|
630
|
+
const { disableRef, onSuccess, onFail } = props;
|
|
607
631
|
let resolveLoader;
|
|
608
|
-
|
|
609
|
-
const readyPromise = new Promise((resolve, reject) => {
|
|
632
|
+
const readyPromise = new Promise((resolve) => {
|
|
610
633
|
resolveLoader = resolve;
|
|
611
|
-
rejectLoader = reject;
|
|
612
634
|
});
|
|
613
635
|
const statusRef = shallowRef(
|
|
614
636
|
"LOADING"
|
|
615
637
|
/* LOADING */
|
|
616
638
|
);
|
|
639
|
+
const pingStatusRef = shallowRef("pending");
|
|
617
640
|
const optionsRef = computed(() => {
|
|
618
|
-
const {
|
|
641
|
+
const { onSuccess: onSuccess2, onFail: onFail2, fallback, loading, language, ...options } = props;
|
|
619
642
|
return options;
|
|
620
643
|
});
|
|
621
|
-
|
|
622
|
-
(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (status === "FAILURE")
|
|
630
|
-
rejectLoader();
|
|
631
|
-
onChange == null ? void 0 : onChange(statusRef.value);
|
|
632
|
-
};
|
|
633
|
-
setStatusAndExecuteCallback(
|
|
634
|
-
"LOADING"
|
|
635
|
-
/* LOADING */
|
|
636
|
-
);
|
|
637
|
-
loadGmapOnce({ ...options, language }).then(
|
|
638
|
-
() => setStatusAndExecuteCallback(
|
|
639
|
-
"SUCCESS"
|
|
640
|
-
/* SUCCESS */
|
|
641
|
-
),
|
|
642
|
-
() => setStatusAndExecuteCallback(
|
|
643
|
-
"FAILURE"
|
|
644
|
-
/* FAILURE */
|
|
645
|
-
)
|
|
646
|
-
);
|
|
644
|
+
const reload = createOneConcurrent((options, signal) => {
|
|
645
|
+
if (statusRef.value === "SUCCESS")
|
|
646
|
+
return Promise.resolve();
|
|
647
|
+
const loader = new Loader({ ...options, retries: 0 });
|
|
648
|
+
patchGoogleMapLoader(loader);
|
|
649
|
+
if (loader.status !== LoaderStatus.INITIALIZED) {
|
|
650
|
+
window.google = void 0;
|
|
651
|
+
loader.reset();
|
|
647
652
|
}
|
|
648
|
-
|
|
649
|
-
|
|
653
|
+
const abortPromise = new Promise((resolve) => signal == null ? void 0 : signal.addEventListener("abort", resolve));
|
|
654
|
+
statusRef.value = "LOADING";
|
|
655
|
+
const loadPromise = loader.load().then(
|
|
656
|
+
() => {
|
|
657
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
658
|
+
return;
|
|
659
|
+
statusRef.value = "SUCCESS";
|
|
660
|
+
resolveLoader();
|
|
661
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
662
|
+
},
|
|
663
|
+
() => {
|
|
664
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
665
|
+
return;
|
|
666
|
+
statusRef.value = "FAILURE";
|
|
667
|
+
onFail == null ? void 0 : onFail();
|
|
668
|
+
}
|
|
669
|
+
);
|
|
670
|
+
return Promise.race([abortPromise, loadPromise]);
|
|
671
|
+
});
|
|
672
|
+
const keepRetry = createOneConcurrent(async () => {
|
|
673
|
+
if (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value === "SUCCESS") {
|
|
674
|
+
pingStatusRef.value = "pending";
|
|
675
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && pingStatusRef.value !== "connected") {
|
|
676
|
+
if (pingStatusRef.value === "unconnected")
|
|
677
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
678
|
+
pingStatusRef.value = await apiPingGmap();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
const language = navigator.language;
|
|
682
|
+
const options = { ...optionsRef.value, language };
|
|
683
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
|
|
684
|
+
if (statusRef.value === "FAILURE" || pingStatusRef.value === "unconnected") {
|
|
685
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
686
|
+
pingStatusRef.value = await apiPingGmap();
|
|
687
|
+
if (pingStatusRef.value === "connected")
|
|
688
|
+
statusRef.value = "LOADING";
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
const controller = new AbortController();
|
|
692
|
+
const reloadPromise = reload(options, controller.signal);
|
|
693
|
+
pingStatusRef.value = await apiPingGmap();
|
|
694
|
+
if (pingStatusRef.value === "unconnected") {
|
|
695
|
+
controller.abort();
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
await reloadPromise;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
|
|
702
|
+
return { statusRef, pingStatusRef, readyPromise };
|
|
650
703
|
};
|
|
651
704
|
const useMapLoader = (props) => {
|
|
652
|
-
const { gmapKey, amapKey, amapSecret, amapServiceHost,
|
|
653
|
-
|
|
705
|
+
const { gmapKey, amapKey, amapSecret, amapServiceHost, language, onSuccess, onFail } = props;
|
|
706
|
+
const {
|
|
707
|
+
statusRef: amapStatusRef,
|
|
708
|
+
pingStatusRef: amapPingStatusRef,
|
|
709
|
+
readyPromise: amapReadyPromise
|
|
710
|
+
} = useAmapLoader({
|
|
711
|
+
apiKey: amapKey,
|
|
712
|
+
apiSecret: amapSecret,
|
|
713
|
+
apiServiceHost: amapServiceHost,
|
|
714
|
+
plugins: DEFAULT_AMAP_PLUGINS,
|
|
715
|
+
disableRef: computed(() => props.supplier !== "amap"),
|
|
716
|
+
onSuccess,
|
|
717
|
+
onFail
|
|
718
|
+
});
|
|
719
|
+
const {
|
|
720
|
+
statusRef: gmapStatusRef,
|
|
721
|
+
pingStatusRef: gmapPingStatusRef,
|
|
722
|
+
readyPromise: gmapReadyPromise
|
|
723
|
+
} = useGmapLoader({
|
|
654
724
|
apiKey: gmapKey,
|
|
655
725
|
language,
|
|
656
726
|
version: "weekly",
|
|
657
727
|
// todo: 需要提前设置 region
|
|
658
728
|
// region: "CN",
|
|
659
729
|
libraries: DEFAULT_GMAP_LIBRARIES,
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
apiSecret: amapSecret,
|
|
664
|
-
apiServiceHost: amapServiceHost,
|
|
665
|
-
plugins: DEFAULT_AMAP_PLUGINS,
|
|
666
|
-
onChange
|
|
730
|
+
disableRef: computed(() => props.supplier !== "gmap"),
|
|
731
|
+
onSuccess,
|
|
732
|
+
onFail
|
|
667
733
|
});
|
|
734
|
+
return {
|
|
735
|
+
get statusRef() {
|
|
736
|
+
return props.supplier === "gmap" ? gmapStatusRef : amapStatusRef;
|
|
737
|
+
},
|
|
738
|
+
get pingStatusRef() {
|
|
739
|
+
return props.supplier === "gmap" ? gmapPingStatusRef : amapPingStatusRef;
|
|
740
|
+
},
|
|
741
|
+
get readyPromise() {
|
|
742
|
+
return props.supplier === "gmap" ? gmapReadyPromise : amapReadyPromise;
|
|
743
|
+
}
|
|
744
|
+
};
|
|
668
745
|
};
|
|
669
746
|
export {
|
|
670
747
|
DEFAULT_AMAP_PLUGINS,
|
|
@@ -3,6 +3,7 @@ import type { Place, Point } from "../types/interface";
|
|
|
3
3
|
export interface UseMapPlaceProps {
|
|
4
4
|
pointRef: Ref<Point>;
|
|
5
5
|
emptyPlaceName: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
6
7
|
onChange?: (value: Place) => any;
|
|
7
8
|
}
|
|
8
9
|
export declare const useAmapPlace: (props: UseMapPlaceProps) => {
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { ref, reactive, watch } from "vue-demi";
|
|
2
2
|
import { REGEO_TIMEOUT } from "../api/contants.js";
|
|
3
3
|
import { createPipeTw } from "../utils/cn2tw.js";
|
|
4
|
-
import { equalAssign } from "../utils/helper.js";
|
|
4
|
+
import { equalAssign, createAbortable } from "../utils/helper.js";
|
|
5
5
|
import { amapPlaceName2DisplayName, gmapPlaceName2DisplayName } from "../utils/transform.js";
|
|
6
|
-
import {
|
|
6
|
+
import { inChina } from "./useMapInChina.js";
|
|
7
7
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
8
8
|
import { useUpdate } from "./useUdate.js";
|
|
9
9
|
const useAmapPlace = (props) => {
|
|
10
|
-
const { onChange, emptyPlaceName } = props;
|
|
10
|
+
const { signal, onChange, emptyPlaceName } = props;
|
|
11
11
|
const defaultPoint = [...props.pointRef.value];
|
|
12
12
|
const pointRef = ref(defaultPoint);
|
|
13
13
|
const { readyPromise, language } = useMapSupplier();
|
|
14
|
-
const { inChina } = useAmapInChina();
|
|
15
14
|
const place = reactive({
|
|
16
15
|
lng: pointRef.value[0],
|
|
17
16
|
lat: pointRef.value[1],
|
|
18
17
|
name: "",
|
|
19
18
|
displayName: ""
|
|
20
19
|
});
|
|
20
|
+
const abortable = createAbortable(signal);
|
|
21
21
|
const { idx: placeKey, update } = useUpdate();
|
|
22
22
|
const updatePlace = (value) => {
|
|
23
23
|
pointRef.value = value;
|
|
@@ -29,37 +29,42 @@ const useAmapPlace = (props) => {
|
|
|
29
29
|
place.name = value.name;
|
|
30
30
|
place.displayName = value.displayName;
|
|
31
31
|
};
|
|
32
|
-
const getPlaceByRegeo = ([lng, lat]) => {
|
|
32
|
+
const getPlaceByRegeo = abortable(([lng, lat]) => {
|
|
33
33
|
return new Promise((resolve) => {
|
|
34
|
-
const
|
|
35
|
-
const pipeTw = createPipeTw(language === "zh-TW");
|
|
36
|
-
const isChina = inChina([lng, lat]);
|
|
37
|
-
geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
|
|
38
|
-
switch (status) {
|
|
39
|
-
case "complete": {
|
|
40
|
-
const { formattedAddress, addressComponent } = result.regeocode;
|
|
41
|
-
const name = formattedAddress ? formattedAddress : emptyPlaceName;
|
|
42
|
-
const displayName = amapPlaceName2DisplayName(name, { isChina, ...addressComponent });
|
|
43
|
-
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
case "no_data":
|
|
47
|
-
case "error": {
|
|
48
|
-
const name = emptyPlaceName;
|
|
49
|
-
const displayName = emptyPlaceName;
|
|
50
|
-
resolve({ lng, lat, name, displayName });
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
console.warn("高德逆地理请求超时!");
|
|
34
|
+
const handleFailed = () => {
|
|
57
35
|
const name = emptyPlaceName;
|
|
58
36
|
const displayName = emptyPlaceName;
|
|
59
37
|
resolve({ lng, lat, name, displayName });
|
|
38
|
+
};
|
|
39
|
+
readyPromise.then(() => {
|
|
40
|
+
const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
|
|
41
|
+
const pipeTw = createPipeTw(language === "zh-TW");
|
|
42
|
+
const isChina = inChina([lng, lat]);
|
|
43
|
+
geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
|
|
44
|
+
switch (status) {
|
|
45
|
+
case "complete": {
|
|
46
|
+
const { formattedAddress, addressComponent } = result.regeocode;
|
|
47
|
+
const name = formattedAddress ? formattedAddress : emptyPlaceName;
|
|
48
|
+
const displayName = amapPlaceName2DisplayName(name, {
|
|
49
|
+
isChina,
|
|
50
|
+
...addressComponent
|
|
51
|
+
});
|
|
52
|
+
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
case "no_data":
|
|
56
|
+
case "error": {
|
|
57
|
+
handleFailed();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}, handleFailed);
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
console.warn("高德逆地理请求超时!");
|
|
64
|
+
handleFailed();
|
|
60
65
|
}, REGEO_TIMEOUT);
|
|
61
66
|
});
|
|
62
|
-
};
|
|
67
|
+
});
|
|
63
68
|
watch(
|
|
64
69
|
() => [placeKey.value],
|
|
65
70
|
async () => {
|
|
@@ -72,7 +77,7 @@ const useAmapPlace = (props) => {
|
|
|
72
77
|
return { place, updatePlace, setPlace, getPlaceByRegeo };
|
|
73
78
|
};
|
|
74
79
|
const useGmapPlace = (props) => {
|
|
75
|
-
const { onChange, emptyPlaceName } = props;
|
|
80
|
+
const { signal, onChange, emptyPlaceName } = props;
|
|
76
81
|
const defaultPoint = [...props.pointRef.value];
|
|
77
82
|
const pointRef = ref(defaultPoint);
|
|
78
83
|
const { readyPromise, language } = useMapSupplier();
|
|
@@ -83,6 +88,7 @@ const useGmapPlace = (props) => {
|
|
|
83
88
|
name: "",
|
|
84
89
|
displayName: ""
|
|
85
90
|
});
|
|
91
|
+
const abortable = createAbortable(signal);
|
|
86
92
|
const updatePlace = (value) => {
|
|
87
93
|
pointRef.value = value;
|
|
88
94
|
update();
|
|
@@ -93,28 +99,30 @@ const useGmapPlace = (props) => {
|
|
|
93
99
|
place.name = value.name;
|
|
94
100
|
place.displayName = value.displayName;
|
|
95
101
|
};
|
|
96
|
-
const getPlaceByRegeo = ([lng, lat]) => {
|
|
102
|
+
const getPlaceByRegeo = abortable(([lng, lat]) => {
|
|
97
103
|
return new Promise((resolve) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
|
|
102
|
-
const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
|
|
103
|
-
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
104
|
-
}).catch((err) => {
|
|
105
|
-
console.error(err);
|
|
104
|
+
const handleFailed = (err) => {
|
|
105
|
+
if (err)
|
|
106
|
+
console.error(err);
|
|
106
107
|
const name = emptyPlaceName;
|
|
107
108
|
const displayName = emptyPlaceName;
|
|
108
109
|
resolve({ lng, lat, name, displayName });
|
|
109
|
-
}
|
|
110
|
+
};
|
|
111
|
+
readyPromise.then(() => {
|
|
112
|
+
const geocoder = new google.maps.Geocoder();
|
|
113
|
+
const pipeTw = createPipeTw(language === "zh-TW");
|
|
114
|
+
geocoder.geocode({ language, location: { lng, lat } }).then(({ results }) => {
|
|
115
|
+
const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
|
|
116
|
+
const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
|
|
117
|
+
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
118
|
+
}).catch(handleFailed);
|
|
119
|
+
}, handleFailed);
|
|
110
120
|
setTimeout(() => {
|
|
111
121
|
console.warn("谷歌逆地理请求超时!");
|
|
112
|
-
|
|
113
|
-
const displayName = emptyPlaceName;
|
|
114
|
-
resolve({ lng, lat, name, displayName });
|
|
122
|
+
handleFailed();
|
|
115
123
|
}, REGEO_TIMEOUT);
|
|
116
124
|
});
|
|
117
|
-
};
|
|
125
|
+
});
|
|
118
126
|
watch(
|
|
119
127
|
() => placeKey.value,
|
|
120
128
|
async () => {
|
|
@@ -5,6 +5,7 @@ export interface UseMapRecomendPlaceProps<C = Record<string, any>> {
|
|
|
5
5
|
context?: C;
|
|
6
6
|
emptyPlaceName: string;
|
|
7
7
|
queryingPlaceName: string;
|
|
8
|
+
signal?: AbortSignal;
|
|
8
9
|
getLimit: (context?: C) => number;
|
|
9
10
|
getAvailable?: (place: Place) => Promise<boolean>;
|
|
10
11
|
getRecomendPlace: (place: Place, context?: C) => Promise<RecommendZonePlaces | undefined>;
|