@heycar/heycars-map 2.0.0-switchMap3 → 2.0.0-switchMap5
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/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v2/api/pingConnection.d.ts +9 -0
- package/dist/v2/api/pingConnection.js +107 -0
- package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
- package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
- package/dist/v2/chunks/{BusinessRecomendPlaceMap.f589ebf7.js → BusinessRecomendPlaceMap.4b641c71.js} +6 -3
- package/dist/v2/chunks/{Loading.da68a2a6.js → Loading.492acbc2.js} +10 -12
- package/dist/v2/components/Loading/Loading.css.d.ts +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/css/{Loading-0e058b68.css → Loading-49e58ced.css} +6 -11
- package/dist/v2/hooks/useDeviceOrientation.js +17 -1
- package/dist/v2/hooks/useMapGCJ02.js +0 -3
- package/dist/v2/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v2/hooks/useMapGeometry.js +4 -4
- package/dist/v2/hooks/useMapLoader.d.ts +4 -2
- package/dist/v2/hooks/useMapLoader.js +110 -85
- package/dist/v2/hooks/useMapPlace.js +42 -35
- package/dist/v2/hooks/useMapRecomendPlace.js +4 -4
- 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/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- 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/helper.d.ts +1 -0
- package/dist/v2/utils/helper.js +12 -0
- package/dist/v2/utils/log.js +1 -1
- package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
- package/dist/v3/api/pingConnection.d.ts +9 -0
- package/dist/v3/api/pingConnection.js +107 -0
- package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
- package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
- package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
- package/dist/v3/chunks/{BusinessRecomendPlaceMap.86e9c287.js → BusinessRecomendPlaceMap.4befb6c7.js} +6 -3
- package/dist/v3/chunks/{Loading.98d687c0.js → Loading.21d8e759.js} +10 -12
- package/dist/v3/components/Loading/Loading.css.d.ts +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/css/{Loading-0e058b68.css → Loading-49e58ced.css} +6 -11
- package/dist/v3/hooks/useDeviceOrientation.js +17 -1
- package/dist/v3/hooks/useMapGCJ02.js +0 -3
- package/dist/v3/hooks/useMapGeometry.d.ts +1 -3
- package/dist/v3/hooks/useMapGeometry.js +4 -4
- package/dist/v3/hooks/useMapLoader.d.ts +4 -2
- package/dist/v3/hooks/useMapLoader.js +110 -85
- package/dist/v3/hooks/useMapPlace.js +42 -35
- package/dist/v3/hooks/useMapRecomendPlace.js +4 -4
- 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/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
- 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/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
|
@@ -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
|
}
|
|
@@ -31,32 +31,37 @@ const useAmapPlace = (props) => {
|
|
|
31
31
|
};
|
|
32
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
|
});
|
|
@@ -96,23 +101,25 @@ const useGmapPlace = (props) => {
|
|
|
96
101
|
};
|
|
97
102
|
const getPlaceByRegeo = abortable(([lng, lat]) => {
|
|
98
103
|
return new Promise((resolve) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
|
|
103
|
-
const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
|
|
104
|
-
resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
|
|
105
|
-
}).catch((err) => {
|
|
106
|
-
console.error(err);
|
|
104
|
+
const handleFailed = (err) => {
|
|
105
|
+
if (err)
|
|
106
|
+
console.error(err);
|
|
107
107
|
const name = emptyPlaceName;
|
|
108
108
|
const displayName = emptyPlaceName;
|
|
109
109
|
resolve({ lng, lat, name, displayName });
|
|
110
|
-
}
|
|
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);
|
|
111
120
|
setTimeout(() => {
|
|
112
121
|
console.warn("谷歌逆地理请求超时!");
|
|
113
|
-
|
|
114
|
-
const displayName = emptyPlaceName;
|
|
115
|
-
resolve({ lng, lat, name, displayName });
|
|
122
|
+
handleFailed();
|
|
116
123
|
}, REGEO_TIMEOUT);
|
|
117
124
|
});
|
|
118
125
|
});
|
|
@@ -3,7 +3,7 @@ import { GET_RECOMMEND_PLACE_TIMEOUT } from "../api/contants.js";
|
|
|
3
3
|
import { logNoneManualAbortError } from "../utils/ManualAbortError.js";
|
|
4
4
|
import { equalAssign, createAbortable, isPlacesInclude } from "../utils/helper.js";
|
|
5
5
|
import { isZoneEqual, place2point, isPlaceEqual, businessCandidatesToAdsorptionPlace } from "../utils/transform.js";
|
|
6
|
-
import { useMapGeometry } from "./useMapGeometry.js";
|
|
6
|
+
import { useMapGeometry, apiLocalIsPointInRing } from "./useMapGeometry.js";
|
|
7
7
|
import { useMapPlace } from "./useMapPlace.js";
|
|
8
8
|
function mergeGetRecommendPlaceAndGetAvailable(getRecomendPlace, getAvailable, timeout) {
|
|
9
9
|
return function mergedGetRecommendPlace(place, context) {
|
|
@@ -53,7 +53,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
53
53
|
const placeCandidatesRef = ref([]);
|
|
54
54
|
const zoneRef = ref();
|
|
55
55
|
const abortable = createAbortable(signal);
|
|
56
|
-
const {
|
|
56
|
+
const { apiMapDistance } = useMapGeometry();
|
|
57
57
|
const { getPlaceByRegeo } = useMapPlace({
|
|
58
58
|
emptyPlaceName,
|
|
59
59
|
pointRef: ref([...defaultPoint]),
|
|
@@ -99,7 +99,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
99
99
|
async (point, prevState) => {
|
|
100
100
|
const [lng, lat] = point;
|
|
101
101
|
const zone = zoneRef.value;
|
|
102
|
-
if (!zone || !
|
|
102
|
+
if (!zone || !apiLocalIsPointInRing(point, zone.path)) {
|
|
103
103
|
const reGeoPlacePromise = getPlaceByRegeo(point);
|
|
104
104
|
const {
|
|
105
105
|
place: closestPlace,
|
|
@@ -130,7 +130,7 @@ const useMapRecomendPlace = (props) => {
|
|
|
130
130
|
);
|
|
131
131
|
const updateIntermediateQueryingState = (point) => {
|
|
132
132
|
const zone = zoneRef.value;
|
|
133
|
-
if (zone &&
|
|
133
|
+
if (zone && apiLocalIsPointInRing(point, zone.path))
|
|
134
134
|
return;
|
|
135
135
|
const [lng, lat] = point;
|
|
136
136
|
const intermediateQueryingPlace = {
|
|
@@ -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
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reactive, ref, readonly } from "vue-demi";
|
|
2
|
-
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.
|
|
2
|
+
import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.4b641c71.js";
|
|
3
3
|
import { CenterPlaceStatus } from "../types/interface.js";
|
|
4
4
|
import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
|
|
5
5
|
const useBusinessRecomendPlaceMap = () => {
|
package/dist/v2/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import "./utils/alipayPolyfill.js";
|
|
|
2
2
|
import { AbsoluteAddressBox } from "./business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
|
|
3
3
|
import { AddressBox } from "./business-components/AddressBox/AddressBox.js";
|
|
4
4
|
import { BusinessQuotingMap } from "./business-components/BusinessQuotingMap/BusinessQuotingMap.js";
|
|
5
|
-
import { B } from "./chunks/BusinessRecomendPlaceMap.
|
|
5
|
+
import { B } from "./chunks/BusinessRecomendPlaceMap.4b641c71.js";
|
|
6
6
|
import { BusinessReselectPlaceMap } from "./business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js";
|
|
7
7
|
import { BusinessTaxiEndMap } from "./business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js";
|
|
8
8
|
import { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js";
|
|
@@ -93,7 +93,7 @@ export declare enum CenterPlaceStatus {
|
|
|
93
93
|
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
94
94
|
OK = "OK"
|
|
95
95
|
}
|
|
96
|
-
export type
|
|
96
|
+
export type ConnectionStatus = "pending" | "connected" | "unconnected";
|
|
97
97
|
export interface BusinessGeolocationPositionError extends GeolocationPositionError {
|
|
98
98
|
isBusinessTimeout: boolean;
|
|
99
99
|
}
|
|
@@ -22,6 +22,7 @@ export declare const pausableSleep: (milliSeconds: number) => {
|
|
|
22
22
|
restart: () => void;
|
|
23
23
|
};
|
|
24
24
|
export declare const createRunOnce: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => R;
|
|
25
|
+
export declare const createOneConcurrent: <P extends any[], R>(fn: (...args: P) => Promise<R>) => (...args: P) => Promise<R> | undefined;
|
|
25
26
|
export declare const createReadOnce: <T>(value: T) => () => T | undefined;
|
|
26
27
|
export declare const createAsyncNoFailNonNullable: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: NonNullable<R>) => (...args: P) => Promise<NonNullable<R>>;
|
|
27
28
|
export declare const pipeTimeout: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: R, timeout: number) => (...args: P) => Promise<R>;
|
package/dist/v2/utils/helper.js
CHANGED
|
@@ -93,6 +93,17 @@ const createRunOnce = (fn) => {
|
|
|
93
93
|
return result;
|
|
94
94
|
};
|
|
95
95
|
};
|
|
96
|
+
const createOneConcurrent = (fn) => {
|
|
97
|
+
let isRunning = false;
|
|
98
|
+
return function runOneConcurrent(...args) {
|
|
99
|
+
if (isRunning)
|
|
100
|
+
return;
|
|
101
|
+
isRunning = true;
|
|
102
|
+
const result = fn(...args);
|
|
103
|
+
result.finally(() => isRunning = false);
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
96
107
|
const createReadOnce = (value) => {
|
|
97
108
|
let isRead = false;
|
|
98
109
|
return function read() {
|
|
@@ -171,6 +182,7 @@ export {
|
|
|
171
182
|
assertZone,
|
|
172
183
|
createAbortable,
|
|
173
184
|
createAsyncNoFailNonNullable,
|
|
185
|
+
createOneConcurrent,
|
|
174
186
|
createReadOnce,
|
|
175
187
|
createRunOnce,
|
|
176
188
|
defered,
|
package/dist/v2/utils/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const availableLogKeys = /* @__PURE__ */ new Set();
|
|
2
2
|
const pkgName = "@heycar/heycars-map";
|
|
3
|
-
const pkgVersion = "2.0.0-
|
|
3
|
+
const pkgVersion = "2.0.0-switchMap5";
|
|
4
4
|
const isEnableLog = (name) => {
|
|
5
5
|
const searchParam = new URLSearchParams(location.search);
|
|
6
6
|
return searchParam.has(`log-${name}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createVNode } from "vue";
|
|
2
|
-
import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.
|
|
2
|
+
import { B as BusinessRecomendPlaceMap } from "../chunks/BusinessRecomendPlaceMap.4befb6c7.js";
|
|
3
3
|
import { useBusinessRecomendPlaceMap } from "../hooks-business/useBusinessRecomendPlaceMap.js";
|
|
4
4
|
import { defineSetup } from "../types/helper.js";
|
|
5
5
|
import { d as demo } from "../chunks/Demo.css.e921a2f6.js";
|
|
@@ -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
|
+
};
|