@heycar/heycars-map 0.9.13 → 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.13";
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);
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.13";
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);
@@ -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.13",
3
+ "version": "0.9.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js"