@heycar/heycars-map 0.9.20-timeout3 → 0.9.21-alpha

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.cjs CHANGED
@@ -19,7 +19,7 @@ if (typeof GeolocationPositionError === "undefined") {
19
19
  };
20
20
  }
21
21
  const name = "@heycar/heycars-map";
22
- const version = "0.9.20-timeout3";
22
+ const version = "0.9.21-alpha";
23
23
  const type = "module";
24
24
  const bin = {
25
25
  checkVersion: "./bin/checkVersion.js"
@@ -4554,7 +4554,8 @@ function wechatWatchPosition(onSuccess, onError, option) {
4554
4554
  const { timeout } = option;
4555
4555
  let enable = true;
4556
4556
  let prevGeoPosition = void 0;
4557
- const isGeoWorkingRef = Vue.ref(true);
4557
+ let lastSuccessfulResponse = void 0;
4558
+ let geoErrorMessage = void 0;
4558
4559
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4559
4560
  const startWatch = async () => {
4560
4561
  try {
@@ -4583,26 +4584,24 @@ function wechatWatchPosition(onSuccess, onError, option) {
4583
4584
  if (isHandled)
4584
4585
  return;
4585
4586
  isHandled = true;
4586
- isGeoWorkingRef.value = true;
4587
+ lastSuccessfulResponse = res;
4588
+ geoErrorMessage = void 0;
4587
4589
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
4588
4590
  },
4589
4591
  fail(res) {
4590
4592
  if (isHandled)
4591
4593
  return;
4592
4594
  isHandled = true;
4593
- const isGeoWorking = isGeoWorkingRef.value;
4594
- isGeoWorkingRef.value = false;
4595
- console.warn(
4596
- "MyWarning: wx.getLocation failed errcode, errmsg = ",
4597
- res.errCode,
4598
- res.errMsg
4599
- );
4595
+ const { errMsg: message, errCode: code } = res;
4596
+ const prevMessage = geoErrorMessage;
4597
+ geoErrorMessage = message;
4600
4598
  resolve(void 0);
4601
- if (!isGeoWorking)
4599
+ if (prevMessage === message)
4602
4600
  return;
4601
+ console.warn("MyWarning: wx.getLocation failed code, message = ", code, message);
4603
4602
  onError == null ? void 0 : onError(
4604
4603
  createCustomGeolocationPositionError(
4605
- res.errMsg,
4604
+ message,
4606
4605
  GeolocationPositionError.PERMISSION_DENIED
4607
4606
  )
4608
4607
  );
@@ -4613,12 +4612,21 @@ function wechatWatchPosition(onSuccess, onError, option) {
4613
4612
  setTimeout(() => {
4614
4613
  if (isHandled)
4615
4614
  return;
4615
+ if (lastSuccessfulResponse) {
4616
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4617
+ return resolve(
4618
+ wxGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4619
+ );
4620
+ }
4621
+ const message = `Custom Timeout: exceed ${timeout}s`;
4622
+ const prevMessage = geoErrorMessage;
4623
+ geoErrorMessage = message;
4616
4624
  resolve(void 0);
4625
+ if (prevMessage === message)
4626
+ return;
4627
+ console.warn("MyWarning: wx.getLocation 触发自定义超时, message = ", message);
4617
4628
  onError == null ? void 0 : onError(
4618
- createCustomGeolocationPositionError(
4619
- `Custom Timeout: exceed ${timeout}s`,
4620
- GeolocationPositionError.TIMEOUT
4621
- )
4629
+ createCustomGeolocationPositionError(message, GeolocationPositionError.TIMEOUT)
4622
4630
  );
4623
4631
  }, timeout);
4624
4632
  });
@@ -4637,9 +4645,9 @@ function wechatWatchPosition(onSuccess, onError, option) {
4637
4645
  function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4638
4646
  let enable = true;
4639
4647
  let prevGeoPosition = void 0;
4648
+ let lastSuccessfulResponse = void 0;
4649
+ let geoErrorMessage = void 0;
4640
4650
  const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4641
- const isGeoWorkingRef = Vue.ref(true);
4642
- const lastSuccessfulResponseRef = Vue.ref();
4643
4651
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4644
4652
  const startWatch = async () => {
4645
4653
  do {
@@ -4649,8 +4657,8 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4649
4657
  }
4650
4658
  const geoPosition = await new Promise((resolve) => {
4651
4659
  const handleSuccess = (res) => {
4652
- lastSuccessfulResponseRef.value = res;
4653
- isGeoWorkingRef.value = true;
4660
+ lastSuccessfulResponse = res;
4661
+ geoErrorMessage = void 0;
4654
4662
  resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4655
4663
  };
4656
4664
  getLocationFn({
@@ -4658,25 +4666,21 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4658
4666
  cacheTimeout: timeout / 1e3,
4659
4667
  success: handleSuccess,
4660
4668
  fail(res) {
4661
- if (res.error === 13 && lastSuccessfulResponseRef.value) {
4662
- console.warn(
4663
- "MyWarning: my.getLocation failed with errcode 13 which has been bypassed"
4669
+ if (res.error === 13 && lastSuccessfulResponse) {
4670
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4671
+ return resolve(
4672
+ alipayMyGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4664
4673
  );
4665
- return handleSuccess(lastSuccessfulResponseRef.value);
4666
4674
  }
4667
- const isGeoWorking = isGeoWorkingRef.value;
4668
- isGeoWorkingRef.value = false;
4675
+ const { errorMessage: message, error: code } = res;
4676
+ const prevMessage = geoErrorMessage;
4677
+ geoErrorMessage = message;
4669
4678
  resolve(void 0);
4670
- if (!isGeoWorking)
4679
+ if (prevMessage === message)
4671
4680
  return;
4672
- const { error, errorMessage } = res;
4673
- console.warn(
4674
- "MyWarning: my.getLocation failed errcode, errmsg = ",
4675
- error,
4676
- errorMessage
4677
- );
4678
- const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(error);
4679
- onError == null ? void 0 : onError(createCustomGeolocationPositionError(errorMessage, geoErrorCode));
4681
+ console.warn("MyWarning: my.getLocation failed code, message = ", code, message);
4682
+ const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(code);
4683
+ onError == null ? void 0 : onError(createCustomGeolocationPositionError(message, geoErrorCode));
4680
4684
  }
4681
4685
  });
4682
4686
  });
@@ -4699,7 +4703,7 @@ const apGetLocation = ({ type: type2, cacheTimeout, success, fail }) => {
4699
4703
  function androidWatchPosition(onSuccess, onError, option) {
4700
4704
  let enable = true;
4701
4705
  let prevGeoPosition = void 0;
4702
- const isGeoWorkingRef = Vue.ref(true);
4706
+ let geoErrorMessage = void 0;
4703
4707
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4704
4708
  const startWatch = async () => {
4705
4709
  do {
@@ -4710,19 +4714,22 @@ function androidWatchPosition(onSuccess, onError, option) {
4710
4714
  const geoPosition = await new Promise((resolve) => {
4711
4715
  navigator.geolocation.getCurrentPosition(
4712
4716
  function onSuccess2(geoLocationPosition) {
4713
- isGeoWorkingRef.value = true;
4717
+ geoErrorMessage = void 0;
4714
4718
  resolve(geoLocationPosition);
4715
4719
  },
4716
4720
  function onFail(geoError) {
4717
- const isGeoWorking = isGeoWorkingRef.value;
4718
- isGeoWorkingRef.value = false;
4721
+ if (geoError.code === 3 && !!prevGeoPosition) {
4722
+ console.warn("警告: navigator.geolocation.getCurrentPosition 超时跳过");
4723
+ resolve(prevGeoPosition);
4724
+ return;
4725
+ }
4726
+ const { message } = geoError;
4727
+ const prevMessage = geoErrorMessage;
4728
+ geoErrorMessage = message;
4719
4729
  resolve(void 0);
4720
- if (!isGeoWorking)
4730
+ if (prevMessage === message)
4721
4731
  return;
4722
- console.warn(
4723
- "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
4724
- geoError.message
4725
- );
4732
+ console.warn("MyWarning: navigator.geolocation.getCurrentPosition failed: ", message);
4726
4733
  onError == null ? void 0 : onError(geoError);
4727
4734
  },
4728
4735
  option
@@ -4743,8 +4750,8 @@ function androidWatchPosition(onSuccess, onError, option) {
4743
4750
  function compatibleWathPosition(onSuccess, onError, option) {
4744
4751
  const isForceBrowserGeo = takeIsForceBrowserGeo();
4745
4752
  if (isForceBrowserGeo) {
4746
- const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
4747
- return () => navigator.geolocation.clearWatch(watchId2);
4753
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4754
+ return () => navigator.geolocation.clearWatch(watchId);
4748
4755
  }
4749
4756
  const browserPlatform = detectBrowserPlatform();
4750
4757
  const osPlatform = detectOSPlatform();
@@ -4758,11 +4765,7 @@ function compatibleWathPosition(onSuccess, onError, option) {
4758
4765
  if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4759
4766
  return alipayWatchPosition(onSuccess, onError, option, (props) => my.getLocation(props));
4760
4767
  }
4761
- if (osPlatform === OS_PLATFORM.ANDROID) {
4762
- return androidWatchPosition(onSuccess, onError, option);
4763
- }
4764
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4765
- return () => navigator.geolocation.clearWatch(watchId);
4768
+ return androidWatchPosition(onSuccess, onError, option);
4766
4769
  }
4767
4770
  function compatibleGeoPositionTransform(position, transform2) {
4768
4771
  const os = detectOSPlatform();
@@ -6835,10 +6838,14 @@ const useAmapGCJ02 = () => {
6835
6838
  async function toGcj02Points(points) {
6836
6839
  await readyPromise;
6837
6840
  return new Promise((resolve) => {
6841
+ let isHandled = false;
6838
6842
  AMap.convertFrom(
6839
- points,
6843
+ [...points],
6840
6844
  "gps",
6841
6845
  (_, result) => {
6846
+ if (isHandled)
6847
+ return;
6848
+ isHandled = true;
6842
6849
  if (result.info === "ok") {
6843
6850
  resolve(result.locations.map(lnglat2point));
6844
6851
  } else {
@@ -6848,6 +6855,9 @@ const useAmapGCJ02 = () => {
6848
6855
  }
6849
6856
  );
6850
6857
  setTimeout(() => {
6858
+ if (isHandled)
6859
+ return;
6860
+ isHandled = true;
6851
6861
  console.warn("警告: 高德坐标转换请求超时,启用本地转换");
6852
6862
  resolve(toLocalGcj02Points(points));
6853
6863
  }, AMAP_TO_GCJ02_TIMEOUT);
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ if (typeof GeolocationPositionError === "undefined") {
17
17
  };
18
18
  }
19
19
  const name = "@heycar/heycars-map";
20
- const version = "0.9.20-timeout3";
20
+ const version = "0.9.21-alpha";
21
21
  const type = "module";
22
22
  const bin = {
23
23
  checkVersion: "./bin/checkVersion.js"
@@ -4552,7 +4552,8 @@ function wechatWatchPosition(onSuccess, onError, option) {
4552
4552
  const { timeout } = option;
4553
4553
  let enable = true;
4554
4554
  let prevGeoPosition = void 0;
4555
- const isGeoWorkingRef = ref(true);
4555
+ let lastSuccessfulResponse = void 0;
4556
+ let geoErrorMessage = void 0;
4556
4557
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4557
4558
  const startWatch = async () => {
4558
4559
  try {
@@ -4581,26 +4582,24 @@ function wechatWatchPosition(onSuccess, onError, option) {
4581
4582
  if (isHandled)
4582
4583
  return;
4583
4584
  isHandled = true;
4584
- isGeoWorkingRef.value = true;
4585
+ lastSuccessfulResponse = res;
4586
+ geoErrorMessage = void 0;
4585
4587
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
4586
4588
  },
4587
4589
  fail(res) {
4588
4590
  if (isHandled)
4589
4591
  return;
4590
4592
  isHandled = true;
4591
- const isGeoWorking = isGeoWorkingRef.value;
4592
- isGeoWorkingRef.value = false;
4593
- console.warn(
4594
- "MyWarning: wx.getLocation failed errcode, errmsg = ",
4595
- res.errCode,
4596
- res.errMsg
4597
- );
4593
+ const { errMsg: message, errCode: code } = res;
4594
+ const prevMessage = geoErrorMessage;
4595
+ geoErrorMessage = message;
4598
4596
  resolve(void 0);
4599
- if (!isGeoWorking)
4597
+ if (prevMessage === message)
4600
4598
  return;
4599
+ console.warn("MyWarning: wx.getLocation failed code, message = ", code, message);
4601
4600
  onError == null ? void 0 : onError(
4602
4601
  createCustomGeolocationPositionError(
4603
- res.errMsg,
4602
+ message,
4604
4603
  GeolocationPositionError.PERMISSION_DENIED
4605
4604
  )
4606
4605
  );
@@ -4611,12 +4610,21 @@ function wechatWatchPosition(onSuccess, onError, option) {
4611
4610
  setTimeout(() => {
4612
4611
  if (isHandled)
4613
4612
  return;
4613
+ if (lastSuccessfulResponse) {
4614
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4615
+ return resolve(
4616
+ wxGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4617
+ );
4618
+ }
4619
+ const message = `Custom Timeout: exceed ${timeout}s`;
4620
+ const prevMessage = geoErrorMessage;
4621
+ geoErrorMessage = message;
4614
4622
  resolve(void 0);
4623
+ if (prevMessage === message)
4624
+ return;
4625
+ console.warn("MyWarning: wx.getLocation 触发自定义超时, message = ", message);
4615
4626
  onError == null ? void 0 : onError(
4616
- createCustomGeolocationPositionError(
4617
- `Custom Timeout: exceed ${timeout}s`,
4618
- GeolocationPositionError.TIMEOUT
4619
- )
4627
+ createCustomGeolocationPositionError(message, GeolocationPositionError.TIMEOUT)
4620
4628
  );
4621
4629
  }, timeout);
4622
4630
  });
@@ -4635,9 +4643,9 @@ function wechatWatchPosition(onSuccess, onError, option) {
4635
4643
  function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4636
4644
  let enable = true;
4637
4645
  let prevGeoPosition = void 0;
4646
+ let lastSuccessfulResponse = void 0;
4647
+ let geoErrorMessage = void 0;
4638
4648
  const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4639
- const isGeoWorkingRef = ref(true);
4640
- const lastSuccessfulResponseRef = ref();
4641
4649
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4642
4650
  const startWatch = async () => {
4643
4651
  do {
@@ -4647,8 +4655,8 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4647
4655
  }
4648
4656
  const geoPosition = await new Promise((resolve) => {
4649
4657
  const handleSuccess = (res) => {
4650
- lastSuccessfulResponseRef.value = res;
4651
- isGeoWorkingRef.value = true;
4658
+ lastSuccessfulResponse = res;
4659
+ geoErrorMessage = void 0;
4652
4660
  resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4653
4661
  };
4654
4662
  getLocationFn({
@@ -4656,25 +4664,21 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4656
4664
  cacheTimeout: timeout / 1e3,
4657
4665
  success: handleSuccess,
4658
4666
  fail(res) {
4659
- if (res.error === 13 && lastSuccessfulResponseRef.value) {
4660
- console.warn(
4661
- "MyWarning: my.getLocation failed with errcode 13 which has been bypassed"
4667
+ if (res.error === 13 && lastSuccessfulResponse) {
4668
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4669
+ return resolve(
4670
+ alipayMyGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4662
4671
  );
4663
- return handleSuccess(lastSuccessfulResponseRef.value);
4664
4672
  }
4665
- const isGeoWorking = isGeoWorkingRef.value;
4666
- isGeoWorkingRef.value = false;
4673
+ const { errorMessage: message, error: code } = res;
4674
+ const prevMessage = geoErrorMessage;
4675
+ geoErrorMessage = message;
4667
4676
  resolve(void 0);
4668
- if (!isGeoWorking)
4677
+ if (prevMessage === message)
4669
4678
  return;
4670
- const { error, errorMessage } = res;
4671
- console.warn(
4672
- "MyWarning: my.getLocation failed errcode, errmsg = ",
4673
- error,
4674
- errorMessage
4675
- );
4676
- const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(error);
4677
- onError == null ? void 0 : onError(createCustomGeolocationPositionError(errorMessage, geoErrorCode));
4679
+ console.warn("MyWarning: my.getLocation failed code, message = ", code, message);
4680
+ const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(code);
4681
+ onError == null ? void 0 : onError(createCustomGeolocationPositionError(message, geoErrorCode));
4678
4682
  }
4679
4683
  });
4680
4684
  });
@@ -4697,7 +4701,7 @@ const apGetLocation = ({ type: type2, cacheTimeout, success, fail }) => {
4697
4701
  function androidWatchPosition(onSuccess, onError, option) {
4698
4702
  let enable = true;
4699
4703
  let prevGeoPosition = void 0;
4700
- const isGeoWorkingRef = ref(true);
4704
+ let geoErrorMessage = void 0;
4701
4705
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4702
4706
  const startWatch = async () => {
4703
4707
  do {
@@ -4708,19 +4712,22 @@ function androidWatchPosition(onSuccess, onError, option) {
4708
4712
  const geoPosition = await new Promise((resolve) => {
4709
4713
  navigator.geolocation.getCurrentPosition(
4710
4714
  function onSuccess2(geoLocationPosition) {
4711
- isGeoWorkingRef.value = true;
4715
+ geoErrorMessage = void 0;
4712
4716
  resolve(geoLocationPosition);
4713
4717
  },
4714
4718
  function onFail(geoError) {
4715
- const isGeoWorking = isGeoWorkingRef.value;
4716
- isGeoWorkingRef.value = false;
4719
+ if (geoError.code === 3 && !!prevGeoPosition) {
4720
+ console.warn("警告: navigator.geolocation.getCurrentPosition 超时跳过");
4721
+ resolve(prevGeoPosition);
4722
+ return;
4723
+ }
4724
+ const { message } = geoError;
4725
+ const prevMessage = geoErrorMessage;
4726
+ geoErrorMessage = message;
4717
4727
  resolve(void 0);
4718
- if (!isGeoWorking)
4728
+ if (prevMessage === message)
4719
4729
  return;
4720
- console.warn(
4721
- "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
4722
- geoError.message
4723
- );
4730
+ console.warn("MyWarning: navigator.geolocation.getCurrentPosition failed: ", message);
4724
4731
  onError == null ? void 0 : onError(geoError);
4725
4732
  },
4726
4733
  option
@@ -4741,8 +4748,8 @@ function androidWatchPosition(onSuccess, onError, option) {
4741
4748
  function compatibleWathPosition(onSuccess, onError, option) {
4742
4749
  const isForceBrowserGeo = takeIsForceBrowserGeo();
4743
4750
  if (isForceBrowserGeo) {
4744
- const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
4745
- return () => navigator.geolocation.clearWatch(watchId2);
4751
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4752
+ return () => navigator.geolocation.clearWatch(watchId);
4746
4753
  }
4747
4754
  const browserPlatform = detectBrowserPlatform();
4748
4755
  const osPlatform = detectOSPlatform();
@@ -4756,11 +4763,7 @@ function compatibleWathPosition(onSuccess, onError, option) {
4756
4763
  if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4757
4764
  return alipayWatchPosition(onSuccess, onError, option, (props) => my.getLocation(props));
4758
4765
  }
4759
- if (osPlatform === OS_PLATFORM.ANDROID) {
4760
- return androidWatchPosition(onSuccess, onError, option);
4761
- }
4762
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4763
- return () => navigator.geolocation.clearWatch(watchId);
4766
+ return androidWatchPosition(onSuccess, onError, option);
4764
4767
  }
4765
4768
  function compatibleGeoPositionTransform(position, transform2) {
4766
4769
  const os = detectOSPlatform();
@@ -6833,10 +6836,14 @@ const useAmapGCJ02 = () => {
6833
6836
  async function toGcj02Points(points) {
6834
6837
  await readyPromise;
6835
6838
  return new Promise((resolve) => {
6839
+ let isHandled = false;
6836
6840
  AMap.convertFrom(
6837
- points,
6841
+ [...points],
6838
6842
  "gps",
6839
6843
  (_, result) => {
6844
+ if (isHandled)
6845
+ return;
6846
+ isHandled = true;
6840
6847
  if (result.info === "ok") {
6841
6848
  resolve(result.locations.map(lnglat2point));
6842
6849
  } else {
@@ -6846,6 +6853,9 @@ const useAmapGCJ02 = () => {
6846
6853
  }
6847
6854
  );
6848
6855
  setTimeout(() => {
6856
+ if (isHandled)
6857
+ return;
6858
+ isHandled = true;
6849
6859
  console.warn("警告: 高德坐标转换请求超时,启用本地转换");
6850
6860
  resolve(toLocalGcj02Points(points));
6851
6861
  }, AMAP_TO_GCJ02_TIMEOUT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.9.20-timeout3",
3
+ "version": "0.9.21-alpha",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js"