@heycar/heycars-map 0.8.10 → 0.9.0

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
@@ -9,7 +9,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const Vue = require("vue");
10
10
  const style = "";
11
11
  const name = "@heycar/heycars-map";
12
- const version = "0.8.10";
12
+ const version = "0.9.0";
13
13
  const type = "module";
14
14
  const scripts = {
15
15
  dev: "vite -c vite.config.dev.ts",
@@ -3473,12 +3473,13 @@ const patchMiniprogramRedirectTo = (wx2) => {
3473
3473
  };
3474
3474
  return patchedRedirectTo;
3475
3475
  };
3476
- const DEVICE_ORIENTATION_INTERVAL = 1e3;
3476
+ const DEVICE_ORIENTATION_INTERVAL = 200;
3477
3477
  const CSS_DEVICE_ORIENTATION_VAR_PREFIX = "--CSS_DEVICE_ORIENTATION_VAR_ROTATION_DEGREE_";
3478
3478
  const useDeviceOrientation = (props) => {
3479
3479
  const { onChange, elementRef } = props;
3480
3480
  const orientation = Vue.reactive({ cssRotationVariableName: void 0 });
3481
3481
  const cssVarName = `${CSS_DEVICE_ORIENTATION_VAR_PREFIX}${Date.now()}`;
3482
+ const toTransitionAngle = createToTransitionAngle();
3482
3483
  Vue.watch(
3483
3484
  () => elementRef.value,
3484
3485
  (element, _, onCleanup) => {
@@ -3488,7 +3489,7 @@ const useDeviceOrientation = (props) => {
3488
3489
  const alpha = webkitCompassHeading !== void 0 ? 360 - webkitCompassHeading : (_b = event.alpha) != null ? _b : void 0;
3489
3490
  const beta = (_c = event.beta) != null ? _c : void 0;
3490
3491
  const gamma = (_d = event.gamma) != null ? _d : void 0;
3491
- const cssRotationVariableValue = `${360 - (alpha != null ? alpha : 0)}deg`;
3492
+ const cssRotationVariableValue = `${toTransitionAngle(360 - (alpha != null ? alpha : 0))}deg`;
3492
3493
  const cssRotationVariableName = alpha === void 0 ? void 0 : cssVarName;
3493
3494
  Object.assign(orientation, { alpha, beta, gamma });
3494
3495
  if (orientation.cssRotationVariableName !== cssRotationVariableName) {
@@ -3560,6 +3561,32 @@ function waitMiniProgramWebviewClose(duration) {
3560
3561
  }, duration);
3561
3562
  });
3562
3563
  }
3564
+ function createToTransitionAngle() {
3565
+ let prev = void 0;
3566
+ const mod = (x, m) => {
3567
+ const negatabbleValue = x % m;
3568
+ return negatabbleValue < 0 ? m + negatabbleValue : negatabbleValue;
3569
+ };
3570
+ return function toTransitionAngle(angle) {
3571
+ if (prev === void 0) {
3572
+ prev = angle;
3573
+ console.log("toTransitionAngle angle = ", angle);
3574
+ return angle;
3575
+ }
3576
+ const prevRemainder = mod(prev, 360);
3577
+ const cycles = (prev - prevRemainder) / 360;
3578
+ if (Math.abs(angle - prevRemainder) <= 180) {
3579
+ const result = angle + cycles * 360;
3580
+ prev = result;
3581
+ return result;
3582
+ } else {
3583
+ const deltaCycles = angle > prevRemainder ? -1 : 1;
3584
+ const result = angle + (cycles + deltaCycles) * 360;
3585
+ prev = result;
3586
+ return result;
3587
+ }
3588
+ };
3589
+ }
3563
3590
  const watchVisibilityState = () => {
3564
3591
  const visibilityStateRef = Vue.ref(document.visibilityState);
3565
3592
  const handleVisibilityChange = () => {
@@ -3574,6 +3601,7 @@ const watchVisibilityState = () => {
3574
3601
  const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
3575
3602
  const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
3576
3603
  const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
3604
+ const ANDROID_GET_LOCATION_INTERVAL = 1 * 1e3;
3577
3605
  const takeIsForceBrowserGeo = () => {
3578
3606
  const searchParam = new URLSearchParams(location.search);
3579
3607
  return searchParam.has(`force-browser-geo`);
@@ -3582,14 +3610,6 @@ const wxReady = () => new Promise((resolve, reject) => {
3582
3610
  wx.ready(resolve);
3583
3611
  wx.error(reject);
3584
3612
  });
3585
- const detectPlatform = () => {
3586
- const useragent = navigator.userAgent.toLowerCase();
3587
- if (useragent.includes("micromessenger"))
3588
- return "wechat";
3589
- if (useragent.includes("alipay"))
3590
- return "alipay";
3591
- return "other";
3592
- };
3593
3613
  function wechatWatchPosition(onSuccess, onError, option) {
3594
3614
  const { timeout } = option;
3595
3615
  let enable = true;
@@ -3651,20 +3671,67 @@ function wechatWatchPosition(onSuccess, onError, option) {
3651
3671
  unwatchVisibilityState();
3652
3672
  };
3653
3673
  }
3674
+ function androidWatchPosition(onSuccess, onError, option) {
3675
+ let enable = true;
3676
+ let prevGeoPosition = void 0;
3677
+ const isGeoWorkingRef = Vue.ref(true);
3678
+ const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
3679
+ const startWatch = async () => {
3680
+ do {
3681
+ if (visibilityStateRef.value === "hidden") {
3682
+ await sleep(ANDROID_GET_LOCATION_INTERVAL);
3683
+ continue;
3684
+ }
3685
+ const geoPosition = await new Promise((resolve) => {
3686
+ navigator.geolocation.getCurrentPosition(
3687
+ function onSuccess2(geoLocationPosition) {
3688
+ isGeoWorkingRef.value = true;
3689
+ resolve(geoLocationPosition);
3690
+ },
3691
+ function onFail(geoError) {
3692
+ const isGeoWorking = isGeoWorkingRef.value;
3693
+ isGeoWorkingRef.value = false;
3694
+ resolve(void 0);
3695
+ if (!isGeoWorking)
3696
+ return;
3697
+ console.warn(
3698
+ "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
3699
+ geoError.message
3700
+ );
3701
+ onError == null ? void 0 : onError(geoError);
3702
+ },
3703
+ option
3704
+ );
3705
+ });
3706
+ if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
3707
+ onSuccess(geoPosition);
3708
+ prevGeoPosition = geoPosition;
3709
+ await sleep(ANDROID_GET_LOCATION_INTERVAL);
3710
+ } while (enable);
3711
+ };
3712
+ startWatch();
3713
+ return () => {
3714
+ enable = false;
3715
+ unwatchVisibilityState();
3716
+ };
3717
+ }
3654
3718
  function compatibleWathPosition(onSuccess, onError, option) {
3655
3719
  const isForceBrowserGeo = takeIsForceBrowserGeo();
3656
3720
  if (isForceBrowserGeo) {
3657
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3658
- return () => navigator.geolocation.clearWatch(watchId);
3721
+ const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
3722
+ return () => navigator.geolocation.clearWatch(watchId2);
3659
3723
  }
3660
- switch (detectPlatform()) {
3661
- case "wechat":
3662
- return wechatWatchPosition(onSuccess, onError, option);
3663
- default: {
3664
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3665
- return () => navigator.geolocation.clearWatch(watchId);
3666
- }
3724
+ const browserPlatform = detectBrowserPlatform();
3725
+ const osPlatform = detectOSPlatform();
3726
+ console.log("osPlatform = ", osPlatform);
3727
+ if (browserPlatform === BRWOSER_PLATFORM.WECHAT || browserPlatform === BRWOSER_PLATFORM.WECHAT_MINIPROGRAM) {
3728
+ return wechatWatchPosition(onSuccess, onError, option);
3729
+ }
3730
+ if (osPlatform === OS_PLATFORM.ANDROID) {
3731
+ return androidWatchPosition(onSuccess, onError, option);
3667
3732
  }
3733
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3734
+ return () => navigator.geolocation.clearWatch(watchId);
3668
3735
  }
3669
3736
  class SingleGeoWatch {
3670
3737
  constructor(option) {
@@ -5758,6 +5825,69 @@ const useMapRecomendPlace = (props) => {
5758
5825
  const { supplier } = useMapSupplier();
5759
5826
  return supplier === "gmap" ? useGmapRecomendPlace(props) : useAmapRecomendPlace(props);
5760
5827
  };
5828
+ const GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT = 50;
5829
+ const DEFAULT_ZOOM$1 = 13;
5830
+ const useAmapZoom = (props) => {
5831
+ var _a, _b, _c;
5832
+ const { onChange, mapRef, defaultValue } = props;
5833
+ const zoomRef = Vue.ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
5834
+ const setZoom = (v) => {
5835
+ var _a2;
5836
+ zoomRef.value = v;
5837
+ (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v, true);
5838
+ };
5839
+ const handleZoomEnd = (_, { target }) => {
5840
+ const zoom = target.getZoom();
5841
+ zoomRef.value = zoom;
5842
+ onChange == null ? void 0 : onChange(zoom);
5843
+ };
5844
+ Vue.watch(
5845
+ () => mapRef.value,
5846
+ (map) => {
5847
+ if (!map)
5848
+ return;
5849
+ zoomRef.value = map.getZoom();
5850
+ }
5851
+ );
5852
+ watchPostEffectForAMapEvent(mapRef, {}, handleZoomEnd, [
5853
+ "onZoomEnd"
5854
+ ]);
5855
+ return { zoomRef, setZoom };
5856
+ };
5857
+ const useGmapZoom = (props) => {
5858
+ var _a, _b, _c;
5859
+ const { onChange, mapRef, defaultValue } = props;
5860
+ const zoomRef = Vue.ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
5861
+ const setZoom = (v) => {
5862
+ var _a2;
5863
+ zoomRef.value = v;
5864
+ (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v);
5865
+ };
5866
+ const handleZoomChange = debounce(
5867
+ (_, { target }) => {
5868
+ const zoom = target.getZoom();
5869
+ zoomRef.value = zoom;
5870
+ onChange == null ? void 0 : onChange(zoom);
5871
+ },
5872
+ GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT
5873
+ );
5874
+ Vue.watch(
5875
+ () => mapRef.value,
5876
+ (map) => {
5877
+ if (!map)
5878
+ return;
5879
+ zoomRef.value = map.getZoom();
5880
+ }
5881
+ );
5882
+ watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
5883
+ "onZoom_changed"
5884
+ ]);
5885
+ return { zoomRef, setZoom };
5886
+ };
5887
+ const useMapZoom = (props) => {
5888
+ const { supplier } = useMapSupplier();
5889
+ return supplier === "gmap" ? useGmapZoom(props) : useAmapZoom(props);
5890
+ };
5761
5891
  const AmapPolygon = defineSetup(function AmapPolygon2(props) {
5762
5892
  const polygonRef = Vue.shallowRef();
5763
5893
  const mapRef = useAmap();
@@ -6020,69 +6150,6 @@ const ConditionalFittablePassengerCircle = defineSetup(function ConditionalFitta
6020
6150
  })]);
6021
6151
  };
6022
6152
  });
6023
- const GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT = 50;
6024
- const DEFAULT_ZOOM$1 = 13;
6025
- const useAmapZoom = (props) => {
6026
- var _a, _b, _c;
6027
- const { onChange, mapRef, defaultValue } = props;
6028
- const zoomRef = Vue.ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
6029
- const setZoom = (v) => {
6030
- var _a2;
6031
- zoomRef.value = v;
6032
- (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v, true);
6033
- };
6034
- const handleZoomEnd = (_, { target }) => {
6035
- const zoom = target.getZoom();
6036
- zoomRef.value = zoom;
6037
- onChange == null ? void 0 : onChange(zoom);
6038
- };
6039
- Vue.watch(
6040
- () => mapRef.value,
6041
- (map) => {
6042
- if (!map)
6043
- return;
6044
- zoomRef.value = map.getZoom();
6045
- }
6046
- );
6047
- watchPostEffectForAMapEvent(mapRef, {}, handleZoomEnd, [
6048
- "onZoomEnd"
6049
- ]);
6050
- return { zoomRef, setZoom };
6051
- };
6052
- const useGmapZoom = (props) => {
6053
- var _a, _b, _c;
6054
- const { onChange, mapRef, defaultValue } = props;
6055
- const zoomRef = Vue.ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
6056
- const setZoom = (v) => {
6057
- var _a2;
6058
- zoomRef.value = v;
6059
- (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v);
6060
- };
6061
- const handleZoomChange = debounce(
6062
- (_, { target }) => {
6063
- const zoom = target.getZoom();
6064
- zoomRef.value = zoom;
6065
- onChange == null ? void 0 : onChange(zoom);
6066
- },
6067
- GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT
6068
- );
6069
- Vue.watch(
6070
- () => mapRef.value,
6071
- (map) => {
6072
- if (!map)
6073
- return;
6074
- zoomRef.value = map.getZoom();
6075
- }
6076
- );
6077
- watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
6078
- "onZoom_changed"
6079
- ]);
6080
- return { zoomRef, setZoom };
6081
- };
6082
- const useMapZoom = (props) => {
6083
- const { supplier } = useMapSupplier();
6084
- return supplier === "gmap" ? useGmapZoom(props) : useAmapZoom(props);
6085
- };
6086
6153
  const usePointsLabelDirection = (props) => {
6087
6154
  const { widthLimit, heightLimit } = props;
6088
6155
  const mapRef = useMap();
@@ -6460,10 +6527,11 @@ const RECOMMEND_PLACE_DRAG_LIMIT = 10;
6460
6527
  const RECOMMEND_PLACE_LARGE_LIMIT = 100;
6461
6528
  const RECOMMEND_PLACE_ICON_ZOOM_MIN = 16.25;
6462
6529
  const RECOMMEND_PLACE_TEXT_ZOOM_MIN = 16.25;
6463
- const RECOMMEND_PLACE_ZONE_ICON_MIN = 15.25;
6530
+ const RECOMMEND_PLACE_ZONE_ICON_MIN = 12.75;
6464
6531
  const RECOMMEND_PLACE_ZONE_TEXT_MIN = 21;
6465
6532
  const DEFAULT_PLACE_NAME = "当前位置";
6466
6533
  const DEFAULT_ZOOM = 17;
6534
+ const ZONE_ZOOM = 13.75;
6467
6535
  const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlaceMap2(props, {
6468
6536
  emit,
6469
6537
  slots
@@ -6483,6 +6551,13 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6483
6551
  setMap,
6484
6552
  panTo
6485
6553
  } = useHeycarMap();
6554
+ const {
6555
+ zoomRef,
6556
+ setZoom
6557
+ } = useMapZoom({
6558
+ mapRef,
6559
+ defaultValue: DEFAULT_ZOOM
6560
+ });
6486
6561
  const {
6487
6562
  readyPromise
6488
6563
  } = useMapSupplier();
@@ -6521,6 +6596,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6521
6596
  centerPlace.name = place.name;
6522
6597
  centerPlace.displayName = place.displayName;
6523
6598
  setPlaceCandidatesAndZone(recommends);
6599
+ setZoom(ZONE_ZOOM);
6524
6600
  emit("changePlace", {
6525
6601
  ...place
6526
6602
  });
@@ -6532,6 +6608,8 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6532
6608
  centerPlace.lat = place.lat;
6533
6609
  centerPlace.name = place.name;
6534
6610
  centerPlace.displayName = place.displayName;
6611
+ if (zoneRef.value)
6612
+ setZoom(ZONE_ZOOM);
6535
6613
  emit("changePlace", {
6536
6614
  ...place
6537
6615
  });
@@ -6640,6 +6718,8 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6640
6718
  Object.assign(centerPlace, {
6641
6719
  ...place
6642
6720
  });
6721
+ if (isInZone)
6722
+ setZoom(ZONE_ZOOM);
6643
6723
  emit("changeRecomandPlace", {
6644
6724
  place,
6645
6725
  inputPlace,
@@ -6667,7 +6747,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6667
6747
  return Vue.h(HeycarMap, {
6668
6748
  "attrs": {
6669
6749
  "center": centerPoint.value,
6670
- "zoom": DEFAULT_ZOOM,
6750
+ "zoom": zoomRef.value,
6671
6751
  "touchZoomCenter": true,
6672
6752
  "mapRef": setMap,
6673
6753
  "fallback": slots.fallback,
@@ -6729,6 +6809,13 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6729
6809
  setMap,
6730
6810
  panTo
6731
6811
  } = useHeycarMap();
6812
+ const {
6813
+ zoomRef,
6814
+ setZoom
6815
+ } = useMapZoom({
6816
+ mapRef,
6817
+ defaultValue: DEFAULT_ZOOM
6818
+ });
6732
6819
  const centerPlace = Vue.reactive({
6733
6820
  lng: defaultPlace.lng,
6734
6821
  lat: defaultPlace.lat,
@@ -6763,6 +6850,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6763
6850
  centerPlace.lat = place.lat;
6764
6851
  centerPlace.name = place.name;
6765
6852
  centerPlace.displayName = place.displayName;
6853
+ setZoom(ZONE_ZOOM);
6766
6854
  setPlaceCandidatesAndZone(recommends);
6767
6855
  emit("changePlace", {
6768
6856
  ...place
@@ -6775,6 +6863,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6775
6863
  centerPlace.lat = place.lat;
6776
6864
  centerPlace.name = place.name;
6777
6865
  centerPlace.displayName = place.displayName;
6866
+ if (zoneRef.value)
6867
+ setZoom(ZONE_ZOOM);
6778
6868
  emit("changePlace", {
6779
6869
  ...place
6780
6870
  });
@@ -6862,6 +6952,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6862
6952
  Object.assign(centerPlace, {
6863
6953
  ...place
6864
6954
  });
6955
+ if (isInZone)
6956
+ setZoom(ZONE_ZOOM);
6865
6957
  emit("changeRecomandPlace", {
6866
6958
  place,
6867
6959
  inputPlace,
@@ -6892,7 +6984,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6892
6984
  return Vue.h(HeycarMap, {
6893
6985
  "attrs": {
6894
6986
  "center": centerPoint.value,
6895
- "zoom": DEFAULT_ZOOM,
6987
+ "zoom": zoomRef.value,
6896
6988
  "touchZoomCenter": true,
6897
6989
  "mapRef": setMap,
6898
6990
  "fallback": slots.fallback,
@@ -6911,8 +7003,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6911
7003
  "attrs": {
6912
7004
  "basePlace": centerPlace,
6913
7005
  "places": placeCandidates.value,
6914
- "zoomIconMin": RECOMMEND_PLACE_ICON_ZOOM_MIN,
6915
- "zoomTextMin": RECOMMEND_PLACE_TEXT_ZOOM_MIN
7006
+ "zoomIconMin": zoneRef.value ? RECOMMEND_PLACE_ZONE_ICON_MIN : RECOMMEND_PLACE_ICON_ZOOM_MIN,
7007
+ "zoomTextMin": zoneRef.value ? RECOMMEND_PLACE_ZONE_TEXT_MIN : RECOMMEND_PLACE_TEXT_ZOOM_MIN
6916
7008
  },
6917
7009
  "on": {
6918
7010
  "click": panToCenterByPlace
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  import Vue, { defineComponent, h, computed, inject, provide, watch, onMounted, onUnmounted, watchPostEffect, shallowRef, ref, watchEffect, reactive, toRefs, toRef } from "vue";
8
8
  const style = "";
9
9
  const name = "@heycar/heycars-map";
10
- const version = "0.8.10";
10
+ const version = "0.9.0";
11
11
  const type = "module";
12
12
  const scripts = {
13
13
  dev: "vite -c vite.config.dev.ts",
@@ -3471,12 +3471,13 @@ const patchMiniprogramRedirectTo = (wx2) => {
3471
3471
  };
3472
3472
  return patchedRedirectTo;
3473
3473
  };
3474
- const DEVICE_ORIENTATION_INTERVAL = 1e3;
3474
+ const DEVICE_ORIENTATION_INTERVAL = 200;
3475
3475
  const CSS_DEVICE_ORIENTATION_VAR_PREFIX = "--CSS_DEVICE_ORIENTATION_VAR_ROTATION_DEGREE_";
3476
3476
  const useDeviceOrientation = (props) => {
3477
3477
  const { onChange, elementRef } = props;
3478
3478
  const orientation = reactive({ cssRotationVariableName: void 0 });
3479
3479
  const cssVarName = `${CSS_DEVICE_ORIENTATION_VAR_PREFIX}${Date.now()}`;
3480
+ const toTransitionAngle = createToTransitionAngle();
3480
3481
  watch(
3481
3482
  () => elementRef.value,
3482
3483
  (element, _, onCleanup) => {
@@ -3486,7 +3487,7 @@ const useDeviceOrientation = (props) => {
3486
3487
  const alpha = webkitCompassHeading !== void 0 ? 360 - webkitCompassHeading : (_b = event.alpha) != null ? _b : void 0;
3487
3488
  const beta = (_c = event.beta) != null ? _c : void 0;
3488
3489
  const gamma = (_d = event.gamma) != null ? _d : void 0;
3489
- const cssRotationVariableValue = `${360 - (alpha != null ? alpha : 0)}deg`;
3490
+ const cssRotationVariableValue = `${toTransitionAngle(360 - (alpha != null ? alpha : 0))}deg`;
3490
3491
  const cssRotationVariableName = alpha === void 0 ? void 0 : cssVarName;
3491
3492
  Object.assign(orientation, { alpha, beta, gamma });
3492
3493
  if (orientation.cssRotationVariableName !== cssRotationVariableName) {
@@ -3558,6 +3559,32 @@ function waitMiniProgramWebviewClose(duration) {
3558
3559
  }, duration);
3559
3560
  });
3560
3561
  }
3562
+ function createToTransitionAngle() {
3563
+ let prev = void 0;
3564
+ const mod = (x, m) => {
3565
+ const negatabbleValue = x % m;
3566
+ return negatabbleValue < 0 ? m + negatabbleValue : negatabbleValue;
3567
+ };
3568
+ return function toTransitionAngle(angle) {
3569
+ if (prev === void 0) {
3570
+ prev = angle;
3571
+ console.log("toTransitionAngle angle = ", angle);
3572
+ return angle;
3573
+ }
3574
+ const prevRemainder = mod(prev, 360);
3575
+ const cycles = (prev - prevRemainder) / 360;
3576
+ if (Math.abs(angle - prevRemainder) <= 180) {
3577
+ const result = angle + cycles * 360;
3578
+ prev = result;
3579
+ return result;
3580
+ } else {
3581
+ const deltaCycles = angle > prevRemainder ? -1 : 1;
3582
+ const result = angle + (cycles + deltaCycles) * 360;
3583
+ prev = result;
3584
+ return result;
3585
+ }
3586
+ };
3587
+ }
3561
3588
  const watchVisibilityState = () => {
3562
3589
  const visibilityStateRef = ref(document.visibilityState);
3563
3590
  const handleVisibilityChange = () => {
@@ -3572,6 +3599,7 @@ const watchVisibilityState = () => {
3572
3599
  const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
3573
3600
  const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
3574
3601
  const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
3602
+ const ANDROID_GET_LOCATION_INTERVAL = 1 * 1e3;
3575
3603
  const takeIsForceBrowserGeo = () => {
3576
3604
  const searchParam = new URLSearchParams(location.search);
3577
3605
  return searchParam.has(`force-browser-geo`);
@@ -3580,14 +3608,6 @@ const wxReady = () => new Promise((resolve, reject) => {
3580
3608
  wx.ready(resolve);
3581
3609
  wx.error(reject);
3582
3610
  });
3583
- const detectPlatform = () => {
3584
- const useragent = navigator.userAgent.toLowerCase();
3585
- if (useragent.includes("micromessenger"))
3586
- return "wechat";
3587
- if (useragent.includes("alipay"))
3588
- return "alipay";
3589
- return "other";
3590
- };
3591
3611
  function wechatWatchPosition(onSuccess, onError, option) {
3592
3612
  const { timeout } = option;
3593
3613
  let enable = true;
@@ -3649,20 +3669,67 @@ function wechatWatchPosition(onSuccess, onError, option) {
3649
3669
  unwatchVisibilityState();
3650
3670
  };
3651
3671
  }
3672
+ function androidWatchPosition(onSuccess, onError, option) {
3673
+ let enable = true;
3674
+ let prevGeoPosition = void 0;
3675
+ const isGeoWorkingRef = ref(true);
3676
+ const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
3677
+ const startWatch = async () => {
3678
+ do {
3679
+ if (visibilityStateRef.value === "hidden") {
3680
+ await sleep(ANDROID_GET_LOCATION_INTERVAL);
3681
+ continue;
3682
+ }
3683
+ const geoPosition = await new Promise((resolve) => {
3684
+ navigator.geolocation.getCurrentPosition(
3685
+ function onSuccess2(geoLocationPosition) {
3686
+ isGeoWorkingRef.value = true;
3687
+ resolve(geoLocationPosition);
3688
+ },
3689
+ function onFail(geoError) {
3690
+ const isGeoWorking = isGeoWorkingRef.value;
3691
+ isGeoWorkingRef.value = false;
3692
+ resolve(void 0);
3693
+ if (!isGeoWorking)
3694
+ return;
3695
+ console.warn(
3696
+ "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
3697
+ geoError.message
3698
+ );
3699
+ onError == null ? void 0 : onError(geoError);
3700
+ },
3701
+ option
3702
+ );
3703
+ });
3704
+ if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
3705
+ onSuccess(geoPosition);
3706
+ prevGeoPosition = geoPosition;
3707
+ await sleep(ANDROID_GET_LOCATION_INTERVAL);
3708
+ } while (enable);
3709
+ };
3710
+ startWatch();
3711
+ return () => {
3712
+ enable = false;
3713
+ unwatchVisibilityState();
3714
+ };
3715
+ }
3652
3716
  function compatibleWathPosition(onSuccess, onError, option) {
3653
3717
  const isForceBrowserGeo = takeIsForceBrowserGeo();
3654
3718
  if (isForceBrowserGeo) {
3655
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3656
- return () => navigator.geolocation.clearWatch(watchId);
3719
+ const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
3720
+ return () => navigator.geolocation.clearWatch(watchId2);
3657
3721
  }
3658
- switch (detectPlatform()) {
3659
- case "wechat":
3660
- return wechatWatchPosition(onSuccess, onError, option);
3661
- default: {
3662
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3663
- return () => navigator.geolocation.clearWatch(watchId);
3664
- }
3722
+ const browserPlatform = detectBrowserPlatform();
3723
+ const osPlatform = detectOSPlatform();
3724
+ console.log("osPlatform = ", osPlatform);
3725
+ if (browserPlatform === BRWOSER_PLATFORM.WECHAT || browserPlatform === BRWOSER_PLATFORM.WECHAT_MINIPROGRAM) {
3726
+ return wechatWatchPosition(onSuccess, onError, option);
3727
+ }
3728
+ if (osPlatform === OS_PLATFORM.ANDROID) {
3729
+ return androidWatchPosition(onSuccess, onError, option);
3665
3730
  }
3731
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
3732
+ return () => navigator.geolocation.clearWatch(watchId);
3666
3733
  }
3667
3734
  class SingleGeoWatch {
3668
3735
  constructor(option) {
@@ -5756,6 +5823,69 @@ const useMapRecomendPlace = (props) => {
5756
5823
  const { supplier } = useMapSupplier();
5757
5824
  return supplier === "gmap" ? useGmapRecomendPlace(props) : useAmapRecomendPlace(props);
5758
5825
  };
5826
+ const GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT = 50;
5827
+ const DEFAULT_ZOOM$1 = 13;
5828
+ const useAmapZoom = (props) => {
5829
+ var _a, _b, _c;
5830
+ const { onChange, mapRef, defaultValue } = props;
5831
+ const zoomRef = ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
5832
+ const setZoom = (v) => {
5833
+ var _a2;
5834
+ zoomRef.value = v;
5835
+ (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v, true);
5836
+ };
5837
+ const handleZoomEnd = (_, { target }) => {
5838
+ const zoom = target.getZoom();
5839
+ zoomRef.value = zoom;
5840
+ onChange == null ? void 0 : onChange(zoom);
5841
+ };
5842
+ watch(
5843
+ () => mapRef.value,
5844
+ (map) => {
5845
+ if (!map)
5846
+ return;
5847
+ zoomRef.value = map.getZoom();
5848
+ }
5849
+ );
5850
+ watchPostEffectForAMapEvent(mapRef, {}, handleZoomEnd, [
5851
+ "onZoomEnd"
5852
+ ]);
5853
+ return { zoomRef, setZoom };
5854
+ };
5855
+ const useGmapZoom = (props) => {
5856
+ var _a, _b, _c;
5857
+ const { onChange, mapRef, defaultValue } = props;
5858
+ const zoomRef = ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
5859
+ const setZoom = (v) => {
5860
+ var _a2;
5861
+ zoomRef.value = v;
5862
+ (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v);
5863
+ };
5864
+ const handleZoomChange = debounce(
5865
+ (_, { target }) => {
5866
+ const zoom = target.getZoom();
5867
+ zoomRef.value = zoom;
5868
+ onChange == null ? void 0 : onChange(zoom);
5869
+ },
5870
+ GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT
5871
+ );
5872
+ watch(
5873
+ () => mapRef.value,
5874
+ (map) => {
5875
+ if (!map)
5876
+ return;
5877
+ zoomRef.value = map.getZoom();
5878
+ }
5879
+ );
5880
+ watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
5881
+ "onZoom_changed"
5882
+ ]);
5883
+ return { zoomRef, setZoom };
5884
+ };
5885
+ const useMapZoom = (props) => {
5886
+ const { supplier } = useMapSupplier();
5887
+ return supplier === "gmap" ? useGmapZoom(props) : useAmapZoom(props);
5888
+ };
5759
5889
  const AmapPolygon = defineSetup(function AmapPolygon2(props) {
5760
5890
  const polygonRef = shallowRef();
5761
5891
  const mapRef = useAmap();
@@ -6018,69 +6148,6 @@ const ConditionalFittablePassengerCircle = defineSetup(function ConditionalFitta
6018
6148
  })]);
6019
6149
  };
6020
6150
  });
6021
- const GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT = 50;
6022
- const DEFAULT_ZOOM$1 = 13;
6023
- const useAmapZoom = (props) => {
6024
- var _a, _b, _c;
6025
- const { onChange, mapRef, defaultValue } = props;
6026
- const zoomRef = ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
6027
- const setZoom = (v) => {
6028
- var _a2;
6029
- zoomRef.value = v;
6030
- (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v, true);
6031
- };
6032
- const handleZoomEnd = (_, { target }) => {
6033
- const zoom = target.getZoom();
6034
- zoomRef.value = zoom;
6035
- onChange == null ? void 0 : onChange(zoom);
6036
- };
6037
- watch(
6038
- () => mapRef.value,
6039
- (map) => {
6040
- if (!map)
6041
- return;
6042
- zoomRef.value = map.getZoom();
6043
- }
6044
- );
6045
- watchPostEffectForAMapEvent(mapRef, {}, handleZoomEnd, [
6046
- "onZoomEnd"
6047
- ]);
6048
- return { zoomRef, setZoom };
6049
- };
6050
- const useGmapZoom = (props) => {
6051
- var _a, _b, _c;
6052
- const { onChange, mapRef, defaultValue } = props;
6053
- const zoomRef = ref((_c = (_b = (_a = mapRef.value) == null ? void 0 : _a.getZoom()) != null ? _b : defaultValue) != null ? _c : DEFAULT_ZOOM$1);
6054
- const setZoom = (v) => {
6055
- var _a2;
6056
- zoomRef.value = v;
6057
- (_a2 = mapRef.value) == null ? void 0 : _a2.setZoom(v);
6058
- };
6059
- const handleZoomChange = debounce(
6060
- (_, { target }) => {
6061
- const zoom = target.getZoom();
6062
- zoomRef.value = zoom;
6063
- onChange == null ? void 0 : onChange(zoom);
6064
- },
6065
- GOOGLE_MAP_ZOOM_CHANGE_DEBOUNCE_TIMEOUT
6066
- );
6067
- watch(
6068
- () => mapRef.value,
6069
- (map) => {
6070
- if (!map)
6071
- return;
6072
- zoomRef.value = map.getZoom();
6073
- }
6074
- );
6075
- watchPostEffectForGMapEvent(mapRef, {}, handleZoomChange, [
6076
- "onZoom_changed"
6077
- ]);
6078
- return { zoomRef, setZoom };
6079
- };
6080
- const useMapZoom = (props) => {
6081
- const { supplier } = useMapSupplier();
6082
- return supplier === "gmap" ? useGmapZoom(props) : useAmapZoom(props);
6083
- };
6084
6151
  const usePointsLabelDirection = (props) => {
6085
6152
  const { widthLimit, heightLimit } = props;
6086
6153
  const mapRef = useMap();
@@ -6458,10 +6525,11 @@ const RECOMMEND_PLACE_DRAG_LIMIT = 10;
6458
6525
  const RECOMMEND_PLACE_LARGE_LIMIT = 100;
6459
6526
  const RECOMMEND_PLACE_ICON_ZOOM_MIN = 16.25;
6460
6527
  const RECOMMEND_PLACE_TEXT_ZOOM_MIN = 16.25;
6461
- const RECOMMEND_PLACE_ZONE_ICON_MIN = 15.25;
6528
+ const RECOMMEND_PLACE_ZONE_ICON_MIN = 12.75;
6462
6529
  const RECOMMEND_PLACE_ZONE_TEXT_MIN = 21;
6463
6530
  const DEFAULT_PLACE_NAME = "当前位置";
6464
6531
  const DEFAULT_ZOOM = 17;
6532
+ const ZONE_ZOOM = 13.75;
6465
6533
  const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlaceMap2(props, {
6466
6534
  emit,
6467
6535
  slots
@@ -6481,6 +6549,13 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6481
6549
  setMap,
6482
6550
  panTo
6483
6551
  } = useHeycarMap();
6552
+ const {
6553
+ zoomRef,
6554
+ setZoom
6555
+ } = useMapZoom({
6556
+ mapRef,
6557
+ defaultValue: DEFAULT_ZOOM
6558
+ });
6484
6559
  const {
6485
6560
  readyPromise
6486
6561
  } = useMapSupplier();
@@ -6519,6 +6594,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6519
6594
  centerPlace.name = place.name;
6520
6595
  centerPlace.displayName = place.displayName;
6521
6596
  setPlaceCandidatesAndZone(recommends);
6597
+ setZoom(ZONE_ZOOM);
6522
6598
  emit("changePlace", {
6523
6599
  ...place
6524
6600
  });
@@ -6530,6 +6606,8 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6530
6606
  centerPlace.lat = place.lat;
6531
6607
  centerPlace.name = place.name;
6532
6608
  centerPlace.displayName = place.displayName;
6609
+ if (zoneRef.value)
6610
+ setZoom(ZONE_ZOOM);
6533
6611
  emit("changePlace", {
6534
6612
  ...place
6535
6613
  });
@@ -6638,6 +6716,8 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6638
6716
  Object.assign(centerPlace, {
6639
6717
  ...place
6640
6718
  });
6719
+ if (isInZone)
6720
+ setZoom(ZONE_ZOOM);
6641
6721
  emit("changeRecomandPlace", {
6642
6722
  place,
6643
6723
  inputPlace,
@@ -6665,7 +6745,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
6665
6745
  return h(HeycarMap, {
6666
6746
  "attrs": {
6667
6747
  "center": centerPoint.value,
6668
- "zoom": DEFAULT_ZOOM,
6748
+ "zoom": zoomRef.value,
6669
6749
  "touchZoomCenter": true,
6670
6750
  "mapRef": setMap,
6671
6751
  "fallback": slots.fallback,
@@ -6727,6 +6807,13 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6727
6807
  setMap,
6728
6808
  panTo
6729
6809
  } = useHeycarMap();
6810
+ const {
6811
+ zoomRef,
6812
+ setZoom
6813
+ } = useMapZoom({
6814
+ mapRef,
6815
+ defaultValue: DEFAULT_ZOOM
6816
+ });
6730
6817
  const centerPlace = reactive({
6731
6818
  lng: defaultPlace.lng,
6732
6819
  lat: defaultPlace.lat,
@@ -6761,6 +6848,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6761
6848
  centerPlace.lat = place.lat;
6762
6849
  centerPlace.name = place.name;
6763
6850
  centerPlace.displayName = place.displayName;
6851
+ setZoom(ZONE_ZOOM);
6764
6852
  setPlaceCandidatesAndZone(recommends);
6765
6853
  emit("changePlace", {
6766
6854
  ...place
@@ -6773,6 +6861,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6773
6861
  centerPlace.lat = place.lat;
6774
6862
  centerPlace.name = place.name;
6775
6863
  centerPlace.displayName = place.displayName;
6864
+ if (zoneRef.value)
6865
+ setZoom(ZONE_ZOOM);
6776
6866
  emit("changePlace", {
6777
6867
  ...place
6778
6868
  });
@@ -6860,6 +6950,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6860
6950
  Object.assign(centerPlace, {
6861
6951
  ...place
6862
6952
  });
6953
+ if (isInZone)
6954
+ setZoom(ZONE_ZOOM);
6863
6955
  emit("changeRecomandPlace", {
6864
6956
  place,
6865
6957
  inputPlace,
@@ -6890,7 +6982,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6890
6982
  return h(HeycarMap, {
6891
6983
  "attrs": {
6892
6984
  "center": centerPoint.value,
6893
- "zoom": DEFAULT_ZOOM,
6985
+ "zoom": zoomRef.value,
6894
6986
  "touchZoomCenter": true,
6895
6987
  "mapRef": setMap,
6896
6988
  "fallback": slots.fallback,
@@ -6909,8 +7001,8 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
6909
7001
  "attrs": {
6910
7002
  "basePlace": centerPlace,
6911
7003
  "places": placeCandidates.value,
6912
- "zoomIconMin": RECOMMEND_PLACE_ICON_ZOOM_MIN,
6913
- "zoomTextMin": RECOMMEND_PLACE_TEXT_ZOOM_MIN
7004
+ "zoomIconMin": zoneRef.value ? RECOMMEND_PLACE_ZONE_ICON_MIN : RECOMMEND_PLACE_ICON_ZOOM_MIN,
7005
+ "zoomTextMin": zoneRef.value ? RECOMMEND_PLACE_ZONE_TEXT_MIN : RECOMMEND_PLACE_TEXT_ZOOM_MIN
6914
7006
  },
6915
7007
  "on": {
6916
7008
  "click": panToCenterByPlace
@@ -10,10 +10,11 @@ export declare const RECOMMEND_PLACE_DRAG_LIMIT = 10;
10
10
  export declare const RECOMMEND_PLACE_LARGE_LIMIT = 100;
11
11
  export declare const RECOMMEND_PLACE_ICON_ZOOM_MIN = 16.25;
12
12
  export declare const RECOMMEND_PLACE_TEXT_ZOOM_MIN = 16.25;
13
- export declare const RECOMMEND_PLACE_ZONE_ICON_MIN = 15.25;
13
+ export declare const RECOMMEND_PLACE_ZONE_ICON_MIN = 12.75;
14
14
  export declare const RECOMMEND_PLACE_ZONE_TEXT_MIN = 21;
15
15
  export declare const DEFAULT_PLACE_NAME = "\u5F53\u524D\u4F4D\u7F6E";
16
16
  export declare const DEFAULT_ZOOM = 17;
17
+ export declare const ZONE_ZOOM = 13.75;
17
18
  export interface CenterPlaceSource {
18
19
  source: "default" | "geo" | "drag" | "recomend" | "api";
19
20
  }
package/dist/style.css CHANGED
@@ -216,6 +216,7 @@ a[title*="Google"]>div>img[alt="Google"], .gmnoprint {
216
216
  display: none;
217
217
  }._1l6offo0 {
218
218
  display: flex;
219
+ transition: transform .2s;
219
220
  }
220
221
  ._1l6offo1 {
221
222
  width: 6.6vw;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.8.10",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",