@heycar/heycars-map 2.17.0-curve9 → 2.18.0-apiLocalization2

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/v2/App.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { h } from "vue";
2
2
  import { defineComponent, ref } from "vue-demi";
3
3
  import { MapProvider } from "./components/MapProvider/MapProvider.js";
4
- import { DemoBusinessQuoting } from "./Demo/DemoBusinessQuoting.js";
4
+ import { DemoBusinessRecomendPlace } from "./Demo/DemoBusinessRecomendPlace.js";
5
5
  const gmapApiKey = {}.VITE_GMAP_API_KEY;
6
6
  const gmapId = {}.VITE_GMAP_MAP_ID;
7
7
  const amapApiKey = {}.VITE_AMAP_API_KEY;
@@ -18,6 +18,7 @@ const App = defineComponent({
18
18
  "gmapKey": gmapApiKey,
19
19
  "language": "en",
20
20
  "supplier": supplierRef.value,
21
+ "gaodeRegeoProxyUrl": "/overseas/amap/regeo",
21
22
  "hkGovernRegeoProxyUrl": "/overseas/gov/hk/identify",
22
23
  "googleSnapRoadProxyUrl": "/overseas/maps/snapToRoads",
23
24
  "googleRoutesProxyUrl": "/overseas/maps/routes/directions/v2",
@@ -50,7 +51,7 @@ const App = defineComponent({
50
51
  "fail": () => console.log(`${supplierRef.value} load failed`),
51
52
  "downloadOptimizeEnd": () => console.log(`${supplierRef.value} load download optimize end`)
52
53
  }
53
- }, [h(DemoBusinessQuoting)]);
54
+ }, [h(DemoBusinessRecomendPlace)]);
54
55
  }
55
56
  });
56
57
  export {
@@ -0,0 +1,7 @@
1
+ export interface GaodeRegeoProps {
2
+ proxyUrl: string;
3
+ lng: number;
4
+ lat: number;
5
+ language: string;
6
+ }
7
+ export declare const apiGaodeRegeo: (props: GaodeRegeoProps) => Promise<any>;
@@ -0,0 +1,28 @@
1
+ import { isProxyServiceError } from "../utils/typeChecking.js";
2
+ import { guid } from "../utils/helper.js";
3
+ const apiGaodeRegeo = async (props) => {
4
+ 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);
8
+ url.searchParams.set("language", language);
9
+ url.searchParams.set("location", `${lng.toString()},${lat.toString()}`);
10
+ url.searchParams.set("reqSid", guid());
11
+ const response = await fetch(url);
12
+ if (response.ok) {
13
+ const result = await response.json();
14
+ return result;
15
+ }
16
+ const error = await response.json();
17
+ if (isProxyServiceError(error)) {
18
+ const { code, msg } = error;
19
+ throw new Error(`apiGaodeRegeo proxy failed code: ${code}, msg:
20
+ ${msg}`);
21
+ }
22
+ throw new Error(
23
+ `apiGaodeRegeo failed with unrecognized server response: ${JSON.stringify(error)}`
24
+ );
25
+ };
26
+ export {
27
+ apiGaodeRegeo
28
+ };
@@ -1,4 +1,10 @@
1
- export declare const apiHongKongGovernDriving: (props: any) => Promise<{
1
+ export interface HongKongGovernDrivingProps {
2
+ proxyUrl: string;
3
+ lng: number;
4
+ lat: number;
5
+ language: string;
6
+ }
7
+ export declare const apiHongKongGovernDriving: (props: HongKongGovernDrivingProps) => Promise<{
2
8
  result: any;
3
9
  origin: {
4
10
  x: number;
@@ -5,7 +5,7 @@ import { type GmapLoaderProps, type UseMapLoaderProps } from "../../hooks/useMap
5
5
  import { type MapSupplierPayolad } from "../../hooks/useMapSupplier";
6
6
  import type { AmapMap } from "../../types/interface";
7
7
  import { type AmapProps } from "../Amap";
8
- export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl">;
8
+ export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl">;
9
9
  export declare const MapProvider: import("vue-demi").DefineComponent<import("vue3").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "success" | "fail" | "downloadOptimizeEnd", MapProviderProps>;
10
10
  export interface HeycarMapProps extends Pick<GmapLoaderProps, "fallback" | "loading">, Pick<AmapProps, "center" | "zoom"> {
11
11
  mapRef?: SetMap<AmapMap> | SetMap<google.maps.Map>;
@@ -50,7 +50,7 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
50
50
  var _a;
51
51
  return h("div", [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
52
52
  };
53
- }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl"]);
53
+ }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl"]);
54
54
  const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
55
55
  slots,
56
56
  emit,
@@ -1,10 +1,10 @@
1
1
  import { reactive } from "vue-demi";
2
2
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
- import { googleServiceApiDrivingRoute, amapJsApiDrivingRoute, gaodeServiceApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
3
+ import { googleServiceApiDrivingRoute, gaodeServiceApiDrivingRoute, amapJsApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
4
4
  import { inTaiwan, inKorean } from "./useMapInChina.js";
5
5
  import { useMapSupplier } from "./useMapSupplier.js";
6
6
  const useADrivingRoute = (props) => {
7
- const { googleRoutesProxyUrl } = useMapSupplier();
7
+ const { googleRoutesProxyUrl, gaodeDirectionDrivingProxyUrl } = useMapSupplier();
8
8
  const outputRoute = reactive({
9
9
  path: [],
10
10
  distance: 0,
@@ -15,7 +15,7 @@ const useADrivingRoute = (props) => {
15
15
  });
16
16
  const amapDriving = new AMap.Driving({ ferry: 1 });
17
17
  const apiMapDrivingRoute = (from, to, waypoints = []) => {
18
- return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : amapJsApiDrivingRoute(from, to, waypoints, amapDriving);
18
+ return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : gaodeDirectionDrivingProxyUrl ? gaodeServiceApiDrivingRoute(from, to, waypoints, gaodeDirectionDrivingProxyUrl) : amapJsApiDrivingRoute(from, to, waypoints, amapDriving);
19
19
  };
20
20
  watchPostEffectForDeepOption(
21
21
  () => {
@@ -9,11 +9,12 @@ import { inChina, inTaiwan, inHongkong } from "./useMapInChina.js";
9
9
  import { useMapSupplier } from "./useMapSupplier.js";
10
10
  import { useUpdate } from "./useUdate.js";
11
11
  import { useMapGCJ02 } from "./useMapGCJ02.js";
12
+ import { apiGaodeRegeo } from "../api/gaodeRegeo.js";
12
13
  const useAmapPlace = (props) => {
13
14
  const { signal: inputSignal, onChange, emptyPlaceName } = props;
14
15
  const defaultPoint = [...props.pointRef.value];
15
16
  const pointRef = ref(defaultPoint);
16
- const { readyPromise, language, hkGovernRegeoProxyUrl } = useMapSupplier();
17
+ const { readyPromise, language, hkGovernRegeoProxyUrl, gaodeRegeoProxyUrl } = useMapSupplier();
17
18
  const { toCoordinateType } = useMapGCJ02();
18
19
  const place = reactive({
19
20
  lng: pointRef.value[0],
@@ -41,7 +42,6 @@ const useAmapPlace = (props) => {
41
42
  resolve({ lng, lat, name, displayName });
42
43
  };
43
44
  readyPromise.then(() => {
44
- const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
45
45
  const pipeTw = createPipeTw(language === "zh-TW");
46
46
  const isChinese = inChina([lng, lat]) || inTaiwan([lng, lat]);
47
47
  const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
@@ -75,36 +75,68 @@ const useAmapPlace = (props) => {
75
75
  }
76
76
  });
77
77
  }
78
- geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
79
- clearTimeout(timer);
80
- if (isUseHKGovern) {
81
- const diff = Date.now() - startTime;
82
- console.log("==time of AmapReGeo==", diff);
83
- const rest = HK_GOVERN_API_TIMEOUT - diff;
84
- if (rest >= 0)
85
- await sleep(rest);
86
- console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
87
- if (hkReturned)
88
- return;
89
- }
90
- switch (status) {
91
- case "complete": {
92
- const { formattedAddress, addressComponent } = result.regeocode;
93
- const name = formattedAddress ? formattedAddress : emptyPlaceName;
94
- const displayName = amapPlaceName2DisplayName(name, {
95
- isChinese,
96
- ...addressComponent
97
- });
98
- amapReturned = true;
99
- resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
100
- return;
78
+ if (gaodeRegeoProxyUrl) {
79
+ apiGaodeRegeo({
80
+ proxyUrl: gaodeRegeoProxyUrl,
81
+ lng,
82
+ lat,
83
+ language: language === "en" ? "en" : "zh_cn"
84
+ }).then(async (result) => {
85
+ clearTimeout(timer);
86
+ if (isUseHKGovern) {
87
+ const diff = Date.now() - startTime;
88
+ console.log("==time of AmapReGeo==", diff);
89
+ const rest = HK_GOVERN_API_TIMEOUT - diff;
90
+ if (rest >= 0)
91
+ await sleep(rest);
92
+ console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
93
+ if (hkReturned)
94
+ return;
101
95
  }
102
- case "no_data":
103
- case "error": {
104
- handleFailed();
96
+ const { formatted_address, addressComponent } = result.regeocode;
97
+ const name = formatted_address || emptyPlaceName;
98
+ const displayName = amapPlaceName2DisplayName(name, {
99
+ isChinese,
100
+ ...addressComponent
101
+ });
102
+ amapReturned = true;
103
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
104
+ }).catch(() => {
105
+ handleFailed();
106
+ });
107
+ } else {
108
+ const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
109
+ geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
110
+ clearTimeout(timer);
111
+ if (isUseHKGovern) {
112
+ const diff = Date.now() - startTime;
113
+ console.log("==time of AmapReGeo==", diff);
114
+ const rest = HK_GOVERN_API_TIMEOUT - diff;
115
+ if (rest >= 0)
116
+ await sleep(rest);
117
+ console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
118
+ if (hkReturned)
119
+ return;
105
120
  }
106
- }
107
- });
121
+ switch (status) {
122
+ case "complete": {
123
+ const { formattedAddress, addressComponent } = result.regeocode;
124
+ const name = formattedAddress ? formattedAddress : emptyPlaceName;
125
+ const displayName = amapPlaceName2DisplayName(name, {
126
+ isChinese,
127
+ ...addressComponent
128
+ });
129
+ amapReturned = true;
130
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
131
+ return;
132
+ }
133
+ case "no_data":
134
+ case "error": {
135
+ handleFailed();
136
+ }
137
+ }
138
+ });
139
+ }
108
140
  }, handleFailed);
109
141
  const timer = setTimeout(() => {
110
142
  console.warn("高德逆地理请求超时!");
@@ -13,6 +13,7 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
13
13
  googleRoutesProxyUrl?: string;
14
14
  googleSnapRoadProxyUrl?: string;
15
15
  hkGovernRegeoProxyUrl?: string;
16
+ gaodeRegeoProxyUrl?: string;
16
17
  themeVariables?: MapThemeVariables;
17
18
  renderLoadFailedTitle?: (status: Status) => string | undefined;
18
19
  renderLoadFailedDescription?: (status: Status) => string | undefined;
@@ -1,7 +1,7 @@
1
1
  import { shallowRef } from "vue-demi";
2
2
  import { MAX_DEVIATION_DISTANCE_WALKING } from "../api/contants.js";
3
3
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
4
- import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
4
+ import { googleServiceApiWalkingRoute, gaodeServiceApiWalkingRoute, amapJsApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
5
5
  import { findClosestPointInLine } from "../utils/geometry.js";
6
6
  import { distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
7
7
  import { spaceLog } from "../utils/log.js";
@@ -44,12 +44,12 @@ const findBestContinuation = (args, cacheEntries) => {
44
44
  const memoizeAmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
45
45
  const memoizeGmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
46
46
  const useAWalkingRoute = (props) => {
47
- const { googleRoutesProxyUrl } = useMapSupplier();
47
+ const { googleRoutesProxyUrl, gaodeDirectionWalkingProxyUrl } = useMapSupplier();
48
48
  const pathRef = shallowRef([]);
49
49
  const amapWalking = new AMap.Walking({});
50
50
  const apiMapWalkingRoute = memoizeAmapWalkingRoute((from, to) => {
51
51
  spaceLog("apiMapWalkingRoute", `amap from = ${from} to = ${to}`);
52
- return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
52
+ return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : gaodeDirectionWalkingProxyUrl ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
53
53
  });
54
54
  watchPostEffectForDeepOption(
55
55
  () => {
@@ -72,7 +72,8 @@ async function gaodeServiceApiDrivingRoute(from, to, waypoints, proxyUrl) {
72
72
  proxyUrl,
73
73
  origin: [from],
74
74
  destination: to,
75
- waypoints
75
+ waypoints,
76
+ ferry: 1
76
77
  });
77
78
  const trafficJams = {};
78
79
  switch (status) {
@@ -219,6 +219,7 @@ function androidWatchPosition(onSuccess, onError, option, getLocationFn) {
219
219
  if (isHandled)
220
220
  return;
221
221
  isHandled = true;
222
+ console.log("==GeoLocation assert==", JSON.stringify(geoLocationPosition), typeof HEYCAR_GEOLOCATION_GET_CURRENT_POSITION === "function");
222
223
  geoErrorMessage = void 0;
223
224
  resolve(geoLocationPosition);
224
225
  },
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.17.0-curve9";
3
+ const pkgVersion = "2.18.0-apiLocalization2";
4
4
  const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
5
  const enableSessionLogKey = (key) => {
6
6
  const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
@@ -119,10 +119,22 @@ const amapPlaceName2DisplayName = (name, options) => {
119
119
  };
120
120
  function amapPlaceName2DisplayNameInChinese(name, options) {
121
121
  const { province, city, district, township, building, neighborhood } = options;
122
- if (building)
123
- return building;
124
- if (neighborhood)
125
- return neighborhood;
122
+ if (typeof building === "string") {
123
+ if (building)
124
+ return building;
125
+ } else {
126
+ const { name: name2 } = building;
127
+ if (typeof name2 === "string" && name2)
128
+ return name2;
129
+ }
130
+ if (typeof neighborhood === "string") {
131
+ if (neighborhood)
132
+ return neighborhood;
133
+ } else {
134
+ const { name: name2 } = neighborhood;
135
+ if (typeof name2 === "string" && name2)
136
+ return name2;
137
+ }
126
138
  let result = name;
127
139
  for (const item of [province, city, district]) {
128
140
  const replacedName2 = result.replace(item, "");
@@ -138,10 +150,20 @@ function amapPlaceName2DisplayNameInChinese(name, options) {
138
150
  const NOT_ONLY_NUMBERS_REGEX = /[^\d\s-]/;
139
151
  function amapPlaceName2DisplayNameOutChinese(name, options) {
140
152
  const { adcode, province, city, district, township, street, streetNumber } = options;
141
- if (street === "Unnamed Road")
142
- return name;
143
- if (street || streetNumber)
144
- return `${street} ${streetNumber}`;
153
+ if (typeof streetNumber === "string") {
154
+ if (street === "Unnamed Road")
155
+ return name;
156
+ if (street || streetNumber)
157
+ return `${street} ${streetNumber}`;
158
+ } else {
159
+ const { number, street: streetNumberStreet } = streetNumber;
160
+ if (streetNumberStreet === "Unnamed Road")
161
+ return name;
162
+ const streetNumberItem = typeof number === "string" ? number : "";
163
+ const _streetNumberStreet = typeof streetNumberStreet === "string" ? streetNumberStreet : "";
164
+ if (_streetNumberStreet || streetNumberItem)
165
+ return `${streetNumberStreet} ${streetNumberItem}`;
166
+ }
145
167
  const idxs = [];
146
168
  for (const token of [adcode, province, city, district, township]) {
147
169
  if (!token)
@@ -150,6 +150,7 @@ function toGeolocationGetCurrentPosition(fn, fnName = fn.name) {
150
150
  });
151
151
  return;
152
152
  }
153
+ console.log("==injected geoPosition==", JSON.stringify(position));
153
154
  onSuccess(position);
154
155
  };
155
156
  const asseertedOnError = (error) => onError(toGeolocationPositionError(error, prefix));
package/dist/v3/App.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createVNode } from "vue";
2
2
  import { defineComponent, ref } from "vue-demi";
3
3
  import { MapProvider } from "./components/MapProvider/MapProvider.js";
4
- import { DemoBusinessQuoting } from "./Demo/DemoBusinessQuoting.js";
4
+ import { DemoBusinessRecomendPlace } from "./Demo/DemoBusinessRecomendPlace.js";
5
5
  const gmapApiKey = {}.VITE_GMAP_API_KEY;
6
6
  const gmapId = {}.VITE_GMAP_MAP_ID;
7
7
  const amapApiKey = {}.VITE_AMAP_API_KEY;
@@ -17,6 +17,7 @@ const App = /* @__PURE__ */ defineComponent({
17
17
  "gmapKey": gmapApiKey,
18
18
  "language": "en",
19
19
  "supplier": supplierRef.value,
20
+ "gaodeRegeoProxyUrl": "/overseas/amap/regeo",
20
21
  "hkGovernRegeoProxyUrl": "/overseas/gov/hk/identify",
21
22
  "googleSnapRoadProxyUrl": "/overseas/maps/snapToRoads",
22
23
  "googleRoutesProxyUrl": "/overseas/maps/routes/directions/v2",
@@ -47,7 +48,7 @@ const App = /* @__PURE__ */ defineComponent({
47
48
  "onDownloadOptimizeEnd": () => console.log(`${supplierRef.value} load download optimize end`),
48
49
  "reportLog": () => console.log("reportLog function is called")
49
50
  }, {
50
- default: () => [createVNode(DemoBusinessQuoting, null, null)]
51
+ default: () => [createVNode(DemoBusinessRecomendPlace, null, null)]
51
52
  });
52
53
  }
53
54
  });
@@ -0,0 +1,7 @@
1
+ export interface GaodeRegeoProps {
2
+ proxyUrl: string;
3
+ lng: number;
4
+ lat: number;
5
+ language: string;
6
+ }
7
+ export declare const apiGaodeRegeo: (props: GaodeRegeoProps) => Promise<any>;
@@ -0,0 +1,28 @@
1
+ import { isProxyServiceError } from "../utils/typeChecking.js";
2
+ import { guid } from "../utils/helper.js";
3
+ const apiGaodeRegeo = async (props) => {
4
+ 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);
8
+ url.searchParams.set("language", language);
9
+ url.searchParams.set("location", `${lng.toString()},${lat.toString()}`);
10
+ url.searchParams.set("reqSid", guid());
11
+ const response = await fetch(url);
12
+ if (response.ok) {
13
+ const result = await response.json();
14
+ return result;
15
+ }
16
+ const error = await response.json();
17
+ if (isProxyServiceError(error)) {
18
+ const { code, msg } = error;
19
+ throw new Error(`apiGaodeRegeo proxy failed code: ${code}, msg:
20
+ ${msg}`);
21
+ }
22
+ throw new Error(
23
+ `apiGaodeRegeo failed with unrecognized server response: ${JSON.stringify(error)}`
24
+ );
25
+ };
26
+ export {
27
+ apiGaodeRegeo
28
+ };
@@ -1,4 +1,10 @@
1
- export declare const apiHongKongGovernDriving: (props: any) => Promise<{
1
+ export interface HongKongGovernDrivingProps {
2
+ proxyUrl: string;
3
+ lng: number;
4
+ lat: number;
5
+ language: string;
6
+ }
7
+ export declare const apiHongKongGovernDriving: (props: HongKongGovernDrivingProps) => Promise<{
2
8
  result: any;
3
9
  origin: {
4
10
  x: number;
@@ -5,7 +5,7 @@ import { Status, type GmapLoaderProps, type UseMapLoaderProps } from "../../hook
5
5
  import { type MapSupplierPayolad } from "../../hooks/useMapSupplier";
6
6
  import type { AmapMap } from "../../types/interface";
7
7
  import { type AmapProps } from "../Amap";
8
- export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl">;
8
+ export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "reportLog" | "hkGovernRegeoProxyUrl" | "gaodeRegeoProxyUrl">;
9
9
  export declare const MapProvider: import("vue-demi").DefineComponent<import("vue-demi").ComponentObjectPropsOptions<MapProviderProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<MapProviderProps, Required<MapProviderProps>>, "success" | "fail" | "downloadOptimizeEnd", import("vue-demi").PublicProps, MapProviderProps, MapProviderProps, import("vue-demi").SlotsType<{
10
10
  renderLoadFailedTitle?: ((status: Status) => string | undefined) | undefined;
11
11
  renderLoadFailedDescription?: ((status: Status) => string | undefined) | undefined;
@@ -53,7 +53,7 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
53
53
  var _a;
54
54
  return createVNode("div", null, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
55
55
  };
56
- }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl"]);
56
+ }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "reportLog", "hkGovernRegeoProxyUrl", "gaodeRegeoProxyUrl"]);
57
57
  const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
58
58
  slots,
59
59
  emit,
@@ -1,10 +1,10 @@
1
1
  import { reactive } from "vue-demi";
2
2
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
- import { googleServiceApiDrivingRoute, amapJsApiDrivingRoute, gaodeServiceApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
3
+ import { googleServiceApiDrivingRoute, gaodeServiceApiDrivingRoute, amapJsApiDrivingRoute, gmapJsApiDrivingRoute } from "../utils/compatibleDrivingRoute.js";
4
4
  import { inTaiwan, inKorean } from "./useMapInChina.js";
5
5
  import { useMapSupplier } from "./useMapSupplier.js";
6
6
  const useADrivingRoute = (props) => {
7
- const { googleRoutesProxyUrl } = useMapSupplier();
7
+ const { googleRoutesProxyUrl, gaodeDirectionDrivingProxyUrl } = useMapSupplier();
8
8
  const outputRoute = reactive({
9
9
  path: [],
10
10
  distance: 0,
@@ -15,7 +15,7 @@ const useADrivingRoute = (props) => {
15
15
  });
16
16
  const amapDriving = new AMap.Driving({ ferry: 1 });
17
17
  const apiMapDrivingRoute = (from, to, waypoints = []) => {
18
- return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : amapJsApiDrivingRoute(from, to, waypoints, amapDriving);
18
+ return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : gaodeDirectionDrivingProxyUrl ? gaodeServiceApiDrivingRoute(from, to, waypoints, gaodeDirectionDrivingProxyUrl) : amapJsApiDrivingRoute(from, to, waypoints, amapDriving);
19
19
  };
20
20
  watchPostEffectForDeepOption(
21
21
  () => {
@@ -9,11 +9,12 @@ import { inChina, inTaiwan, inHongkong } from "./useMapInChina.js";
9
9
  import { useMapSupplier } from "./useMapSupplier.js";
10
10
  import { useUpdate } from "./useUdate.js";
11
11
  import { useMapGCJ02 } from "./useMapGCJ02.js";
12
+ import { apiGaodeRegeo } from "../api/gaodeRegeo.js";
12
13
  const useAmapPlace = (props) => {
13
14
  const { signal: inputSignal, onChange, emptyPlaceName } = props;
14
15
  const defaultPoint = [...props.pointRef.value];
15
16
  const pointRef = ref(defaultPoint);
16
- const { readyPromise, language, hkGovernRegeoProxyUrl } = useMapSupplier();
17
+ const { readyPromise, language, hkGovernRegeoProxyUrl, gaodeRegeoProxyUrl } = useMapSupplier();
17
18
  const { toCoordinateType } = useMapGCJ02();
18
19
  const place = reactive({
19
20
  lng: pointRef.value[0],
@@ -41,7 +42,6 @@ const useAmapPlace = (props) => {
41
42
  resolve({ lng, lat, name, displayName });
42
43
  };
43
44
  readyPromise.then(() => {
44
- const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
45
45
  const pipeTw = createPipeTw(language === "zh-TW");
46
46
  const isChinese = inChina([lng, lat]) || inTaiwan([lng, lat]);
47
47
  const isUseHKGovern = inHongkong([lng, lat]) && hkGovernRegeoProxyUrl;
@@ -75,36 +75,68 @@ const useAmapPlace = (props) => {
75
75
  }
76
76
  });
77
77
  }
78
- geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
79
- clearTimeout(timer);
80
- if (isUseHKGovern) {
81
- const diff = Date.now() - startTime;
82
- console.log("==time of AmapReGeo==", diff);
83
- const rest = HK_GOVERN_API_TIMEOUT - diff;
84
- if (rest >= 0)
85
- await sleep(rest);
86
- console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
87
- if (hkReturned)
88
- return;
89
- }
90
- switch (status) {
91
- case "complete": {
92
- const { formattedAddress, addressComponent } = result.regeocode;
93
- const name = formattedAddress ? formattedAddress : emptyPlaceName;
94
- const displayName = amapPlaceName2DisplayName(name, {
95
- isChinese,
96
- ...addressComponent
97
- });
98
- amapReturned = true;
99
- resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
100
- return;
78
+ if (gaodeRegeoProxyUrl) {
79
+ apiGaodeRegeo({
80
+ proxyUrl: gaodeRegeoProxyUrl,
81
+ lng,
82
+ lat,
83
+ language: language === "en" ? "en" : "zh_cn"
84
+ }).then(async (result) => {
85
+ clearTimeout(timer);
86
+ if (isUseHKGovern) {
87
+ const diff = Date.now() - startTime;
88
+ console.log("==time of AmapReGeo==", diff);
89
+ const rest = HK_GOVERN_API_TIMEOUT - diff;
90
+ if (rest >= 0)
91
+ await sleep(rest);
92
+ console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
93
+ if (hkReturned)
94
+ return;
101
95
  }
102
- case "no_data":
103
- case "error": {
104
- handleFailed();
96
+ const { formatted_address, addressComponent } = result.regeocode;
97
+ const name = formatted_address || emptyPlaceName;
98
+ const displayName = amapPlaceName2DisplayName(name, {
99
+ isChinese,
100
+ ...addressComponent
101
+ });
102
+ amapReturned = true;
103
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
104
+ }).catch(() => {
105
+ handleFailed();
106
+ });
107
+ } else {
108
+ const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
109
+ geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
110
+ clearTimeout(timer);
111
+ if (isUseHKGovern) {
112
+ const diff = Date.now() - startTime;
113
+ console.log("==time of AmapReGeo==", diff);
114
+ const rest = HK_GOVERN_API_TIMEOUT - diff;
115
+ if (rest >= 0)
116
+ await sleep(rest);
117
+ console.log("==time of AmapReGeoWaitEnd==", Date.now() - startTime);
118
+ if (hkReturned)
119
+ return;
105
120
  }
106
- }
107
- });
121
+ switch (status) {
122
+ case "complete": {
123
+ const { formattedAddress, addressComponent } = result.regeocode;
124
+ const name = formattedAddress ? formattedAddress : emptyPlaceName;
125
+ const displayName = amapPlaceName2DisplayName(name, {
126
+ isChinese,
127
+ ...addressComponent
128
+ });
129
+ amapReturned = true;
130
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
131
+ return;
132
+ }
133
+ case "no_data":
134
+ case "error": {
135
+ handleFailed();
136
+ }
137
+ }
138
+ });
139
+ }
108
140
  }, handleFailed);
109
141
  const timer = setTimeout(() => {
110
142
  console.warn("高德逆地理请求超时!");
@@ -13,6 +13,7 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
13
13
  googleRoutesProxyUrl?: string;
14
14
  googleSnapRoadProxyUrl?: string;
15
15
  hkGovernRegeoProxyUrl?: string;
16
+ gaodeRegeoProxyUrl?: string;
16
17
  themeVariables?: MapThemeVariables;
17
18
  renderLoadFailedTitle?: (status: Status) => string | undefined;
18
19
  renderLoadFailedDescription?: (status: Status) => string | undefined;
@@ -1,7 +1,7 @@
1
1
  import { shallowRef } from "vue-demi";
2
2
  import { MAX_DEVIATION_DISTANCE_WALKING } from "../api/contants.js";
3
3
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
4
- import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
4
+ import { googleServiceApiWalkingRoute, gaodeServiceApiWalkingRoute, amapJsApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
5
5
  import { findClosestPointInLine } from "../utils/geometry.js";
6
6
  import { distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
7
7
  import { spaceLog } from "../utils/log.js";
@@ -44,12 +44,12 @@ const findBestContinuation = (args, cacheEntries) => {
44
44
  const memoizeAmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
45
45
  const memoizeGmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
46
46
  const useAWalkingRoute = (props) => {
47
- const { googleRoutesProxyUrl } = useMapSupplier();
47
+ const { googleRoutesProxyUrl, gaodeDirectionWalkingProxyUrl } = useMapSupplier();
48
48
  const pathRef = shallowRef([]);
49
49
  const amapWalking = new AMap.Walking({});
50
50
  const apiMapWalkingRoute = memoizeAmapWalkingRoute((from, to) => {
51
51
  spaceLog("apiMapWalkingRoute", `amap from = ${from} to = ${to}`);
52
- return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
52
+ return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : gaodeDirectionWalkingProxyUrl ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
53
53
  });
54
54
  watchPostEffectForDeepOption(
55
55
  () => {
@@ -72,7 +72,8 @@ async function gaodeServiceApiDrivingRoute(from, to, waypoints, proxyUrl) {
72
72
  proxyUrl,
73
73
  origin: [from],
74
74
  destination: to,
75
- waypoints
75
+ waypoints,
76
+ ferry: 1
76
77
  });
77
78
  const trafficJams = {};
78
79
  switch (status) {
@@ -219,6 +219,7 @@ function androidWatchPosition(onSuccess, onError, option, getLocationFn) {
219
219
  if (isHandled)
220
220
  return;
221
221
  isHandled = true;
222
+ console.log("==GeoLocation assert==", JSON.stringify(geoLocationPosition), typeof HEYCAR_GEOLOCATION_GET_CURRENT_POSITION === "function");
222
223
  geoErrorMessage = void 0;
223
224
  resolve(geoLocationPosition);
224
225
  },
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.17.0-curve9";
3
+ const pkgVersion = "2.18.0-apiLocalization2";
4
4
  const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
5
  const enableSessionLogKey = (key) => {
6
6
  const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
@@ -119,10 +119,22 @@ const amapPlaceName2DisplayName = (name, options) => {
119
119
  };
120
120
  function amapPlaceName2DisplayNameInChinese(name, options) {
121
121
  const { province, city, district, township, building, neighborhood } = options;
122
- if (building)
123
- return building;
124
- if (neighborhood)
125
- return neighborhood;
122
+ if (typeof building === "string") {
123
+ if (building)
124
+ return building;
125
+ } else {
126
+ const { name: name2 } = building;
127
+ if (typeof name2 === "string" && name2)
128
+ return name2;
129
+ }
130
+ if (typeof neighborhood === "string") {
131
+ if (neighborhood)
132
+ return neighborhood;
133
+ } else {
134
+ const { name: name2 } = neighborhood;
135
+ if (typeof name2 === "string" && name2)
136
+ return name2;
137
+ }
126
138
  let result = name;
127
139
  for (const item of [province, city, district]) {
128
140
  const replacedName2 = result.replace(item, "");
@@ -138,10 +150,20 @@ function amapPlaceName2DisplayNameInChinese(name, options) {
138
150
  const NOT_ONLY_NUMBERS_REGEX = /[^\d\s-]/;
139
151
  function amapPlaceName2DisplayNameOutChinese(name, options) {
140
152
  const { adcode, province, city, district, township, street, streetNumber } = options;
141
- if (street === "Unnamed Road")
142
- return name;
143
- if (street || streetNumber)
144
- return `${street} ${streetNumber}`;
153
+ if (typeof streetNumber === "string") {
154
+ if (street === "Unnamed Road")
155
+ return name;
156
+ if (street || streetNumber)
157
+ return `${street} ${streetNumber}`;
158
+ } else {
159
+ const { number, street: streetNumberStreet } = streetNumber;
160
+ if (streetNumberStreet === "Unnamed Road")
161
+ return name;
162
+ const streetNumberItem = typeof number === "string" ? number : "";
163
+ const _streetNumberStreet = typeof streetNumberStreet === "string" ? streetNumberStreet : "";
164
+ if (_streetNumberStreet || streetNumberItem)
165
+ return `${streetNumberStreet} ${streetNumberItem}`;
166
+ }
145
167
  const idxs = [];
146
168
  for (const token of [adcode, province, city, district, township]) {
147
169
  if (!token)
@@ -150,6 +150,7 @@ function toGeolocationGetCurrentPosition(fn, fnName = fn.name) {
150
150
  });
151
151
  return;
152
152
  }
153
+ console.log("==injected geoPosition==", JSON.stringify(position));
153
154
  onSuccess(position);
154
155
  };
155
156
  const asseertedOnError = (error) => onError(toGeolocationPositionError(error, prefix));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.17.0-curve9",
3
+ "version": "2.18.0-apiLocalization2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",