@heycar/heycars-map 2.19.0-drivingRouteFail4 → 2.19.0-drivingRouteFail5

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.
@@ -1,5 +1,6 @@
1
1
  import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
2
2
  import { createTypeError, isProxyServiceError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const GAODE_POLYLINE_REGEX = /^(?:-?\d*\.\d+,-?\d*\.\d+)?(?:;-?\d*\.\d+,-?\d*\.\d+)*$/;
4
5
  var GaodeDirectionStatus = /* @__PURE__ */ ((GaodeDirectionStatus2) => {
5
6
  GaodeDirectionStatus2["SUCCESS"] = "1";
@@ -104,9 +105,7 @@ async function apiGaodeDirectionDriving(props) {
104
105
  console.warn(error_message);
105
106
  return { status: "no_data", routes: [], error_message };
106
107
  }
107
- const { protocol, host } = location;
108
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
109
- const url = new URL(proxyUrl, baseUrl);
108
+ const url = createUrlObject(proxyUrl);
110
109
  url.searchParams.set("origin", gaodePointsStringify(origin));
111
110
  url.searchParams.set("destination", gaodePointsStringify([destination]));
112
111
  url.searchParams.set("extensions", extensions);
@@ -1,5 +1,6 @@
1
1
  import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  import { gaodeDirectionStatus2amapDirectionCallbackStatus, isGaodeDirectionResponse, isGaodeMeasurableObject, isGaodeDirectionBasicStep } from "./gaodeDirectionDriving.js";
4
5
  function assertGaodoDirectionWalkingStep(value) {
5
6
  if (isGaodeDirectionBasicStep(value))
@@ -58,9 +59,7 @@ async function apiGaodeDirectionWalking(props) {
58
59
  error_message
59
60
  };
60
61
  }
61
- const { protocol, host } = location;
62
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
63
- const url = new URL(proxyUrl, baseUrl);
62
+ const url = createUrlObject(proxyUrl);
64
63
  url.searchParams.set("origin", gaodePointsStringify([origin]));
65
64
  url.searchParams.set("destination", gaodePointsStringify([destination]));
66
65
  for (const key of [
@@ -1,10 +1,9 @@
1
1
  import { isProxyServiceError } from "../utils/typeChecking.js";
2
2
  import { guid } from "../utils/helper.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const apiGaodeRegeo = async (props) => {
4
5
  const { proxyUrl, lng, lat, language } = props;
5
- const { protocol, host } = location;
6
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
7
- const url = new URL(proxyUrl, baseUrl);
6
+ const url = createUrlObject(proxyUrl);
8
7
  url.searchParams.set("language", language);
9
8
  url.searchParams.set("location", `${lng.toString()},${lat.toString()}`);
10
9
  url.searchParams.set("reqSid", guid());
@@ -1,5 +1,6 @@
1
1
  import { googlePointsStringify, googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const ALL_DIRECTIONS_STATUS = [
4
5
  "INVALID_REQUEST",
5
6
  "MAX_WAYPOINTS_EXCEEDED",
@@ -92,9 +93,7 @@ async function apiGoogleDirections(props) {
92
93
  error_message
93
94
  };
94
95
  }
95
- const { protocol, host } = location;
96
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
97
- const url = new URL(proxyUrl, baseUrl);
96
+ const url = createUrlObject(proxyUrl);
98
97
  url.searchParams.set("origin", googlePointsStringify([origin]));
99
98
  url.searchParams.set("destination", googlePointsStringify([destination]));
100
99
  if (waypoints && waypoints.length > 0)
@@ -1,5 +1,6 @@
1
1
  import { googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const DEFAULT_GOOGLE_ROUTES_FIELDS = ["routes.polyline", "routes.legs"];
4
5
  const ALL_ROUTES_STATUS = [
5
6
  "OK",
@@ -106,9 +107,7 @@ async function apiGoogleRoutes(props) {
106
107
  console.warn("Warning: google routes service is bypassed due to proxyUrl is not provided!");
107
108
  return { routes: [], isCrossBorder: false };
108
109
  }
109
- const { protocol, host } = location;
110
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
111
- const url = new URL(proxyUrl, baseUrl);
110
+ const url = createUrlObject(proxyUrl);
112
111
  url.searchParams.set("fields", DEFAULT_GOOGLE_ROUTES_FIELDS.join(","));
113
112
  const response = await fetch(url, {
114
113
  method: "POST",
@@ -1,5 +1,6 @@
1
1
  import { googlePointsStringify } from "../utils/transform.js";
2
2
  import { isProxyServiceError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const point2snappedPoint = (point) => {
4
5
  const [longitude, latitude] = point;
5
6
  return { location: { longitude, latitude }, placeId: "" };
@@ -37,9 +38,7 @@ async function apiGoogleSnapRoad(props) {
37
38
  snappedPoints: path.map(point2snappedPoint),
38
39
  warningMessage: "Warning: snapRoad service is bypassed due to proxyUrl is not provided!"
39
40
  };
40
- const { protocol, host } = location;
41
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
42
- const url = new URL(proxyUrl, baseUrl);
41
+ const url = createUrlObject(proxyUrl);
43
42
  if (interpolate !== void 0)
44
43
  url.searchParams.set("interpolate", String(interpolate));
45
44
  url.searchParams.set("path", googlePointsStringify(path));
@@ -1,11 +1,10 @@
1
1
  import { isProxyServiceError } from "../utils/typeChecking.js";
2
2
  import { guid } from "../utils/helper.js";
3
3
  import { wgs84ToHK80 } from "../utils/transform.js";
4
+ import { createUrlObject } from "../utils/url.js";
4
5
  const apiHongKongGovernDriving = async (props) => {
5
6
  const { proxyUrl, lng, lat, language } = props;
6
- const { protocol, host } = location;
7
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
8
- const url = new URL(proxyUrl, baseUrl);
7
+ const url = createUrlObject(proxyUrl);
9
8
  const hk80Coord = wgs84ToHK80(lat, lng);
10
9
  url.searchParams.set("lang", language);
11
10
  url.searchParams.set("x", hk80Coord.x.toString());
@@ -94,7 +94,8 @@ const useAmapPlace = (props) => {
94
94
  return;
95
95
  }
96
96
  const { formatted_address, addressComponent } = result.regeocode;
97
- const name = formatted_address || emptyPlaceName;
97
+ const _formmatted_address = typeof formatted_address === "string" ? formatted_address : "";
98
+ const name = _formmatted_address || emptyPlaceName;
98
99
  const displayName = amapPlaceName2DisplayName(name, {
99
100
  isChinese,
100
101
  ...addressComponent
@@ -201,7 +202,7 @@ const useGmapPlace = (props) => {
201
202
  }
202
203
  });
203
204
  geocoder.geocode({ language, location: { lng, lat } }).finally(() => clearTimeout(timer)).then(({ results }) => {
204
- const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
205
+ const name = results[0].formatted_address || emptyPlaceName;
205
206
  const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
206
207
  resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
207
208
  }).catch(handleFailed);
@@ -225,7 +225,7 @@ async function googleServiceApiDrivingRoute(from, to, waypoints, proxyUrl) {
225
225
  });
226
226
  const firstRoute = routes == null ? void 0 : routes[0];
227
227
  if (!firstRoute)
228
- return { path: [], distance: 0, duration: 0, steps: [] };
228
+ return { path: [], distance: 0, duration: 0, steps: [], isCrossBorder };
229
229
  let path = [];
230
230
  let distance = 0;
231
231
  let duration = 0;
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.19.0-drivingRouteFail4";
3
+ const pkgVersion = "2.19.0-drivingRouteFail5";
4
4
  const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
5
  const enableSessionLogKey = (key) => {
6
6
  const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
@@ -0,0 +1 @@
1
+ export declare const createUrlObject: (proxyUrl: string) => URL;
@@ -0,0 +1,9 @@
1
+ const createUrlObject = (proxyUrl) => {
2
+ const { protocol, host } = window.location;
3
+ const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
4
+ const url = new URL(proxyUrl, baseUrl);
5
+ return url;
6
+ };
7
+ export {
8
+ createUrlObject
9
+ };
@@ -1,5 +1,6 @@
1
1
  import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
2
2
  import { createTypeError, isProxyServiceError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const GAODE_POLYLINE_REGEX = /^(?:-?\d*\.\d+,-?\d*\.\d+)?(?:;-?\d*\.\d+,-?\d*\.\d+)*$/;
4
5
  var GaodeDirectionStatus = /* @__PURE__ */ ((GaodeDirectionStatus2) => {
5
6
  GaodeDirectionStatus2["SUCCESS"] = "1";
@@ -104,9 +105,7 @@ async function apiGaodeDirectionDriving(props) {
104
105
  console.warn(error_message);
105
106
  return { status: "no_data", routes: [], error_message };
106
107
  }
107
- const { protocol, host } = location;
108
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
109
- const url = new URL(proxyUrl, baseUrl);
108
+ const url = createUrlObject(proxyUrl);
110
109
  url.searchParams.set("origin", gaodePointsStringify(origin));
111
110
  url.searchParams.set("destination", gaodePointsStringify([destination]));
112
111
  url.searchParams.set("extensions", extensions);
@@ -1,5 +1,6 @@
1
1
  import { gaodePointsStringify, gaodePolyline2amapLngLat } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  import { gaodeDirectionStatus2amapDirectionCallbackStatus, isGaodeDirectionResponse, isGaodeMeasurableObject, isGaodeDirectionBasicStep } from "./gaodeDirectionDriving.js";
4
5
  function assertGaodoDirectionWalkingStep(value) {
5
6
  if (isGaodeDirectionBasicStep(value))
@@ -58,9 +59,7 @@ async function apiGaodeDirectionWalking(props) {
58
59
  error_message
59
60
  };
60
61
  }
61
- const { protocol, host } = location;
62
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
63
- const url = new URL(proxyUrl, baseUrl);
62
+ const url = createUrlObject(proxyUrl);
64
63
  url.searchParams.set("origin", gaodePointsStringify([origin]));
65
64
  url.searchParams.set("destination", gaodePointsStringify([destination]));
66
65
  for (const key of [
@@ -1,10 +1,9 @@
1
1
  import { isProxyServiceError } from "../utils/typeChecking.js";
2
2
  import { guid } from "../utils/helper.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const apiGaodeRegeo = async (props) => {
4
5
  const { proxyUrl, lng, lat, language } = props;
5
- const { protocol, host } = location;
6
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
7
- const url = new URL(proxyUrl, baseUrl);
6
+ const url = createUrlObject(proxyUrl);
8
7
  url.searchParams.set("language", language);
9
8
  url.searchParams.set("location", `${lng.toString()},${lat.toString()}`);
10
9
  url.searchParams.set("reqSid", guid());
@@ -1,5 +1,6 @@
1
1
  import { googlePointsStringify, googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const ALL_DIRECTIONS_STATUS = [
4
5
  "INVALID_REQUEST",
5
6
  "MAX_WAYPOINTS_EXCEEDED",
@@ -92,9 +93,7 @@ async function apiGoogleDirections(props) {
92
93
  error_message
93
94
  };
94
95
  }
95
- const { protocol, host } = location;
96
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
97
- const url = new URL(proxyUrl, baseUrl);
96
+ const url = createUrlObject(proxyUrl);
98
97
  url.searchParams.set("origin", googlePointsStringify([origin]));
99
98
  url.searchParams.set("destination", googlePointsStringify([destination]));
100
99
  if (waypoints && waypoints.length > 0)
@@ -1,5 +1,6 @@
1
1
  import { googleEncodedPolyline2googleLatLng } from "../utils/transform.js";
2
2
  import { isProxyServiceError, createTypeError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const DEFAULT_GOOGLE_ROUTES_FIELDS = ["routes.polyline", "routes.legs"];
4
5
  const ALL_ROUTES_STATUS = [
5
6
  "OK",
@@ -106,9 +107,7 @@ async function apiGoogleRoutes(props) {
106
107
  console.warn("Warning: google routes service is bypassed due to proxyUrl is not provided!");
107
108
  return { routes: [], isCrossBorder: false };
108
109
  }
109
- const { protocol, host } = location;
110
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
111
- const url = new URL(proxyUrl, baseUrl);
110
+ const url = createUrlObject(proxyUrl);
112
111
  url.searchParams.set("fields", DEFAULT_GOOGLE_ROUTES_FIELDS.join(","));
113
112
  const response = await fetch(url, {
114
113
  method: "POST",
@@ -1,5 +1,6 @@
1
1
  import { googlePointsStringify } from "../utils/transform.js";
2
2
  import { isProxyServiceError } from "../utils/typeChecking.js";
3
+ import { createUrlObject } from "../utils/url.js";
3
4
  const point2snappedPoint = (point) => {
4
5
  const [longitude, latitude] = point;
5
6
  return { location: { longitude, latitude }, placeId: "" };
@@ -37,9 +38,7 @@ async function apiGoogleSnapRoad(props) {
37
38
  snappedPoints: path.map(point2snappedPoint),
38
39
  warningMessage: "Warning: snapRoad service is bypassed due to proxyUrl is not provided!"
39
40
  };
40
- const { protocol, host } = location;
41
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
42
- const url = new URL(proxyUrl, baseUrl);
41
+ const url = createUrlObject(proxyUrl);
43
42
  if (interpolate !== void 0)
44
43
  url.searchParams.set("interpolate", String(interpolate));
45
44
  url.searchParams.set("path", googlePointsStringify(path));
@@ -1,11 +1,10 @@
1
1
  import { isProxyServiceError } from "../utils/typeChecking.js";
2
2
  import { guid } from "../utils/helper.js";
3
3
  import { wgs84ToHK80 } from "../utils/transform.js";
4
+ import { createUrlObject } from "../utils/url.js";
4
5
  const apiHongKongGovernDriving = async (props) => {
5
6
  const { proxyUrl, lng, lat, language } = props;
6
- const { protocol, host } = location;
7
- const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
8
- const url = new URL(proxyUrl, baseUrl);
7
+ const url = createUrlObject(proxyUrl);
9
8
  const hk80Coord = wgs84ToHK80(lat, lng);
10
9
  url.searchParams.set("lang", language);
11
10
  url.searchParams.set("x", hk80Coord.x.toString());
@@ -94,7 +94,8 @@ const useAmapPlace = (props) => {
94
94
  return;
95
95
  }
96
96
  const { formatted_address, addressComponent } = result.regeocode;
97
- const name = formatted_address || emptyPlaceName;
97
+ const _formmatted_address = typeof formatted_address === "string" ? formatted_address : "";
98
+ const name = _formmatted_address || emptyPlaceName;
98
99
  const displayName = amapPlaceName2DisplayName(name, {
99
100
  isChinese,
100
101
  ...addressComponent
@@ -201,7 +202,7 @@ const useGmapPlace = (props) => {
201
202
  }
202
203
  });
203
204
  geocoder.geocode({ language, location: { lng, lat } }).finally(() => clearTimeout(timer)).then(({ results }) => {
204
- const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
205
+ const name = results[0].formatted_address || emptyPlaceName;
205
206
  const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
206
207
  resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
207
208
  }).catch(handleFailed);
@@ -225,7 +225,7 @@ async function googleServiceApiDrivingRoute(from, to, waypoints, proxyUrl) {
225
225
  });
226
226
  const firstRoute = routes == null ? void 0 : routes[0];
227
227
  if (!firstRoute)
228
- return { path: [], distance: 0, duration: 0, steps: [] };
228
+ return { path: [], distance: 0, duration: 0, steps: [], isCrossBorder };
229
229
  let path = [];
230
230
  let distance = 0;
231
231
  let duration = 0;
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.19.0-drivingRouteFail4";
3
+ const pkgVersion = "2.19.0-drivingRouteFail5";
4
4
  const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
5
  const enableSessionLogKey = (key) => {
6
6
  const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
@@ -0,0 +1 @@
1
+ export declare const createUrlObject: (proxyUrl: string) => URL;
@@ -0,0 +1,9 @@
1
+ const createUrlObject = (proxyUrl) => {
2
+ const { protocol, host } = window.location;
3
+ const baseUrl = proxyUrl.startsWith(protocol) ? void 0 : `${protocol}//${host}`;
4
+ const url = new URL(proxyUrl, baseUrl);
5
+ return url;
6
+ };
7
+ export {
8
+ createUrlObject
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.19.0-drivingRouteFail4",
3
+ "version": "2.19.0-drivingRouteFail5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",