ola-map-sdk 1.3.0 → 2.0.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/LICENSE +20 -20
- package/README.md +380 -215
- package/dist/chunk-22747AE4.js +978 -0
- package/dist/chunk-22747AE4.js.map +1 -0
- package/dist/chunk-5YVHNDSA.cjs +282 -0
- package/dist/chunk-5YVHNDSA.cjs.map +1 -0
- package/dist/chunk-6J7XUGWD.cjs +443 -0
- package/dist/chunk-6J7XUGWD.cjs.map +1 -0
- package/dist/chunk-7LV3RPED.js +440 -0
- package/dist/chunk-7LV3RPED.js.map +1 -0
- package/dist/chunk-D5T5ZDIQ.js +268 -0
- package/dist/chunk-D5T5ZDIQ.js.map +1 -0
- package/dist/chunk-SJJRTEQG.js +94 -0
- package/dist/chunk-SJJRTEQG.js.map +1 -0
- package/dist/chunk-WLUKC7YU.cjs +991 -0
- package/dist/chunk-WLUKC7YU.cjs.map +1 -0
- package/dist/chunk-XRJXKY7C.cjs +100 -0
- package/dist/chunk-XRJXKY7C.cjs.map +1 -0
- package/dist/client-Cd22y5wG.d.cts +782 -0
- package/dist/client-DsBMyuG9.d.ts +782 -0
- package/dist/common-Bt8xNzhK.d.cts +115 -0
- package/dist/common-Bt8xNzhK.d.ts +115 -0
- package/dist/index.cjs +115 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/maplibre/index.cjs +29 -0
- package/dist/maplibre/index.cjs.map +1 -0
- package/dist/maplibre/index.d.cts +63 -0
- package/dist/maplibre/index.d.ts +63 -0
- package/dist/maplibre/index.js +4 -0
- package/dist/maplibre/index.js.map +1 -0
- package/dist/next/index.cjs +173 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +65 -0
- package/dist/next/index.d.ts +65 -0
- package/dist/next/index.js +169 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.cjs +257 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +77 -0
- package/dist/react/index.d.ts +77 -0
- package/dist/react/index.js +251 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +111 -11
- package/src/client.js +0 -95
- package/src/endpoints/elevation.js +0 -58
- package/src/endpoints/geofencing.js +0 -118
- package/src/endpoints/places.js +0 -106
- package/src/endpoints/roads.js +0 -57
- package/src/endpoints/routing.js +0 -160
- package/src/endpoints/tiles.js +0 -115
- package/src/index.js +0 -5
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
class Geofencing {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async getRequest(endpoint, params = {}) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey },
|
|
11
|
-
headers: { 'Accept': 'application/json' },
|
|
12
|
-
});
|
|
13
|
-
return data;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
const errorMessage = error.response
|
|
16
|
-
? `Geofencing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
17
|
-
: `Geofencing API Error: ${error.message}`;
|
|
18
|
-
console.error(errorMessage);
|
|
19
|
-
throw new Error(errorMessage);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create a new geofence.
|
|
25
|
-
* @param {Object} data - { name, type ('polygon'|'circle'), coordinates, radius, status ('active'|'inactive'), projectId }
|
|
26
|
-
*/
|
|
27
|
-
async create(geofenceData) {
|
|
28
|
-
if (!geofenceData) throw new Error('geofence data is required');
|
|
29
|
-
try {
|
|
30
|
-
const { data } = await this.client.post('/places/v1/geofence', geofenceData, {
|
|
31
|
-
params: { api_key: this.apiKey },
|
|
32
|
-
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
|
|
33
|
-
});
|
|
34
|
-
return data;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
const errorMessage = error.response
|
|
37
|
-
? `Geofencing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
38
|
-
: `Geofencing API Error: ${error.message}`;
|
|
39
|
-
console.error(errorMessage);
|
|
40
|
-
throw new Error(errorMessage);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Update an existing geofence.
|
|
46
|
-
* @param {string} id - Geofence ID
|
|
47
|
-
* @param {Object} data - Updated geofence data
|
|
48
|
-
*/
|
|
49
|
-
async update(id, geofenceData) {
|
|
50
|
-
if (!id || !geofenceData) throw new Error('id and geofence data are required');
|
|
51
|
-
try {
|
|
52
|
-
const { data } = await this.client.put(`/places/v1/geofence/${encodeURIComponent(id)}`, geofenceData, {
|
|
53
|
-
params: { api_key: this.apiKey },
|
|
54
|
-
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
|
|
55
|
-
});
|
|
56
|
-
return data;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
const errorMessage = error.response
|
|
59
|
-
? `Geofencing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
60
|
-
: `Geofencing API Error: ${error.message}`;
|
|
61
|
-
console.error(errorMessage);
|
|
62
|
-
throw new Error(errorMessage);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get a geofence by ID.
|
|
68
|
-
* @param {string} id - Geofence ID
|
|
69
|
-
*/
|
|
70
|
-
getById(id) {
|
|
71
|
-
if (!id) throw new Error('id is required');
|
|
72
|
-
return this.getRequest(`/places/v1/geofence/${encodeURIComponent(id)}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Delete a geofence by ID.
|
|
77
|
-
* @param {string} id - Geofence ID
|
|
78
|
-
*/
|
|
79
|
-
async deleteById(id) {
|
|
80
|
-
if (!id) throw new Error('id is required');
|
|
81
|
-
try {
|
|
82
|
-
const { data } = await this.client.delete(`/places/v1/geofence/${encodeURIComponent(id)}`, {
|
|
83
|
-
params: { api_key: this.apiKey },
|
|
84
|
-
headers: { 'Accept': 'application/json' },
|
|
85
|
-
});
|
|
86
|
-
return data;
|
|
87
|
-
} catch (error) {
|
|
88
|
-
const errorMessage = error.response
|
|
89
|
-
? `Geofencing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
90
|
-
: `Geofencing API Error: ${error.message}`;
|
|
91
|
-
console.error(errorMessage);
|
|
92
|
-
throw new Error(errorMessage);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* List geofences for a project.
|
|
98
|
-
* @param {string} projectId - Project ID
|
|
99
|
-
* @param {number} page - Page number
|
|
100
|
-
* @param {number} size - Records per page
|
|
101
|
-
*/
|
|
102
|
-
list(projectId, page = 1, size = 10) {
|
|
103
|
-
if (!projectId) throw new Error('projectId is required');
|
|
104
|
-
return this.getRequest('/places/v1/geofences', { projectId, page, size });
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Check if coordinates are inside/outside a geofence.
|
|
109
|
-
* @param {string} geofenceId - Geofence ID
|
|
110
|
-
* @param {string} coordinates - lat,lng format
|
|
111
|
-
*/
|
|
112
|
-
checkStatus(geofenceId, coordinates) {
|
|
113
|
-
if (!geofenceId || !coordinates) throw new Error('geofenceId and coordinates are required');
|
|
114
|
-
return this.getRequest('/places/v1/geofence/status', { geofenceId, coordinates });
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = Geofencing;
|
package/src/endpoints/places.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
class Places {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async request(endpoint, params) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey }
|
|
11
|
-
});
|
|
12
|
-
return data;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
const errorMessage = error.response
|
|
15
|
-
? `Error ${error.response.status}: ${error.response.data.message}`
|
|
16
|
-
: `Request failed: ${error.message}`;
|
|
17
|
-
console.error(`Places API request failed: ${errorMessage}`);
|
|
18
|
-
throw new Error(`Places API request failed: ${errorMessage}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
autocomplete(input, options = {}) {
|
|
23
|
-
const params = { input };
|
|
24
|
-
if (options.location) params.location = options.location;
|
|
25
|
-
if (options.radius != null) params.radius = options.radius;
|
|
26
|
-
if (options.strictbounds != null) params.strictbounds = options.strictbounds;
|
|
27
|
-
if (options.language) params.language = options.language;
|
|
28
|
-
if (options.types) params.types = options.types;
|
|
29
|
-
return this.request('/places/v1/autocomplete', params);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
geocode(address, language) {
|
|
33
|
-
const params = { address };
|
|
34
|
-
if (language) params.language = language;
|
|
35
|
-
return this.request('/places/v1/geocode', params);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
reverseGeocode(lat, lng, language) {
|
|
39
|
-
if (typeof lat !== 'number' || typeof lng !== 'number') {
|
|
40
|
-
throw new TypeError('Latitude and longitude must be numbers');
|
|
41
|
-
}
|
|
42
|
-
const params = { latlng: `${lat},${lng}` };
|
|
43
|
-
if (language) params.language = language;
|
|
44
|
-
return this.request('/places/v1/reverse-geocode', params);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
placeDetails(placeId, language) {
|
|
48
|
-
if (!placeId) throw new Error('place_id is required');
|
|
49
|
-
const params = { place_id: placeId };
|
|
50
|
-
if (language) params.language = language;
|
|
51
|
-
return this.request('/places/v1/details', params);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
placeDetailsAdvanced(placeId, language) {
|
|
55
|
-
if (!placeId) throw new Error('place_id is required');
|
|
56
|
-
const params = { place_id: placeId };
|
|
57
|
-
if (language) params.language = language;
|
|
58
|
-
return this.request('/places/v1/details/advanced', params);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
nearbySearch(location, options = {}) {
|
|
62
|
-
if (!location) throw new Error('location is required (lat,lng format)');
|
|
63
|
-
const params = { location };
|
|
64
|
-
if (options.types) params.types = options.types;
|
|
65
|
-
if (options.language) params.language = options.language;
|
|
66
|
-
if (options.radius != null) params.radius = options.radius;
|
|
67
|
-
if (options.withCentroid != null) params.withCentroid = options.withCentroid;
|
|
68
|
-
if (options.rankBy) params.rankBy = options.rankBy;
|
|
69
|
-
if (options.limit != null) params.limit = options.limit;
|
|
70
|
-
return this.request('/places/v1/nearbysearch', params);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
nearbySearchAdvanced(location, options = {}) {
|
|
74
|
-
if (!location) throw new Error('location is required (lat,lng format)');
|
|
75
|
-
const params = { location };
|
|
76
|
-
if (options.types) params.types = options.types;
|
|
77
|
-
if (options.language) params.language = options.language;
|
|
78
|
-
if (options.radius != null) params.radius = options.radius;
|
|
79
|
-
if (options.withCentroid != null) params.withCentroid = options.withCentroid;
|
|
80
|
-
if (options.rankBy) params.rankBy = options.rankBy;
|
|
81
|
-
if (options.limit != null) params.limit = options.limit;
|
|
82
|
-
return this.request('/places/v1/nearbysearch/advanced', params);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
textSearch(input, options = {}) {
|
|
86
|
-
if (!input) throw new Error('input text is required');
|
|
87
|
-
const params = { input };
|
|
88
|
-
if (options.location) params.location = options.location;
|
|
89
|
-
if (options.radius != null) params.radius = options.radius;
|
|
90
|
-
if (options.types) params.types = options.types;
|
|
91
|
-
if (options.size != null) params.size = options.size;
|
|
92
|
-
return this.request('/places/v1/textsearch', params);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
addressValidation(address) {
|
|
96
|
-
if (!address) throw new Error('address is required');
|
|
97
|
-
return this.request('/places/v1/addressvalidation', { address });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
photo(photoReference) {
|
|
101
|
-
if (!photoReference) throw new Error('photo_reference is required');
|
|
102
|
-
return this.request('/places/v1/photo', { photo_reference: photoReference });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = Places;
|
package/src/endpoints/roads.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
class Roads {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async request(endpoint, params = {}) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey },
|
|
11
|
-
headers: { 'Accept': 'application/json' },
|
|
12
|
-
});
|
|
13
|
-
return data;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
const errorMessage = error.response
|
|
16
|
-
? `Roads API Error: ${error.response.status} - ${error.response.data.message}`
|
|
17
|
-
: `Roads API Error: ${error.message}`;
|
|
18
|
-
console.error(errorMessage);
|
|
19
|
-
throw new Error(errorMessage);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Snap coordinates to the nearest road segments.
|
|
25
|
-
* @param {string} points - Pipe-separated lat,lng pairs (max 50)
|
|
26
|
-
* @param {boolean} [enhancePath=false] - Add intermediate points for road curvature
|
|
27
|
-
*/
|
|
28
|
-
snapToRoad(points, enhancePath = false) {
|
|
29
|
-
if (!points) throw new Error('points are required');
|
|
30
|
-
return this.request('/routing/v1/snapToRoad', { points, enhancePath });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Find nearest roads for each coordinate.
|
|
35
|
-
* @param {string} points - Pipe-separated lat,lng pairs (max 100)
|
|
36
|
-
* @param {string} mode - DRIVING, WALKING, BICYCLING, or TRANSIT
|
|
37
|
-
* @param {number} [radius=500] - Search radius in meters
|
|
38
|
-
*/
|
|
39
|
-
nearestRoads(points, mode, radius) {
|
|
40
|
-
if (!points || !mode) throw new Error('points and mode are required');
|
|
41
|
-
const params = { points, mode };
|
|
42
|
-
if (radius != null) params.radius = radius;
|
|
43
|
-
return this.request('/routing/v1/nearestRoads', params);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get speed limits for snapped road segments.
|
|
48
|
-
* @param {string} points - Pipe-separated lat,lng pairs (max 50)
|
|
49
|
-
* @param {string} [snapStrategy='snaptoroad'] - snaptoroad or nearestroad
|
|
50
|
-
*/
|
|
51
|
-
speedLimits(points, snapStrategy = 'snaptoroad') {
|
|
52
|
-
if (!points) throw new Error('points are required');
|
|
53
|
-
return this.request('/routing/v1/speedLimits', { points, snapStrategy });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = Roads;
|
package/src/endpoints/routing.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
class Routing {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async postRequest(endpoint, params) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await this.client.post(endpoint, null, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey },
|
|
11
|
-
headers: { 'Accept': 'application/json' },
|
|
12
|
-
});
|
|
13
|
-
return data;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
const errorMessage = error.response
|
|
16
|
-
? `Routing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
17
|
-
: `Routing API Error: ${error.message}`;
|
|
18
|
-
console.error(errorMessage);
|
|
19
|
-
throw new Error(errorMessage);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getRequest(endpoint, params) {
|
|
24
|
-
try {
|
|
25
|
-
const { data } = await this.client.get(endpoint, {
|
|
26
|
-
params: { ...params, api_key: this.apiKey },
|
|
27
|
-
headers: { 'Accept': 'application/json' },
|
|
28
|
-
});
|
|
29
|
-
return data;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
const errorMessage = error.response
|
|
32
|
-
? `Routing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
33
|
-
: `Routing API Error: ${error.message}`;
|
|
34
|
-
console.error(errorMessage);
|
|
35
|
-
throw new Error(errorMessage);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getDirections(origin, destination, options = {}) {
|
|
40
|
-
const { lat: originLat, lon: originLon } = origin;
|
|
41
|
-
const { lat: destLat, lon: destLon } = destination;
|
|
42
|
-
|
|
43
|
-
const params = {
|
|
44
|
-
origin: `${originLat},${originLon}`,
|
|
45
|
-
destination: `${destLat},${destLon}`,
|
|
46
|
-
alternatives: options.alternatives ?? false,
|
|
47
|
-
steps: options.steps ?? true,
|
|
48
|
-
overview: options.overview ?? 'full',
|
|
49
|
-
language: options.language ?? 'en',
|
|
50
|
-
traffic_metadata: options.traffic_metadata ?? false,
|
|
51
|
-
};
|
|
52
|
-
if (options.waypoints) params.waypoints = options.waypoints;
|
|
53
|
-
if (options.mode) params.mode = options.mode;
|
|
54
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
55
|
-
|
|
56
|
-
return this.postRequest('/routing/v1/directions', params);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getDirectionsBasic(origin, destination, options = {}) {
|
|
60
|
-
const { lat: originLat, lon: originLon } = origin;
|
|
61
|
-
const { lat: destLat, lon: destLon } = destination;
|
|
62
|
-
|
|
63
|
-
const params = {
|
|
64
|
-
origin: `${originLat},${originLon}`,
|
|
65
|
-
destination: `${destLat},${destLon}`,
|
|
66
|
-
alternatives: options.alternatives ?? false,
|
|
67
|
-
steps: options.steps ?? true,
|
|
68
|
-
overview: options.overview ?? 'full',
|
|
69
|
-
language: options.language ?? 'en',
|
|
70
|
-
};
|
|
71
|
-
if (options.waypoints) params.waypoints = options.waypoints;
|
|
72
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
73
|
-
|
|
74
|
-
return this.postRequest('/routing/v1/directions/basic', params);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getDistanceMatrix(origins, destinations, options = {}) {
|
|
78
|
-
if (!origins || !destinations) {
|
|
79
|
-
throw new Error('origins and destinations are required');
|
|
80
|
-
}
|
|
81
|
-
const params = {
|
|
82
|
-
origins,
|
|
83
|
-
destinations,
|
|
84
|
-
mode: options.mode ?? 'driving',
|
|
85
|
-
};
|
|
86
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
87
|
-
|
|
88
|
-
return this.getRequest('/routing/v1/distanceMatrix', params);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getDistanceMatrixBasic(origins, destinations, options = {}) {
|
|
92
|
-
if (!origins || !destinations) {
|
|
93
|
-
throw new Error('origins and destinations are required');
|
|
94
|
-
}
|
|
95
|
-
const params = { origins, destinations };
|
|
96
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
97
|
-
|
|
98
|
-
return this.getRequest('/routing/v1/distanceMatrix/basic', params);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
routeOptimizer(locations, options = {}) {
|
|
102
|
-
if (!locations) throw new Error('locations are required');
|
|
103
|
-
|
|
104
|
-
const params = {
|
|
105
|
-
locations,
|
|
106
|
-
source: options.source ?? 'first',
|
|
107
|
-
destination: options.destination ?? 'last',
|
|
108
|
-
round_trip: options.round_trip ?? false,
|
|
109
|
-
mode: options.mode ?? 'driving',
|
|
110
|
-
steps: options.steps ?? true,
|
|
111
|
-
overview: options.overview ?? 'full',
|
|
112
|
-
language: options.language ?? 'en',
|
|
113
|
-
traffic_metadata: options.traffic_metadata ?? false,
|
|
114
|
-
};
|
|
115
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
116
|
-
|
|
117
|
-
return this.postRequest('/routing/v1/routeOptimizer', params);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async fleetPlanner(inputData, strategy, options = {}) {
|
|
121
|
-
if (!inputData || !strategy) {
|
|
122
|
-
throw new Error('inputData and strategy are required');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const FormData = require('form-data');
|
|
126
|
-
const form = new FormData();
|
|
127
|
-
|
|
128
|
-
if (typeof inputData === 'string') {
|
|
129
|
-
const fs = require('fs');
|
|
130
|
-
form.append('input', fs.createReadStream(inputData));
|
|
131
|
-
} else {
|
|
132
|
-
form.append('input', Buffer.from(JSON.stringify(inputData)), {
|
|
133
|
-
filename: 'input.json',
|
|
134
|
-
contentType: 'application/json',
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const params = {
|
|
139
|
-
strategy,
|
|
140
|
-
api_key: this.apiKey,
|
|
141
|
-
};
|
|
142
|
-
if (options.route_preference) params.route_preference = options.route_preference;
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const { data } = await this.client.post('/routing/v1/fleetPlanner', form, {
|
|
146
|
-
params,
|
|
147
|
-
headers: { ...form.getHeaders() },
|
|
148
|
-
});
|
|
149
|
-
return data;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
const errorMessage = error.response
|
|
152
|
-
? `Fleet Planner API Error: ${error.response.status} - ${error.response.data.message}`
|
|
153
|
-
: `Fleet Planner API Error: ${error.message}`;
|
|
154
|
-
console.error(errorMessage);
|
|
155
|
-
throw new Error(errorMessage);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
module.exports = Routing;
|
package/src/endpoints/tiles.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
class Tiles {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async request(endpoint, params = {}, headers = {}, responseType = 'json') {
|
|
8
|
-
try {
|
|
9
|
-
const response = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey },
|
|
11
|
-
headers: { 'Accept': 'application/json', ...headers },
|
|
12
|
-
responseType,
|
|
13
|
-
});
|
|
14
|
-
return response.data;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
const errorMessage = error.response
|
|
17
|
-
? `Tiles API Error: ${error.response.status} - ${error.response.data.message}`
|
|
18
|
-
: `Tiles API Error: ${error.message}`;
|
|
19
|
-
console.error(errorMessage);
|
|
20
|
-
throw new Error(errorMessage);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getDataTileJSON(datasetName) {
|
|
25
|
-
return this.request(`/tiles/vector/v1/data/${encodeURIComponent(datasetName)}.json`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getPBFFile(datasetName, z, x, y) {
|
|
29
|
-
return this.request(
|
|
30
|
-
`/tiles/vector/v1/data/${encodeURIComponent(datasetName)}/${z}/${x}/${y}.pbf`,
|
|
31
|
-
{},
|
|
32
|
-
{ 'Accept': 'application/x-protobuf' },
|
|
33
|
-
'arraybuffer'
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getStyles() {
|
|
38
|
-
return this.request('/tiles/vector/v1/styles.json');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getStyleDetail(styleName) {
|
|
42
|
-
return this.request(`/tiles/vector/v1/styles/${encodeURIComponent(styleName)}/style.json`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getFontGlyphs(fontstack, start, end) {
|
|
46
|
-
return this.request(
|
|
47
|
-
`/tiles/vector/v1/fonts/${encodeURIComponent(fontstack)}/${start}-${end}.pbf`,
|
|
48
|
-
{},
|
|
49
|
-
{ 'Accept': 'application/x-protobuf' },
|
|
50
|
-
'arraybuffer'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get a static map image centered on a specific point.
|
|
56
|
-
* @param {string} styleName - e.g. 'default-light-standard'
|
|
57
|
-
* @param {number} lon - Longitude
|
|
58
|
-
* @param {number} lat - Latitude
|
|
59
|
-
* @param {number} zoom - Zoom level (0-23)
|
|
60
|
-
* @param {number} width - Image width (1-2048)
|
|
61
|
-
* @param {number} height - Image height (1-2048)
|
|
62
|
-
* @param {string} format - 'png' or 'jpg'
|
|
63
|
-
* @param {Object} [options] - { marker, path }
|
|
64
|
-
*/
|
|
65
|
-
getStaticMapByCenter(styleName, lon, lat, zoom, width, height, format, options = {}) {
|
|
66
|
-
const endpoint = `/tiles/v1/styles/${encodeURIComponent(styleName)}/static/${lon},${lat},${zoom}/${width}x${height}.${format}`;
|
|
67
|
-
const params = {};
|
|
68
|
-
if (options.marker) params.marker = options.marker;
|
|
69
|
-
if (options.path) params.path = options.path;
|
|
70
|
-
return this.request(endpoint, params, {}, 'arraybuffer');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get a static map image for a bounding box.
|
|
75
|
-
* @param {string} styleName
|
|
76
|
-
* @param {{ minx: number, miny: number, maxx: number, maxy: number }} bbox
|
|
77
|
-
* @param {number} width
|
|
78
|
-
* @param {number} height
|
|
79
|
-
* @param {string} format
|
|
80
|
-
* @param {Object} [options]
|
|
81
|
-
*/
|
|
82
|
-
getStaticMapByBBox(styleName, bbox, width, height, format, options = {}) {
|
|
83
|
-
const { minx, miny, maxx, maxy } = bbox;
|
|
84
|
-
const endpoint = `/tiles/v1/styles/${encodeURIComponent(styleName)}/static/${minx},${miny},${maxx},${maxy}/${width}x${height}.${format}`;
|
|
85
|
-
const params = {};
|
|
86
|
-
if (options.marker) params.marker = options.marker;
|
|
87
|
-
if (options.path) params.path = options.path;
|
|
88
|
-
return this.request(endpoint, params, {}, 'arraybuffer');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get a static map image with auto-fit bounds.
|
|
93
|
-
* @param {string} styleName
|
|
94
|
-
* @param {number} width
|
|
95
|
-
* @param {number} height
|
|
96
|
-
* @param {string} format
|
|
97
|
-
* @param {Object} [options]
|
|
98
|
-
*/
|
|
99
|
-
getStaticMapAuto(styleName, width, height, format, options = {}) {
|
|
100
|
-
const endpoint = `/tiles/v1/styles/${encodeURIComponent(styleName)}/static/auto/${width}x${height}.${format}`;
|
|
101
|
-
const params = {};
|
|
102
|
-
if (options.marker) params.marker = options.marker;
|
|
103
|
-
if (options.path) params.path = options.path;
|
|
104
|
-
return this.request(endpoint, params, {}, 'arraybuffer');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Get 3D tileset JSON.
|
|
109
|
-
*/
|
|
110
|
-
get3DTileset() {
|
|
111
|
-
return this.request('/tiles/vector/v1/3dtiles/tileset.json');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
module.exports = Tiles;
|