@heycar/heycars-map 2.15.5-drivingCorrect → 2.15.6-hkGovernApi

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.
Files changed (47) hide show
  1. package/dist/v2/App.js +3 -2
  2. package/dist/v2/Demo/DemoBusinessRecomendPlace.js +2 -2
  3. package/dist/v2/api/contants.d.ts +2 -0
  4. package/dist/v2/api/contants.js +4 -0
  5. package/dist/v2/api/hongkongGovernDriving.d.ts +7 -0
  6. package/dist/v2/api/hongkongGovernDriving.js +31 -0
  7. package/dist/v2/components/MapProvider/MapProvider.d.ts +1 -1
  8. package/dist/v2/components/MapProvider/MapProvider.js +1 -1
  9. package/dist/v2/hooks/useDrivingRoute.js +1 -1
  10. package/dist/v2/hooks/useMapPlace.js +52 -6
  11. package/dist/v2/hooks/useMapRecomendPlace.js +1 -0
  12. package/dist/v2/hooks/useMapSupplier.d.ts +1 -0
  13. package/dist/v2/index.d.ts +1 -0
  14. package/dist/v2/index.js +6 -0
  15. package/dist/v2/utils/geometryPolygon.d.ts +1 -0
  16. package/dist/v2/utils/geometryPolygon.js +8 -0
  17. package/dist/v2/utils/helper.d.ts +1 -0
  18. package/dist/v2/utils/helper.js +14 -0
  19. package/dist/v2/utils/hongkongGovernGeoCoder.d.ts +46 -0
  20. package/dist/v2/utils/hongkongGovernGeoCoder.js +134 -0
  21. package/dist/v2/utils/log.js +1 -1
  22. package/dist/v2/utils/transform.d.ts +15 -1
  23. package/dist/v2/utils/transform.js +81 -0
  24. package/dist/v3/App.js +3 -2
  25. package/dist/v3/Demo/DemoBusinessRecomendPlace.js +2 -2
  26. package/dist/v3/api/contants.d.ts +2 -0
  27. package/dist/v3/api/contants.js +4 -0
  28. package/dist/v3/api/hongkongGovernDriving.d.ts +7 -0
  29. package/dist/v3/api/hongkongGovernDriving.js +31 -0
  30. package/dist/v3/components/MapProvider/MapProvider.d.ts +1 -1
  31. package/dist/v3/components/MapProvider/MapProvider.js +1 -1
  32. package/dist/v3/hooks/useDrivingRoute.js +1 -1
  33. package/dist/v3/hooks/useMapPlace.js +52 -6
  34. package/dist/v3/hooks/useMapRecomendPlace.js +1 -0
  35. package/dist/v3/hooks/useMapSupplier.d.ts +1 -0
  36. package/dist/v3/index.d.ts +1 -0
  37. package/dist/v3/index.js +6 -0
  38. package/dist/v3/utils/geometryPolygon.d.ts +1 -0
  39. package/dist/v3/utils/geometryPolygon.js +8 -0
  40. package/dist/v3/utils/helper.d.ts +1 -0
  41. package/dist/v3/utils/helper.js +14 -0
  42. package/dist/v3/utils/hongkongGovernGeoCoder.d.ts +46 -0
  43. package/dist/v3/utils/hongkongGovernGeoCoder.js +134 -0
  44. package/dist/v3/utils/log.js +1 -1
  45. package/dist/v3/utils/transform.d.ts +15 -1
  46. package/dist/v3/utils/transform.js +81 -0
  47. package/package.json +1 -1
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
- import { DemoBusinessQuoting } from "./Demo/DemoBusinessQuoting.js";
4
3
  import { MapProvider } from "./components/MapProvider/MapProvider.js";
4
+ import { DemoBusinessRecomendPlace } from "./Demo/DemoBusinessRecomendPlace.js";
5
5
  const gmapApiKey = "AIzaSyCCOe8MAeS3EYvSraKsBX6ztVyLxj69z94";
6
6
  const gmapId = "d0af0c05331af64a";
7
7
  const amapApiKey = "fcb7b14c930354a248e21f4031dfa179";
@@ -17,6 +17,7 @@ const App = /* @__PURE__ */ defineComponent({
17
17
  "gmapKey": gmapApiKey,
18
18
  "language": "en",
19
19
  "supplier": supplierRef.value,
20
+ "isHKGovernAble": true,
20
21
  "googleSnapRoadProxyUrl": "/overseas/maps/snapToRoads",
21
22
  "googleRoutesProxyUrl": "/overseas/maps/routes/directions",
22
23
  "themeVariables": {
@@ -45,7 +46,7 @@ const App = /* @__PURE__ */ defineComponent({
45
46
  "onFail": () => console.log(`${supplierRef.value} load failed`),
46
47
  "onDownloadOptimizeEnd": () => console.log(`${supplierRef.value} load download optimize end`)
47
48
  }, {
48
- default: () => [createVNode(DemoBusinessQuoting, null, null)]
49
+ default: () => [createVNode(DemoBusinessRecomendPlace, null, null)]
49
50
  });
50
51
  }
51
52
  });
@@ -60,8 +60,8 @@ const DemoBusinessRecomendPlace = defineSetup("DemoBusinessRecomendPlace", funct
60
60
  setCenterPlaceByUserSpecifiedInZone
61
61
  } = useBusinessRecomendPlaceMap();
62
62
  window.changeUserSpecifiedPlace = () => setCenterPlaceByUserSpecified({
63
- lng: 139.55,
64
- lat: 35.55,
63
+ lng: 114.226288,
64
+ lat: 22.27965,
65
65
  type: "gcj02",
66
66
  name: "user specified place",
67
67
  displayName: "user specified place"
@@ -17,8 +17,10 @@ export declare const ZINDEX_PASSENGER_LAYER = 20;
17
17
  export declare const ZINDEX_AUXILIARY_GRASP = 14;
18
18
  export declare const ZINDEX_LINE_LAYER = 12;
19
19
  export declare const ZINDEX_GREEN_ZONE = 10;
20
+ export declare const HK_GOVERN_API_DISTANCE_MAX = 20;
20
21
  export declare const TRACKS_MATCH_MAX_LENGTH = 3;
21
22
  export declare const REGEO_TIMEOUT = 5000;
23
+ export declare const HK_GOVERN_API_TIMEOUT = 500;
22
24
  export declare const GET_RECOMMEND_PLACE_TIMEOUT = 5000;
23
25
  export declare const GET_DEFAULT_CENTER_PLACE_TIMEOUT = 5000;
24
26
  export declare const AMAP_TO_GCJ02_TIMEOUT = 2000;
@@ -16,8 +16,10 @@ const ZINDEX_PASSENGER_LAYER = 20;
16
16
  const ZINDEX_AUXILIARY_GRASP = 14;
17
17
  const ZINDEX_LINE_LAYER = 12;
18
18
  const ZINDEX_GREEN_ZONE = 10;
19
+ const HK_GOVERN_API_DISTANCE_MAX = 20;
19
20
  const TRACKS_MATCH_MAX_LENGTH = 3;
20
21
  const REGEO_TIMEOUT = 5e3;
22
+ const HK_GOVERN_API_TIMEOUT = 500;
21
23
  const GET_RECOMMEND_PLACE_TIMEOUT = 5e3;
22
24
  const GET_DEFAULT_CENTER_PLACE_TIMEOUT = 5e3;
23
25
  const AMAP_TO_GCJ02_TIMEOUT = 2e3;
@@ -31,6 +33,8 @@ export {
31
33
  CAR_DISTANCE_MIN,
32
34
  GET_DEFAULT_CENTER_PLACE_TIMEOUT,
33
35
  GET_RECOMMEND_PLACE_TIMEOUT,
36
+ HK_GOVERN_API_DISTANCE_MAX,
37
+ HK_GOVERN_API_TIMEOUT,
34
38
  MAX_ANIMATION_DISTANCE_VW,
35
39
  MAX_DEVIATION_DISTANCE,
36
40
  MAX_DEVIATION_DISTANCE_WALKING,
@@ -0,0 +1,7 @@
1
+ export declare const apiHongKongGovernDriving: (props: any) => Promise<{
2
+ result: any;
3
+ origin: {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ }>;
@@ -0,0 +1,31 @@
1
+ import { isProxyServiceError } from "../utils/typeChecking.js";
2
+ import { guid } from "../utils/helper.js";
3
+ import { wgs84ToHK80 } from "../utils/transform.js";
4
+ const apiHongKongGovernDriving = async (props) => {
5
+ 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);
9
+ const hk80Coord = wgs84ToHK80(lat, lng);
10
+ url.searchParams.set("lang", language);
11
+ url.searchParams.set("x", hk80Coord.x.toString());
12
+ url.searchParams.set("y", hk80Coord.y.toString());
13
+ url.searchParams.set("reqSid", guid());
14
+ const response = await fetch(url);
15
+ if (response.ok) {
16
+ const result = await response.json();
17
+ return { result, origin: hk80Coord };
18
+ }
19
+ const error = await response.json();
20
+ if (isProxyServiceError(error)) {
21
+ const { code, msg } = error;
22
+ throw new Error(`apiHongKongGovernDriving proxy failed code: ${code}, msg:
23
+ ${msg}`);
24
+ }
25
+ throw new Error(
26
+ `apiHongKongGovernDriving failed with unrecognized server response: ${JSON.stringify(error)}`
27
+ );
28
+ };
29
+ export {
30
+ apiHongKongGovernDriving
31
+ };
@@ -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">;
8
+ export type MapProviderProps = UseMapLoaderProps & Pick<MapSupplierPayolad, "gmapId" | "gmapRasterId" | "gaodeDirectionDrivingProxyUrl" | "gaodeDirectionWalkingProxyUrl" | "googleDirectionsProxyUrl" | "googleRoutesProxyUrl" | "googleSnapRoadProxyUrl" | "themeVariables" | "renderLoadFailedTitle" | "renderLoadFailedDescription" | "isHKGovernAble">;
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"]);
56
+ }).props(["amapKey", "amapSecret", "amapServiceHost", "gmapId", "gmapRasterId", "gmapKey", "supplier", "language", "gaodeDirectionDrivingProxyUrl", "gaodeDirectionWalkingProxyUrl", "googleDirectionsProxyUrl", "googleRoutesProxyUrl", "googleSnapRoadProxyUrl", "themeVariables", "renderLoadFailedTitle", "renderLoadFailedDescription", "isHKGovernAble"]);
57
57
  const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
58
58
  slots,
59
59
  emit,
@@ -13,7 +13,7 @@ const useADrivingRoute = (props) => {
13
13
  steps: [],
14
14
  trafficJams: void 0
15
15
  });
16
- const amapDriving = new AMap.Driving({});
16
+ const amapDriving = new AMap.Driving({ ferry: 1 });
17
17
  const apiMapDrivingRoute = (from, to, waypoints = []) => {
18
18
  return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiDrivingRoute(from, to, waypoints, googleRoutesProxyUrl) : amapJsApiDrivingRoute(from, to, waypoints, amapDriving);
19
19
  };
@@ -1,16 +1,20 @@
1
1
  import { ref, reactive, watch } from "vue-demi";
2
- import { REGEO_TIMEOUT } from "../api/contants.js";
2
+ import { REGEO_TIMEOUT, HK_GOVERN_API_TIMEOUT } from "../api/contants.js";
3
+ import { apiHongKongGovernDriving } from "../api/hongkongGovernDriving.js";
3
4
  import { createPipeTw } from "../utils/cn2tw.js";
4
- import { equalAssign, AbortSignalAny } from "../utils/helper.js";
5
- import { amapPlaceName2DisplayName, signal2promise, gmapPlaceName2DisplayName } from "../utils/transform.js";
6
- import { inChina, inTaiwan } from "./useMapInChina.js";
5
+ import { equalAssign, AbortSignalAny, sleep } from "../utils/helper.js";
6
+ import { getHKGovernResult } from "../utils/hongkongGovernGeoCoder.js";
7
+ import { toLocalWgs84Force, amapPlaceName2DisplayName, signal2promise, gmapPlaceName2DisplayName } from "../utils/transform.js";
8
+ import { inChina, inTaiwan, inHongkong } from "./useMapInChina.js";
7
9
  import { useMapSupplier } from "./useMapSupplier.js";
8
10
  import { useUpdate } from "./useUdate.js";
11
+ import { useMapGCJ02 } from "./useMapGCJ02.js";
9
12
  const useAmapPlace = (props) => {
10
13
  const { signal: inputSignal, onChange, emptyPlaceName } = props;
11
14
  const defaultPoint = [...props.pointRef.value];
12
15
  const pointRef = ref(defaultPoint);
13
- const { readyPromise, language } = useMapSupplier();
16
+ const { readyPromise, language, isHKGovernAble } = useMapSupplier();
17
+ const { toCoordinateType } = useMapGCJ02();
14
18
  const place = reactive({
15
19
  lng: pointRef.value[0],
16
20
  lat: pointRef.value[1],
@@ -40,8 +44,49 @@ const useAmapPlace = (props) => {
40
44
  const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
41
45
  const pipeTw = createPipeTw(language === "zh-TW");
42
46
  const isChinese = inChina([lng, lat]) || inTaiwan([lng, lat]);
43
- geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
47
+ const isUseHKGovern = inHongkong([lng, lat]) && isHKGovernAble;
48
+ const startTime = Date.now();
49
+ let hkReturned = !isUseHKGovern;
50
+ let amapReturned = false;
51
+ if (isUseHKGovern) {
52
+ const [finalLng, finalLat] = toLocalWgs84Force([lng, lat], toCoordinateType([lng, lat]));
53
+ console.log("lng:", lng, finalLng);
54
+ console.log("lat:", lat, finalLat);
55
+ apiHongKongGovernDriving({
56
+ proxyUrl: "/overseas/gov/hk/identify",
57
+ lng: finalLng,
58
+ lat: finalLat,
59
+ language: language === "zh-TW" ? "zh" : language
60
+ }).then(({ result, origin }) => {
61
+ var _a, _b;
62
+ const hkGovernRes = getHKGovernResult((_b = (_a = result == null ? void 0 : result.data) == null ? void 0 : _a.rawResponse) == null ? void 0 : _b.results, origin);
63
+ const diff = Date.now() - startTime;
64
+ console.log("==return value of hkGovernApi==", hkGovernRes);
65
+ console.log("==time of hkGovernApi==", diff);
66
+ if (!amapReturned && hkGovernRes) {
67
+ const name = language === "en" ? hkGovernRes.ename : hkGovernRes.cname;
68
+ hkReturned = true;
69
+ resolve({
70
+ lng,
71
+ lat,
72
+ name,
73
+ displayName: name
74
+ });
75
+ }
76
+ });
77
+ }
78
+ geocoder.getAddress(new AMap.LngLat(lng, lat), async (status, result) => {
44
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
+ }
45
90
  switch (status) {
46
91
  case "complete": {
47
92
  const { formattedAddress, addressComponent } = result.regeocode;
@@ -50,6 +95,7 @@ const useAmapPlace = (props) => {
50
95
  isChinese,
51
96
  ...addressComponent
52
97
  });
98
+ amapReturned = true;
53
99
  resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
54
100
  return;
55
101
  }
@@ -117,6 +117,7 @@ const useMapRecomendPlace = (props) => {
117
117
  return { place: { ...closestPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 };
118
118
  }
119
119
  const regeoPlace = await reGeoPlacePromiseIgnored.recover();
120
+ console.log(54566544, regeoPlace);
120
121
  return { place: { ...regeoPlace }, zone: zone2, available: available2, candidates: candidates2, type: type2 };
121
122
  }
122
123
  if (type === "Forbidden") {
@@ -15,6 +15,7 @@ export interface MapSupplierPayolad extends UseMapLoaderProps {
15
15
  themeVariables?: MapThemeVariables;
16
16
  renderLoadFailedTitle?: (status: Status) => string | undefined;
17
17
  renderLoadFailedDescription?: (status: Status) => string | undefined;
18
+ isHKGovernAble?: boolean;
18
19
  }
19
20
  export declare const useMapSupplier: () => MapSupplierPayolad;
20
21
  export declare const provideMapSupplier: (payload: MapSupplierPayolad) => void;
@@ -31,6 +31,7 @@ export { useMapGeometry } from "./hooks/useMapGeometry";
31
31
  export { useMapPlace } from "./hooks/useMapPlace";
32
32
  export { useMapRecomendPlace } from "./hooks/useMapRecomendPlace";
33
33
  export { useWalkingRoute } from "./hooks/useWalkingRoute";
34
+ export * from "./hooks/useMapInChina";
34
35
  export * from "./types/global";
35
36
  export * from "./types/interface";
36
37
  export * from "./utils/patchMiniprogram";
package/dist/v3/index.js CHANGED
@@ -32,6 +32,7 @@ import { useMapGeometry } from "./hooks/useMapGeometry.js";
32
32
  import { useMapPlace } from "./hooks/useMapPlace.js";
33
33
  import { useMapRecomendPlace } from "./hooks/useMapRecomendPlace.js";
34
34
  import { useWalkingRoute } from "./hooks/useWalkingRoute.js";
35
+ import { inChina, inHongkong, inKorean, inMacau, inTaiwan } from "./hooks/useMapInChina.js";
35
36
  import { CenterPlaceStatus } from "./types/interface.js";
36
37
  import { MINI_PROGRAM_WEB_VIEW_CLOSE_EVENT, MINI_PROGRAM_WEB_VIEW_CLOSE_TIMEOUT, patchMiniprogramRedirectTo } from "./utils/patchMiniprogram.js";
37
38
  export {
@@ -56,6 +57,11 @@ export {
56
57
  WalkingLine,
57
58
  WalkingRoute,
58
59
  WaveCircle,
60
+ inChina,
61
+ inHongkong,
62
+ inKorean,
63
+ inMacau,
64
+ inTaiwan,
59
65
  isCoordinatePointEqual,
60
66
  patchMiniprogramRedirectTo,
61
67
  useBusinessAlarm,
@@ -5,6 +5,7 @@ import type { Point } from "../types/interface";
5
5
  */
6
6
  export declare function pointInPolygon(point: Point, polygon: Point[]): 1 | 0 | -1;
7
7
  export declare const distanceBetweenTwoPoints: (from: Point, to: Point) => number;
8
+ export declare const distanceTwoHK80Points: (from: Point, to: Point) => number;
8
9
  /**
9
10
  * 计算折线(按顺序连接各点)总长度。
10
11
  */
@@ -37,6 +37,13 @@ const distanceBetweenTwoPoints = (from, to) => {
37
37
  const c = 2 * Math.asin(Math.min(1, Math.sqrt(a)));
38
38
  return R * c;
39
39
  };
40
+ const distanceTwoHK80Points = (from, to) => {
41
+ const [x1, y1] = from;
42
+ const [x2, y2] = to;
43
+ if (x1 === x2 && y1 === y2)
44
+ return 0;
45
+ return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
46
+ };
40
47
  const computeLineLength = (line) => {
41
48
  var _a;
42
49
  if (!Array.isArray(line) || line.length < 2)
@@ -50,5 +57,6 @@ const computeLineLength = (line) => {
50
57
  export {
51
58
  computeLineLength,
52
59
  distanceBetweenTwoPoints,
60
+ distanceTwoHK80Points,
53
61
  pointInPolygon
54
62
  };
@@ -46,4 +46,5 @@ export declare const createAbortableOneConcurrent: <F extends (...args: any[]) =
46
46
  abort: () => void;
47
47
  };
48
48
  export declare const AbortSignalAny: (signals: (AbortSignal | undefined)[]) => AbortSignal;
49
+ export declare const guid: () => string;
49
50
  export {};
@@ -205,6 +205,19 @@ const AbortSignalAny = (signals) => {
205
205
  }
206
206
  return controller.signal;
207
207
  };
208
+ const guid = () => {
209
+ const s = [];
210
+ const hexDigits = "0123456789abcdef";
211
+ for (let i = 0; i < 36; i++) {
212
+ const start2 = Math.floor(Math.random() * 16);
213
+ s[i] = hexDigits.substring(start2, start2 + 1);
214
+ }
215
+ s[14] = "4";
216
+ const start = +s[19] & 3 | 8;
217
+ s[19] = hexDigits.substring(start, start + 1);
218
+ s[8] = s[13] = s[18] = s[23] = "-";
219
+ return s.join("");
220
+ };
208
221
  export {
209
222
  AbortSignalAny,
210
223
  assertAngle,
@@ -220,6 +233,7 @@ export {
220
233
  createRunOnce,
221
234
  defered,
222
235
  equalAssign,
236
+ guid,
223
237
  isLatLngLiteral,
224
238
  isPlacesInclude,
225
239
  pausableSleep,
@@ -0,0 +1,46 @@
1
+ declare enum AddressTypeEnum {
2
+ ST = "ST",
3
+ S = "S",
4
+ B = "B",
5
+ SS = "SS",
6
+ P = "P",
7
+ FACI = "FACI",
8
+ F = "F"
9
+ }
10
+ declare const FACITYPE_EXCLUDE: readonly ["WIFI", "WIFIHK", "SIG", "HKONWS", "AED", "HLP"];
11
+ type FaciType = (typeof FACITYPE_EXCLUDE)[number];
12
+ interface AddressReturnValue {
13
+ level: AddressTypeEnum;
14
+ cname: string;
15
+ ename: string;
16
+ }
17
+ type NamePair = {
18
+ cname: string;
19
+ ename: string;
20
+ };
21
+ type DisplayPair = {
22
+ cdisplay: string;
23
+ edisplay: string;
24
+ };
25
+ type CommonAddressItem<T> = T & Partial<OriginCoordinate> & (NamePair | DisplayPair | (NamePair & DisplayPair));
26
+ type AddressInfoItem = CommonAddressItem<{
27
+ addressType: AddressTypeEnum;
28
+ hashTag?: AddressInfoItem[];
29
+ facility?: FacilityItem[];
30
+ }>;
31
+ type FaciItem = CommonAddressItem<{
32
+ addressType: AddressTypeEnum.F;
33
+ faciType: FaciType;
34
+ }>;
35
+ interface FacilityItem {
36
+ addressInfo: Array<FaciItem>;
37
+ }
38
+ interface RawDataItem {
39
+ addressInfo: AddressInfoItem[];
40
+ }
41
+ interface OriginCoordinate {
42
+ x: number;
43
+ y: number;
44
+ }
45
+ export declare const getHKGovernResult: (data: RawDataItem[], origin: OriginCoordinate) => AddressReturnValue | null;
46
+ export {};
@@ -0,0 +1,134 @@
1
+ import { HK_GOVERN_API_DISTANCE_MAX } from "../api/contants.js";
2
+ import { distanceTwoHK80Points } from "./geometryPolygon.js";
3
+ var AddressTypeEnum = /* @__PURE__ */ ((AddressTypeEnum2) => {
4
+ AddressTypeEnum2["ST"] = "ST";
5
+ AddressTypeEnum2["S"] = "S";
6
+ AddressTypeEnum2["B"] = "B";
7
+ AddressTypeEnum2["SS"] = "SS";
8
+ AddressTypeEnum2["P"] = "P";
9
+ AddressTypeEnum2["FACI"] = "FACI";
10
+ AddressTypeEnum2["F"] = "F";
11
+ return AddressTypeEnum2;
12
+ })(AddressTypeEnum || {});
13
+ const RETURN_ORDER_ARRAY = [
14
+ "SS",
15
+ "B",
16
+ "S",
17
+ "ST"
18
+ /* ST */
19
+ ];
20
+ const RETURN_ORDER_MAP = {
21
+ [
22
+ "ST"
23
+ /* ST */
24
+ ]: "S",
25
+ [
26
+ "S"
27
+ /* S */
28
+ ]: "B",
29
+ [
30
+ "SS"
31
+ /* SS */
32
+ ]: null,
33
+ [
34
+ "B"
35
+ /* B */
36
+ ]: null
37
+ };
38
+ const FACITYPE_EXCLUDE = ["WIFI", "WIFIHK", "SIG", "HKONWS", "AED", "HLP"];
39
+ const getReturnValue = (item, origin) => {
40
+ if (!pointCoordinateValid(item, origin))
41
+ return null;
42
+ const cname = "cname" in item ? item.cname : item.cdisplay;
43
+ const ename = "ename" in item ? item.ename : item.edisplay;
44
+ return {
45
+ level: item.addressType,
46
+ cname,
47
+ ename
48
+ };
49
+ };
50
+ const isReturnValueValid = (item) => {
51
+ return (item == null ? void 0 : item.cname) && (item == null ? void 0 : item.ename);
52
+ };
53
+ const isFaciValid = (faciItem, origin) => {
54
+ const cname = "cname" in faciItem ? faciItem.cname : faciItem.cdisplay;
55
+ const ename = "ename" in faciItem ? faciItem.ename : faciItem.edisplay;
56
+ const item = { cname, ename, addressType: "F", x: faciItem.x, y: faciItem.y };
57
+ return !FACITYPE_EXCLUDE.includes(faciItem.faciType) && isReturnValueValid(getReturnValue(item, origin));
58
+ };
59
+ const pointCoordinateValid = (item, origin) => {
60
+ if (typeof item.x !== "number" || typeof item.y !== "number")
61
+ return false;
62
+ return distanceTwoHK80Points([item.x, item.y], [origin.x, origin.y]) <= HK_GOVERN_API_DISTANCE_MAX;
63
+ };
64
+ const recursiveFind = (data, level, origin) => {
65
+ if (!Array.isArray(data) || data.length === 0)
66
+ return null;
67
+ let firstSubResult = null;
68
+ for (let i = 0; i < data.length; i++) {
69
+ const { hashTag: originHashTag, facility: originFacility } = data[i];
70
+ const hashTag = originHashTag || [];
71
+ const facility = originFacility || [];
72
+ for (let j = 0; j < facility.length; j++) {
73
+ const faci = facility[j];
74
+ for (let k = 0; k < faci.addressInfo.length; k++) {
75
+ const faciItem = faci.addressInfo[k];
76
+ if (isFaciValid(faciItem, origin)) {
77
+ return getReturnValue(
78
+ {
79
+ ...faciItem,
80
+ addressType: "F"
81
+ /* F */
82
+ },
83
+ origin
84
+ );
85
+ }
86
+ }
87
+ }
88
+ if (!(level in RETURN_ORDER_MAP))
89
+ return null;
90
+ const nextLevel = RETURN_ORDER_MAP[level];
91
+ if (nextLevel) {
92
+ const childRes = recursiveFind(hashTag, nextLevel, origin);
93
+ if (!firstSubResult)
94
+ firstSubResult = childRes;
95
+ if ((childRes == null ? void 0 : childRes.level) === "F")
96
+ return childRes;
97
+ }
98
+ }
99
+ if (isReturnValueValid(firstSubResult))
100
+ return firstSubResult;
101
+ const firstValidItem = data.find((item) => item.addressType === level && pointCoordinateValid(item, origin)) || null;
102
+ return firstValidItem && isReturnValueValid(getReturnValue(firstValidItem, origin)) ? getReturnValue(firstValidItem, origin) : null;
103
+ };
104
+ const getHKGovernResult = (data, origin) => {
105
+ if (!Array.isArray(data) || data.length === 0)
106
+ return null;
107
+ const resultList = [];
108
+ const ADDRESS_TYPE_VALUES = Object.values(AddressTypeEnum);
109
+ for (const rawItem of data) {
110
+ const addressInfo = rawItem.addressInfo || [];
111
+ const validAddressInfo = addressInfo.filter(
112
+ (item) => ADDRESS_TYPE_VALUES.includes(item.addressType)
113
+ );
114
+ if (validAddressInfo.length === 0)
115
+ continue;
116
+ const firstLevelType = validAddressInfo[0].addressType;
117
+ const levelResult = recursiveFind(validAddressInfo, firstLevelType, origin);
118
+ if ((levelResult == null ? void 0 : levelResult.level) === "F")
119
+ return levelResult;
120
+ if (levelResult)
121
+ resultList.push(levelResult);
122
+ }
123
+ const result = RETURN_ORDER_ARRAY.reduce(
124
+ (res, lvl) => {
125
+ var _a;
126
+ return (_a = res != null ? res : resultList.find((i) => i.level === lvl)) != null ? _a : null;
127
+ },
128
+ null
129
+ );
130
+ return isReturnValueValid(result) ? result : null;
131
+ };
132
+ export {
133
+ getHKGovernResult
134
+ };
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.15.0-sgn1";
3
+ const pkgVersion = "2.15.6-hkGovernApi";
4
4
  const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
5
  const enableSessionLogKey = (key) => {
6
6
  const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="google.maps" />
2
- import type { LngLatLiterial, Place, Point, TrackPoint, TrafficStatus, Zone } from "../types/interface";
2
+ import type { CoordinateType, LngLatLiterial, Place, Point, TrackPoint, TrafficStatus, Zone } from "../types/interface";
3
3
  import type { AlipayMyGetLocationSuccessResponse } from "../types/my";
4
4
  import type { WxGetLocationSuccessResponse } from "../types/wx";
5
5
  import { BRWOSER_PLATFORM } from "./platform";
@@ -54,4 +54,18 @@ export declare const splitColorAlpha: (colorInput: string) => {
54
54
  color: string;
55
55
  alpha: number;
56
56
  };
57
+ /**
58
+ * WGS84转HK1980坐标代码
59
+ * 参考文档:https://www.geodetic.gov.hk/common/data/pdf/explanatorynotes_c.pdf
60
+ */
61
+ export declare const wgs84ToHK80: (lat: number, lon: number) => {
62
+ x: number;
63
+ y: number;
64
+ };
65
+ export declare const wgs84ToHK80HighPrecision: (lat: number, lon: number) => {
66
+ x: number;
67
+ y: number;
68
+ };
69
+ export declare const toLocalGcj02Force: (point: Point, type: CoordinateType) => Point;
70
+ export declare const toLocalWgs84Force: (point: Point, type: CoordinateType) => Point;
57
71
  export {};
@@ -1,3 +1,4 @@
1
+ import { e as exported } from "../chunks/gcoord.esm-bundler.3f2f1369.js";
1
2
  import { MIN_ANIMATION_DURATION, ANIMATION_DURATION_FOR_100VW, ANIMATION_DURATION_PER_ZOOM } from "../api/contants.js";
2
3
  import { GoogleLatLng } from "./compatibleGoogleTypes.js";
3
4
  import { BRWOSER_PLATFORM } from "./platform.js";
@@ -375,6 +376,82 @@ const splitColorAlpha = (colorInput) => {
375
376
  }
376
377
  return { color: trimmedColor, alpha: 1 };
377
378
  };
379
+ const dmsToDd = (deg, min, sec) => deg + min / 60 + sec / 3600;
380
+ const deg2rad = (deg) => deg * Math.PI / 180;
381
+ const wgs84ToHK80 = (lat, lon) => {
382
+ const e2 = 0.006722670022;
383
+ const A0 = 1 - e2 / 4 - 3 * e2 * e2 / 64;
384
+ const A2 = 3 * (e2 + e2 * e2 / 4) / 8;
385
+ const A4 = 15 * e2 * e2 / 256;
386
+ const a = 6378388;
387
+ const N0 = 819069.8;
388
+ const M0 = 2468395728e-3;
389
+ const Vs = 6381480502e-3;
390
+ const E0 = 836694.05;
391
+ const iso_lat = 1.005792635;
392
+ const lon0 = deg2rad(dmsToDd(114, 10, 42.8));
393
+ lat += 5.5 / 3600;
394
+ lon -= 8.8 / 3600;
395
+ lat = deg2rad(lat);
396
+ lon = deg2rad(lon);
397
+ const M = a * (A0 * lat - A2 * Math.sin(2 * lat) + A4 * Math.sin(4 * lat));
398
+ const lonP = lon - lon0;
399
+ const x = E0 + Vs * lonP * Math.cos(lat) + Vs * Math.pow(lonP, 3) / 6 * Math.pow(Math.cos(lat), 3) * (iso_lat - Math.pow(Math.tan(lat), 2));
400
+ const y = N0 + M - M0 + Vs * Math.sin(lat) * lonP * lonP / 2 * Math.cos(lat);
401
+ return { x, y };
402
+ };
403
+ const wgs84ToHK80HighPrecision = (lat, lon) => {
404
+ const a = 6378388;
405
+ const e2 = 0.0067226700223;
406
+ const lon0 = deg2rad(114 + 10 / 60 + 42.8 / 3600);
407
+ const E0 = 836694.05;
408
+ const N0 = 819069.8;
409
+ lat += 5.5 / 3600;
410
+ lon -= 8.8 / 3600;
411
+ const phi = deg2rad(lat);
412
+ const lambda = deg2rad(lon);
413
+ const sinPhi = Math.sin(phi);
414
+ const cosPhi = Math.cos(phi);
415
+ const tanPhi = Math.tan(phi);
416
+ const N = a / Math.sqrt(1 - e2 * sinPhi * sinPhi);
417
+ const e4 = e2 * e2;
418
+ const A0 = 1 - e2 / 4 - 3 * e4 / 64;
419
+ const A2 = 3 * (e2 + e4 / 4) / 8;
420
+ const A4 = 15 * e4 / 256;
421
+ const M = a * (A0 * phi - A2 * Math.sin(2 * phi) + A4 * Math.sin(4 * phi));
422
+ const M0 = 2467521728e-3;
423
+ const dl = lambda - lon0;
424
+ const dl2 = dl * dl;
425
+ const dl3 = dl2 * dl;
426
+ const eta2 = e2 * cosPhi * cosPhi / (1 - e2);
427
+ const x = E0 + N * cosPhi * dl + N / 6 * Math.pow(cosPhi, 3) * (1 - Math.pow(tanPhi, 2) + eta2) * dl3;
428
+ const y = N0 + (M - M0) + N / 2 * sinPhi * cosPhi * dl2;
429
+ return { x, y };
430
+ };
431
+ const toLocalGcj02Force = (point, type) => {
432
+ if (type === "gcj02")
433
+ return point;
434
+ try {
435
+ return exported.transform(point, exported.WGS84, exported.GCJ02);
436
+ } catch (err) {
437
+ const error = err;
438
+ console.error(`本地转换GCJ02失败: ${error.message}
439
+ ${error.stack}`);
440
+ return point;
441
+ }
442
+ };
443
+ const toLocalWgs84Force = (point, type) => {
444
+ if (type === "wgs84")
445
+ return point;
446
+ try {
447
+ return exported.transform(point, exported.GCJ02, exported.WGS1984);
448
+ } catch (err) {
449
+ const error = err;
450
+ console.error(`本地转换WGS84失败: ${error.message}
451
+ ${error.stack}`);
452
+ return point;
453
+ }
454
+ };
378
455
  export {
379
456
  alipayMyGetLocationError2GeolocationPositionErrorCode,
380
457
  alipayMyGetLocationSuccessResponse2GeolocationPosition,
@@ -410,7 +487,11 @@ export {
410
487
  signal2promise,
411
488
  splitColorAlpha,
412
489
  stringifyPoint,
490
+ toLocalGcj02Force,
491
+ toLocalWgs84Force,
413
492
  trackPoints2amapGraspRoadPoints,
414
493
  vec2lnglat,
494
+ wgs84ToHK80,
495
+ wgs84ToHK80HighPrecision,
415
496
  wxGetLocationSuccessResponse2GeolocationPosition
416
497
  };