@heycar/heycars-map 0.6.8 → 0.6.10

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
@@ -1893,6 +1893,34 @@ const useMapLoader = (props) => {
1893
1893
  onChange
1894
1894
  });
1895
1895
  };
1896
+ var WEBGL_STATUS = /* @__PURE__ */ ((WEBGL_STATUS2) => {
1897
+ WEBGL_STATUS2["NOT_SUPPORTED"] = "NOT_SUPPORTED";
1898
+ WEBGL_STATUS2["DISABLED"] = "DISABLED";
1899
+ WEBGL_STATUS2["ENABLED"] = "ENABLED";
1900
+ return WEBGL_STATUS2;
1901
+ })(WEBGL_STATUS || {});
1902
+ function detectWebGL() {
1903
+ if (typeof window === "undefined")
1904
+ return "NOT_SUPPORTED";
1905
+ if (window.WebGLRenderingContext) {
1906
+ const canvas = document.createElement("canvas");
1907
+ const names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"];
1908
+ let context2 = null;
1909
+ for (const name of names) {
1910
+ try {
1911
+ context2 = canvas.getContext(name);
1912
+ if (context2 && typeof context2.getParameter === "function") {
1913
+ return "ENABLED";
1914
+ }
1915
+ } catch (e) {
1916
+ console.error("MyError: detectWebGL catch e = ", e);
1917
+ return "NOT_SUPPORTED";
1918
+ }
1919
+ }
1920
+ return "DISABLED";
1921
+ }
1922
+ return "NOT_SUPPORTED";
1923
+ }
1896
1924
  const ZOOM_WHEEL_RATIO = -135e-5;
1897
1925
  const useAmapWheelZoomCenter = (props) => {
1898
1926
  const { mapRef, enableRef } = props;
@@ -1984,7 +2012,7 @@ const Amap = defineSetup(function Amap2(props, { slots, emit }) {
1984
2012
  );
1985
2013
  watchNoneImmediatePostEffectForMapProperty(mapRef, props, [
1986
2014
  { name: "center", defaultValue: [0, 0] },
1987
- { name: "zooms", defaultValue: [0, 0] },
2015
+ { name: "zooms", defaultValue: [2, 20] },
1988
2016
  { name: "zoom", defaultValue: 0 },
1989
2017
  { name: "layers", defaultValue: [] },
1990
2018
  { name: "limitBounds", defaultValue: [] },
@@ -2134,7 +2162,6 @@ var createRuntimeFn = (config) => (options) => {
2134
2162
  return className;
2135
2163
  };
2136
2164
  var gmap = "_7anfuo0";
2137
- createRuntimeFn({ defaultClassName: "", variantClassNames: { enable: { true: "_7anfuo1", false: "_7anfuo2" } }, defaultVariants: {}, compoundVariants: [] });
2138
2165
  const Gmap = defineSetup(function Gmap2(props, { slots, emit }) {
2139
2166
  const setMap = props.mapRef;
2140
2167
  const { onResize } = props;
@@ -2207,6 +2234,9 @@ const Loading = defineSetup(function Loading2() {
2207
2234
  })]);
2208
2235
  });
2209
2236
  window.movingDraw = !new URLSearchParams(location.search).has("disableMovingDraw");
2237
+ if (detectWebGL() === WEBGL_STATUS.ENABLED) {
2238
+ window.forceWebGL = true;
2239
+ }
2210
2240
  const MapProvider = defineLagecySetup(function MapProvider2(props, {
2211
2241
  slots
2212
2242
  }) {
@@ -3129,6 +3159,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3129
3159
  let enable = true;
3130
3160
  let interval = WX_GET_LOCATION_INTERVAL_STILL;
3131
3161
  let prevGeoPosition = void 0;
3162
+ const isGeoWorkingRef = Vue.ref(true);
3132
3163
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
3133
3164
  const startWatch = async () => {
3134
3165
  await wxReady();
@@ -3137,7 +3168,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3137
3168
  await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
3138
3169
  continue;
3139
3170
  }
3140
- const geoPosition = await new Promise((resolve, reject) => {
3171
+ const geoPosition = await new Promise((resolve) => {
3141
3172
  let isHandled = false;
3142
3173
  wx.getLocation({
3143
3174
  type: "wgs84",
@@ -3145,6 +3176,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3145
3176
  if (isHandled)
3146
3177
  return;
3147
3178
  isHandled = true;
3179
+ isGeoWorkingRef.value = true;
3148
3180
  const speed = Number(res.speed);
3149
3181
  interval = speed === 0 ? WX_GET_LOCATION_INTERVAL_STILL : speed < 2 ? WX_GET_LOCATION_INTERVAL_SLOW : WX_GET_LOCATION_INTERVAL_FAST;
3150
3182
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
@@ -3153,9 +3185,13 @@ function wechatWatchPosition(onSuccess, onError, option) {
3153
3185
  if (isHandled)
3154
3186
  return;
3155
3187
  isHandled = true;
3156
- const error = new Error(res.errMsg);
3157
- reject(error);
3158
- onError == null ? void 0 : onError(error);
3188
+ const isGeoWorking = isGeoWorkingRef.value;
3189
+ isGeoWorkingRef.value = false;
3190
+ console.warn("MyWarning: wx.getLocation failed msg = ", res.errMsg);
3191
+ resolve(void 0);
3192
+ if (!isGeoWorking)
3193
+ return;
3194
+ onError == null ? void 0 : onError(new Error(res.errMsg));
3159
3195
  }
3160
3196
  });
3161
3197
  if (!timeout)
@@ -3286,7 +3322,7 @@ const useGeoLocation = (props) => {
3286
3322
  var _a, _b;
3287
3323
  const { onChange, onLoad, onLoadDefault, onError, geoDefaultPosition } = props != null ? props : {};
3288
3324
  const { toGcj02 } = useMapGCJ02();
3289
- let isOnLoadDefaultTriggered = false;
3325
+ let isOnLoadTriggered = false;
3290
3326
  const loading = Vue.ref(false);
3291
3327
  const readyRef = Vue.ref(false);
3292
3328
  const errorRef = Vue.ref();
@@ -3314,9 +3350,11 @@ const useGeoLocation = (props) => {
3314
3350
  const point = await toGcj02(wgsPoint);
3315
3351
  coordinateRef.value = coordinate;
3316
3352
  positionRef.value = point;
3353
+ errorRef.value = void 0;
3317
3354
  if (loading.value) {
3318
3355
  loading.value = false;
3319
3356
  readyRef.value = true;
3357
+ isOnLoadTriggered = true;
3320
3358
  onLoad == null ? void 0 : onLoad({ position: point, coordinate });
3321
3359
  }
3322
3360
  onChange == null ? void 0 : onChange({ position: point, coordinate });
@@ -3326,8 +3364,8 @@ const useGeoLocation = (props) => {
3326
3364
  loading.value = false;
3327
3365
  errorRef.value = error;
3328
3366
  const position = props == null ? void 0 : props.geoDefaultPosition;
3329
- if (position && !isOnLoadDefaultTriggered) {
3330
- isOnLoadDefaultTriggered = true;
3367
+ if (position && !isOnLoadTriggered) {
3368
+ isOnLoadTriggered = true;
3331
3369
  onLoadDefault == null ? void 0 : onLoadDefault({ position });
3332
3370
  }
3333
3371
  onError == null ? void 0 : onError(error);
package/dist/index.js CHANGED
@@ -1891,6 +1891,34 @@ const useMapLoader = (props) => {
1891
1891
  onChange
1892
1892
  });
1893
1893
  };
1894
+ var WEBGL_STATUS = /* @__PURE__ */ ((WEBGL_STATUS2) => {
1895
+ WEBGL_STATUS2["NOT_SUPPORTED"] = "NOT_SUPPORTED";
1896
+ WEBGL_STATUS2["DISABLED"] = "DISABLED";
1897
+ WEBGL_STATUS2["ENABLED"] = "ENABLED";
1898
+ return WEBGL_STATUS2;
1899
+ })(WEBGL_STATUS || {});
1900
+ function detectWebGL() {
1901
+ if (typeof window === "undefined")
1902
+ return "NOT_SUPPORTED";
1903
+ if (window.WebGLRenderingContext) {
1904
+ const canvas = document.createElement("canvas");
1905
+ const names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"];
1906
+ let context2 = null;
1907
+ for (const name of names) {
1908
+ try {
1909
+ context2 = canvas.getContext(name);
1910
+ if (context2 && typeof context2.getParameter === "function") {
1911
+ return "ENABLED";
1912
+ }
1913
+ } catch (e) {
1914
+ console.error("MyError: detectWebGL catch e = ", e);
1915
+ return "NOT_SUPPORTED";
1916
+ }
1917
+ }
1918
+ return "DISABLED";
1919
+ }
1920
+ return "NOT_SUPPORTED";
1921
+ }
1894
1922
  const ZOOM_WHEEL_RATIO = -135e-5;
1895
1923
  const useAmapWheelZoomCenter = (props) => {
1896
1924
  const { mapRef, enableRef } = props;
@@ -1982,7 +2010,7 @@ const Amap = defineSetup(function Amap2(props, { slots, emit }) {
1982
2010
  );
1983
2011
  watchNoneImmediatePostEffectForMapProperty(mapRef, props, [
1984
2012
  { name: "center", defaultValue: [0, 0] },
1985
- { name: "zooms", defaultValue: [0, 0] },
2013
+ { name: "zooms", defaultValue: [2, 20] },
1986
2014
  { name: "zoom", defaultValue: 0 },
1987
2015
  { name: "layers", defaultValue: [] },
1988
2016
  { name: "limitBounds", defaultValue: [] },
@@ -2132,7 +2160,6 @@ var createRuntimeFn = (config) => (options) => {
2132
2160
  return className;
2133
2161
  };
2134
2162
  var gmap = "_7anfuo0";
2135
- createRuntimeFn({ defaultClassName: "", variantClassNames: { enable: { true: "_7anfuo1", false: "_7anfuo2" } }, defaultVariants: {}, compoundVariants: [] });
2136
2163
  const Gmap = defineSetup(function Gmap2(props, { slots, emit }) {
2137
2164
  const setMap = props.mapRef;
2138
2165
  const { onResize } = props;
@@ -2205,6 +2232,9 @@ const Loading = defineSetup(function Loading2() {
2205
2232
  })]);
2206
2233
  });
2207
2234
  window.movingDraw = !new URLSearchParams(location.search).has("disableMovingDraw");
2235
+ if (detectWebGL() === WEBGL_STATUS.ENABLED) {
2236
+ window.forceWebGL = true;
2237
+ }
2208
2238
  const MapProvider = defineLagecySetup(function MapProvider2(props, {
2209
2239
  slots
2210
2240
  }) {
@@ -3127,6 +3157,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3127
3157
  let enable = true;
3128
3158
  let interval = WX_GET_LOCATION_INTERVAL_STILL;
3129
3159
  let prevGeoPosition = void 0;
3160
+ const isGeoWorkingRef = ref(true);
3130
3161
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
3131
3162
  const startWatch = async () => {
3132
3163
  await wxReady();
@@ -3135,7 +3166,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3135
3166
  await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
3136
3167
  continue;
3137
3168
  }
3138
- const geoPosition = await new Promise((resolve, reject) => {
3169
+ const geoPosition = await new Promise((resolve) => {
3139
3170
  let isHandled = false;
3140
3171
  wx.getLocation({
3141
3172
  type: "wgs84",
@@ -3143,6 +3174,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
3143
3174
  if (isHandled)
3144
3175
  return;
3145
3176
  isHandled = true;
3177
+ isGeoWorkingRef.value = true;
3146
3178
  const speed = Number(res.speed);
3147
3179
  interval = speed === 0 ? WX_GET_LOCATION_INTERVAL_STILL : speed < 2 ? WX_GET_LOCATION_INTERVAL_SLOW : WX_GET_LOCATION_INTERVAL_FAST;
3148
3180
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
@@ -3151,9 +3183,13 @@ function wechatWatchPosition(onSuccess, onError, option) {
3151
3183
  if (isHandled)
3152
3184
  return;
3153
3185
  isHandled = true;
3154
- const error = new Error(res.errMsg);
3155
- reject(error);
3156
- onError == null ? void 0 : onError(error);
3186
+ const isGeoWorking = isGeoWorkingRef.value;
3187
+ isGeoWorkingRef.value = false;
3188
+ console.warn("MyWarning: wx.getLocation failed msg = ", res.errMsg);
3189
+ resolve(void 0);
3190
+ if (!isGeoWorking)
3191
+ return;
3192
+ onError == null ? void 0 : onError(new Error(res.errMsg));
3157
3193
  }
3158
3194
  });
3159
3195
  if (!timeout)
@@ -3284,7 +3320,7 @@ const useGeoLocation = (props) => {
3284
3320
  var _a, _b;
3285
3321
  const { onChange, onLoad, onLoadDefault, onError, geoDefaultPosition } = props != null ? props : {};
3286
3322
  const { toGcj02 } = useMapGCJ02();
3287
- let isOnLoadDefaultTriggered = false;
3323
+ let isOnLoadTriggered = false;
3288
3324
  const loading = ref(false);
3289
3325
  const readyRef = ref(false);
3290
3326
  const errorRef = ref();
@@ -3312,9 +3348,11 @@ const useGeoLocation = (props) => {
3312
3348
  const point = await toGcj02(wgsPoint);
3313
3349
  coordinateRef.value = coordinate;
3314
3350
  positionRef.value = point;
3351
+ errorRef.value = void 0;
3315
3352
  if (loading.value) {
3316
3353
  loading.value = false;
3317
3354
  readyRef.value = true;
3355
+ isOnLoadTriggered = true;
3318
3356
  onLoad == null ? void 0 : onLoad({ position: point, coordinate });
3319
3357
  }
3320
3358
  onChange == null ? void 0 : onChange({ position: point, coordinate });
@@ -3324,8 +3362,8 @@ const useGeoLocation = (props) => {
3324
3362
  loading.value = false;
3325
3363
  errorRef.value = error;
3326
3364
  const position = props == null ? void 0 : props.geoDefaultPosition;
3327
- if (position && !isOnLoadDefaultTriggered) {
3328
- isOnLoadDefaultTriggered = true;
3365
+ if (position && !isOnLoadTriggered) {
3366
+ isOnLoadTriggered = true;
3329
3367
  onLoadDefault == null ? void 0 : onLoadDefault({ position });
3330
3368
  }
3331
3369
  onError == null ? void 0 : onError(error);
@@ -0,0 +1,25 @@
1
+ export declare enum BRWOSER_PLATFORM {
2
+ WECHAT = "WECHAT",
3
+ WECHAT_MINIPROGRAM = "WECHAT_MINIPROGRAM",
4
+ ALIPAY = "ALIPAY",
5
+ ALIPAY_MINIPROGRAM = "ALIPAY_MINIPROGRAM",
6
+ H5 = "H5",
7
+ NODE_JS = "NODE_JS"
8
+ }
9
+ export declare enum OS_PLATFORM {
10
+ IOS = "IOS",
11
+ ANDROID = "ANDROID",
12
+ OTHER = "OTHER"
13
+ }
14
+ export declare enum WEBGL_STATUS {
15
+ NOT_SUPPORTED = "NOT_SUPPORTED",
16
+ DISABLED = "DISABLED",
17
+ ENABLED = "ENABLED"
18
+ }
19
+ export declare const detectBrowserPlatform: () => BRWOSER_PLATFORM;
20
+ export declare const detectOSPlatform: () => OS_PLATFORM;
21
+ /**
22
+ * Detects if WebGL is enabled.
23
+ * Inspired from http://www.browserleaks.com/webgl#howto-detect-webgl
24
+ */
25
+ export declare function detectWebGL(): WEBGL_STATUS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite -c vite.config.dev.ts",