@heycar/heycars-map 2.0.0-switchMap5 → 2.0.0-switchMap7

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 CHANGED
@@ -1 +1 @@
1
- export * from "./v2"
1
+ export * from "./v3"
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./v2"
1
+ export * from "./v3"
@@ -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 function toGcj02Points(points) {
535
- await readyPromise;
536
- return new Promise((resolve) => {
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
  }
@@ -602,6 +602,14 @@ const useAmapLoader = (props) => {
602
602
  );
603
603
  });
604
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
+ }
612
+ }
605
613
  const options = optionsRef.value;
606
614
  while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
607
615
  if (statusRef.value === "LOADING") {
@@ -662,9 +670,9 @@ const useGmapLoader = (props) => {
662
670
  return Promise.race([abortPromise, loadPromise]);
663
671
  });
664
672
  const keepRetry = createOneConcurrent(async () => {
665
- if (statusRef.value === "SUCCESS") {
673
+ if (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value === "SUCCESS") {
666
674
  pingStatusRef.value = "pending";
667
- while (pingStatusRef.value !== "connected") {
675
+ while (!(disableRef == null ? void 0 : disableRef.value) && pingStatusRef.value !== "connected") {
668
676
  if (pingStatusRef.value === "unconnected")
669
677
  await sleep(MIN_MAP_RELOAD_INTERVAL);
670
678
  pingStatusRef.value = await apiPingGmap();
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap5";
3
+ const pkgVersion = "2.0.0-switchMap7";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -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 function toGcj02Points(points) {
535
- await readyPromise;
536
- return new Promise((resolve) => {
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
  }
@@ -602,6 +602,14 @@ const useAmapLoader = (props) => {
602
602
  );
603
603
  });
604
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
+ }
612
+ }
605
613
  const options = optionsRef.value;
606
614
  while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
607
615
  if (statusRef.value === "LOADING") {
@@ -662,9 +670,9 @@ const useGmapLoader = (props) => {
662
670
  return Promise.race([abortPromise, loadPromise]);
663
671
  });
664
672
  const keepRetry = createOneConcurrent(async () => {
665
- if (statusRef.value === "SUCCESS") {
673
+ if (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value === "SUCCESS") {
666
674
  pingStatusRef.value = "pending";
667
- while (pingStatusRef.value !== "connected") {
675
+ while (!(disableRef == null ? void 0 : disableRef.value) && pingStatusRef.value !== "connected") {
668
676
  if (pingStatusRef.value === "unconnected")
669
677
  await sleep(MIN_MAP_RELOAD_INTERVAL);
670
678
  pingStatusRef.value = await apiPingGmap();
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap5";
3
+ const pkgVersion = "2.0.0-switchMap7";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.0.0-switchMap5",
3
+ "version": "2.0.0-switchMap7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",