@heycar/heycars-map 0.6.5 → 0.6.7
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/hooks/useVisibilityState.d.ts +7 -0
- package/dist/index.cjs +130 -10
- package/dist/index.js +130 -10
- package/dist/types/wx.d.ts +21 -0
- package/dist/utils/{singleGeoWatch.d.ts → SingleGeoWatch.d.ts} +2 -1
- package/dist/utils/compatibleWatchPosition.d.ts +2 -0
- package/dist/utils/transform.d.ts +3 -0
- package/package.json +3 -20
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const useVisibilityState: () => {
|
|
2
|
+
visibilityStateRef: import("vue-demi").Ref<DocumentVisibilityState>;
|
|
3
|
+
};
|
|
4
|
+
export declare const watchVisibilityState: () => {
|
|
5
|
+
visibilityStateRef: import("vue-demi").Ref<DocumentVisibilityState>;
|
|
6
|
+
unwatchVisibilityState: () => void;
|
|
7
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -943,6 +943,11 @@ const isPlaceEqual = (p1, p2) => {
|
|
|
943
943
|
const isPointEqual = (p1, p2) => {
|
|
944
944
|
return p1[0] === (p2 == null ? void 0 : p2[0]) && p1[1] === (p2 == null ? void 0 : p2[1]);
|
|
945
945
|
};
|
|
946
|
+
const isGeoPositionEqual = (p1, p2) => {
|
|
947
|
+
if (!p2)
|
|
948
|
+
return false;
|
|
949
|
+
return p1.coords.longitude === p2.coords.longitude && p1.coords.latitude === p2.coords.latitude;
|
|
950
|
+
};
|
|
946
951
|
const toPlaceType = (maybePlace) => {
|
|
947
952
|
const lng = Number(maybePlace.lng);
|
|
948
953
|
if (isNaN(lng))
|
|
@@ -952,6 +957,21 @@ const toPlaceType = (maybePlace) => {
|
|
|
952
957
|
throw new Error("MyError: expect lat to be number");
|
|
953
958
|
return { lng, lat, name: maybePlace.name };
|
|
954
959
|
};
|
|
960
|
+
const wxGetLocationSuccessResponse2GeolocationPosition = (res) => {
|
|
961
|
+
const { longitude, latitude, accuracy } = res;
|
|
962
|
+
const speed = Number(res.speed);
|
|
963
|
+
const timestamp = Date.now();
|
|
964
|
+
const coords = {
|
|
965
|
+
accuracy: Number(accuracy),
|
|
966
|
+
altitude: null,
|
|
967
|
+
altitudeAccuracy: null,
|
|
968
|
+
heading: null,
|
|
969
|
+
latitude: Number(latitude),
|
|
970
|
+
longitude: Number(longitude),
|
|
971
|
+
speed
|
|
972
|
+
};
|
|
973
|
+
return { timestamp, coords };
|
|
974
|
+
};
|
|
955
975
|
const deepCompareEqualsForMaps = createComparator((deepEqual) => (a, b) => {
|
|
956
976
|
if (isLatLngLiteral(a) || isLatLngLiteral(b)) {
|
|
957
977
|
return new google.maps.LatLng(a).equals(new google.maps.LatLng(b));
|
|
@@ -3036,6 +3056,107 @@ const BusinessQuotingMap = defineLagecySetup(function BusinessQuotingMap2(props)
|
|
|
3036
3056
|
})]);
|
|
3037
3057
|
};
|
|
3038
3058
|
}).props(["fallback", "from", "loading", "mapRef", "registerOverlay", "renderDescription", "to", "fromDescription", "log"]);
|
|
3059
|
+
const watchVisibilityState = () => {
|
|
3060
|
+
const visibilityStateRef = Vue.ref(document.visibilityState);
|
|
3061
|
+
const handleVisibilityChange = () => {
|
|
3062
|
+
visibilityStateRef.value = document.visibilityState;
|
|
3063
|
+
};
|
|
3064
|
+
const unwatchVisibilityState = () => {
|
|
3065
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
3066
|
+
};
|
|
3067
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
3068
|
+
return { visibilityStateRef, unwatchVisibilityState };
|
|
3069
|
+
};
|
|
3070
|
+
const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
|
|
3071
|
+
const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
|
|
3072
|
+
const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
|
|
3073
|
+
const takeIsForceBrowserGeo = () => {
|
|
3074
|
+
const searchParam = new URLSearchParams(location.search);
|
|
3075
|
+
return searchParam.has(`force-browser-geo`);
|
|
3076
|
+
};
|
|
3077
|
+
const sleep$1 = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
3078
|
+
const wxReady = () => new Promise((resolve, reject) => {
|
|
3079
|
+
wx.ready(resolve);
|
|
3080
|
+
wx.error(reject);
|
|
3081
|
+
});
|
|
3082
|
+
const detectPlatform = () => {
|
|
3083
|
+
const useragent = navigator.userAgent.toLowerCase();
|
|
3084
|
+
if (useragent.includes("micromessenger"))
|
|
3085
|
+
return "wechat";
|
|
3086
|
+
if (useragent.includes("alipay"))
|
|
3087
|
+
return "alipay";
|
|
3088
|
+
return "other";
|
|
3089
|
+
};
|
|
3090
|
+
function wechatWatchPosition(onSuccess, onError, option) {
|
|
3091
|
+
const { timeout } = option;
|
|
3092
|
+
let enable = true;
|
|
3093
|
+
let interval = WX_GET_LOCATION_INTERVAL_STILL;
|
|
3094
|
+
let prevGeoPosition = void 0;
|
|
3095
|
+
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
3096
|
+
const startWatch = async () => {
|
|
3097
|
+
await wxReady();
|
|
3098
|
+
do {
|
|
3099
|
+
if (visibilityStateRef.value === "hidden") {
|
|
3100
|
+
await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
|
|
3101
|
+
continue;
|
|
3102
|
+
}
|
|
3103
|
+
const geoPosition = await new Promise((resolve, reject) => {
|
|
3104
|
+
let isHandled = false;
|
|
3105
|
+
wx.getLocation({
|
|
3106
|
+
type: "wgs84",
|
|
3107
|
+
success(res) {
|
|
3108
|
+
if (isHandled)
|
|
3109
|
+
return;
|
|
3110
|
+
isHandled = true;
|
|
3111
|
+
const speed = Number(res.speed);
|
|
3112
|
+
interval = speed === 0 ? WX_GET_LOCATION_INTERVAL_STILL : speed < 2 ? WX_GET_LOCATION_INTERVAL_SLOW : WX_GET_LOCATION_INTERVAL_FAST;
|
|
3113
|
+
resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
|
|
3114
|
+
},
|
|
3115
|
+
fail(res) {
|
|
3116
|
+
if (isHandled)
|
|
3117
|
+
return;
|
|
3118
|
+
isHandled = true;
|
|
3119
|
+
const error = new Error(res.errMsg);
|
|
3120
|
+
reject(error);
|
|
3121
|
+
onError == null ? void 0 : onError(error);
|
|
3122
|
+
}
|
|
3123
|
+
});
|
|
3124
|
+
if (!timeout)
|
|
3125
|
+
return;
|
|
3126
|
+
setTimeout(() => {
|
|
3127
|
+
if (isHandled)
|
|
3128
|
+
return;
|
|
3129
|
+
interval = WX_GET_LOCATION_INTERVAL_SLOW;
|
|
3130
|
+
resolve(void 0);
|
|
3131
|
+
}, timeout);
|
|
3132
|
+
});
|
|
3133
|
+
if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
|
|
3134
|
+
onSuccess(geoPosition);
|
|
3135
|
+
prevGeoPosition = geoPosition;
|
|
3136
|
+
await sleep$1(interval);
|
|
3137
|
+
} while (enable);
|
|
3138
|
+
};
|
|
3139
|
+
startWatch();
|
|
3140
|
+
return () => {
|
|
3141
|
+
enable = false;
|
|
3142
|
+
unwatchVisibilityState();
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
function compatibleWathPosition(onSuccess, onError, option) {
|
|
3146
|
+
const isForceBrowserGeo = takeIsForceBrowserGeo();
|
|
3147
|
+
if (isForceBrowserGeo) {
|
|
3148
|
+
const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
|
|
3149
|
+
return () => navigator.geolocation.clearWatch(watchId);
|
|
3150
|
+
}
|
|
3151
|
+
switch (detectPlatform()) {
|
|
3152
|
+
case "wechat":
|
|
3153
|
+
return wechatWatchPosition(onSuccess, onError, option);
|
|
3154
|
+
default: {
|
|
3155
|
+
const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
|
|
3156
|
+
return () => navigator.geolocation.clearWatch(watchId);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3039
3160
|
const isPlace = (place) => {
|
|
3040
3161
|
return place.lng !== void 0 && place.lat !== void 0;
|
|
3041
3162
|
};
|
|
@@ -3055,7 +3176,7 @@ class SingleGeoWatch {
|
|
|
3055
3176
|
__publicField(this, "id", 0);
|
|
3056
3177
|
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
3057
3178
|
__publicField(this, "option", {});
|
|
3058
|
-
__publicField(this, "
|
|
3179
|
+
__publicField(this, "unwatch");
|
|
3059
3180
|
this.option = option != null ? option : {};
|
|
3060
3181
|
}
|
|
3061
3182
|
watchPosition(onSuccess, onError) {
|
|
@@ -3069,12 +3190,12 @@ class SingleGeoWatch {
|
|
|
3069
3190
|
this.listeners.delete(id);
|
|
3070
3191
|
}
|
|
3071
3192
|
async start() {
|
|
3072
|
-
const { listeners, option,
|
|
3073
|
-
if (
|
|
3074
|
-
|
|
3193
|
+
const { listeners, option, unwatch } = this;
|
|
3194
|
+
if (unwatch) {
|
|
3195
|
+
unwatch();
|
|
3075
3196
|
await sleep(20);
|
|
3076
3197
|
}
|
|
3077
|
-
this.
|
|
3198
|
+
this.unwatch = compatibleWathPosition(
|
|
3078
3199
|
(position) => {
|
|
3079
3200
|
for (const [onSuccess] of listeners.values()) {
|
|
3080
3201
|
onSuccess(position);
|
|
@@ -3145,10 +3266,12 @@ const useGeoLocation = (props) => {
|
|
|
3145
3266
|
Vue.watch(
|
|
3146
3267
|
() => true,
|
|
3147
3268
|
(_1, _2, onCleanup) => {
|
|
3269
|
+
const logStartTime = Date.now();
|
|
3148
3270
|
loading.value = true;
|
|
3149
3271
|
const watchId = singleGeoWatch.watchPosition(
|
|
3150
3272
|
async (position) => {
|
|
3151
|
-
|
|
3273
|
+
const duration = Date.now() - logStartTime;
|
|
3274
|
+
spaceLog("watchPosition", "success duration, position = ", duration, position);
|
|
3152
3275
|
const coordinate = position.coords;
|
|
3153
3276
|
const wgsPoint = [position.coords.longitude, position.coords.latitude];
|
|
3154
3277
|
const point = await toGcj02(wgsPoint);
|
|
@@ -3162,7 +3285,7 @@ const useGeoLocation = (props) => {
|
|
|
3162
3285
|
onChange == null ? void 0 : onChange({ position: point, coordinate });
|
|
3163
3286
|
},
|
|
3164
3287
|
(error) => {
|
|
3165
|
-
|
|
3288
|
+
spaceLog("watchPosition", "error.message = ", error.message);
|
|
3166
3289
|
loading.value = false;
|
|
3167
3290
|
errorRef.value = error;
|
|
3168
3291
|
const position = props == null ? void 0 : props.geoDefaultPosition;
|
|
@@ -3985,14 +4108,12 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
3985
4108
|
} = useGeoLocation({
|
|
3986
4109
|
geoDefaultPosition,
|
|
3987
4110
|
onLoad: async (value) => {
|
|
3988
|
-
console.log("useGeoLocation onLoad value = ", value);
|
|
3989
4111
|
await readyPromise;
|
|
3990
4112
|
centerSource.source = "geo";
|
|
3991
4113
|
updatePlace(value.position);
|
|
3992
4114
|
emit("loadGeoLocation", value);
|
|
3993
4115
|
},
|
|
3994
4116
|
onLoadDefault: async (value) => {
|
|
3995
|
-
console.log("useGeoLocation onLoadDefault value = ", value);
|
|
3996
4117
|
await readyPromise;
|
|
3997
4118
|
const place = await defaultCenterPlacePromise;
|
|
3998
4119
|
centerSource.source = "geo";
|
|
@@ -4086,7 +4207,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
4086
4207
|
} = props;
|
|
4087
4208
|
const title = geoLoading.value ? geoLoadingTitle : !availableRef.value ? unavailableTitle : centerPlace.name;
|
|
4088
4209
|
const description = !availableRef.value ? void 0 : isElectedRef.value ? recomendDescription : void 0;
|
|
4089
|
-
console.log("BusinessRecomendPlaceMap render geoLoading, isFirstWorkflowRecomendLoadingRef = ", geoLoading.value, isFirstWorkflowRecomendLoadingRef.value);
|
|
4090
4210
|
return Vue.h(HeycarMap, {
|
|
4091
4211
|
"attrs": {
|
|
4092
4212
|
"center": centerPoint.value,
|
package/dist/index.js
CHANGED
|
@@ -941,6 +941,11 @@ const isPlaceEqual = (p1, p2) => {
|
|
|
941
941
|
const isPointEqual = (p1, p2) => {
|
|
942
942
|
return p1[0] === (p2 == null ? void 0 : p2[0]) && p1[1] === (p2 == null ? void 0 : p2[1]);
|
|
943
943
|
};
|
|
944
|
+
const isGeoPositionEqual = (p1, p2) => {
|
|
945
|
+
if (!p2)
|
|
946
|
+
return false;
|
|
947
|
+
return p1.coords.longitude === p2.coords.longitude && p1.coords.latitude === p2.coords.latitude;
|
|
948
|
+
};
|
|
944
949
|
const toPlaceType = (maybePlace) => {
|
|
945
950
|
const lng = Number(maybePlace.lng);
|
|
946
951
|
if (isNaN(lng))
|
|
@@ -950,6 +955,21 @@ const toPlaceType = (maybePlace) => {
|
|
|
950
955
|
throw new Error("MyError: expect lat to be number");
|
|
951
956
|
return { lng, lat, name: maybePlace.name };
|
|
952
957
|
};
|
|
958
|
+
const wxGetLocationSuccessResponse2GeolocationPosition = (res) => {
|
|
959
|
+
const { longitude, latitude, accuracy } = res;
|
|
960
|
+
const speed = Number(res.speed);
|
|
961
|
+
const timestamp = Date.now();
|
|
962
|
+
const coords = {
|
|
963
|
+
accuracy: Number(accuracy),
|
|
964
|
+
altitude: null,
|
|
965
|
+
altitudeAccuracy: null,
|
|
966
|
+
heading: null,
|
|
967
|
+
latitude: Number(latitude),
|
|
968
|
+
longitude: Number(longitude),
|
|
969
|
+
speed
|
|
970
|
+
};
|
|
971
|
+
return { timestamp, coords };
|
|
972
|
+
};
|
|
953
973
|
const deepCompareEqualsForMaps = createComparator((deepEqual) => (a, b) => {
|
|
954
974
|
if (isLatLngLiteral(a) || isLatLngLiteral(b)) {
|
|
955
975
|
return new google.maps.LatLng(a).equals(new google.maps.LatLng(b));
|
|
@@ -3034,6 +3054,107 @@ const BusinessQuotingMap = defineLagecySetup(function BusinessQuotingMap2(props)
|
|
|
3034
3054
|
})]);
|
|
3035
3055
|
};
|
|
3036
3056
|
}).props(["fallback", "from", "loading", "mapRef", "registerOverlay", "renderDescription", "to", "fromDescription", "log"]);
|
|
3057
|
+
const watchVisibilityState = () => {
|
|
3058
|
+
const visibilityStateRef = ref(document.visibilityState);
|
|
3059
|
+
const handleVisibilityChange = () => {
|
|
3060
|
+
visibilityStateRef.value = document.visibilityState;
|
|
3061
|
+
};
|
|
3062
|
+
const unwatchVisibilityState = () => {
|
|
3063
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
3064
|
+
};
|
|
3065
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
3066
|
+
return { visibilityStateRef, unwatchVisibilityState };
|
|
3067
|
+
};
|
|
3068
|
+
const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
|
|
3069
|
+
const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
|
|
3070
|
+
const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
|
|
3071
|
+
const takeIsForceBrowserGeo = () => {
|
|
3072
|
+
const searchParam = new URLSearchParams(location.search);
|
|
3073
|
+
return searchParam.has(`force-browser-geo`);
|
|
3074
|
+
};
|
|
3075
|
+
const sleep$1 = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
3076
|
+
const wxReady = () => new Promise((resolve, reject) => {
|
|
3077
|
+
wx.ready(resolve);
|
|
3078
|
+
wx.error(reject);
|
|
3079
|
+
});
|
|
3080
|
+
const detectPlatform = () => {
|
|
3081
|
+
const useragent = navigator.userAgent.toLowerCase();
|
|
3082
|
+
if (useragent.includes("micromessenger"))
|
|
3083
|
+
return "wechat";
|
|
3084
|
+
if (useragent.includes("alipay"))
|
|
3085
|
+
return "alipay";
|
|
3086
|
+
return "other";
|
|
3087
|
+
};
|
|
3088
|
+
function wechatWatchPosition(onSuccess, onError, option) {
|
|
3089
|
+
const { timeout } = option;
|
|
3090
|
+
let enable = true;
|
|
3091
|
+
let interval = WX_GET_LOCATION_INTERVAL_STILL;
|
|
3092
|
+
let prevGeoPosition = void 0;
|
|
3093
|
+
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
3094
|
+
const startWatch = async () => {
|
|
3095
|
+
await wxReady();
|
|
3096
|
+
do {
|
|
3097
|
+
if (visibilityStateRef.value === "hidden") {
|
|
3098
|
+
await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
|
|
3099
|
+
continue;
|
|
3100
|
+
}
|
|
3101
|
+
const geoPosition = await new Promise((resolve, reject) => {
|
|
3102
|
+
let isHandled = false;
|
|
3103
|
+
wx.getLocation({
|
|
3104
|
+
type: "wgs84",
|
|
3105
|
+
success(res) {
|
|
3106
|
+
if (isHandled)
|
|
3107
|
+
return;
|
|
3108
|
+
isHandled = true;
|
|
3109
|
+
const speed = Number(res.speed);
|
|
3110
|
+
interval = speed === 0 ? WX_GET_LOCATION_INTERVAL_STILL : speed < 2 ? WX_GET_LOCATION_INTERVAL_SLOW : WX_GET_LOCATION_INTERVAL_FAST;
|
|
3111
|
+
resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
|
|
3112
|
+
},
|
|
3113
|
+
fail(res) {
|
|
3114
|
+
if (isHandled)
|
|
3115
|
+
return;
|
|
3116
|
+
isHandled = true;
|
|
3117
|
+
const error = new Error(res.errMsg);
|
|
3118
|
+
reject(error);
|
|
3119
|
+
onError == null ? void 0 : onError(error);
|
|
3120
|
+
}
|
|
3121
|
+
});
|
|
3122
|
+
if (!timeout)
|
|
3123
|
+
return;
|
|
3124
|
+
setTimeout(() => {
|
|
3125
|
+
if (isHandled)
|
|
3126
|
+
return;
|
|
3127
|
+
interval = WX_GET_LOCATION_INTERVAL_SLOW;
|
|
3128
|
+
resolve(void 0);
|
|
3129
|
+
}, timeout);
|
|
3130
|
+
});
|
|
3131
|
+
if (geoPosition && !isGeoPositionEqual(geoPosition, prevGeoPosition))
|
|
3132
|
+
onSuccess(geoPosition);
|
|
3133
|
+
prevGeoPosition = geoPosition;
|
|
3134
|
+
await sleep$1(interval);
|
|
3135
|
+
} while (enable);
|
|
3136
|
+
};
|
|
3137
|
+
startWatch();
|
|
3138
|
+
return () => {
|
|
3139
|
+
enable = false;
|
|
3140
|
+
unwatchVisibilityState();
|
|
3141
|
+
};
|
|
3142
|
+
}
|
|
3143
|
+
function compatibleWathPosition(onSuccess, onError, option) {
|
|
3144
|
+
const isForceBrowserGeo = takeIsForceBrowserGeo();
|
|
3145
|
+
if (isForceBrowserGeo) {
|
|
3146
|
+
const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
|
|
3147
|
+
return () => navigator.geolocation.clearWatch(watchId);
|
|
3148
|
+
}
|
|
3149
|
+
switch (detectPlatform()) {
|
|
3150
|
+
case "wechat":
|
|
3151
|
+
return wechatWatchPosition(onSuccess, onError, option);
|
|
3152
|
+
default: {
|
|
3153
|
+
const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
|
|
3154
|
+
return () => navigator.geolocation.clearWatch(watchId);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3037
3158
|
const isPlace = (place) => {
|
|
3038
3159
|
return place.lng !== void 0 && place.lat !== void 0;
|
|
3039
3160
|
};
|
|
@@ -3053,7 +3174,7 @@ class SingleGeoWatch {
|
|
|
3053
3174
|
__publicField(this, "id", 0);
|
|
3054
3175
|
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
3055
3176
|
__publicField(this, "option", {});
|
|
3056
|
-
__publicField(this, "
|
|
3177
|
+
__publicField(this, "unwatch");
|
|
3057
3178
|
this.option = option != null ? option : {};
|
|
3058
3179
|
}
|
|
3059
3180
|
watchPosition(onSuccess, onError) {
|
|
@@ -3067,12 +3188,12 @@ class SingleGeoWatch {
|
|
|
3067
3188
|
this.listeners.delete(id);
|
|
3068
3189
|
}
|
|
3069
3190
|
async start() {
|
|
3070
|
-
const { listeners, option,
|
|
3071
|
-
if (
|
|
3072
|
-
|
|
3191
|
+
const { listeners, option, unwatch } = this;
|
|
3192
|
+
if (unwatch) {
|
|
3193
|
+
unwatch();
|
|
3073
3194
|
await sleep(20);
|
|
3074
3195
|
}
|
|
3075
|
-
this.
|
|
3196
|
+
this.unwatch = compatibleWathPosition(
|
|
3076
3197
|
(position) => {
|
|
3077
3198
|
for (const [onSuccess] of listeners.values()) {
|
|
3078
3199
|
onSuccess(position);
|
|
@@ -3143,10 +3264,12 @@ const useGeoLocation = (props) => {
|
|
|
3143
3264
|
watch(
|
|
3144
3265
|
() => true,
|
|
3145
3266
|
(_1, _2, onCleanup) => {
|
|
3267
|
+
const logStartTime = Date.now();
|
|
3146
3268
|
loading.value = true;
|
|
3147
3269
|
const watchId = singleGeoWatch.watchPosition(
|
|
3148
3270
|
async (position) => {
|
|
3149
|
-
|
|
3271
|
+
const duration = Date.now() - logStartTime;
|
|
3272
|
+
spaceLog("watchPosition", "success duration, position = ", duration, position);
|
|
3150
3273
|
const coordinate = position.coords;
|
|
3151
3274
|
const wgsPoint = [position.coords.longitude, position.coords.latitude];
|
|
3152
3275
|
const point = await toGcj02(wgsPoint);
|
|
@@ -3160,7 +3283,7 @@ const useGeoLocation = (props) => {
|
|
|
3160
3283
|
onChange == null ? void 0 : onChange({ position: point, coordinate });
|
|
3161
3284
|
},
|
|
3162
3285
|
(error) => {
|
|
3163
|
-
|
|
3286
|
+
spaceLog("watchPosition", "error.message = ", error.message);
|
|
3164
3287
|
loading.value = false;
|
|
3165
3288
|
errorRef.value = error;
|
|
3166
3289
|
const position = props == null ? void 0 : props.geoDefaultPosition;
|
|
@@ -3983,14 +4106,12 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
3983
4106
|
} = useGeoLocation({
|
|
3984
4107
|
geoDefaultPosition,
|
|
3985
4108
|
onLoad: async (value) => {
|
|
3986
|
-
console.log("useGeoLocation onLoad value = ", value);
|
|
3987
4109
|
await readyPromise;
|
|
3988
4110
|
centerSource.source = "geo";
|
|
3989
4111
|
updatePlace(value.position);
|
|
3990
4112
|
emit("loadGeoLocation", value);
|
|
3991
4113
|
},
|
|
3992
4114
|
onLoadDefault: async (value) => {
|
|
3993
|
-
console.log("useGeoLocation onLoadDefault value = ", value);
|
|
3994
4115
|
await readyPromise;
|
|
3995
4116
|
const place = await defaultCenterPlacePromise;
|
|
3996
4117
|
centerSource.source = "geo";
|
|
@@ -4084,7 +4205,6 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
|
|
|
4084
4205
|
} = props;
|
|
4085
4206
|
const title = geoLoading.value ? geoLoadingTitle : !availableRef.value ? unavailableTitle : centerPlace.name;
|
|
4086
4207
|
const description = !availableRef.value ? void 0 : isElectedRef.value ? recomendDescription : void 0;
|
|
4087
|
-
console.log("BusinessRecomendPlaceMap render geoLoading, isFirstWorkflowRecomendLoadingRef = ", geoLoading.value, isFirstWorkflowRecomendLoadingRef.value);
|
|
4088
4208
|
return h(HeycarMap, {
|
|
4089
4209
|
"attrs": {
|
|
4090
4210
|
"center": centerPoint.value,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface WxResponse {
|
|
2
|
+
errMsg: string;
|
|
3
|
+
}
|
|
4
|
+
export interface WxGetLocationSuccessResponse extends WxResponse {
|
|
5
|
+
latitude: string;
|
|
6
|
+
longitude: string;
|
|
7
|
+
speed: string;
|
|
8
|
+
accuracy: string;
|
|
9
|
+
}
|
|
10
|
+
interface WxGetLocationProps {
|
|
11
|
+
type: "wgs84" | "gcj02";
|
|
12
|
+
success: (response: WxGetLocationSuccessResponse) => void;
|
|
13
|
+
fail?: (response: WxResponse) => void;
|
|
14
|
+
complete?: (response: WxResponse) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface Wx {
|
|
17
|
+
ready: (callback: () => void) => void;
|
|
18
|
+
error: (callback: (response: WxResponse) => void) => void;
|
|
19
|
+
getLocation: (props: WxGetLocationProps) => void;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ClearWathPosition } from "./compatibleWatchPosition";
|
|
1
2
|
/**
|
|
2
3
|
* @note navigator.geolocation.watchPosition 期间,再调用 watchPosition 或 getCurrentPosition 会导致定位失败。
|
|
3
4
|
*/
|
|
@@ -5,7 +6,7 @@ export declare class SingleGeoWatch {
|
|
|
5
6
|
id: number;
|
|
6
7
|
listeners: Map<number, [PositionCallback, PositionErrorCallback | undefined]>;
|
|
7
8
|
option: PositionOptions;
|
|
8
|
-
|
|
9
|
+
unwatch: ClearWathPosition | undefined;
|
|
9
10
|
constructor(option?: PositionOptions);
|
|
10
11
|
watchPosition(onSuccess: PositionCallback, onError?: PositionErrorCallback): number;
|
|
11
12
|
clearWatch(id: number): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="google.maps" />
|
|
2
2
|
import type { Place, Point } from "../types/interface";
|
|
3
|
+
import type { WxGetLocationSuccessResponse } from "../types/wx";
|
|
3
4
|
export declare const vec2lnglat: ([lng, lat]: [number, number]) => google.maps.LatLngLiteral;
|
|
4
5
|
export interface AsteriskItem {
|
|
5
6
|
type: "normal" | "emphasize";
|
|
@@ -16,8 +17,10 @@ export declare const pipeDefer: <P extends any[], R>(fn: (...args: P) => R) => (
|
|
|
16
17
|
export declare const pipeOnlyLastEffect: <P extends any[], R>(fn: (...arg: P) => Promise<R>) => (...args: P) => Promise<R>;
|
|
17
18
|
export declare const isPlaceEqual: (p1: Place, p2?: Place) => boolean;
|
|
18
19
|
export declare const isPointEqual: (p1: Point, p2?: Point) => boolean;
|
|
20
|
+
export declare const isGeoPositionEqual: (p1: GeolocationPosition, p2?: GeolocationPosition) => boolean;
|
|
19
21
|
export declare const toPlaceType: (maybePlace: {
|
|
20
22
|
name: string;
|
|
21
23
|
lng: string | number;
|
|
22
24
|
lat: string | number;
|
|
23
25
|
}) => Place;
|
|
26
|
+
export declare const wxGetLocationSuccessResponse2GeolocationPosition: (res: WxGetLocationSuccessResponse) => GeolocationPosition;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heycar/heycars-map",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite -c vite.config.dev.ts",
|
|
7
7
|
"dev:lib": "concurrently \"vite build -c vite.config.dev.lib.ts --watch --emptyOutDir false\" \"tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration --watch\"",
|
|
8
|
-
"build": "rm -rf dist && vite build && tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration"
|
|
8
|
+
"build": "rm -rf dist && vite build && tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration",
|
|
9
|
+
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --report-unused-disable-directives --max-warnings 0"
|
|
9
10
|
},
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"module": "./dist/index.js",
|
|
@@ -41,9 +42,6 @@
|
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^17.3.0",
|
|
45
|
-
"@commitlint/config-conventional": "^17.3.0",
|
|
46
|
-
"@commitlint/types": "^17.0.0",
|
|
47
45
|
"@types/google.maps": "^3.52.0",
|
|
48
46
|
"@types/lodash-es": "^4.17.6",
|
|
49
47
|
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
@@ -63,9 +61,7 @@
|
|
|
63
61
|
"eslint-plugin-import": "^2.27.5",
|
|
64
62
|
"eslint-plugin-prettier": "^4.2.1",
|
|
65
63
|
"eslint-plugin-vue": "^9.9.0",
|
|
66
|
-
"lint-staged": "^13.1.2",
|
|
67
64
|
"prettier": "^2.8.4",
|
|
68
|
-
"simple-git-hooks": "^2.8.1",
|
|
69
65
|
"typescript": "^4.9.3",
|
|
70
66
|
"unplugin-vue-jsx": "^0.1.2",
|
|
71
67
|
"vite": "^4.1.0",
|
|
@@ -74,19 +70,6 @@
|
|
|
74
70
|
"vue": "2.7.14",
|
|
75
71
|
"vue-tsc": "^1.0.24"
|
|
76
72
|
},
|
|
77
|
-
"simple-git-hooks": {
|
|
78
|
-
"pre-commit": "pnpm exec lint-staged --concurrent false",
|
|
79
|
-
"commit-msg": "pnpm exec commitlint --edit ${1}"
|
|
80
|
-
},
|
|
81
|
-
"lint-staged": {
|
|
82
|
-
"*.{js,jsx,ts,tsx}": [
|
|
83
|
-
"eslint --fix",
|
|
84
|
-
"prettier --write"
|
|
85
|
-
],
|
|
86
|
-
"*.{md,json,yml,html,css}": [
|
|
87
|
-
"prettier --write"
|
|
88
|
-
]
|
|
89
|
-
},
|
|
90
73
|
"publishConfig": {
|
|
91
74
|
"registry": "https://registry.npmjs.com"
|
|
92
75
|
},
|