@heycar/heycars-map 2.0.0-switchMap4 → 2.0.0-switchMap6
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/v2/api/pingConnection.d.ts +9 -0
- package/dist/v2/api/pingConnection.js +107 -0
- package/dist/v2/chunks/{Loading.f2515cd7.js → Loading.492acbc2.js} +2 -2
- package/dist/v2/components/Loading/Loading.js +3 -3
- package/dist/v2/components/Loading/index.js +3 -3
- package/dist/v2/components/MapProvider/MapProvider.js +13 -10
- package/dist/v2/hooks/useDeviceOrientation.js +17 -1
- package/dist/v2/hooks/useDrivingRoute.js +4 -0
- package/dist/v2/hooks/useMapGCJ02.js +3 -31
- package/dist/v2/hooks/useMapLoader.d.ts +4 -2
- package/dist/v2/hooks/useMapLoader.js +110 -85
- package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
- package/dist/v2/hooks/usePingConnection.d.ts +10 -0
- package/dist/v2/hooks/usePingConnection.js +26 -0
- package/dist/v2/types/global.d.ts +3 -0
- package/dist/v2/types/interface.d.ts +1 -1
- package/dist/v2/utils/helper.d.ts +1 -0
- package/dist/v2/utils/helper.js +12 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v3/api/pingConnection.d.ts +9 -0
- package/dist/v3/api/pingConnection.js +107 -0
- package/dist/v3/chunks/{Loading.32ae3c98.js → Loading.21d8e759.js} +2 -2
- package/dist/v3/components/Loading/Loading.js +3 -3
- package/dist/v3/components/Loading/index.js +3 -3
- package/dist/v3/components/MapProvider/MapProvider.js +13 -10
- package/dist/v3/hooks/useDeviceOrientation.js +17 -1
- package/dist/v3/hooks/useDrivingRoute.js +4 -0
- package/dist/v3/hooks/useMapGCJ02.js +3 -31
- package/dist/v3/hooks/useMapLoader.d.ts +4 -2
- package/dist/v3/hooks/useMapLoader.js +110 -85
- package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
- package/dist/v3/hooks/usePingConnection.d.ts +10 -0
- package/dist/v3/hooks/usePingConnection.js +26 -0
- package/dist/v3/types/global.d.ts +3 -0
- package/dist/v3/types/interface.d.ts +1 -1
- package/dist/v3/utils/helper.d.ts +1 -0
- package/dist/v3/utils/helper.js +12 -0
- package/dist/v3/utils/log.js +1 -1
- package/package.json +1 -1
- package/dist/v2/api/googleConnection.d.ts +0 -5
- package/dist/v2/api/googleConnection.js +0 -51
- package/dist/v2/chunks/throttle.8bdd8d3b.js +0 -20
- package/dist/v2/hooks/useGoogleConnection.d.ts +0 -7
- package/dist/v2/hooks/useGoogleConnection.js +0 -15
- package/dist/v3/api/googleConnection.d.ts +0 -5
- package/dist/v3/api/googleConnection.js +0 -51
- package/dist/v3/chunks/throttle.8bdd8d3b.js +0 -20
- package/dist/v3/hooks/useGoogleConnection.d.ts +0 -7
- package/dist/v3/hooks/useGoogleConnection.js +0 -15
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v2"
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./v2"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConnectionStatus } from "../types/interface";
|
|
2
|
+
export type PingConnectionOnChangeHandler = (status: ConnectionStatus) => void;
|
|
3
|
+
export type PingConnectionOnChangeCleanup = () => void;
|
|
4
|
+
export declare const apiGetPingAmapStatus: () => ConnectionStatus;
|
|
5
|
+
export declare const apiGetPingGmapStatus: () => ConnectionStatus;
|
|
6
|
+
export declare const apiPingAmap: () => Promise<ConnectionStatus>;
|
|
7
|
+
export declare const apiPingGmap: () => Promise<ConnectionStatus>;
|
|
8
|
+
export declare const apiSubscribePingAmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;
|
|
9
|
+
export declare const apiSubscribePingGmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { sleep } from "../utils/helper.js";
|
|
8
|
+
const PING_AMAP_URL = "https://webapi.amap.com/favicon.ico";
|
|
9
|
+
const PING_AMAP_TIMEOUT = 5e3;
|
|
10
|
+
const PING_AMAP_INTERVAL = 5e3;
|
|
11
|
+
const PING_GMAP_URL = "https://maps.googleapis.com/";
|
|
12
|
+
const PING_GMAP_TIMEOUT = 5e3;
|
|
13
|
+
const PING_GMAP_INTERVAL = 5e3;
|
|
14
|
+
const noop = () => {
|
|
15
|
+
};
|
|
16
|
+
const toUncachableUrl = (url, label = "") => {
|
|
17
|
+
const parsedUrl = new URL(url);
|
|
18
|
+
const randomKey = `ping${Date.now()}`;
|
|
19
|
+
parsedUrl.searchParams.set(randomKey, label);
|
|
20
|
+
return parsedUrl.toString();
|
|
21
|
+
};
|
|
22
|
+
class PingConnection {
|
|
23
|
+
constructor({ timeout, url }) {
|
|
24
|
+
__publicField(this, "timeout");
|
|
25
|
+
__publicField(this, "url");
|
|
26
|
+
__publicField(this, "status", "pending");
|
|
27
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
28
|
+
__publicField(this, "updatingPromise");
|
|
29
|
+
this.timeout = timeout;
|
|
30
|
+
this.url = url;
|
|
31
|
+
}
|
|
32
|
+
// 只有订阅了 onChange 事件,listen 才会更新状态
|
|
33
|
+
async listen(interval) {
|
|
34
|
+
while (true) {
|
|
35
|
+
if (this.listeners.size > 0)
|
|
36
|
+
await this.updateStatus();
|
|
37
|
+
await sleep(interval);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async updateStatus() {
|
|
41
|
+
const { url, timeout } = this;
|
|
42
|
+
if (this.updatingPromise)
|
|
43
|
+
return this.updatingPromise;
|
|
44
|
+
return this.updatingPromise = this.check(url, timeout).then((status) => {
|
|
45
|
+
this.status = status;
|
|
46
|
+
this.updatingPromise = void 0;
|
|
47
|
+
for (const handler of this.listeners) {
|
|
48
|
+
try {
|
|
49
|
+
handler(status);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error(err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return status;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
check(url, timeout) {
|
|
58
|
+
const controller = new AbortController();
|
|
59
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
60
|
+
return fetch(toUncachableUrl(url, timeout.toString()), {
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
method: "HEAD",
|
|
63
|
+
mode: "no-cors"
|
|
64
|
+
}).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
|
|
65
|
+
}
|
|
66
|
+
onChange(handler) {
|
|
67
|
+
if (typeof handler !== "function")
|
|
68
|
+
return noop;
|
|
69
|
+
this.listeners.add(handler);
|
|
70
|
+
const clear = () => {
|
|
71
|
+
this.listeners.delete(handler);
|
|
72
|
+
};
|
|
73
|
+
return clear;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const pingAmapConnection = new PingConnection({
|
|
77
|
+
timeout: PING_AMAP_TIMEOUT,
|
|
78
|
+
url: PING_AMAP_URL
|
|
79
|
+
});
|
|
80
|
+
const pingGmapConnection = new PingConnection({
|
|
81
|
+
timeout: PING_GMAP_TIMEOUT,
|
|
82
|
+
url: PING_GMAP_URL
|
|
83
|
+
});
|
|
84
|
+
pingAmapConnection.listen(PING_AMAP_INTERVAL);
|
|
85
|
+
pingGmapConnection.listen(PING_GMAP_INTERVAL);
|
|
86
|
+
const apiGetPingAmapStatus = () => {
|
|
87
|
+
return pingAmapConnection.status;
|
|
88
|
+
};
|
|
89
|
+
const apiGetPingGmapStatus = () => {
|
|
90
|
+
return pingGmapConnection.status;
|
|
91
|
+
};
|
|
92
|
+
const apiPingAmap = () => {
|
|
93
|
+
return pingAmapConnection.updateStatus();
|
|
94
|
+
};
|
|
95
|
+
const apiPingGmap = () => {
|
|
96
|
+
return pingGmapConnection.updateStatus();
|
|
97
|
+
};
|
|
98
|
+
const apiSubscribePingAmapChange = (handler) => pingAmapConnection.onChange(handler);
|
|
99
|
+
const apiSubscribePingGmapChange = (handler) => pingGmapConnection.onChange(handler);
|
|
100
|
+
export {
|
|
101
|
+
apiGetPingAmapStatus,
|
|
102
|
+
apiGetPingGmapStatus,
|
|
103
|
+
apiPingAmap,
|
|
104
|
+
apiPingGmap,
|
|
105
|
+
apiSubscribePingAmapChange,
|
|
106
|
+
apiSubscribePingGmapChange
|
|
107
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "vue";
|
|
2
2
|
import "../../api/cdn.js";
|
|
3
|
-
import {
|
|
3
|
+
import { L, a } from "../../chunks/Loading.492acbc2.js";
|
|
4
4
|
import "../../business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
|
|
5
5
|
import "../../types/helper.js";
|
|
6
6
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
L as LoadFailed,
|
|
8
|
+
a as Loading
|
|
9
9
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../css/MapProvider-156bfd53.css";
|
|
2
2
|
import { h } from "vue";
|
|
3
|
-
import { L as
|
|
3
|
+
import { L as LoadFailed, a as Loading, i as imgGrid } from "../../chunks/Loading.492acbc2.js";
|
|
4
4
|
import { useMapLoader, Status } from "../../hooks/useMapLoader.js";
|
|
5
5
|
import { provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier.js";
|
|
6
6
|
import { defineLagecySetup } from "../../types/helper.js";
|
|
@@ -26,6 +26,8 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
|
|
|
26
26
|
get(target, name, receiver) {
|
|
27
27
|
if (name === "status")
|
|
28
28
|
return payload.statusRef.value;
|
|
29
|
+
if (name === "pingStatus")
|
|
30
|
+
return payload.pingStatusRef.value;
|
|
29
31
|
if (name === "readyPromise")
|
|
30
32
|
return payload.readyPromise;
|
|
31
33
|
return Reflect.get(target, name, receiver);
|
|
@@ -70,7 +72,8 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
|
|
|
70
72
|
gmapId,
|
|
71
73
|
gmapRasterId,
|
|
72
74
|
language = "zh",
|
|
73
|
-
status
|
|
75
|
+
status,
|
|
76
|
+
pingStatus
|
|
74
77
|
} = payload;
|
|
75
78
|
const {
|
|
76
79
|
mapRef: setMap,
|
|
@@ -79,14 +82,10 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
|
|
|
79
82
|
touchEnable = true,
|
|
80
83
|
touchZoomCenter
|
|
81
84
|
} = props;
|
|
82
|
-
if (status === Status.
|
|
83
|
-
const node = (_a = slots.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (status === Status.FAILURE || status === Status.TIMEOUT) {
|
|
87
|
-
const node = (_b = slots.fallback) == null ? void 0 : _b.call(slots);
|
|
88
|
-
const title = (_c = payload.renderLoadFailedTitle) == null ? void 0 : _c.call(payload, status);
|
|
89
|
-
const description = (_d = payload.renderLoadFailedDescription) == null ? void 0 : _d.call(payload, status);
|
|
85
|
+
if (status === Status.FAILURE || pingStatus === "unconnected") {
|
|
86
|
+
const node = (_a = slots.fallback) == null ? void 0 : _a.call(slots);
|
|
87
|
+
const title = (_b = payload.renderLoadFailedTitle) == null ? void 0 : _b.call(payload, status);
|
|
88
|
+
const description = (_c = payload.renderLoadFailedDescription) == null ? void 0 : _c.call(payload, status);
|
|
90
89
|
return node ? h("div", [node]) : h(LoadFailed, {
|
|
91
90
|
"attrs": {
|
|
92
91
|
"title": title,
|
|
@@ -94,6 +93,10 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
|
|
|
94
93
|
}
|
|
95
94
|
});
|
|
96
95
|
}
|
|
96
|
+
if (status === Status.LOADING || status === Status.SUCCESS && pingStatus === "pending") {
|
|
97
|
+
const node = (_d = slots.loading) == null ? void 0 : _d.call(slots);
|
|
98
|
+
return node ? h("div", [node]) : h(Loading);
|
|
99
|
+
}
|
|
97
100
|
const children = (_e = slots.default) == null ? void 0 : _e.call(slots);
|
|
98
101
|
const outArea = (_f = slots.outerArea) == null ? void 0 : _f.call(slots);
|
|
99
102
|
const mapId = patchGmapIdForAlipayCompatible({
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { reactive, watch } from "vue-demi";
|
|
2
2
|
import { MINI_PROGRAM_WEB_VIEW_CLOSE_EVENT } from "../utils/patchMiniprogram.js";
|
|
3
3
|
import { OS_PLATFORM, detectOSPlatform } from "../utils/platform.js";
|
|
4
|
-
import {
|
|
4
|
+
import { i as isObject, d as debounce } from "../chunks/debounce.5afe7867.js";
|
|
5
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
6
|
+
function throttle(func, wait, options) {
|
|
7
|
+
var leading = true, trailing = true;
|
|
8
|
+
if (typeof func != "function") {
|
|
9
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
10
|
+
}
|
|
11
|
+
if (isObject(options)) {
|
|
12
|
+
leading = "leading" in options ? !!options.leading : leading;
|
|
13
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
14
|
+
}
|
|
15
|
+
return debounce(func, wait, {
|
|
16
|
+
"leading": leading,
|
|
17
|
+
"maxWait": wait,
|
|
18
|
+
"trailing": trailing
|
|
19
|
+
});
|
|
20
|
+
}
|
|
5
21
|
const DEVICE_ORIENTATION_INTERVAL = 200;
|
|
6
22
|
const CSS_DEVICE_ORIENTATION_VAR_PREFIX = "--CSS_DEVICE_ORIENTATION_VAR_ROTATION_DEGREE_";
|
|
7
23
|
const useDeviceOrientation = (props) => {
|
|
@@ -23,6 +23,8 @@ const useADrivingRoute = (props) => {
|
|
|
23
23
|
const drivingResult = result;
|
|
24
24
|
const routeSteps = [];
|
|
25
25
|
const firstRoute = drivingResult.routes[0];
|
|
26
|
+
if (!firstRoute)
|
|
27
|
+
return resolve({ path: [], distance: 0, duration: 0, steps: [] });
|
|
26
28
|
for (const step of firstRoute.steps) {
|
|
27
29
|
const basicStep = step;
|
|
28
30
|
const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
|
|
@@ -83,6 +85,8 @@ const useGDrivingRoute = (props) => {
|
|
|
83
85
|
let duration = 0;
|
|
84
86
|
const routeSteps = [];
|
|
85
87
|
const firstRoute = result.routes[0];
|
|
88
|
+
if (!firstRoute)
|
|
89
|
+
return resolve({ path: [], distance: 0, duration: 0, steps: [] });
|
|
86
90
|
for (const leg of firstRoute.legs) {
|
|
87
91
|
distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
|
|
88
92
|
duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AMAP_TO_GCJ02_TIMEOUT } from "../api/contants.js";
|
|
2
|
-
import { lnglat2point } from "../utils/transform.js";
|
|
3
1
|
import { inChina, inHongkong, inMacau } from "./useMapInChina.js";
|
|
4
2
|
import { useMapSupplier } from "./useMapSupplier.js";
|
|
5
3
|
/**
|
|
@@ -514,7 +512,6 @@ const exported = Object.assign(Object.assign({}, CRSTypes), {
|
|
|
514
512
|
transform
|
|
515
513
|
});
|
|
516
514
|
const useAmapGCJ02 = () => {
|
|
517
|
-
const { readyPromise } = useMapSupplier();
|
|
518
515
|
const toCoordinateType = (p) => {
|
|
519
516
|
return inChina(p) ? "gcj02" : "wgs84";
|
|
520
517
|
};
|
|
@@ -531,34 +528,9 @@ const useAmapGCJ02 = () => {
|
|
|
531
528
|
}
|
|
532
529
|
};
|
|
533
530
|
const toLocalGcj02Points = (points) => points.map(toLocalGcj02);
|
|
534
|
-
async
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
let isHandled = false;
|
|
538
|
-
AMap.convertFrom(
|
|
539
|
-
[...points],
|
|
540
|
-
"gps",
|
|
541
|
-
(_, result) => {
|
|
542
|
-
if (isHandled)
|
|
543
|
-
return;
|
|
544
|
-
isHandled = true;
|
|
545
|
-
if (result.info === "ok") {
|
|
546
|
-
resolve(result.locations.map(lnglat2point));
|
|
547
|
-
} else {
|
|
548
|
-
console.warn("警告: 高德坐标转换请求失败,启用本地转换");
|
|
549
|
-
resolve(toLocalGcj02Points(points));
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
);
|
|
553
|
-
setTimeout(() => {
|
|
554
|
-
if (isHandled)
|
|
555
|
-
return;
|
|
556
|
-
isHandled = true;
|
|
557
|
-
console.warn("警告: 高德坐标转换请求超时,启用本地转换");
|
|
558
|
-
resolve(toLocalGcj02Points(points));
|
|
559
|
-
}, AMAP_TO_GCJ02_TIMEOUT);
|
|
560
|
-
});
|
|
561
|
-
}
|
|
531
|
+
const toGcj02Points = async (points) => {
|
|
532
|
+
return toLocalGcj02Points(points);
|
|
533
|
+
};
|
|
562
534
|
function toGcj02(point) {
|
|
563
535
|
return toGcj02Points([point]).then(([result]) => result);
|
|
564
536
|
}
|
|
@@ -2,12 +2,11 @@ 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
4
|
import type { VNodeChild } from "../demi-polyfill";
|
|
5
|
-
import type { Language } from "../types/interface";
|
|
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 {
|
|
9
9
|
LOADING = "LOADING",
|
|
10
|
-
TIMEOUT = "TIMEOUT",
|
|
11
10
|
FAILURE = "FAILURE",
|
|
12
11
|
SUCCESS = "SUCCESS"
|
|
13
12
|
}
|
|
@@ -30,6 +29,7 @@ export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loa
|
|
|
30
29
|
}
|
|
31
30
|
export declare const useAmapLoader: (props: AmapLoaderProps) => {
|
|
32
31
|
statusRef: import("vue-demi").ShallowRef<Status>;
|
|
32
|
+
pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
|
|
33
33
|
readyPromise: Promise<undefined>;
|
|
34
34
|
};
|
|
35
35
|
export interface GmapLoaderProps extends LoaderOptions {
|
|
@@ -53,11 +53,13 @@ export interface GmapLoaderProps extends LoaderOptions {
|
|
|
53
53
|
}
|
|
54
54
|
export declare const useGmapLoader: (props: GmapLoaderProps) => {
|
|
55
55
|
statusRef: import("vue-demi").ShallowRef<Status>;
|
|
56
|
+
pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
|
|
56
57
|
readyPromise: Promise<undefined>;
|
|
57
58
|
};
|
|
58
59
|
export type MapSupplier = "gmap" | "amap";
|
|
59
60
|
export interface UseMapLoaderOutput {
|
|
60
61
|
statusRef: Ref<Status>;
|
|
62
|
+
pingStatusRef: Ref<ConnectionStatus>;
|
|
61
63
|
readyPromise: Promise<undefined>;
|
|
62
64
|
}
|
|
63
65
|
export interface UseMapLoaderProps {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { shallowRef, computed
|
|
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";
|
|
4
5
|
import { patchGoogleMapLoader } from "../utils/patchGoogleMapLoader.js";
|
|
5
|
-
import { t as throttle } from "../chunks/throttle.8bdd8d3b.js";
|
|
6
6
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
7
7
|
var distExports = {};
|
|
8
8
|
var dist = {
|
|
@@ -540,7 +540,6 @@ class Loader {
|
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
const MIN_MAP_RELOAD_INTERVAL = 5e3;
|
|
543
|
-
const GMAP_LOAD_TIMEOUT = 1e4;
|
|
544
543
|
const DEFAULT_AMAP_PLUGINS = [
|
|
545
544
|
"AMap.Geocoder",
|
|
546
545
|
"AMap.Driving",
|
|
@@ -550,7 +549,6 @@ const DEFAULT_AMAP_PLUGINS = [
|
|
|
550
549
|
const DEFAULT_GMAP_LIBRARIES = ["marker", "geometry"];
|
|
551
550
|
var Status = /* @__PURE__ */ ((Status2) => {
|
|
552
551
|
Status2["LOADING"] = "LOADING";
|
|
553
|
-
Status2["TIMEOUT"] = "TIMEOUT";
|
|
554
552
|
Status2["FAILURE"] = "FAILURE";
|
|
555
553
|
Status2["SUCCESS"] = "SUCCESS";
|
|
556
554
|
return Status2;
|
|
@@ -558,15 +556,14 @@ var Status = /* @__PURE__ */ ((Status2) => {
|
|
|
558
556
|
const useAmapLoader = (props) => {
|
|
559
557
|
const { disableRef, onSuccess, onFail } = props;
|
|
560
558
|
let resolveLoader;
|
|
561
|
-
|
|
562
|
-
const readyPromise = new Promise((resolve, reject) => {
|
|
559
|
+
const readyPromise = new Promise((resolve) => {
|
|
563
560
|
resolveLoader = resolve;
|
|
564
|
-
rejectLoader = reject;
|
|
565
561
|
});
|
|
566
562
|
const statusRef = shallowRef(
|
|
567
563
|
"LOADING"
|
|
568
564
|
/* LOADING */
|
|
569
565
|
);
|
|
566
|
+
const pingStatusRef = shallowRef("connected");
|
|
570
567
|
const optionsRef = computed(() => {
|
|
571
568
|
const {
|
|
572
569
|
onSuccess: onSuccess2,
|
|
@@ -586,102 +583,123 @@ const useAmapLoader = (props) => {
|
|
|
586
583
|
serviceHost: props.apiServiceHost
|
|
587
584
|
} : { securityJsCode: props.apiSecret };
|
|
588
585
|
});
|
|
589
|
-
const reload =
|
|
590
|
-
(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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
|
+
const options = optionsRef.value;
|
|
606
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
|
|
607
|
+
if (statusRef.value === "LOADING") {
|
|
608
|
+
await reload(options);
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
612
|
+
const pingStatus = await apiPingAmap();
|
|
613
|
+
if (pingStatus === "unconnected")
|
|
614
|
+
continue;
|
|
615
|
+
await reload(options);
|
|
617
616
|
}
|
|
618
|
-
);
|
|
619
|
-
|
|
617
|
+
});
|
|
618
|
+
watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
|
|
619
|
+
return { statusRef, pingStatusRef, readyPromise };
|
|
620
620
|
};
|
|
621
621
|
const useGmapLoader = (props) => {
|
|
622
622
|
const { disableRef, onSuccess, onFail } = props;
|
|
623
623
|
let resolveLoader;
|
|
624
|
-
|
|
625
|
-
const readyPromise = new Promise((resolve, reject) => {
|
|
624
|
+
const readyPromise = new Promise((resolve) => {
|
|
626
625
|
resolveLoader = resolve;
|
|
627
|
-
rejectLoader = reject;
|
|
628
626
|
});
|
|
629
627
|
const statusRef = shallowRef(
|
|
630
628
|
"LOADING"
|
|
631
629
|
/* LOADING */
|
|
632
630
|
);
|
|
631
|
+
const pingStatusRef = shallowRef("pending");
|
|
633
632
|
const optionsRef = computed(() => {
|
|
634
633
|
const { onSuccess: onSuccess2, onFail: onFail2, fallback, loading, language, ...options } = props;
|
|
635
634
|
return options;
|
|
636
635
|
});
|
|
637
|
-
const
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
636
|
+
const reload = createOneConcurrent((options, signal) => {
|
|
637
|
+
if (statusRef.value === "SUCCESS")
|
|
638
|
+
return Promise.resolve();
|
|
639
|
+
const loader = new Loader({ ...options, retries: 0 });
|
|
640
|
+
patchGoogleMapLoader(loader);
|
|
641
|
+
if (loader.status !== LoaderStatus.INITIALIZED) {
|
|
642
|
+
window.google = void 0;
|
|
643
|
+
loader.reset();
|
|
644
|
+
}
|
|
645
|
+
const abortPromise = new Promise((resolve) => signal == null ? void 0 : signal.addEventListener("abort", resolve));
|
|
646
|
+
statusRef.value = "LOADING";
|
|
647
|
+
const loadPromise = loader.load().then(
|
|
648
|
+
() => {
|
|
649
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
650
|
+
return;
|
|
651
|
+
statusRef.value = "SUCCESS";
|
|
652
|
+
resolveLoader();
|
|
653
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
654
|
+
},
|
|
655
|
+
() => {
|
|
656
|
+
if (signal == null ? void 0 : signal.aborted)
|
|
657
|
+
return;
|
|
658
|
+
statusRef.value = "FAILURE";
|
|
659
|
+
onFail == null ? void 0 : onFail();
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
return Promise.race([abortPromise, loadPromise]);
|
|
663
|
+
});
|
|
664
|
+
const keepRetry = createOneConcurrent(async () => {
|
|
665
|
+
if (statusRef.value === "SUCCESS") {
|
|
666
|
+
pingStatusRef.value = "pending";
|
|
667
|
+
while (pingStatusRef.value !== "connected") {
|
|
668
|
+
if (pingStatusRef.value === "unconnected")
|
|
669
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
670
|
+
pingStatusRef.value = await apiPingGmap();
|
|
651
671
|
}
|
|
652
|
-
statusRef.value = "LOADING";
|
|
653
|
-
return loader.load().then(
|
|
654
|
-
() => {
|
|
655
|
-
clearTimeout(timerRef.value);
|
|
656
|
-
statusRef.value = "SUCCESS";
|
|
657
|
-
resolveLoader();
|
|
658
|
-
onSuccess == null ? void 0 : onSuccess();
|
|
659
|
-
},
|
|
660
|
-
() => {
|
|
661
|
-
clearTimeout(timerRef.value);
|
|
662
|
-
statusRef.value = "FAILURE";
|
|
663
|
-
rejectLoader();
|
|
664
|
-
onFail == null ? void 0 : onFail();
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
},
|
|
668
|
-
MIN_MAP_RELOAD_INTERVAL,
|
|
669
|
-
{ trailing: false }
|
|
670
|
-
);
|
|
671
|
-
watchPostEffectForDeepOption(
|
|
672
|
-
() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value],
|
|
673
|
-
([options, disable]) => {
|
|
674
|
-
if (disable)
|
|
675
|
-
return;
|
|
676
|
-
const language = navigator.language;
|
|
677
|
-
reload({ ...options, language });
|
|
678
672
|
}
|
|
679
|
-
|
|
680
|
-
|
|
673
|
+
const language = navigator.language;
|
|
674
|
+
const options = { ...optionsRef.value, language };
|
|
675
|
+
while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
|
|
676
|
+
if (statusRef.value === "FAILURE" || pingStatusRef.value === "unconnected") {
|
|
677
|
+
await sleep(MIN_MAP_RELOAD_INTERVAL);
|
|
678
|
+
pingStatusRef.value = await apiPingGmap();
|
|
679
|
+
if (pingStatusRef.value === "connected")
|
|
680
|
+
statusRef.value = "LOADING";
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const controller = new AbortController();
|
|
684
|
+
const reloadPromise = reload(options, controller.signal);
|
|
685
|
+
pingStatusRef.value = await apiPingGmap();
|
|
686
|
+
if (pingStatusRef.value === "unconnected") {
|
|
687
|
+
controller.abort();
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
await reloadPromise;
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
|
|
694
|
+
return { statusRef, pingStatusRef, readyPromise };
|
|
681
695
|
};
|
|
682
696
|
const useMapLoader = (props) => {
|
|
683
697
|
const { gmapKey, amapKey, amapSecret, amapServiceHost, language, onSuccess, onFail } = props;
|
|
684
|
-
const {
|
|
698
|
+
const {
|
|
699
|
+
statusRef: amapStatusRef,
|
|
700
|
+
pingStatusRef: amapPingStatusRef,
|
|
701
|
+
readyPromise: amapReadyPromise
|
|
702
|
+
} = useAmapLoader({
|
|
685
703
|
apiKey: amapKey,
|
|
686
704
|
apiSecret: amapSecret,
|
|
687
705
|
apiServiceHost: amapServiceHost,
|
|
@@ -690,7 +708,11 @@ const useMapLoader = (props) => {
|
|
|
690
708
|
onSuccess,
|
|
691
709
|
onFail
|
|
692
710
|
});
|
|
693
|
-
const {
|
|
711
|
+
const {
|
|
712
|
+
statusRef: gmapStatusRef,
|
|
713
|
+
pingStatusRef: gmapPingStatusRef,
|
|
714
|
+
readyPromise: gmapReadyPromise
|
|
715
|
+
} = useGmapLoader({
|
|
694
716
|
apiKey: gmapKey,
|
|
695
717
|
language,
|
|
696
718
|
version: "weekly",
|
|
@@ -705,6 +727,9 @@ const useMapLoader = (props) => {
|
|
|
705
727
|
get statusRef() {
|
|
706
728
|
return props.supplier === "gmap" ? gmapStatusRef : amapStatusRef;
|
|
707
729
|
},
|
|
730
|
+
get pingStatusRef() {
|
|
731
|
+
return props.supplier === "gmap" ? gmapPingStatusRef : amapPingStatusRef;
|
|
732
|
+
},
|
|
708
733
|
get readyPromise() {
|
|
709
734
|
return props.supplier === "gmap" ? gmapReadyPromise : amapReadyPromise;
|
|
710
735
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AnyFn } from "@vueuse/core";
|
|
2
|
+
import type { ConnectionStatus } from "../types/interface";
|
|
2
3
|
import type { Status, UseMapLoaderOutput, UseMapLoaderProps } from "./useMapLoader";
|
|
3
4
|
export interface MapSupplierPayolad extends UseMapLoaderProps {
|
|
4
5
|
gmapRasterId: string;
|
|
5
6
|
gmapId: string;
|
|
6
7
|
readyPromise: UseMapLoaderOutput["readyPromise"];
|
|
7
8
|
status: Status;
|
|
9
|
+
pingStatus: ConnectionStatus;
|
|
8
10
|
renderLoadFailedTitle?: (status: Status) => string | undefined;
|
|
9
11
|
renderLoadFailedDescription?: (status: Status) => string | undefined;
|
|
10
12
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PingConnectionOnChangeHandler } from "../api/pingConnection";
|
|
2
|
+
export interface UsePingConnectionProps {
|
|
3
|
+
onChange?: PingConnectionOnChangeHandler;
|
|
4
|
+
}
|
|
5
|
+
export declare const usePingAmapConnection: (props?: UsePingConnectionProps) => {
|
|
6
|
+
connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
|
|
7
|
+
};
|
|
8
|
+
export declare const usePingGmapConnection: (props?: UsePingConnectionProps) => {
|
|
9
|
+
connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ref, onUnmounted, readonly } from "vue-demi";
|
|
2
|
+
import { apiGetPingAmapStatus, apiSubscribePingAmapChange, apiGetPingGmapStatus, apiSubscribePingGmapChange } from "../api/pingConnection.js";
|
|
3
|
+
const usePingAmapConnection = (props) => {
|
|
4
|
+
const statusRef = ref(apiGetPingAmapStatus());
|
|
5
|
+
const unsubscribe = apiSubscribePingAmapChange((status) => {
|
|
6
|
+
var _a;
|
|
7
|
+
statusRef.value = status;
|
|
8
|
+
(_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
|
|
9
|
+
});
|
|
10
|
+
onUnmounted(unsubscribe);
|
|
11
|
+
return { connectionStatus: readonly(statusRef) };
|
|
12
|
+
};
|
|
13
|
+
const usePingGmapConnection = (props) => {
|
|
14
|
+
const statusRef = ref(apiGetPingGmapStatus());
|
|
15
|
+
const unsubscribe = apiSubscribePingGmapChange((status) => {
|
|
16
|
+
var _a;
|
|
17
|
+
statusRef.value = status;
|
|
18
|
+
(_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
|
|
19
|
+
});
|
|
20
|
+
onUnmounted(unsubscribe);
|
|
21
|
+
return { connectionStatus: readonly(statusRef) };
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
usePingAmapConnection,
|
|
25
|
+
usePingGmapConnection
|
|
26
|
+
};
|