expo-gaode-map-web-api 2.0.3 → 2.0.5-next.0
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/README.md +100 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +6 -1
- package/build/legacy.d.ts +3 -0
- package/build/legacy.js +7 -0
- package/build/services/POIService.d.ts +20 -1
- package/build/services/POIService.js +29 -0
- package/build/types/poi.types.d.ts +79 -0
- package/build/utils/client.d.ts +1 -1
- package/build/utils/normalizers.d.ts +23 -0
- package/build/utils/normalizers.js +82 -0
- package/build/v3/capability-selection.d.ts +16 -0
- package/build/v3/capability-selection.js +39 -0
- package/build/v3/contracts.d.ts +77 -0
- package/build/v3/contracts.js +2 -0
- package/build/v3/domain.d.ts +52 -0
- package/build/v3/domain.js +2 -0
- package/build/v3/index.d.ts +14 -0
- package/build/v3/index.js +34 -0
- package/build/v3/map-camera.d.ts +50 -0
- package/build/v3/map-camera.js +114 -0
- package/build/v3/runtime-assembly.d.ts +23 -0
- package/build/v3/runtime-assembly.js +50 -0
- package/build/v3/runtime-factories.d.ts +33 -0
- package/build/v3/runtime-factories.js +42 -0
- package/build/v3/runtime.d.ts +80 -0
- package/build/v3/runtime.js +141 -0
- package/build/v3/web-geocode-provider.d.ts +8 -0
- package/build/v3/web-geocode-provider.js +55 -0
- package/build/v3/web-route-provider.d.ts +8 -0
- package/build/v3/web-route-provider.js +75 -0
- package/build/v3/web-search-provider.d.ts +8 -0
- package/build/v3/web-search-provider.js +125 -0
- package/build/v3/web-service-adapter.d.ts +18 -0
- package/build/v3/web-service-adapter.js +32 -0
- package/package.json +8 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createWebRuntime = exports.createWebDataRuntime = exports.createWebDataCapabilityAdapter = exports.createWebCapabilityAdapter = exports.createWebSearchProvider = exports.createWebRouteProvider = exports.createWebGeocodeProvider = void 0;
|
|
18
|
+
__exportStar(require("./domain"), exports);
|
|
19
|
+
__exportStar(require("./contracts"), exports);
|
|
20
|
+
__exportStar(require("./runtime"), exports);
|
|
21
|
+
__exportStar(require("./map-camera"), exports);
|
|
22
|
+
__exportStar(require("./capability-selection"), exports);
|
|
23
|
+
__exportStar(require("./runtime-assembly"), exports);
|
|
24
|
+
var web_geocode_provider_1 = require("./web-geocode-provider");
|
|
25
|
+
Object.defineProperty(exports, "createWebGeocodeProvider", { enumerable: true, get: function () { return web_geocode_provider_1.createWebGeocodeProvider; } });
|
|
26
|
+
var web_route_provider_1 = require("./web-route-provider");
|
|
27
|
+
Object.defineProperty(exports, "createWebRouteProvider", { enumerable: true, get: function () { return web_route_provider_1.createWebRouteProvider; } });
|
|
28
|
+
var web_search_provider_1 = require("./web-search-provider");
|
|
29
|
+
Object.defineProperty(exports, "createWebSearchProvider", { enumerable: true, get: function () { return web_search_provider_1.createWebSearchProvider; } });
|
|
30
|
+
var runtime_factories_1 = require("./runtime-factories");
|
|
31
|
+
Object.defineProperty(exports, "createWebCapabilityAdapter", { enumerable: true, get: function () { return runtime_factories_1.createWebCapabilityAdapter; } });
|
|
32
|
+
Object.defineProperty(exports, "createWebDataCapabilityAdapter", { enumerable: true, get: function () { return runtime_factories_1.createWebDataCapabilityAdapter; } });
|
|
33
|
+
Object.defineProperty(exports, "createWebDataRuntime", { enumerable: true, get: function () { return runtime_factories_1.createWebDataRuntime; } });
|
|
34
|
+
Object.defineProperty(exports, "createWebRuntime", { enumerable: true, get: function () { return runtime_factories_1.createWebRuntime; } });
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface CameraLatLng {
|
|
2
|
+
latitude: number;
|
|
3
|
+
longitude: number;
|
|
4
|
+
}
|
|
5
|
+
export type CameraLatLngPoint = CameraLatLng | [number, number] | number[];
|
|
6
|
+
export interface CameraUpdateShape {
|
|
7
|
+
target?: CameraLatLng;
|
|
8
|
+
zoom?: number;
|
|
9
|
+
bearing?: number;
|
|
10
|
+
tilt?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CameraPositionShape extends CameraUpdateShape {
|
|
13
|
+
}
|
|
14
|
+
export interface CameraBoundsShape {
|
|
15
|
+
southwest: CameraLatLng;
|
|
16
|
+
northeast: CameraLatLng;
|
|
17
|
+
}
|
|
18
|
+
export interface FitCameraOptions {
|
|
19
|
+
duration?: number;
|
|
20
|
+
paddingFactor?: number;
|
|
21
|
+
minZoom?: number;
|
|
22
|
+
maxZoom?: number;
|
|
23
|
+
singlePointZoom?: number;
|
|
24
|
+
bearing?: number;
|
|
25
|
+
tilt?: number;
|
|
26
|
+
preserveBearing?: boolean;
|
|
27
|
+
preserveTilt?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface RouteBoundsShape {
|
|
30
|
+
center: CameraLatLng;
|
|
31
|
+
bounds: {
|
|
32
|
+
north: number;
|
|
33
|
+
south: number;
|
|
34
|
+
east: number;
|
|
35
|
+
west: number;
|
|
36
|
+
};
|
|
37
|
+
span: {
|
|
38
|
+
latitudeDelta: number;
|
|
39
|
+
longitudeDelta: number;
|
|
40
|
+
};
|
|
41
|
+
recommendedZoom: number;
|
|
42
|
+
}
|
|
43
|
+
export interface FitCameraTarget {
|
|
44
|
+
moveCamera(position: CameraUpdateShape, duration?: number): Promise<void>;
|
|
45
|
+
getCameraPosition(): Promise<CameraPositionShape>;
|
|
46
|
+
}
|
|
47
|
+
export declare function estimateCameraZoom(latitudeDelta: number, longitudeDelta: number, options?: Pick<FitCameraOptions, 'minZoom' | 'maxZoom'>): number;
|
|
48
|
+
export declare function getCameraRouteBounds(points: CameraLatLngPoint[], options?: Pick<FitCameraOptions, 'paddingFactor' | 'minZoom' | 'maxZoom'>): RouteBoundsShape | null;
|
|
49
|
+
export declare function fitCameraFromPoints(map: FitCameraTarget, points: CameraLatLngPoint[], options?: FitCameraOptions): Promise<void>;
|
|
50
|
+
export declare function buildCameraBounds(points: CameraLatLngPoint[]): CameraBoundsShape | null;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateCameraZoom = estimateCameraZoom;
|
|
4
|
+
exports.getCameraRouteBounds = getCameraRouteBounds;
|
|
5
|
+
exports.fitCameraFromPoints = fitCameraFromPoints;
|
|
6
|
+
exports.buildCameraBounds = buildCameraBounds;
|
|
7
|
+
const MIN_ZOOM = 3;
|
|
8
|
+
const MAX_ZOOM = 20;
|
|
9
|
+
const DEFAULT_SINGLE_POINT_ZOOM = 16;
|
|
10
|
+
const DEFAULT_PADDING_FACTOR = 1.2;
|
|
11
|
+
function normalizeLatLng(point) {
|
|
12
|
+
if (Array.isArray(point)) {
|
|
13
|
+
return {
|
|
14
|
+
longitude: Number(point[0]),
|
|
15
|
+
latitude: Number(point[1]),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
latitude: Number(point.latitude),
|
|
20
|
+
longitude: Number(point.longitude),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function normalizeLatLngList(points) {
|
|
24
|
+
return points.map(normalizeLatLng);
|
|
25
|
+
}
|
|
26
|
+
function estimateCameraZoom(latitudeDelta, longitudeDelta, options = {}) {
|
|
27
|
+
const span = Math.max(latitudeDelta, longitudeDelta, 0.0001);
|
|
28
|
+
const rawZoom = Math.log2(360 / span);
|
|
29
|
+
const minZoom = options.minZoom ?? MIN_ZOOM;
|
|
30
|
+
const maxZoom = options.maxZoom ?? MAX_ZOOM;
|
|
31
|
+
return Math.max(minZoom, Math.min(maxZoom, Number(rawZoom.toFixed(2))));
|
|
32
|
+
}
|
|
33
|
+
function getCameraRouteBounds(points, options = {}) {
|
|
34
|
+
const normalized = normalizeLatLngList(points);
|
|
35
|
+
if (normalized.length === 0) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const latitudes = normalized.map((point) => point.latitude);
|
|
39
|
+
const longitudes = normalized.map((point) => point.longitude);
|
|
40
|
+
const north = Math.max(...latitudes);
|
|
41
|
+
const south = Math.min(...latitudes);
|
|
42
|
+
const east = Math.max(...longitudes);
|
|
43
|
+
const west = Math.min(...longitudes);
|
|
44
|
+
const paddingFactor = options.paddingFactor ?? DEFAULT_PADDING_FACTOR;
|
|
45
|
+
const latitudeDelta = Math.max((north - south) * paddingFactor, 0.0001);
|
|
46
|
+
const longitudeDelta = Math.max((east - west) * paddingFactor, 0.0001);
|
|
47
|
+
return {
|
|
48
|
+
center: {
|
|
49
|
+
latitude: (north + south) / 2,
|
|
50
|
+
longitude: (east + west) / 2,
|
|
51
|
+
},
|
|
52
|
+
bounds: {
|
|
53
|
+
north,
|
|
54
|
+
south,
|
|
55
|
+
east,
|
|
56
|
+
west,
|
|
57
|
+
},
|
|
58
|
+
span: {
|
|
59
|
+
latitudeDelta,
|
|
60
|
+
longitudeDelta,
|
|
61
|
+
},
|
|
62
|
+
recommendedZoom: estimateCameraZoom(latitudeDelta, longitudeDelta, options),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async function fitCameraFromPoints(map, points, options = {}) {
|
|
66
|
+
const normalized = normalizeLatLngList(points);
|
|
67
|
+
if (normalized.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const currentCamera = await map.getCameraPosition().catch(() => ({}));
|
|
71
|
+
if (normalized.length === 1) {
|
|
72
|
+
await map.moveCamera({
|
|
73
|
+
target: normalized[0],
|
|
74
|
+
zoom: options.singlePointZoom ?? currentCamera.zoom ?? DEFAULT_SINGLE_POINT_ZOOM,
|
|
75
|
+
bearing: options.preserveBearing === false
|
|
76
|
+
? options.bearing
|
|
77
|
+
: currentCamera.bearing ?? options.bearing,
|
|
78
|
+
tilt: options.preserveTilt === false
|
|
79
|
+
? options.tilt
|
|
80
|
+
: currentCamera.tilt ?? options.tilt,
|
|
81
|
+
}, options.duration ?? 0);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const routeBounds = getCameraRouteBounds(normalized, options);
|
|
85
|
+
if (!routeBounds) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await map.moveCamera({
|
|
89
|
+
target: routeBounds.center,
|
|
90
|
+
zoom: routeBounds.recommendedZoom,
|
|
91
|
+
bearing: options.preserveBearing === false
|
|
92
|
+
? options.bearing
|
|
93
|
+
: currentCamera.bearing ?? options.bearing,
|
|
94
|
+
tilt: options.preserveTilt === false
|
|
95
|
+
? options.tilt
|
|
96
|
+
: currentCamera.tilt ?? options.tilt,
|
|
97
|
+
}, options.duration ?? 0);
|
|
98
|
+
}
|
|
99
|
+
function buildCameraBounds(points) {
|
|
100
|
+
const routeBounds = getCameraRouteBounds(points);
|
|
101
|
+
if (!routeBounds) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
southwest: {
|
|
106
|
+
latitude: routeBounds.bounds.south,
|
|
107
|
+
longitude: routeBounds.bounds.west,
|
|
108
|
+
},
|
|
109
|
+
northeast: {
|
|
110
|
+
latitude: routeBounds.bounds.north,
|
|
111
|
+
longitude: routeBounds.bounds.east,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GeocodeProvider, RouteProvider, SearchProvider } from './contracts';
|
|
2
|
+
import type { GaodeRuntime, RuntimeClientOptions } from './runtime';
|
|
3
|
+
export interface RuntimeCapabilityAdapter {
|
|
4
|
+
source: string;
|
|
5
|
+
priority?: number;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
searchProviders?: SearchProvider[];
|
|
8
|
+
geocodeProviders?: GeocodeProvider[];
|
|
9
|
+
routeProviders?: RouteProvider[];
|
|
10
|
+
}
|
|
11
|
+
export interface RuntimeProviderSet {
|
|
12
|
+
searchProviders: SearchProvider[];
|
|
13
|
+
geocodeProviders: GeocodeProvider[];
|
|
14
|
+
routeProviders: RouteProvider[];
|
|
15
|
+
}
|
|
16
|
+
export interface AssembleRuntimeProvidersOptions {
|
|
17
|
+
adapters: RuntimeCapabilityAdapter[];
|
|
18
|
+
dedupeByKind?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface CapabilityRuntimeOptions extends RuntimeClientOptions, AssembleRuntimeProvidersOptions {
|
|
21
|
+
}
|
|
22
|
+
export declare function assembleRuntimeProviders(options: AssembleRuntimeProvidersOptions): RuntimeProviderSet;
|
|
23
|
+
export declare function createCapabilityRuntime(options: CapabilityRuntimeOptions): GaodeRuntime;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assembleRuntimeProviders = assembleRuntimeProviders;
|
|
4
|
+
exports.createCapabilityRuntime = createCapabilityRuntime;
|
|
5
|
+
const runtime_1 = require("./runtime");
|
|
6
|
+
function dedupeProvidersByKind(providers, dedupeByKind) {
|
|
7
|
+
if (!dedupeByKind) {
|
|
8
|
+
return providers;
|
|
9
|
+
}
|
|
10
|
+
const seenKinds = new Set();
|
|
11
|
+
return providers.filter((provider) => {
|
|
12
|
+
if (seenKinds.has(provider.kind)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
seenKinds.add(provider.kind);
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function assembleRuntimeProviders(options) {
|
|
20
|
+
const sortedAdapters = (options.adapters ?? [])
|
|
21
|
+
.filter((adapter) => adapter.enabled !== false)
|
|
22
|
+
.map((adapter, index) => ({ ...adapter, index }))
|
|
23
|
+
.sort((left, right) => {
|
|
24
|
+
const leftPriority = left.priority ?? 0;
|
|
25
|
+
const rightPriority = right.priority ?? 0;
|
|
26
|
+
if (leftPriority !== rightPriority) {
|
|
27
|
+
return leftPriority - rightPriority;
|
|
28
|
+
}
|
|
29
|
+
return left.index - right.index;
|
|
30
|
+
});
|
|
31
|
+
const searchProviders = sortedAdapters.flatMap((adapter) => adapter.searchProviders ?? []);
|
|
32
|
+
const geocodeProviders = sortedAdapters.flatMap((adapter) => adapter.geocodeProviders ?? []);
|
|
33
|
+
const routeProviders = sortedAdapters.flatMap((adapter) => adapter.routeProviders ?? []);
|
|
34
|
+
const dedupeByKind = options.dedupeByKind ?? true;
|
|
35
|
+
return {
|
|
36
|
+
searchProviders: dedupeProvidersByKind(searchProviders, dedupeByKind),
|
|
37
|
+
geocodeProviders: dedupeProvidersByKind(geocodeProviders, dedupeByKind),
|
|
38
|
+
routeProviders: dedupeProvidersByKind(routeProviders, dedupeByKind),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createCapabilityRuntime(options) {
|
|
42
|
+
const providers = assembleRuntimeProviders(options);
|
|
43
|
+
return (0, runtime_1.createGaodeRuntime)({
|
|
44
|
+
continueOnError: options.continueOnError,
|
|
45
|
+
onProviderError: options.onProviderError,
|
|
46
|
+
searchProviders: providers.searchProviders,
|
|
47
|
+
geocodeProviders: providers.geocodeProviders,
|
|
48
|
+
routeProviders: providers.routeProviders,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { GaodeRuntime, RuntimeClientOptions } from './runtime';
|
|
2
|
+
import type { RuntimeCapabilityAdapter } from './runtime-assembly';
|
|
3
|
+
import type { WebGeocodeProviderFactoryOptions } from './web-geocode-provider';
|
|
4
|
+
import type { WebRouteProviderFactoryOptions } from './web-route-provider';
|
|
5
|
+
import type { WebProviderFactoryOptions } from './web-search-provider';
|
|
6
|
+
export interface WebRuntimeFactoryOptions extends RuntimeClientOptions {
|
|
7
|
+
search?: WebProviderFactoryOptions;
|
|
8
|
+
geocode?: WebGeocodeProviderFactoryOptions;
|
|
9
|
+
route?: WebRouteProviderFactoryOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface WebDataRuntimeFactoryOptions extends RuntimeClientOptions {
|
|
12
|
+
search?: WebProviderFactoryOptions;
|
|
13
|
+
geocode?: WebGeocodeProviderFactoryOptions;
|
|
14
|
+
}
|
|
15
|
+
export interface WebCapabilityAdapterOptions {
|
|
16
|
+
source?: string;
|
|
17
|
+
priority?: number;
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
search?: WebProviderFactoryOptions;
|
|
20
|
+
geocode?: WebGeocodeProviderFactoryOptions;
|
|
21
|
+
route?: WebRouteProviderFactoryOptions;
|
|
22
|
+
}
|
|
23
|
+
export interface WebDataCapabilityAdapterOptions {
|
|
24
|
+
source?: string;
|
|
25
|
+
priority?: number;
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
search?: WebProviderFactoryOptions;
|
|
28
|
+
geocode?: WebGeocodeProviderFactoryOptions;
|
|
29
|
+
}
|
|
30
|
+
export declare function createWebCapabilityAdapter(options?: WebCapabilityAdapterOptions): RuntimeCapabilityAdapter;
|
|
31
|
+
export declare function createWebDataCapabilityAdapter(options?: WebDataCapabilityAdapterOptions): RuntimeCapabilityAdapter;
|
|
32
|
+
export declare function createWebRuntime(options?: WebRuntimeFactoryOptions): GaodeRuntime;
|
|
33
|
+
export declare function createWebDataRuntime(options?: WebDataRuntimeFactoryOptions): GaodeRuntime;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebCapabilityAdapter = createWebCapabilityAdapter;
|
|
4
|
+
exports.createWebDataCapabilityAdapter = createWebDataCapabilityAdapter;
|
|
5
|
+
exports.createWebRuntime = createWebRuntime;
|
|
6
|
+
exports.createWebDataRuntime = createWebDataRuntime;
|
|
7
|
+
const web_geocode_provider_1 = require("./web-geocode-provider");
|
|
8
|
+
const web_route_provider_1 = require("./web-route-provider");
|
|
9
|
+
const web_search_provider_1 = require("./web-search-provider");
|
|
10
|
+
const runtime_assembly_1 = require("./runtime-assembly");
|
|
11
|
+
function createWebCapabilityAdapter(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
source: options.source ?? 'web-api',
|
|
14
|
+
priority: options.priority,
|
|
15
|
+
enabled: options.enabled,
|
|
16
|
+
searchProviders: [(0, web_search_provider_1.createWebSearchProvider)(options.search)],
|
|
17
|
+
geocodeProviders: [(0, web_geocode_provider_1.createWebGeocodeProvider)(options.geocode)],
|
|
18
|
+
routeProviders: [(0, web_route_provider_1.createWebRouteProvider)(options.route)],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createWebDataCapabilityAdapter(options = {}) {
|
|
22
|
+
return {
|
|
23
|
+
source: options.source ?? 'web-data',
|
|
24
|
+
priority: options.priority,
|
|
25
|
+
enabled: options.enabled,
|
|
26
|
+
searchProviders: [(0, web_search_provider_1.createWebSearchProvider)(options.search)],
|
|
27
|
+
geocodeProviders: [(0, web_geocode_provider_1.createWebGeocodeProvider)(options.geocode)],
|
|
28
|
+
routeProviders: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createWebRuntime(options = {}) {
|
|
32
|
+
return (0, runtime_assembly_1.createCapabilityRuntime)({
|
|
33
|
+
...options,
|
|
34
|
+
adapters: [createWebCapabilityAdapter(options)],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function createWebDataRuntime(options = {}) {
|
|
38
|
+
return (0, runtime_assembly_1.createCapabilityRuntime)({
|
|
39
|
+
...options,
|
|
40
|
+
adapters: [createWebDataCapabilityAdapter(options)],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DrivingRouteParams, GeocodeProvider, InputTipsParams, KeywordSearchParams, NearbySearchParams, PolygonSearchParams, ReverseGeocodeParams, RouteProvider, SearchProvider, TransitRouteParams } from './contracts';
|
|
2
|
+
import type { ReverseGeocodeResult, RoutePlan, SearchPOI, SearchPage, SearchSuggestion } from './domain';
|
|
3
|
+
export type RuntimeClientKind = 'search' | 'geocode' | 'route';
|
|
4
|
+
export type GaodeRuntimeErrorType = 'provider' | 'runtime' | 'config' | 'validation' | 'network' | 'unknown';
|
|
5
|
+
export interface GaodeUnifiedError {
|
|
6
|
+
code: string;
|
|
7
|
+
type: GaodeRuntimeErrorType | string;
|
|
8
|
+
message: string;
|
|
9
|
+
retryable: boolean;
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderErrorContext {
|
|
13
|
+
client: RuntimeClientKind;
|
|
14
|
+
method: string;
|
|
15
|
+
providerKind: string;
|
|
16
|
+
providerIndex: number;
|
|
17
|
+
}
|
|
18
|
+
export interface RuntimeClientOptions {
|
|
19
|
+
continueOnError?: boolean;
|
|
20
|
+
onProviderError?: (context: ProviderErrorContext, error: unknown) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare class GaodeProviderError extends Error implements GaodeUnifiedError {
|
|
23
|
+
readonly code: string;
|
|
24
|
+
readonly type: GaodeRuntimeErrorType;
|
|
25
|
+
readonly retryable: boolean;
|
|
26
|
+
readonly cause?: unknown;
|
|
27
|
+
readonly client: RuntimeClientKind;
|
|
28
|
+
readonly method: string;
|
|
29
|
+
readonly attemptedProviders: string[];
|
|
30
|
+
readonly causes: unknown[];
|
|
31
|
+
constructor(options: {
|
|
32
|
+
client: RuntimeClientKind;
|
|
33
|
+
method: string;
|
|
34
|
+
attemptedProviders: string[];
|
|
35
|
+
causes: unknown[];
|
|
36
|
+
message?: string;
|
|
37
|
+
});
|
|
38
|
+
toJSON(): GaodeUnifiedError & {
|
|
39
|
+
client: RuntimeClientKind;
|
|
40
|
+
method: string;
|
|
41
|
+
attemptedProviders: string[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface SearchClient {
|
|
45
|
+
searchKeyword(params: KeywordSearchParams): Promise<SearchPage<SearchPOI>>;
|
|
46
|
+
searchNearby(params: NearbySearchParams): Promise<SearchPage<SearchPOI>>;
|
|
47
|
+
searchAlong(params: import('./contracts').AlongSearchParams): Promise<SearchPage<SearchPOI>>;
|
|
48
|
+
searchPolygon(params: PolygonSearchParams): Promise<SearchPage<SearchPOI>>;
|
|
49
|
+
getInputTips(params: InputTipsParams): Promise<SearchPage<SearchSuggestion>>;
|
|
50
|
+
getPoiDetail(id: string): Promise<SearchPOI | null>;
|
|
51
|
+
}
|
|
52
|
+
export interface GeocodeClient {
|
|
53
|
+
reverseGeocode(params: ReverseGeocodeParams): Promise<ReverseGeocodeResult>;
|
|
54
|
+
}
|
|
55
|
+
export interface RouteClient {
|
|
56
|
+
calculateDrivingRoute(params: DrivingRouteParams): Promise<RoutePlan>;
|
|
57
|
+
calculateWalkingRoute(params: DrivingRouteParams): Promise<RoutePlan>;
|
|
58
|
+
calculateBicyclingRoute(params: DrivingRouteParams): Promise<RoutePlan>;
|
|
59
|
+
calculateElectricBikeRoute(params: DrivingRouteParams): Promise<RoutePlan>;
|
|
60
|
+
calculateTransitRoutes(params: TransitRouteParams): Promise<RoutePlan[]>;
|
|
61
|
+
}
|
|
62
|
+
export interface GaodeRuntimeOptions extends RuntimeClientOptions {
|
|
63
|
+
searchProviders?: SearchProvider[];
|
|
64
|
+
geocodeProviders?: GeocodeProvider[];
|
|
65
|
+
routeProviders?: RouteProvider[];
|
|
66
|
+
}
|
|
67
|
+
export interface GaodeRuntime {
|
|
68
|
+
search: SearchClient;
|
|
69
|
+
geocode: GeocodeClient;
|
|
70
|
+
route: RouteClient;
|
|
71
|
+
providers: {
|
|
72
|
+
search: SearchProvider[];
|
|
73
|
+
geocode: GeocodeProvider[];
|
|
74
|
+
route: RouteProvider[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export declare function createSearchClient(providers: SearchProvider[], options?: RuntimeClientOptions): SearchClient;
|
|
78
|
+
export declare function createGeocodeClient(providers: GeocodeProvider[], options?: RuntimeClientOptions): GeocodeClient;
|
|
79
|
+
export declare function createRouteClient(providers: RouteProvider[], options?: RuntimeClientOptions): RouteClient;
|
|
80
|
+
export declare function createGaodeRuntime(options?: GaodeRuntimeOptions): GaodeRuntime;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GaodeProviderError = void 0;
|
|
4
|
+
exports.createSearchClient = createSearchClient;
|
|
5
|
+
exports.createGeocodeClient = createGeocodeClient;
|
|
6
|
+
exports.createRouteClient = createRouteClient;
|
|
7
|
+
exports.createGaodeRuntime = createGaodeRuntime;
|
|
8
|
+
class GaodeProviderError extends Error {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
const hasProviders = options.attemptedProviders.length > 0;
|
|
11
|
+
super(options.message ??
|
|
12
|
+
`[v3:${options.client}] ${options.method} failed after trying ${options.attemptedProviders.join(', ')}`);
|
|
13
|
+
this.name = 'GaodeProviderError';
|
|
14
|
+
this.code = hasProviders ? 'PROVIDER_CALL_FAILED' : 'PROVIDER_NOT_REGISTERED';
|
|
15
|
+
this.type = hasProviders ? 'provider' : 'config';
|
|
16
|
+
this.retryable = hasProviders;
|
|
17
|
+
this.cause = options.causes[0];
|
|
18
|
+
this.client = options.client;
|
|
19
|
+
this.method = options.method;
|
|
20
|
+
this.attemptedProviders = options.attemptedProviders;
|
|
21
|
+
this.causes = options.causes;
|
|
22
|
+
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
code: this.code,
|
|
26
|
+
type: this.type,
|
|
27
|
+
message: this.message,
|
|
28
|
+
retryable: this.retryable,
|
|
29
|
+
cause: this.cause,
|
|
30
|
+
client: this.client,
|
|
31
|
+
method: this.method,
|
|
32
|
+
attemptedProviders: this.attemptedProviders,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.GaodeProviderError = GaodeProviderError;
|
|
37
|
+
async function callProviders(providers, client, method, runner, options = {}) {
|
|
38
|
+
const attemptedProviders = [];
|
|
39
|
+
const causes = [];
|
|
40
|
+
for (let index = 0; index < providers.length; index += 1) {
|
|
41
|
+
const provider = providers[index];
|
|
42
|
+
attemptedProviders.push(provider.kind);
|
|
43
|
+
try {
|
|
44
|
+
return await runner(provider);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
causes.push(error);
|
|
48
|
+
options.onProviderError?.({
|
|
49
|
+
client,
|
|
50
|
+
method,
|
|
51
|
+
providerKind: provider.kind,
|
|
52
|
+
providerIndex: index,
|
|
53
|
+
}, error);
|
|
54
|
+
if (!options.continueOnError) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new GaodeProviderError({
|
|
60
|
+
client,
|
|
61
|
+
method,
|
|
62
|
+
attemptedProviders,
|
|
63
|
+
causes,
|
|
64
|
+
message: attemptedProviders.length === 0
|
|
65
|
+
? `[v3:${client}] ${method} has no registered providers`
|
|
66
|
+
: undefined,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function getSupportedProviders(providers, predicate) {
|
|
70
|
+
return providers.filter(predicate);
|
|
71
|
+
}
|
|
72
|
+
function createSearchClient(providers, options = {}) {
|
|
73
|
+
return {
|
|
74
|
+
searchKeyword(params) {
|
|
75
|
+
return callProviders(providers, 'search', 'searchKeyword', (provider) => provider.searchKeyword(params), options);
|
|
76
|
+
},
|
|
77
|
+
searchNearby(params) {
|
|
78
|
+
return callProviders(providers, 'search', 'searchNearby', (provider) => provider.searchNearby(params), options);
|
|
79
|
+
},
|
|
80
|
+
searchAlong(params) {
|
|
81
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.searchAlong === 'function');
|
|
82
|
+
return callProviders(supportedProviders, 'search', 'searchAlong', (provider) => provider.searchAlong(params), options);
|
|
83
|
+
},
|
|
84
|
+
searchPolygon(params) {
|
|
85
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.searchPolygon === 'function');
|
|
86
|
+
return callProviders(supportedProviders, 'search', 'searchPolygon', (provider) => provider.searchPolygon(params), options);
|
|
87
|
+
},
|
|
88
|
+
getInputTips(params) {
|
|
89
|
+
return callProviders(providers, 'search', 'getInputTips', (provider) => provider.getInputTips(params), options);
|
|
90
|
+
},
|
|
91
|
+
getPoiDetail(id) {
|
|
92
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.getPoiDetail === 'function');
|
|
93
|
+
return callProviders(supportedProviders, 'search', 'getPoiDetail', (provider) => provider.getPoiDetail(id), options);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function createGeocodeClient(providers, options = {}) {
|
|
98
|
+
return {
|
|
99
|
+
reverseGeocode(params) {
|
|
100
|
+
return callProviders(providers, 'geocode', 'reverseGeocode', (provider) => provider.reverseGeocode(params), options);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function createRouteClient(providers, options = {}) {
|
|
105
|
+
return {
|
|
106
|
+
calculateDrivingRoute(params) {
|
|
107
|
+
return callProviders(providers, 'route', 'calculateDrivingRoute', (provider) => provider.calculateDrivingRoute(params), options);
|
|
108
|
+
},
|
|
109
|
+
calculateWalkingRoute(params) {
|
|
110
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.calculateWalkingRoute === 'function');
|
|
111
|
+
return callProviders(supportedProviders, 'route', 'calculateWalkingRoute', (provider) => provider.calculateWalkingRoute(params), options);
|
|
112
|
+
},
|
|
113
|
+
calculateBicyclingRoute(params) {
|
|
114
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.calculateBicyclingRoute === 'function');
|
|
115
|
+
return callProviders(supportedProviders, 'route', 'calculateBicyclingRoute', (provider) => provider.calculateBicyclingRoute(params), options);
|
|
116
|
+
},
|
|
117
|
+
calculateElectricBikeRoute(params) {
|
|
118
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.calculateElectricBikeRoute === 'function');
|
|
119
|
+
return callProviders(supportedProviders, 'route', 'calculateElectricBikeRoute', (provider) => provider.calculateElectricBikeRoute(params), options);
|
|
120
|
+
},
|
|
121
|
+
calculateTransitRoutes(params) {
|
|
122
|
+
const supportedProviders = getSupportedProviders(providers, (provider) => typeof provider.calculateTransitRoutes === 'function');
|
|
123
|
+
return callProviders(supportedProviders, 'route', 'calculateTransitRoutes', (provider) => provider.calculateTransitRoutes(params), options);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createGaodeRuntime(options = {}) {
|
|
128
|
+
const searchProviders = options.searchProviders ?? [];
|
|
129
|
+
const geocodeProviders = options.geocodeProviders ?? [];
|
|
130
|
+
const routeProviders = options.routeProviders ?? [];
|
|
131
|
+
return {
|
|
132
|
+
search: createSearchClient(searchProviders, options),
|
|
133
|
+
geocode: createGeocodeClient(geocodeProviders, options),
|
|
134
|
+
route: createRouteClient(routeProviders, options),
|
|
135
|
+
providers: {
|
|
136
|
+
search: searchProviders,
|
|
137
|
+
geocode: geocodeProviders,
|
|
138
|
+
route: routeProviders,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClientConfig } from '../utils/client';
|
|
2
|
+
import { type WebGeocodeApiAdapter } from './web-service-adapter';
|
|
3
|
+
import type { GeocodeProvider } from './contracts';
|
|
4
|
+
export interface WebGeocodeProviderFactoryOptions {
|
|
5
|
+
api?: WebGeocodeApiAdapter;
|
|
6
|
+
config?: ClientConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function createWebGeocodeProvider(options?: WebGeocodeProviderFactoryOptions): GeocodeProvider;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebGeocodeProvider = createWebGeocodeProvider;
|
|
4
|
+
const web_service_adapter_1 = require("./web-service-adapter");
|
|
5
|
+
function getApi(options = {}) {
|
|
6
|
+
if (options.api) {
|
|
7
|
+
return options.api;
|
|
8
|
+
}
|
|
9
|
+
return (0, web_service_adapter_1.createWebGeocodeApiAdapter)(options.config);
|
|
10
|
+
}
|
|
11
|
+
function parseLocation(location) {
|
|
12
|
+
if (!location) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const [longitude, latitude] = location.split(',').map((value) => Number(value.trim()));
|
|
16
|
+
if (!Number.isFinite(longitude) || !Number.isFinite(latitude)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
latitude,
|
|
21
|
+
longitude,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function normalizePois(regeocode) {
|
|
25
|
+
return (regeocode.pois ?? []).map((poi) => ({
|
|
26
|
+
id: poi.id,
|
|
27
|
+
name: poi.name,
|
|
28
|
+
address: poi.address,
|
|
29
|
+
location: parseLocation(poi.location),
|
|
30
|
+
typeName: poi.type,
|
|
31
|
+
distanceMeters: poi.distance ? Number(poi.distance) : undefined,
|
|
32
|
+
source: 'web',
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function toReverseGeocodeResult(response, location) {
|
|
36
|
+
return {
|
|
37
|
+
formattedAddress: response.regeocode?.formatted_address ?? '',
|
|
38
|
+
location,
|
|
39
|
+
pois: response.regeocode ? normalizePois(response.regeocode) : [],
|
|
40
|
+
raw: response,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createWebGeocodeProvider(options = {}) {
|
|
44
|
+
const api = getApi(options);
|
|
45
|
+
return {
|
|
46
|
+
kind: 'web-geocode',
|
|
47
|
+
async reverseGeocode(params) {
|
|
48
|
+
const response = await api.geocode.regeocode(params.location, {
|
|
49
|
+
radius: params.radius,
|
|
50
|
+
extensions: params.extensions ?? 'all',
|
|
51
|
+
});
|
|
52
|
+
return toReverseGeocodeResult(response, params.location);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClientConfig } from '../utils/client';
|
|
2
|
+
import { type WebRouteApiAdapter } from './web-service-adapter';
|
|
3
|
+
import type { RouteProvider } from './contracts';
|
|
4
|
+
export interface WebRouteProviderFactoryOptions {
|
|
5
|
+
api?: WebRouteApiAdapter;
|
|
6
|
+
config?: ClientConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function createWebRouteProvider(options?: WebRouteProviderFactoryOptions): RouteProvider;
|