@heycar/heycars-map 0.9.12 → 0.9.14

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
@@ -12,7 +12,7 @@ if (typeof window !== "undefined" && typeof globalThis === "undefined") {
12
12
  window.globalThis = window;
13
13
  }
14
14
  const name = "@heycar/heycars-map";
15
- const version = "0.9.12";
15
+ const version = "0.9.14";
16
16
  const type = "module";
17
17
  const bin = {
18
18
  checkVersion: "./bin/checkVersion.js"
@@ -1342,6 +1342,20 @@ const wxGetLocationSuccessResponse2GeolocationPosition = (res) => {
1342
1342
  };
1343
1343
  return { timestamp, coords };
1344
1344
  };
1345
+ const alipayMyGetLocationSuccessResponse2GeolocationPosition = (res) => {
1346
+ const { longitude, latitude, accuracy, altitude } = res;
1347
+ const timestamp = Date.now();
1348
+ const coords = {
1349
+ accuracy: Number(accuracy),
1350
+ altitude: Number(altitude),
1351
+ altitudeAccuracy: null,
1352
+ heading: null,
1353
+ latitude: Number(latitude),
1354
+ longitude: Number(longitude),
1355
+ speed: null
1356
+ };
1357
+ return { timestamp, coords };
1358
+ };
1345
1359
  const deepCompareEqualsForMaps = createComparator((deepEqual) => (a, b) => {
1346
1360
  if (isLatLngLiteral(a) && isLatLngLiteral(b)) {
1347
1361
  return isPlaceEqual(a, b);
@@ -4153,6 +4167,8 @@ const watchVisibilityState = () => {
4153
4167
  const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
4154
4168
  const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
4155
4169
  const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
4170
+ const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
4171
+ const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
4156
4172
  const ANDROID_GET_LOCATION_INTERVAL = 1 * 1e3;
4157
4173
  const takeIsForceBrowserGeo = () => {
4158
4174
  const searchParam = new URLSearchParams(location.search);
@@ -4227,6 +4243,54 @@ function wechatWatchPosition(onSuccess, onError, option) {
4227
4243
  unwatchVisibilityState();
4228
4244
  };
4229
4245
  }
4246
+ function alipayWatchPosition(onSuccess, onError, option) {
4247
+ let enable = true;
4248
+ let prevGeoPosition = void 0;
4249
+ const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4250
+ const isGeoWorkingRef = Vue.ref(true);
4251
+ const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4252
+ const startWatch = async () => {
4253
+ do {
4254
+ if (visibilityStateRef.value === "hidden") {
4255
+ await sleep(ALIPAY_GET_LOCATION_INTERVAL);
4256
+ continue;
4257
+ }
4258
+ const geoPosition = await new Promise((resolve) => {
4259
+ my.getLocation({
4260
+ type: 0,
4261
+ cacheTimeout: timeout / 1e3,
4262
+ success(res) {
4263
+ isGeoWorkingRef.value = true;
4264
+ resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4265
+ },
4266
+ fail(res) {
4267
+ const isGeoWorking = isGeoWorkingRef.value;
4268
+ isGeoWorkingRef.value = false;
4269
+ resolve(void 0);
4270
+ if (!isGeoWorking)
4271
+ return;
4272
+ const { error, errorMessage } = res;
4273
+ console.warn(
4274
+ "MyWarning: my.getLocation failed errcode, errmsg = ",
4275
+ error,
4276
+ errorMessage
4277
+ );
4278
+ onError == null ? void 0 : onError(new Error(errorMessage));
4279
+ }
4280
+ });
4281
+ });
4282
+ if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
4283
+ onSuccess(geoPosition);
4284
+ prevGeoPosition = geoPosition;
4285
+ await sleep(ALIPAY_GET_LOCATION_INTERVAL);
4286
+ } while (enable);
4287
+ };
4288
+ startWatch();
4289
+ return () => {
4290
+ enable = false;
4291
+ unwatchVisibilityState();
4292
+ };
4293
+ }
4230
4294
  function androidWatchPosition(onSuccess, onError, option) {
4231
4295
  let enable = true;
4232
4296
  let prevGeoPosition = void 0;
@@ -4283,31 +4347,15 @@ function compatibleWathPosition(onSuccess, onError, option) {
4283
4347
  if (browserPlatform === BRWOSER_PLATFORM.WECHAT || browserPlatform === BRWOSER_PLATFORM.WECHAT_MINIPROGRAM) {
4284
4348
  return wechatWatchPosition(onSuccess, onError, option);
4285
4349
  }
4350
+ if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4351
+ return alipayWatchPosition(onSuccess, onError, option);
4352
+ }
4286
4353
  if (osPlatform === OS_PLATFORM.ANDROID) {
4287
4354
  return androidWatchPosition(onSuccess, onError, option);
4288
4355
  }
4289
4356
  const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4290
4357
  return () => navigator.geolocation.clearWatch(watchId);
4291
4358
  }
4292
- window.efg = () => my.getLocation({
4293
- type: 0,
4294
- cacheTimeout: 1,
4295
- success(res) {
4296
- console.log("my.getLocation success = ", JSON.stringify(res, null, 2));
4297
- },
4298
- fail(res) {
4299
- console.log("my.getLocation fail = ", JSON.stringify(res, null, 2));
4300
- }
4301
- });
4302
- window.abc = () => wx.getLocation({
4303
- type: "wgs84",
4304
- success(res) {
4305
- console.log("wx.getLocation success = ", JSON.stringify(res, null, 2));
4306
- },
4307
- fail(res) {
4308
- console.log("wx.getLocation fail = ", JSON.stringify(res, null, 2));
4309
- }
4310
- });
4311
4359
  class SingleGeoWatch {
4312
4360
  constructor(option) {
4313
4361
  __publicField(this, "id", 0);
@@ -6380,6 +6428,22 @@ const useMapRecomendPlace = (props) => {
6380
6428
  isSameZone
6381
6429
  });
6382
6430
  };
6431
+ const updateRecommendPlaceOnlyInZone = async (place) => {
6432
+ const { place: foundPlace, candidates, available, zone } = await findAttachedPlace(place);
6433
+ const resultPlace = zone ? foundPlace : place;
6434
+ const isSameZone = !!zone && isZoneEqual(zone, zoneRef.value);
6435
+ availableRef.value = available;
6436
+ zoneRef.value = zone;
6437
+ placeCandidatesRef.value = candidates;
6438
+ Object.assign(recomendPlace, { ...resultPlace });
6439
+ onChangePlace == null ? void 0 : onChangePlace({ ...resultPlace });
6440
+ onChange == null ? void 0 : onChange({
6441
+ place: { ...resultPlace },
6442
+ inputPlace: { ...place },
6443
+ isInZone: !!zone,
6444
+ isSameZone
6445
+ });
6446
+ };
6383
6447
  const setPlaceCandidatesAndZone = ({
6384
6448
  zone,
6385
6449
  places: inputPlaceCandidates
@@ -6396,6 +6460,7 @@ const useMapRecomendPlace = (props) => {
6396
6460
  availableRef,
6397
6461
  isElectedRef,
6398
6462
  updateRecommendPlace,
6463
+ updateRecommendPlaceOnlyInZone,
6399
6464
  updatePlaceCandidates,
6400
6465
  updatePlace,
6401
6466
  setPlaceCandidatesAndZone
@@ -7170,7 +7235,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
7170
7235
  centerSource.source = "api";
7171
7236
  const place = toPlaceType(input);
7172
7237
  Object.assign(centerPlace, place);
7173
- updateRecommendPlace(place);
7238
+ updateRecommendPlaceOnlyInZone(place);
7174
7239
  };
7175
7240
  const setCenterPlaceByUserSpecifiedInZone = async ({
7176
7241
  place: inputPlace,
@@ -7266,7 +7331,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
7266
7331
  });
7267
7332
  const {
7268
7333
  updatePlace,
7269
- updateRecommendPlace,
7334
+ updateRecommendPlaceOnlyInZone,
7270
7335
  setPlaceCandidatesAndZone,
7271
7336
  placeCandidates,
7272
7337
  zoneRef,
@@ -7420,7 +7485,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
7420
7485
  centerSource.source = "api";
7421
7486
  const place = toPlaceType(input);
7422
7487
  Object.assign(centerPlace, place);
7423
- updateRecommendPlace(place);
7488
+ updateRecommendPlaceOnlyInZone(place);
7424
7489
  };
7425
7490
  const setCenterPlaceByUserSpecifiedInZone = async ({
7426
7491
  place: inputPlace,
@@ -7488,7 +7553,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
7488
7553
  });
7489
7554
  const {
7490
7555
  updatePlace,
7491
- updateRecommendPlace,
7556
+ updateRecommendPlaceOnlyInZone,
7492
7557
  updatePlaceCandidates,
7493
7558
  setPlaceCandidatesAndZone,
7494
7559
  placeCandidates,
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ if (typeof window !== "undefined" && typeof globalThis === "undefined") {
10
10
  window.globalThis = window;
11
11
  }
12
12
  const name = "@heycar/heycars-map";
13
- const version = "0.9.12";
13
+ const version = "0.9.14";
14
14
  const type = "module";
15
15
  const bin = {
16
16
  checkVersion: "./bin/checkVersion.js"
@@ -1340,6 +1340,20 @@ const wxGetLocationSuccessResponse2GeolocationPosition = (res) => {
1340
1340
  };
1341
1341
  return { timestamp, coords };
1342
1342
  };
1343
+ const alipayMyGetLocationSuccessResponse2GeolocationPosition = (res) => {
1344
+ const { longitude, latitude, accuracy, altitude } = res;
1345
+ const timestamp = Date.now();
1346
+ const coords = {
1347
+ accuracy: Number(accuracy),
1348
+ altitude: Number(altitude),
1349
+ altitudeAccuracy: null,
1350
+ heading: null,
1351
+ latitude: Number(latitude),
1352
+ longitude: Number(longitude),
1353
+ speed: null
1354
+ };
1355
+ return { timestamp, coords };
1356
+ };
1343
1357
  const deepCompareEqualsForMaps = createComparator((deepEqual) => (a, b) => {
1344
1358
  if (isLatLngLiteral(a) && isLatLngLiteral(b)) {
1345
1359
  return isPlaceEqual(a, b);
@@ -4151,6 +4165,8 @@ const watchVisibilityState = () => {
4151
4165
  const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
4152
4166
  const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
4153
4167
  const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
4168
+ const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
4169
+ const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
4154
4170
  const ANDROID_GET_LOCATION_INTERVAL = 1 * 1e3;
4155
4171
  const takeIsForceBrowserGeo = () => {
4156
4172
  const searchParam = new URLSearchParams(location.search);
@@ -4225,6 +4241,54 @@ function wechatWatchPosition(onSuccess, onError, option) {
4225
4241
  unwatchVisibilityState();
4226
4242
  };
4227
4243
  }
4244
+ function alipayWatchPosition(onSuccess, onError, option) {
4245
+ let enable = true;
4246
+ let prevGeoPosition = void 0;
4247
+ const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4248
+ const isGeoWorkingRef = ref(true);
4249
+ const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4250
+ const startWatch = async () => {
4251
+ do {
4252
+ if (visibilityStateRef.value === "hidden") {
4253
+ await sleep(ALIPAY_GET_LOCATION_INTERVAL);
4254
+ continue;
4255
+ }
4256
+ const geoPosition = await new Promise((resolve) => {
4257
+ my.getLocation({
4258
+ type: 0,
4259
+ cacheTimeout: timeout / 1e3,
4260
+ success(res) {
4261
+ isGeoWorkingRef.value = true;
4262
+ resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4263
+ },
4264
+ fail(res) {
4265
+ const isGeoWorking = isGeoWorkingRef.value;
4266
+ isGeoWorkingRef.value = false;
4267
+ resolve(void 0);
4268
+ if (!isGeoWorking)
4269
+ return;
4270
+ const { error, errorMessage } = res;
4271
+ console.warn(
4272
+ "MyWarning: my.getLocation failed errcode, errmsg = ",
4273
+ error,
4274
+ errorMessage
4275
+ );
4276
+ onError == null ? void 0 : onError(new Error(errorMessage));
4277
+ }
4278
+ });
4279
+ });
4280
+ if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
4281
+ onSuccess(geoPosition);
4282
+ prevGeoPosition = geoPosition;
4283
+ await sleep(ALIPAY_GET_LOCATION_INTERVAL);
4284
+ } while (enable);
4285
+ };
4286
+ startWatch();
4287
+ return () => {
4288
+ enable = false;
4289
+ unwatchVisibilityState();
4290
+ };
4291
+ }
4228
4292
  function androidWatchPosition(onSuccess, onError, option) {
4229
4293
  let enable = true;
4230
4294
  let prevGeoPosition = void 0;
@@ -4281,31 +4345,15 @@ function compatibleWathPosition(onSuccess, onError, option) {
4281
4345
  if (browserPlatform === BRWOSER_PLATFORM.WECHAT || browserPlatform === BRWOSER_PLATFORM.WECHAT_MINIPROGRAM) {
4282
4346
  return wechatWatchPosition(onSuccess, onError, option);
4283
4347
  }
4348
+ if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4349
+ return alipayWatchPosition(onSuccess, onError, option);
4350
+ }
4284
4351
  if (osPlatform === OS_PLATFORM.ANDROID) {
4285
4352
  return androidWatchPosition(onSuccess, onError, option);
4286
4353
  }
4287
4354
  const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4288
4355
  return () => navigator.geolocation.clearWatch(watchId);
4289
4356
  }
4290
- window.efg = () => my.getLocation({
4291
- type: 0,
4292
- cacheTimeout: 1,
4293
- success(res) {
4294
- console.log("my.getLocation success = ", JSON.stringify(res, null, 2));
4295
- },
4296
- fail(res) {
4297
- console.log("my.getLocation fail = ", JSON.stringify(res, null, 2));
4298
- }
4299
- });
4300
- window.abc = () => wx.getLocation({
4301
- type: "wgs84",
4302
- success(res) {
4303
- console.log("wx.getLocation success = ", JSON.stringify(res, null, 2));
4304
- },
4305
- fail(res) {
4306
- console.log("wx.getLocation fail = ", JSON.stringify(res, null, 2));
4307
- }
4308
- });
4309
4357
  class SingleGeoWatch {
4310
4358
  constructor(option) {
4311
4359
  __publicField(this, "id", 0);
@@ -6378,6 +6426,22 @@ const useMapRecomendPlace = (props) => {
6378
6426
  isSameZone
6379
6427
  });
6380
6428
  };
6429
+ const updateRecommendPlaceOnlyInZone = async (place) => {
6430
+ const { place: foundPlace, candidates, available, zone } = await findAttachedPlace(place);
6431
+ const resultPlace = zone ? foundPlace : place;
6432
+ const isSameZone = !!zone && isZoneEqual(zone, zoneRef.value);
6433
+ availableRef.value = available;
6434
+ zoneRef.value = zone;
6435
+ placeCandidatesRef.value = candidates;
6436
+ Object.assign(recomendPlace, { ...resultPlace });
6437
+ onChangePlace == null ? void 0 : onChangePlace({ ...resultPlace });
6438
+ onChange == null ? void 0 : onChange({
6439
+ place: { ...resultPlace },
6440
+ inputPlace: { ...place },
6441
+ isInZone: !!zone,
6442
+ isSameZone
6443
+ });
6444
+ };
6381
6445
  const setPlaceCandidatesAndZone = ({
6382
6446
  zone,
6383
6447
  places: inputPlaceCandidates
@@ -6394,6 +6458,7 @@ const useMapRecomendPlace = (props) => {
6394
6458
  availableRef,
6395
6459
  isElectedRef,
6396
6460
  updateRecommendPlace,
6461
+ updateRecommendPlaceOnlyInZone,
6397
6462
  updatePlaceCandidates,
6398
6463
  updatePlace,
6399
6464
  setPlaceCandidatesAndZone
@@ -7168,7 +7233,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
7168
7233
  centerSource.source = "api";
7169
7234
  const place = toPlaceType(input);
7170
7235
  Object.assign(centerPlace, place);
7171
- updateRecommendPlace(place);
7236
+ updateRecommendPlaceOnlyInZone(place);
7172
7237
  };
7173
7238
  const setCenterPlaceByUserSpecifiedInZone = async ({
7174
7239
  place: inputPlace,
@@ -7264,7 +7329,7 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
7264
7329
  });
7265
7330
  const {
7266
7331
  updatePlace,
7267
- updateRecommendPlace,
7332
+ updateRecommendPlaceOnlyInZone,
7268
7333
  setPlaceCandidatesAndZone,
7269
7334
  placeCandidates,
7270
7335
  zoneRef,
@@ -7418,7 +7483,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
7418
7483
  centerSource.source = "api";
7419
7484
  const place = toPlaceType(input);
7420
7485
  Object.assign(centerPlace, place);
7421
- updateRecommendPlace(place);
7486
+ updateRecommendPlaceOnlyInZone(place);
7422
7487
  };
7423
7488
  const setCenterPlaceByUserSpecifiedInZone = async ({
7424
7489
  place: inputPlace,
@@ -7486,7 +7551,7 @@ const BusinessReselectPlaceMap = defineLagecySetup(function BusinessReselectPlac
7486
7551
  });
7487
7552
  const {
7488
7553
  updatePlace,
7489
- updateRecommendPlace,
7554
+ updateRecommendPlaceOnlyInZone,
7490
7555
  updatePlaceCandidates,
7491
7556
  setPlaceCandidatesAndZone,
7492
7557
  placeCandidates,
@@ -32,6 +32,7 @@ export declare const useMapRecomendPlace: <C>(props: UseMapRecomendPlaceProps<C>
32
32
  availableRef: import("vue-demi").Ref<boolean>;
33
33
  isElectedRef: import("vue-demi").ComputedRef<boolean>;
34
34
  updateRecommendPlace: (place: Place) => Promise<void>;
35
+ updateRecommendPlaceOnlyInZone: (place: Place) => Promise<void>;
35
36
  updatePlaceCandidates: (place: Place) => Promise<ValueOfOnChangeRecommendPlace>;
36
37
  updatePlace: (point: Point) => Promise<void>;
37
38
  setPlaceCandidatesAndZone: ({ zone, places: inputPlaceCandidates, }: RecommendZonePlaces) => void;
@@ -1,21 +1,20 @@
1
- interface MyGetLocationSuccessResponse {
1
+ export interface AlipayMyGetLocationSuccessResponse {
2
2
  longitude: number;
3
3
  latitude: number;
4
4
  accuracy: number;
5
5
  altitude: number;
6
6
  }
7
- interface MyErrorResponse {
7
+ export interface AlipayMyErrorResponse {
8
8
  error: number;
9
9
  errorMessage: string;
10
10
  }
11
- interface MyGetLocationProps {
11
+ export interface AlipayMyGetLocationProps {
12
12
  type: 0 | 1 | 2 | 3;
13
13
  cacheTimeout: number;
14
- success: (response: MyGetLocationSuccessResponse) => void;
15
- fail?: (response: MyErrorResponse) => void;
14
+ success: (response: AlipayMyGetLocationSuccessResponse) => void;
15
+ fail?: (response: AlipayMyErrorResponse) => void;
16
16
  complete?: () => void;
17
17
  }
18
- export interface My {
19
- getLocation: (props: MyGetLocationProps) => void;
18
+ export interface AlipayMy {
19
+ getLocation: (props: AlipayMyGetLocationProps) => void;
20
20
  }
21
- export {};
@@ -1,5 +1,6 @@
1
1
  /// <reference types="google.maps" />
2
2
  import type { Place, Point, RecommendZonePlaces, Zone } from "../types/interface";
3
+ import type { AlipayMyGetLocationSuccessResponse } from "../types/my";
3
4
  import type { WxGetLocationSuccessResponse } from "../types/wx";
4
5
  export declare const vec2lnglat: ([lng, lat]: [number, number]) => google.maps.LatLngLiteral;
5
6
  export interface AsteriskItem {
@@ -47,4 +48,5 @@ interface MaybeRecomendZonePlaces {
47
48
  }
48
49
  export declare const toRecommendZonePlacesType: (maybeRecomendZonePlaces: MaybeRecomendZonePlaces) => RecommendZonePlaces;
49
50
  export declare const wxGetLocationSuccessResponse2GeolocationPosition: (res: WxGetLocationSuccessResponse) => GeolocationPosition;
51
+ export declare const alipayMyGetLocationSuccessResponse2GeolocationPosition: (res: AlipayMyGetLocationSuccessResponse) => GeolocationPosition;
50
52
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.9.12",
3
+ "version": "0.9.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js"
package/todo.md CHANGED
@@ -6,6 +6,10 @@ https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-
6
6
  4. 手机缩放导致 onPlaceChange 触发,并且 getRecommendPlace 也被调用了
7
7
  5. 绿区内拖动问题
8
8
 
9
+ v3.8
10
+
11
+ - BusinessReselectPlaceMap 加一个初始化 绿区吸附的功能
12
+
9
13
  ### log
10
14
 
11
15
  手机关闭位置信息 errMsg: "getLocation:gps closed"