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,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebRouteProvider = createWebRouteProvider;
|
|
4
|
+
const normalizers_1 = require("../utils/normalizers");
|
|
5
|
+
const web_service_adapter_1 = require("./web-service-adapter");
|
|
6
|
+
function getApi(options = {}) {
|
|
7
|
+
if (options.api) {
|
|
8
|
+
return options.api;
|
|
9
|
+
}
|
|
10
|
+
return (0, web_service_adapter_1.createWebRouteApiAdapter)(options.config);
|
|
11
|
+
}
|
|
12
|
+
function normalizeSinglePlan(response) {
|
|
13
|
+
const firstPath = response.route?.paths?.[0];
|
|
14
|
+
return {
|
|
15
|
+
distanceMeters: Number(firstPath?.distance ?? 0),
|
|
16
|
+
durationSeconds: Number(firstPath?.cost?.duration ?? firstPath?.duration ?? 0),
|
|
17
|
+
path: (0, normalizers_1.extractRoutePoints)(response),
|
|
18
|
+
source: 'web',
|
|
19
|
+
raw: response,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function normalizeTransitPlans(response) {
|
|
23
|
+
const paths = (0, normalizers_1.extractTransitRoutePoints)(response);
|
|
24
|
+
const transits = response.route?.transits ?? [];
|
|
25
|
+
return paths.map((path, index) => ({
|
|
26
|
+
distanceMeters: Number(transits[index]?.distance ?? 0),
|
|
27
|
+
durationSeconds: Number(transits[index]?.cost?.duration ?? 0),
|
|
28
|
+
path,
|
|
29
|
+
source: 'web',
|
|
30
|
+
raw: transits[index] ?? response,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
function toCoordinateString(point) {
|
|
34
|
+
return `${point.longitude},${point.latitude}`;
|
|
35
|
+
}
|
|
36
|
+
function createWebRouteProvider(options = {}) {
|
|
37
|
+
const api = getApi(options);
|
|
38
|
+
return {
|
|
39
|
+
kind: 'web-route',
|
|
40
|
+
async calculateDrivingRoute(params) {
|
|
41
|
+
const response = await api.route.driving(params.origin, params.destination, {
|
|
42
|
+
show_fields: 'cost,polyline',
|
|
43
|
+
strategy: typeof params.strategy === 'number' ? params.strategy : undefined,
|
|
44
|
+
waypoints: params.waypoints?.map(toCoordinateString),
|
|
45
|
+
});
|
|
46
|
+
return normalizeSinglePlan(response);
|
|
47
|
+
},
|
|
48
|
+
async calculateWalkingRoute(params) {
|
|
49
|
+
const response = await api.route.walking(params.origin, params.destination, {
|
|
50
|
+
show_fields: 'cost,polyline',
|
|
51
|
+
});
|
|
52
|
+
return normalizeSinglePlan(response);
|
|
53
|
+
},
|
|
54
|
+
async calculateBicyclingRoute(params) {
|
|
55
|
+
const response = await api.route.bicycling(params.origin, params.destination, {
|
|
56
|
+
show_fields: 'cost,polyline',
|
|
57
|
+
});
|
|
58
|
+
return normalizeSinglePlan(response);
|
|
59
|
+
},
|
|
60
|
+
async calculateElectricBikeRoute(params) {
|
|
61
|
+
const response = await api.route.electricBike(params.origin, params.destination, {
|
|
62
|
+
show_fields: 'cost,polyline',
|
|
63
|
+
});
|
|
64
|
+
return normalizeSinglePlan(response);
|
|
65
|
+
},
|
|
66
|
+
async calculateTransitRoutes(params) {
|
|
67
|
+
const response = await api.route.transit(params.origin, params.destination, params.city1, params.city2, {
|
|
68
|
+
strategy: typeof params.strategy === 'number' ? params.strategy : undefined,
|
|
69
|
+
AlternativeRoute: params.alternativeRoute,
|
|
70
|
+
show_fields: 'cost,polyline',
|
|
71
|
+
});
|
|
72
|
+
return normalizeTransitPlans(response);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClientConfig } from '../utils/client';
|
|
2
|
+
import { type WebSearchApiAdapter } from './web-service-adapter';
|
|
3
|
+
import type { SearchProvider } from './contracts';
|
|
4
|
+
export interface WebProviderFactoryOptions {
|
|
5
|
+
api?: WebSearchApiAdapter;
|
|
6
|
+
config?: ClientConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function createWebSearchProvider(options?: WebProviderFactoryOptions): SearchProvider;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebSearchProvider = createWebSearchProvider;
|
|
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.createWebSearchApiAdapter)(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 toSearchPoi(poi) {
|
|
25
|
+
return {
|
|
26
|
+
id: poi.id,
|
|
27
|
+
name: poi.name,
|
|
28
|
+
address: poi.address,
|
|
29
|
+
location: parseLocation(poi.location),
|
|
30
|
+
typeCode: poi.typecode,
|
|
31
|
+
typeName: poi.type,
|
|
32
|
+
distanceMeters: poi.distance ? Number(poi.distance) : undefined,
|
|
33
|
+
cityCode: poi.citycode,
|
|
34
|
+
cityName: poi.cityname,
|
|
35
|
+
districtCode: poi.adcode,
|
|
36
|
+
districtName: poi.adname,
|
|
37
|
+
provinceName: poi.pname,
|
|
38
|
+
source: 'web',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function toSearchSuggestion(tip) {
|
|
42
|
+
return {
|
|
43
|
+
id: tip.id,
|
|
44
|
+
name: tip.name,
|
|
45
|
+
address: tip.address,
|
|
46
|
+
location: parseLocation(tip.location),
|
|
47
|
+
districtName: tip.district,
|
|
48
|
+
typeCode: tip.typecode,
|
|
49
|
+
source: 'web',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function toSearchPage(response) {
|
|
53
|
+
return {
|
|
54
|
+
items: response.pois.map(toSearchPoi),
|
|
55
|
+
total: Number(response.count),
|
|
56
|
+
page: null,
|
|
57
|
+
pageSize: null,
|
|
58
|
+
raw: response,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function toInputTipsPage(response) {
|
|
62
|
+
return {
|
|
63
|
+
items: response.tips.map(toSearchSuggestion),
|
|
64
|
+
total: Number(response.count),
|
|
65
|
+
page: null,
|
|
66
|
+
pageSize: null,
|
|
67
|
+
raw: response,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function createWebSearchProvider(options = {}) {
|
|
71
|
+
const api = getApi(options);
|
|
72
|
+
return {
|
|
73
|
+
kind: 'web-search',
|
|
74
|
+
async searchKeyword(params) {
|
|
75
|
+
const response = await api.poi.search(params.keyword, {
|
|
76
|
+
region: params.city,
|
|
77
|
+
city_limit: params.cityLimit,
|
|
78
|
+
types: params.types,
|
|
79
|
+
page_num: params.page,
|
|
80
|
+
page_size: params.pageSize,
|
|
81
|
+
});
|
|
82
|
+
return toSearchPage(response);
|
|
83
|
+
},
|
|
84
|
+
async searchNearby(params) {
|
|
85
|
+
const response = await api.poi.searchAround(params.center, {
|
|
86
|
+
keywords: params.keyword,
|
|
87
|
+
radius: params.radius,
|
|
88
|
+
types: params.types,
|
|
89
|
+
page_num: params.page,
|
|
90
|
+
page_size: params.pageSize,
|
|
91
|
+
sortrule: 'distance',
|
|
92
|
+
});
|
|
93
|
+
return toSearchPage(response);
|
|
94
|
+
},
|
|
95
|
+
async searchPolygon(params) {
|
|
96
|
+
const polygon = params.polygon
|
|
97
|
+
.map((point) => `${point.longitude},${point.latitude}`)
|
|
98
|
+
.join('|');
|
|
99
|
+
const response = await api.poi.searchPolygon(polygon, {
|
|
100
|
+
keywords: params.keyword,
|
|
101
|
+
types: params.types,
|
|
102
|
+
page_num: params.page,
|
|
103
|
+
page_size: params.pageSize,
|
|
104
|
+
});
|
|
105
|
+
return toSearchPage(response);
|
|
106
|
+
},
|
|
107
|
+
async getInputTips(params) {
|
|
108
|
+
const response = await api.inputTips.getTips(params.keyword, {
|
|
109
|
+
city: params.city,
|
|
110
|
+
type: params.types,
|
|
111
|
+
datatype: params.datatype,
|
|
112
|
+
citylimit: params.cityLimit,
|
|
113
|
+
location: params.location
|
|
114
|
+
? `${params.location.longitude},${params.location.latitude}`
|
|
115
|
+
: undefined,
|
|
116
|
+
});
|
|
117
|
+
return toInputTipsPage(response);
|
|
118
|
+
},
|
|
119
|
+
async getPoiDetail(id) {
|
|
120
|
+
const response = await api.poi.getDetail(id);
|
|
121
|
+
const [poi] = response.pois ?? [];
|
|
122
|
+
return poi ? toSearchPoi(poi) : null;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ClientConfig } from '../utils/client';
|
|
2
|
+
import { GeocodeService } from '../services/GeocodeService';
|
|
3
|
+
import { InputTipsService } from '../services/InputTipsService';
|
|
4
|
+
import { POIService } from '../services/POIService';
|
|
5
|
+
import { RouteService } from '../services/RouteService';
|
|
6
|
+
export interface WebSearchApiAdapter {
|
|
7
|
+
poi: Pick<POIService, 'search' | 'searchAround' | 'searchPolygon' | 'getDetail'>;
|
|
8
|
+
inputTips: Pick<InputTipsService, 'getTips'>;
|
|
9
|
+
}
|
|
10
|
+
export interface WebGeocodeApiAdapter {
|
|
11
|
+
geocode: Pick<GeocodeService, 'regeocode'>;
|
|
12
|
+
}
|
|
13
|
+
export interface WebRouteApiAdapter {
|
|
14
|
+
route: Pick<RouteService, 'driving' | 'walking' | 'bicycling' | 'electricBike' | 'transit'>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createWebSearchApiAdapter(config?: ClientConfig): WebSearchApiAdapter;
|
|
17
|
+
export declare function createWebGeocodeApiAdapter(config?: ClientConfig): WebGeocodeApiAdapter;
|
|
18
|
+
export declare function createWebRouteApiAdapter(config?: ClientConfig): WebRouteApiAdapter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebSearchApiAdapter = createWebSearchApiAdapter;
|
|
4
|
+
exports.createWebGeocodeApiAdapter = createWebGeocodeApiAdapter;
|
|
5
|
+
exports.createWebRouteApiAdapter = createWebRouteApiAdapter;
|
|
6
|
+
const client_1 = require("../utils/client");
|
|
7
|
+
const GeocodeService_1 = require("../services/GeocodeService");
|
|
8
|
+
const InputTipsService_1 = require("../services/InputTipsService");
|
|
9
|
+
const POIService_1 = require("../services/POIService");
|
|
10
|
+
const RouteService_1 = require("../services/RouteService");
|
|
11
|
+
function createClient(config) {
|
|
12
|
+
return new client_1.GaodeWebAPIClient(config ?? {});
|
|
13
|
+
}
|
|
14
|
+
function createWebSearchApiAdapter(config) {
|
|
15
|
+
const client = createClient(config);
|
|
16
|
+
return {
|
|
17
|
+
poi: new POIService_1.POIService(client),
|
|
18
|
+
inputTips: new InputTipsService_1.InputTipsService(client),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createWebGeocodeApiAdapter(config) {
|
|
22
|
+
const client = createClient(config);
|
|
23
|
+
return {
|
|
24
|
+
geocode: new GeocodeService_1.GeocodeService(client),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createWebRouteApiAdapter(config) {
|
|
28
|
+
const client = createClient(config);
|
|
29
|
+
return {
|
|
30
|
+
route: new RouteService_1.RouteService(client),
|
|
31
|
+
};
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map-web-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5-next.0",
|
|
4
4
|
"description": "高德地图 Web API 服务 - 搜索、路径规划、地理编码(纯 JavaScript 实现),配合 expo-gaode-map或者 expo-gaode-map-navigation 使用",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -27,13 +27,17 @@
|
|
|
27
27
|
"route",
|
|
28
28
|
"高德地图"
|
|
29
29
|
],
|
|
30
|
-
"repository":
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/TomWq/expo-gaode-map",
|
|
33
|
+
"directory": "packages/web-api"
|
|
34
|
+
},
|
|
31
35
|
"bugs": {
|
|
32
36
|
"url": "https://github.com/TomWq/expo-gaode-map/issues"
|
|
33
37
|
},
|
|
34
|
-
"author": "(https://github.com/TomWq)",
|
|
38
|
+
"author": "TomWq <582752848@qq.com> (https://github.com/TomWq)",
|
|
35
39
|
"license": "MIT",
|
|
36
|
-
"homepage": "https://github.
|
|
40
|
+
"homepage": "https://tomwq.github.io/expo-gaode-map/",
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/react": "~19.1.0",
|
|
39
43
|
"bun-types": "^1.3.6",
|