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
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
import { getStyleURL, getTransformRequest, getMapOptions } from './chunk-SJJRTEQG.js';
|
|
2
|
+
import { HttpTransport } from './chunk-7LV3RPED.js';
|
|
3
|
+
import { OlaValidationError, AuthManager, DEFAULT_BASE_URL } from './chunk-D5T5ZDIQ.js';
|
|
4
|
+
|
|
5
|
+
// src/core/validate.ts
|
|
6
|
+
function assertNonEmptyString(value, fieldName) {
|
|
7
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
8
|
+
throw new OlaValidationError(`${fieldName} must be a non-empty string`);
|
|
9
|
+
}
|
|
10
|
+
return value.trim();
|
|
11
|
+
}
|
|
12
|
+
function assertFiniteNumber(value, fieldName) {
|
|
13
|
+
const num = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
|
|
14
|
+
if (typeof num !== "number" || !Number.isFinite(num)) {
|
|
15
|
+
throw new OlaValidationError(`${fieldName} must be a finite number`);
|
|
16
|
+
}
|
|
17
|
+
return num;
|
|
18
|
+
}
|
|
19
|
+
function assertRange(value, min, max, fieldName) {
|
|
20
|
+
if (!Number.isFinite(value) || value < min || value > max) {
|
|
21
|
+
throw new OlaValidationError(
|
|
22
|
+
`${fieldName} must be between ${min} and ${max} (received ${value})`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function assertOneOf(value, allowed, fieldName) {
|
|
28
|
+
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
29
|
+
throw new OlaValidationError(`${fieldName} must be one of: ${allowed.join(", ")}`);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function parseLatLngPair(lat, lng, label = "coordinate") {
|
|
34
|
+
const parsedLat = assertRange(assertFiniteNumber(lat, `${label}.lat`), -90, 90, `${label}.lat`);
|
|
35
|
+
const parsedLng = assertRange(assertFiniteNumber(lng, `${label}.lng`), -180, 180, `${label}.lng`);
|
|
36
|
+
return { lat: parsedLat, lng: parsedLng };
|
|
37
|
+
}
|
|
38
|
+
function normalizeCoordinate(input, label = "coordinate") {
|
|
39
|
+
if (typeof input === "string") {
|
|
40
|
+
const parts = input.split(",");
|
|
41
|
+
if (parts.length !== 2) {
|
|
42
|
+
throw new OlaValidationError(`${label} string must be in "lat,lng" format`);
|
|
43
|
+
}
|
|
44
|
+
return parseLatLngPair(parts[0].trim(), parts[1].trim(), label);
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(input)) {
|
|
47
|
+
if (input.length !== 2) {
|
|
48
|
+
throw new OlaValidationError(`${label} tuple must be [lng, lat] with exactly 2 elements`);
|
|
49
|
+
}
|
|
50
|
+
return parseLatLngPair(input[1], input[0], label);
|
|
51
|
+
}
|
|
52
|
+
if (input !== null && typeof input === "object") {
|
|
53
|
+
const obj = input;
|
|
54
|
+
const rawLng = obj.lng !== void 0 ? obj.lng : obj.lon;
|
|
55
|
+
if (obj.lat === void 0 || rawLng === void 0) {
|
|
56
|
+
throw new OlaValidationError(`${label} object must include "lat" and "lng" (or "lon")`);
|
|
57
|
+
}
|
|
58
|
+
return parseLatLngPair(obj.lat, rawLng, label);
|
|
59
|
+
}
|
|
60
|
+
throw new OlaValidationError(
|
|
61
|
+
`${label} must be { lat, lng }, { lat, lon }, [lng, lat], or "lat,lng"`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function formatLatLng(input, label = "coordinate") {
|
|
65
|
+
const { lat, lng } = normalizeCoordinate(input, label);
|
|
66
|
+
return `${lat},${lng}`;
|
|
67
|
+
}
|
|
68
|
+
function formatCoordinateList(input, options) {
|
|
69
|
+
const { label, min = 1, max } = options;
|
|
70
|
+
let rawItems;
|
|
71
|
+
if (typeof input === "string") {
|
|
72
|
+
const trimmed = input.trim();
|
|
73
|
+
if (!trimmed) {
|
|
74
|
+
throw new OlaValidationError(`${label} must not be empty`);
|
|
75
|
+
}
|
|
76
|
+
rawItems = trimmed.split("|").map((item) => item.trim());
|
|
77
|
+
} else if (Array.isArray(input)) {
|
|
78
|
+
rawItems = input;
|
|
79
|
+
} else {
|
|
80
|
+
throw new OlaValidationError(
|
|
81
|
+
`${label} must be a pipe-separated string or an array of coordinates`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (rawItems.length < min) {
|
|
85
|
+
throw new OlaValidationError(`${label} requires at least ${min} coordinate(s)`);
|
|
86
|
+
}
|
|
87
|
+
if (max !== void 0 && rawItems.length > max) {
|
|
88
|
+
throw new OlaValidationError(
|
|
89
|
+
`${label} supports at most ${max} coordinates (received ${rawItems.length})`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return rawItems.map((coord, i) => formatLatLng(coord, `${label}[${i}]`)).join("|");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/endpoints/elevation.ts
|
|
96
|
+
var Elevation = class {
|
|
97
|
+
constructor(transport) {
|
|
98
|
+
this.transport = transport;
|
|
99
|
+
}
|
|
100
|
+
transport;
|
|
101
|
+
getElevation(latOrCoord, lngOrRequestOptions, maybeRequestOptions) {
|
|
102
|
+
let location;
|
|
103
|
+
let requestOptions;
|
|
104
|
+
if (typeof latOrCoord === "object" && latOrCoord !== null || typeof latOrCoord === "string" && latOrCoord.includes(",")) {
|
|
105
|
+
location = formatLatLng(latOrCoord, "location");
|
|
106
|
+
requestOptions = lngOrRequestOptions;
|
|
107
|
+
} else {
|
|
108
|
+
const parsed = parseLatLngPair(
|
|
109
|
+
latOrCoord,
|
|
110
|
+
lngOrRequestOptions,
|
|
111
|
+
"location"
|
|
112
|
+
);
|
|
113
|
+
location = `${parsed.lat},${parsed.lng}`;
|
|
114
|
+
requestOptions = maybeRequestOptions;
|
|
115
|
+
}
|
|
116
|
+
return this.transport.request({
|
|
117
|
+
method: "GET",
|
|
118
|
+
path: "/places/v1/elevation",
|
|
119
|
+
query: { location },
|
|
120
|
+
requestOptions
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get elevations for multiple locations (max 25 per request).
|
|
125
|
+
*/
|
|
126
|
+
getMultiElevation(locations, requestOptions) {
|
|
127
|
+
if (!Array.isArray(locations) || locations.length === 0) {
|
|
128
|
+
throw new OlaValidationError("locations must be a non-empty array of coordinates");
|
|
129
|
+
}
|
|
130
|
+
if (locations.length > 25) {
|
|
131
|
+
throw new OlaValidationError(
|
|
132
|
+
`Maximum 25 locations allowed per request (received ${locations.length})`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const formatted = locations.map((loc, index) => formatLatLng(loc, `locations[${index}]`));
|
|
136
|
+
return this.transport.request({
|
|
137
|
+
method: "POST",
|
|
138
|
+
path: "/places/v1/elevation",
|
|
139
|
+
body: { locations: formatted },
|
|
140
|
+
requestOptions
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/endpoints/geofencing.ts
|
|
146
|
+
var Geofencing = class {
|
|
147
|
+
constructor(transport) {
|
|
148
|
+
this.transport = transport;
|
|
149
|
+
}
|
|
150
|
+
transport;
|
|
151
|
+
create(geofenceData, requestOptions) {
|
|
152
|
+
if (!geofenceData || typeof geofenceData !== "object") {
|
|
153
|
+
throw new OlaValidationError("geofenceData is required");
|
|
154
|
+
}
|
|
155
|
+
return this.transport.request({
|
|
156
|
+
method: "POST",
|
|
157
|
+
path: "/places/v1/geofence",
|
|
158
|
+
body: geofenceData,
|
|
159
|
+
requestOptions
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
update(id, geofenceData, requestOptions) {
|
|
163
|
+
const validatedId = assertNonEmptyString(id, "id");
|
|
164
|
+
if (!geofenceData || typeof geofenceData !== "object") {
|
|
165
|
+
throw new OlaValidationError("geofenceData is required");
|
|
166
|
+
}
|
|
167
|
+
return this.transport.request({
|
|
168
|
+
method: "PUT",
|
|
169
|
+
path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
|
|
170
|
+
body: geofenceData,
|
|
171
|
+
requestOptions
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
getById(id, requestOptions) {
|
|
175
|
+
const validatedId = assertNonEmptyString(id, "id");
|
|
176
|
+
return this.transport.request({
|
|
177
|
+
method: "GET",
|
|
178
|
+
path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
|
|
179
|
+
requestOptions
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
deleteById(id, requestOptions) {
|
|
183
|
+
const validatedId = assertNonEmptyString(id, "id");
|
|
184
|
+
return this.transport.request({
|
|
185
|
+
method: "DELETE",
|
|
186
|
+
path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
|
|
187
|
+
requestOptions
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
list(projectId, page = 1, size = 10, requestOptions) {
|
|
191
|
+
const validatedProjectId = assertNonEmptyString(projectId, "projectId");
|
|
192
|
+
return this.transport.request({
|
|
193
|
+
method: "GET",
|
|
194
|
+
path: "/places/v1/geofences",
|
|
195
|
+
query: {
|
|
196
|
+
projectId: validatedProjectId,
|
|
197
|
+
page: assertFiniteNumber(page, "page"),
|
|
198
|
+
size: assertFiniteNumber(size, "size")
|
|
199
|
+
},
|
|
200
|
+
requestOptions
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
checkStatus(geofenceId, coordinates, requestOptions) {
|
|
204
|
+
return this.transport.request({
|
|
205
|
+
method: "GET",
|
|
206
|
+
path: "/places/v1/geofence/status",
|
|
207
|
+
query: {
|
|
208
|
+
geofenceId: assertNonEmptyString(geofenceId, "geofenceId"),
|
|
209
|
+
coordinates: formatLatLng(coordinates, "coordinates")
|
|
210
|
+
},
|
|
211
|
+
requestOptions
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/endpoints/places.ts
|
|
217
|
+
var Places = class {
|
|
218
|
+
constructor(transport) {
|
|
219
|
+
this.transport = transport;
|
|
220
|
+
}
|
|
221
|
+
transport;
|
|
222
|
+
autocomplete(input, options = {}, requestOptions) {
|
|
223
|
+
const query = {
|
|
224
|
+
input: assertNonEmptyString(input, "input")
|
|
225
|
+
};
|
|
226
|
+
if (options.location !== void 0) {
|
|
227
|
+
query.location = formatLatLng(options.location, "options.location");
|
|
228
|
+
}
|
|
229
|
+
if (options.radius != null) query.radius = options.radius;
|
|
230
|
+
if (options.strictbounds != null) query.strictbounds = options.strictbounds;
|
|
231
|
+
if (options.language) query.language = options.language;
|
|
232
|
+
if (options.types) query.types = options.types;
|
|
233
|
+
return this.transport.request({
|
|
234
|
+
method: "GET",
|
|
235
|
+
path: "/places/v1/autocomplete",
|
|
236
|
+
query,
|
|
237
|
+
requestOptions
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
geocode(address, languageOrOptions, requestOptions) {
|
|
241
|
+
const query = {
|
|
242
|
+
address: assertNonEmptyString(address, "address")
|
|
243
|
+
};
|
|
244
|
+
if (typeof languageOrOptions === "string") {
|
|
245
|
+
if (languageOrOptions) query.language = languageOrOptions;
|
|
246
|
+
} else if (languageOrOptions) {
|
|
247
|
+
if (languageOrOptions.language) query.language = languageOrOptions.language;
|
|
248
|
+
if (languageOrOptions.bounds) query.bounds = languageOrOptions.bounds;
|
|
249
|
+
}
|
|
250
|
+
return this.transport.request({
|
|
251
|
+
method: "GET",
|
|
252
|
+
path: "/places/v1/geocode",
|
|
253
|
+
query,
|
|
254
|
+
requestOptions
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
reverseGeocode(latOrCoordinate, lngOrOptions, languageOrRequestOptions, maybeRequestOptions) {
|
|
258
|
+
let latlng;
|
|
259
|
+
let language;
|
|
260
|
+
let requestOptions;
|
|
261
|
+
if (typeof latOrCoordinate === "object" && latOrCoordinate !== null) {
|
|
262
|
+
latlng = formatLatLng(latOrCoordinate, "coordinate");
|
|
263
|
+
if (typeof lngOrOptions === "string") {
|
|
264
|
+
language = lngOrOptions;
|
|
265
|
+
} else if (lngOrOptions && typeof lngOrOptions === "object") {
|
|
266
|
+
language = lngOrOptions.language;
|
|
267
|
+
}
|
|
268
|
+
requestOptions = languageOrRequestOptions;
|
|
269
|
+
} else {
|
|
270
|
+
const parsed = parseLatLngPair(
|
|
271
|
+
latOrCoordinate,
|
|
272
|
+
lngOrOptions,
|
|
273
|
+
"reverseGeocode"
|
|
274
|
+
);
|
|
275
|
+
latlng = `${parsed.lat},${parsed.lng}`;
|
|
276
|
+
if (typeof languageOrRequestOptions === "string") {
|
|
277
|
+
language = languageOrRequestOptions;
|
|
278
|
+
} else if (languageOrRequestOptions && typeof languageOrRequestOptions === "object" && "language" in languageOrRequestOptions) {
|
|
279
|
+
language = languageOrRequestOptions.language;
|
|
280
|
+
}
|
|
281
|
+
requestOptions = maybeRequestOptions;
|
|
282
|
+
}
|
|
283
|
+
const query = { latlng };
|
|
284
|
+
if (language) query.language = language;
|
|
285
|
+
return this.transport.request({
|
|
286
|
+
method: "GET",
|
|
287
|
+
path: "/places/v1/reverse-geocode",
|
|
288
|
+
query,
|
|
289
|
+
requestOptions
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
placeDetails(placeId, language, requestOptions) {
|
|
293
|
+
const query = {
|
|
294
|
+
place_id: assertNonEmptyString(placeId, "placeId")
|
|
295
|
+
};
|
|
296
|
+
if (language) query.language = language;
|
|
297
|
+
return this.transport.request({
|
|
298
|
+
method: "GET",
|
|
299
|
+
path: "/places/v1/details",
|
|
300
|
+
query,
|
|
301
|
+
requestOptions
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
placeDetailsAdvanced(placeId, language, requestOptions) {
|
|
305
|
+
const query = {
|
|
306
|
+
place_id: assertNonEmptyString(placeId, "placeId")
|
|
307
|
+
};
|
|
308
|
+
if (language) query.language = language;
|
|
309
|
+
return this.transport.request({
|
|
310
|
+
method: "GET",
|
|
311
|
+
path: "/places/v1/details/advanced",
|
|
312
|
+
query,
|
|
313
|
+
requestOptions
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
nearbySearch(location, options = {}, requestOptions) {
|
|
317
|
+
return this.executeNearbySearch("/places/v1/nearbysearch", location, options, requestOptions);
|
|
318
|
+
}
|
|
319
|
+
nearbySearchAdvanced(location, options = {}, requestOptions) {
|
|
320
|
+
return this.executeNearbySearch(
|
|
321
|
+
"/places/v1/nearbysearch/advanced",
|
|
322
|
+
location,
|
|
323
|
+
options,
|
|
324
|
+
requestOptions
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
textSearch(input, options = {}, requestOptions) {
|
|
328
|
+
const query = {
|
|
329
|
+
input: assertNonEmptyString(input, "input")
|
|
330
|
+
};
|
|
331
|
+
if (options.location !== void 0) {
|
|
332
|
+
query.location = formatLatLng(options.location, "options.location");
|
|
333
|
+
}
|
|
334
|
+
if (options.radius != null) query.radius = options.radius;
|
|
335
|
+
if (options.types) query.types = options.types;
|
|
336
|
+
if (options.size != null) query.size = options.size;
|
|
337
|
+
return this.transport.request({
|
|
338
|
+
method: "GET",
|
|
339
|
+
path: "/places/v1/textsearch",
|
|
340
|
+
query,
|
|
341
|
+
requestOptions
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
addressValidation(address, requestOptions) {
|
|
345
|
+
return this.transport.request({
|
|
346
|
+
method: "GET",
|
|
347
|
+
path: "/places/v1/addressvalidation",
|
|
348
|
+
query: { address: assertNonEmptyString(address, "address") },
|
|
349
|
+
requestOptions
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
photo(photoReference, requestOptions) {
|
|
353
|
+
return this.transport.request({
|
|
354
|
+
method: "GET",
|
|
355
|
+
path: "/places/v1/photo",
|
|
356
|
+
query: { photo_reference: assertNonEmptyString(photoReference, "photoReference") },
|
|
357
|
+
requestOptions
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
executeNearbySearch(path, location, options, requestOptions) {
|
|
361
|
+
const query = {
|
|
362
|
+
location: formatLatLng(location, "location")
|
|
363
|
+
};
|
|
364
|
+
if (options.layers) query.layers = options.layers;
|
|
365
|
+
if (options.types) query.types = options.types;
|
|
366
|
+
if (options.language) query.language = options.language;
|
|
367
|
+
if (options.radius != null) query.radius = options.radius;
|
|
368
|
+
if (options.withCentroid != null) query.withCentroid = options.withCentroid;
|
|
369
|
+
if (options.rankBy) query.rankBy = options.rankBy;
|
|
370
|
+
if (options.limit != null) {
|
|
371
|
+
query.limit = assertRange(options.limit, 1, 50, "options.limit");
|
|
372
|
+
}
|
|
373
|
+
return this.transport.request({
|
|
374
|
+
method: "GET",
|
|
375
|
+
path,
|
|
376
|
+
query,
|
|
377
|
+
requestOptions
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// src/endpoints/roads.ts
|
|
383
|
+
var NEAREST_ROADS_MODES = [
|
|
384
|
+
"DRIVING",
|
|
385
|
+
"WALKING",
|
|
386
|
+
"BICYCLING",
|
|
387
|
+
"TRANSIT"
|
|
388
|
+
];
|
|
389
|
+
var SNAP_STRATEGIES = ["snaptoroad", "nearestroad"];
|
|
390
|
+
var Roads = class {
|
|
391
|
+
constructor(transport) {
|
|
392
|
+
this.transport = transport;
|
|
393
|
+
}
|
|
394
|
+
transport;
|
|
395
|
+
/**
|
|
396
|
+
* Snap up to 50 coordinates to the nearest road segments.
|
|
397
|
+
*/
|
|
398
|
+
snapToRoad(points, enhancePathOrOptions = false, requestOptions) {
|
|
399
|
+
const formattedPoints = formatCoordinateList(points, {
|
|
400
|
+
label: "points",
|
|
401
|
+
min: 1,
|
|
402
|
+
max: 50
|
|
403
|
+
});
|
|
404
|
+
const enhancePath = typeof enhancePathOrOptions === "boolean" ? enhancePathOrOptions : enhancePathOrOptions.enhancePath ?? false;
|
|
405
|
+
return this.transport.request({
|
|
406
|
+
method: "GET",
|
|
407
|
+
path: "/routing/v1/snapToRoad",
|
|
408
|
+
query: { points: formattedPoints, enhancePath },
|
|
409
|
+
requestOptions
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Find nearest roads for up to 100 coordinates.
|
|
414
|
+
*/
|
|
415
|
+
nearestRoads(points, mode, radiusOrOptions, requestOptions) {
|
|
416
|
+
const formattedPoints = formatCoordinateList(points, {
|
|
417
|
+
label: "points",
|
|
418
|
+
min: 1,
|
|
419
|
+
max: 100
|
|
420
|
+
});
|
|
421
|
+
const validatedMode = assertOneOf(mode, NEAREST_ROADS_MODES, "mode");
|
|
422
|
+
const query = {
|
|
423
|
+
points: formattedPoints,
|
|
424
|
+
mode: validatedMode
|
|
425
|
+
};
|
|
426
|
+
const radius = typeof radiusOrOptions === "number" ? radiusOrOptions : radiusOrOptions?.radius;
|
|
427
|
+
if (radius != null) {
|
|
428
|
+
query.radius = assertFiniteNumber(radius, "radius");
|
|
429
|
+
}
|
|
430
|
+
return this.transport.request({
|
|
431
|
+
method: "GET",
|
|
432
|
+
path: "/routing/v1/nearestRoads",
|
|
433
|
+
query,
|
|
434
|
+
requestOptions
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Get speed limits for up to 50 coordinates along snapped road segments.
|
|
439
|
+
*/
|
|
440
|
+
speedLimits(points, snapStrategyOrOptions = "snaptoroad", requestOptions) {
|
|
441
|
+
const formattedPoints = formatCoordinateList(points, {
|
|
442
|
+
label: "points",
|
|
443
|
+
min: 1,
|
|
444
|
+
max: 50
|
|
445
|
+
});
|
|
446
|
+
const rawStrategy = typeof snapStrategyOrOptions === "string" ? snapStrategyOrOptions : snapStrategyOrOptions.snapStrategy ?? "snaptoroad";
|
|
447
|
+
const snapStrategy = assertOneOf(rawStrategy, SNAP_STRATEGIES, "snapStrategy");
|
|
448
|
+
return this.transport.request({
|
|
449
|
+
method: "GET",
|
|
450
|
+
path: "/routing/v1/speedLimits",
|
|
451
|
+
query: { points: formattedPoints, snapStrategy },
|
|
452
|
+
requestOptions
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/endpoints/routing.ts
|
|
458
|
+
var Routing = class {
|
|
459
|
+
constructor(transport) {
|
|
460
|
+
this.transport = transport;
|
|
461
|
+
}
|
|
462
|
+
transport;
|
|
463
|
+
getDirections(origin, destination, options = {}, requestOptions) {
|
|
464
|
+
const query = {
|
|
465
|
+
origin: formatLatLng(origin, "origin"),
|
|
466
|
+
destination: formatLatLng(destination, "destination"),
|
|
467
|
+
alternatives: options.alternatives ?? false,
|
|
468
|
+
steps: options.steps ?? true,
|
|
469
|
+
overview: options.overview ?? "full",
|
|
470
|
+
language: options.language ?? "en",
|
|
471
|
+
traffic_metadata: options.traffic_metadata ?? false
|
|
472
|
+
};
|
|
473
|
+
if (options.waypoints !== void 0) {
|
|
474
|
+
query.waypoints = formatCoordinateList(options.waypoints, {
|
|
475
|
+
label: "options.waypoints",
|
|
476
|
+
min: 1
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
if (options.mode) query.mode = options.mode;
|
|
480
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
481
|
+
return this.transport.request({
|
|
482
|
+
method: "POST",
|
|
483
|
+
path: "/routing/v1/directions",
|
|
484
|
+
query,
|
|
485
|
+
requestOptions
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
getDirectionsBasic(origin, destination, options = {}, requestOptions) {
|
|
489
|
+
const query = {
|
|
490
|
+
origin: formatLatLng(origin, "origin"),
|
|
491
|
+
destination: formatLatLng(destination, "destination"),
|
|
492
|
+
alternatives: options.alternatives ?? false,
|
|
493
|
+
steps: options.steps ?? true,
|
|
494
|
+
overview: options.overview ?? "full",
|
|
495
|
+
language: options.language ?? "en"
|
|
496
|
+
};
|
|
497
|
+
if (options.waypoints !== void 0) {
|
|
498
|
+
query.waypoints = formatCoordinateList(options.waypoints, {
|
|
499
|
+
label: "options.waypoints",
|
|
500
|
+
min: 1
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
504
|
+
return this.transport.request({
|
|
505
|
+
method: "POST",
|
|
506
|
+
path: "/routing/v1/directions/basic",
|
|
507
|
+
query,
|
|
508
|
+
requestOptions
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
getDistanceMatrix(origins, destinations, options = {}, requestOptions) {
|
|
512
|
+
const query = {
|
|
513
|
+
origins: formatCoordinateList(origins, { label: "origins", min: 1 }),
|
|
514
|
+
destinations: formatCoordinateList(destinations, { label: "destinations", min: 1 }),
|
|
515
|
+
mode: options.mode ?? "driving"
|
|
516
|
+
};
|
|
517
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
518
|
+
return this.transport.request({
|
|
519
|
+
method: "GET",
|
|
520
|
+
path: "/routing/v1/distanceMatrix",
|
|
521
|
+
query,
|
|
522
|
+
requestOptions
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
getDistanceMatrixBasic(origins, destinations, options = {}, requestOptions) {
|
|
526
|
+
const query = {
|
|
527
|
+
origins: formatCoordinateList(origins, { label: "origins", min: 1 }),
|
|
528
|
+
destinations: formatCoordinateList(destinations, { label: "destinations", min: 1 })
|
|
529
|
+
};
|
|
530
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
531
|
+
return this.transport.request({
|
|
532
|
+
method: "GET",
|
|
533
|
+
path: "/routing/v1/distanceMatrix/basic",
|
|
534
|
+
query,
|
|
535
|
+
requestOptions
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Optimize waypoint order for up to 25 locations.
|
|
540
|
+
*/
|
|
541
|
+
routeOptimizer(locations, options = {}, requestOptions) {
|
|
542
|
+
const query = {
|
|
543
|
+
locations: formatCoordinateList(locations, {
|
|
544
|
+
label: "locations",
|
|
545
|
+
min: 1,
|
|
546
|
+
max: 25
|
|
547
|
+
}),
|
|
548
|
+
source: options.source ?? "first",
|
|
549
|
+
destination: options.destination ?? "last",
|
|
550
|
+
round_trip: options.round_trip ?? false,
|
|
551
|
+
mode: options.mode ?? "driving",
|
|
552
|
+
steps: options.steps ?? true,
|
|
553
|
+
overview: options.overview ?? "full",
|
|
554
|
+
language: options.language ?? "en",
|
|
555
|
+
traffic_metadata: options.traffic_metadata ?? false
|
|
556
|
+
};
|
|
557
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
558
|
+
return this.transport.request({
|
|
559
|
+
method: "POST",
|
|
560
|
+
path: "/routing/v1/routeOptimizer",
|
|
561
|
+
query,
|
|
562
|
+
requestOptions
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Plan multi-vehicle fleet routes using browser/Edge/Node-safe Web `FormData` & `Blob`.
|
|
567
|
+
* Accepts a plain JSON object, JSON string, `Blob`/`File`, `Uint8Array`, or `ArrayBuffer`.
|
|
568
|
+
*/
|
|
569
|
+
fleetPlanner(inputData, strategy, options = {}, requestOptions) {
|
|
570
|
+
if (inputData === void 0 || inputData === null) {
|
|
571
|
+
throw new OlaValidationError("inputData is required");
|
|
572
|
+
}
|
|
573
|
+
const normalizedStrategy = assertNonEmptyString(strategy, "strategy");
|
|
574
|
+
const filename = options.filename ?? "input.json";
|
|
575
|
+
const form = new FormData();
|
|
576
|
+
let blob;
|
|
577
|
+
if (typeof Blob !== "undefined" && inputData instanceof Blob) {
|
|
578
|
+
blob = inputData;
|
|
579
|
+
} else if (inputData instanceof ArrayBuffer) {
|
|
580
|
+
blob = new Blob([inputData], { type: "application/json" });
|
|
581
|
+
} else if (inputData instanceof Uint8Array) {
|
|
582
|
+
const copy = new Uint8Array(inputData.byteLength);
|
|
583
|
+
copy.set(inputData);
|
|
584
|
+
blob = new Blob([copy], { type: "application/json" });
|
|
585
|
+
} else if (typeof inputData === "string") {
|
|
586
|
+
blob = new Blob([inputData], { type: "application/json" });
|
|
587
|
+
} else if (typeof inputData === "object") {
|
|
588
|
+
blob = new Blob([JSON.stringify(inputData)], { type: "application/json" });
|
|
589
|
+
} else {
|
|
590
|
+
throw new OlaValidationError(
|
|
591
|
+
"inputData must be a JSON object, JSON string, Blob, Uint8Array, or ArrayBuffer"
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
form.append("input", blob, filename);
|
|
595
|
+
const query = {
|
|
596
|
+
strategy: normalizedStrategy
|
|
597
|
+
};
|
|
598
|
+
if (options.route_preference) query.route_preference = options.route_preference;
|
|
599
|
+
return this.transport.request({
|
|
600
|
+
method: "POST",
|
|
601
|
+
path: "/routing/v1/fleetPlanner",
|
|
602
|
+
query,
|
|
603
|
+
body: form,
|
|
604
|
+
requestOptions
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/endpoints/streetview.ts
|
|
610
|
+
var StreetView = class {
|
|
611
|
+
constructor(transport) {
|
|
612
|
+
this.transport = transport;
|
|
613
|
+
}
|
|
614
|
+
transport;
|
|
615
|
+
/**
|
|
616
|
+
* Fetch Street View coverage geometry within a bounding box.
|
|
617
|
+
* Accepts `{ xMin, yMin, xMax, yMax }` or `{ minLng, minLat, maxLng, maxLat }`.
|
|
618
|
+
*/
|
|
619
|
+
getCoverage(bbox, requestOptions) {
|
|
620
|
+
if (!bbox || typeof bbox !== "object") {
|
|
621
|
+
throw new OlaValidationError(
|
|
622
|
+
"bbox must be an object with { xMin, yMin, xMax, yMax } or { minLng, minLat, maxLng, maxLat }"
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
const rawXMin = "xMin" in bbox ? bbox.xMin : bbox.minLng;
|
|
626
|
+
const rawYMin = "yMin" in bbox ? bbox.yMin : bbox.minLat;
|
|
627
|
+
const rawXMax = "xMax" in bbox ? bbox.xMax : bbox.maxLng;
|
|
628
|
+
const rawYMax = "yMax" in bbox ? bbox.yMax : bbox.maxLat;
|
|
629
|
+
const xMin = assertRange(assertFiniteNumber(rawXMin, "xMin"), -180, 180, "xMin");
|
|
630
|
+
const yMin = assertRange(assertFiniteNumber(rawYMin, "yMin"), -90, 90, "yMin");
|
|
631
|
+
const xMax = assertRange(assertFiniteNumber(rawXMax, "xMax"), -180, 180, "xMax");
|
|
632
|
+
const yMax = assertRange(assertFiniteNumber(rawYMax, "yMax"), -90, 90, "yMax");
|
|
633
|
+
if (xMin >= xMax || yMin >= yMax) {
|
|
634
|
+
throw new OlaValidationError("bbox requires xMin < xMax and yMin < yMax");
|
|
635
|
+
}
|
|
636
|
+
return this.transport.request({
|
|
637
|
+
method: "GET",
|
|
638
|
+
path: "/sli/v1/streetview/coverage",
|
|
639
|
+
query: { xMin, yMin, xMax, yMax },
|
|
640
|
+
requestOptions
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
getImageId(latOrCoordinate, lonOrOptions, optionsOrRequestOptions, maybeRequestOptions) {
|
|
644
|
+
let lat;
|
|
645
|
+
let lon;
|
|
646
|
+
let options;
|
|
647
|
+
let requestOptions;
|
|
648
|
+
if (typeof latOrCoordinate === "object" && latOrCoordinate !== null) {
|
|
649
|
+
const normalized = normalizeCoordinate(latOrCoordinate, "coordinate");
|
|
650
|
+
lat = normalized.lat;
|
|
651
|
+
lon = normalized.lng;
|
|
652
|
+
options = lonOrOptions;
|
|
653
|
+
requestOptions = optionsOrRequestOptions;
|
|
654
|
+
} else {
|
|
655
|
+
const parsed = parseLatLngPair(
|
|
656
|
+
latOrCoordinate,
|
|
657
|
+
lonOrOptions,
|
|
658
|
+
"streetView.getImageId"
|
|
659
|
+
);
|
|
660
|
+
lat = parsed.lat;
|
|
661
|
+
lon = parsed.lng;
|
|
662
|
+
options = optionsOrRequestOptions;
|
|
663
|
+
requestOptions = maybeRequestOptions;
|
|
664
|
+
}
|
|
665
|
+
const query = { lat, lon };
|
|
666
|
+
if (options?.radius != null) {
|
|
667
|
+
query.radius = assertFiniteNumber(options.radius, "options.radius");
|
|
668
|
+
}
|
|
669
|
+
return this.transport.request({
|
|
670
|
+
method: "GET",
|
|
671
|
+
path: "/sli/streetview/imageId",
|
|
672
|
+
query,
|
|
673
|
+
requestOptions
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Fetch panoramic image metadata (`lat`, `lon`, `bearing`, `imageUrl`, `neighbors`) for an `imageId`.
|
|
678
|
+
*/
|
|
679
|
+
getMetadata(imageId, requestOptions) {
|
|
680
|
+
return this.transport.request({
|
|
681
|
+
method: "GET",
|
|
682
|
+
path: "/sli/streetview/metadata",
|
|
683
|
+
query: { imageId: assertNonEmptyString(imageId, "imageId") },
|
|
684
|
+
requestOptions
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/endpoints/tiles.ts
|
|
690
|
+
var STATIC_MAP_FORMATS = ["png", "jpg"];
|
|
691
|
+
function validateDimensions(width, height) {
|
|
692
|
+
assertRange(assertFiniteNumber(width, "width"), 1, 2048, "width");
|
|
693
|
+
assertRange(assertFiniteNumber(height, "height"), 1, 2048, "height");
|
|
694
|
+
}
|
|
695
|
+
function buildStaticMapQuery(options) {
|
|
696
|
+
const query = {};
|
|
697
|
+
if (options.marker !== void 0) {
|
|
698
|
+
query.marker = options.marker;
|
|
699
|
+
}
|
|
700
|
+
if (options.path !== void 0) {
|
|
701
|
+
query.path = options.path;
|
|
702
|
+
}
|
|
703
|
+
return query;
|
|
704
|
+
}
|
|
705
|
+
var Tiles = class {
|
|
706
|
+
constructor(transport) {
|
|
707
|
+
this.transport = transport;
|
|
708
|
+
}
|
|
709
|
+
transport;
|
|
710
|
+
/**
|
|
711
|
+
* Fetch TileJSON metadata for a vector tile dataset.
|
|
712
|
+
* Note: Vector tile dataset helpers correspond to Ola's vector tile service endpoints.
|
|
713
|
+
*/
|
|
714
|
+
getDataTileJSON(datasetName, requestOptions) {
|
|
715
|
+
const name = assertNonEmptyString(datasetName, "datasetName");
|
|
716
|
+
return this.transport.request({
|
|
717
|
+
method: "GET",
|
|
718
|
+
path: `/tiles/vector/v1/data/${encodeURIComponent(name)}.json`,
|
|
719
|
+
requestOptions
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Fetch a raw Mapbox Vector Tile (.pbf) as an `ArrayBuffer`.
|
|
724
|
+
*/
|
|
725
|
+
getPBFFile(datasetName, z, x, y, requestOptions) {
|
|
726
|
+
const name = assertNonEmptyString(datasetName, "datasetName");
|
|
727
|
+
const zoom = assertRange(assertFiniteNumber(z, "z"), 0, 24, "z");
|
|
728
|
+
const tileX = assertFiniteNumber(x, "x");
|
|
729
|
+
const tileY = assertFiniteNumber(y, "y");
|
|
730
|
+
return this.transport.request({
|
|
731
|
+
method: "GET",
|
|
732
|
+
path: `/tiles/vector/v1/data/${encodeURIComponent(name)}/${zoom}/${tileX}/${tileY}.pbf`,
|
|
733
|
+
headers: { Accept: "application/x-protobuf" },
|
|
734
|
+
responseFormat: "arrayBuffer",
|
|
735
|
+
requestOptions
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Fetch a raster map tile image (`/{z}/{x}/{y}.{format}`) as an `ArrayBuffer`.
|
|
740
|
+
*/
|
|
741
|
+
getRasterTile(styleName, z, x, y, format = "png", requestOptions) {
|
|
742
|
+
const style = assertNonEmptyString(styleName, "styleName");
|
|
743
|
+
const zoom = assertRange(assertFiniteNumber(z, "z"), 0, 24, "z");
|
|
744
|
+
const tileX = assertFiniteNumber(x, "x");
|
|
745
|
+
const tileY = assertFiniteNumber(y, "y");
|
|
746
|
+
const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
|
|
747
|
+
return this.transport.request({
|
|
748
|
+
method: "GET",
|
|
749
|
+
path: `/tiles/v1/styles/${encodeURIComponent(style)}/${zoom}/${tileX}/${tileY}.${validFormat}`,
|
|
750
|
+
headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
|
|
751
|
+
responseFormat: "arrayBuffer",
|
|
752
|
+
requestOptions
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* List all available Ola Maps vector styles.
|
|
757
|
+
*/
|
|
758
|
+
getStyles(requestOptions) {
|
|
759
|
+
return this.transport.request({
|
|
760
|
+
method: "GET",
|
|
761
|
+
path: "/tiles/vector/v1/styles.json",
|
|
762
|
+
requestOptions
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Fetch a MapLibre Style Specification JSON for a named Ola Maps style.
|
|
767
|
+
*/
|
|
768
|
+
getStyleDetail(styleName, requestOptions) {
|
|
769
|
+
const name = assertNonEmptyString(styleName, "styleName");
|
|
770
|
+
return this.transport.request({
|
|
771
|
+
method: "GET",
|
|
772
|
+
path: `/tiles/vector/v1/styles/${encodeURIComponent(name)}/style.json`,
|
|
773
|
+
requestOptions
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Fetch SDF font glyph ranges (.pbf) as an `ArrayBuffer`.
|
|
778
|
+
*/
|
|
779
|
+
getFontGlyphs(fontstack, start, end, requestOptions) {
|
|
780
|
+
const font = assertNonEmptyString(fontstack, "fontstack");
|
|
781
|
+
const startCode = assertRange(assertFiniteNumber(start, "start"), 0, 65535, "start");
|
|
782
|
+
const endCode = assertRange(assertFiniteNumber(end, "end"), startCode, 65535, "end");
|
|
783
|
+
return this.transport.request({
|
|
784
|
+
method: "GET",
|
|
785
|
+
path: `/tiles/vector/v1/fonts/${encodeURIComponent(font)}/${startCode}-${endCode}.pbf`,
|
|
786
|
+
headers: { Accept: "application/x-protobuf" },
|
|
787
|
+
responseFormat: "arrayBuffer",
|
|
788
|
+
requestOptions
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Fetch a static map image centered on `(lon, lat)` at a given `zoom` (0–23).
|
|
793
|
+
* Width and height must be between 1 and 2048 pixels.
|
|
794
|
+
*/
|
|
795
|
+
getStaticMapByCenter(styleName, lon, lat, zoom, width, height, format, options = {}, requestOptions) {
|
|
796
|
+
const style = assertNonEmptyString(styleName, "styleName");
|
|
797
|
+
const validLon = assertRange(assertFiniteNumber(lon, "lon"), -180, 180, "lon");
|
|
798
|
+
const validLat = assertRange(assertFiniteNumber(lat, "lat"), -90, 90, "lat");
|
|
799
|
+
const validZoom = assertRange(assertFiniteNumber(zoom, "zoom"), 0, 23, "zoom");
|
|
800
|
+
validateDimensions(width, height);
|
|
801
|
+
const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
|
|
802
|
+
return this.transport.request({
|
|
803
|
+
method: "GET",
|
|
804
|
+
path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/${validLon},${validLat},${validZoom}/${width}x${height}.${validFormat}`,
|
|
805
|
+
query: buildStaticMapQuery(options),
|
|
806
|
+
headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
|
|
807
|
+
responseFormat: "arrayBuffer",
|
|
808
|
+
requestOptions
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Fetch a static map image bounded by `{ minx, miny, maxx, maxy }`.
|
|
813
|
+
*/
|
|
814
|
+
getStaticMapByBBox(styleName, bbox, width, height, format, options = {}, requestOptions) {
|
|
815
|
+
const style = assertNonEmptyString(styleName, "styleName");
|
|
816
|
+
if (!bbox || typeof bbox !== "object") {
|
|
817
|
+
throw new OlaValidationError("bbox must be an object with { minx, miny, maxx, maxy }");
|
|
818
|
+
}
|
|
819
|
+
const minx = assertRange(assertFiniteNumber(bbox.minx, "bbox.minx"), -180, 180, "bbox.minx");
|
|
820
|
+
const miny = assertRange(assertFiniteNumber(bbox.miny, "bbox.miny"), -90, 90, "bbox.miny");
|
|
821
|
+
const maxx = assertRange(assertFiniteNumber(bbox.maxx, "bbox.maxx"), -180, 180, "bbox.maxx");
|
|
822
|
+
const maxy = assertRange(assertFiniteNumber(bbox.maxy, "bbox.maxy"), -90, 90, "bbox.maxy");
|
|
823
|
+
if (minx >= maxx || miny >= maxy) {
|
|
824
|
+
throw new OlaValidationError("bbox requires minx < maxx and miny < maxy");
|
|
825
|
+
}
|
|
826
|
+
validateDimensions(width, height);
|
|
827
|
+
const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
|
|
828
|
+
return this.transport.request({
|
|
829
|
+
method: "GET",
|
|
830
|
+
path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/${minx},${miny},${maxx},${maxy}/${width}x${height}.${validFormat}`,
|
|
831
|
+
query: buildStaticMapQuery(options),
|
|
832
|
+
headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
|
|
833
|
+
responseFormat: "arrayBuffer",
|
|
834
|
+
requestOptions
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Fetch a static map image with auto-fit bounds.
|
|
839
|
+
* Requires at least one `marker` or `path` in `options`.
|
|
840
|
+
*/
|
|
841
|
+
getStaticMapAuto(styleName, width, height, format, options, requestOptions) {
|
|
842
|
+
const style = assertNonEmptyString(styleName, "styleName");
|
|
843
|
+
validateDimensions(width, height);
|
|
844
|
+
const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
|
|
845
|
+
const hasMarker = Array.isArray(options?.marker) ? options.marker.length > 0 : typeof options?.marker === "string" && options.marker.trim().length > 0;
|
|
846
|
+
const hasPath = typeof options?.path === "string" && options.path.trim().length > 0;
|
|
847
|
+
if (!hasMarker && !hasPath) {
|
|
848
|
+
throw new OlaValidationError(
|
|
849
|
+
"getStaticMapAuto requires at least one marker or path option to compute bounds"
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
return this.transport.request({
|
|
853
|
+
method: "GET",
|
|
854
|
+
path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/auto/${width}x${height}.${validFormat}`,
|
|
855
|
+
query: buildStaticMapQuery(options),
|
|
856
|
+
headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
|
|
857
|
+
responseFormat: "arrayBuffer",
|
|
858
|
+
requestOptions
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Fetch the 3D buildings tileset JSON.
|
|
863
|
+
*/
|
|
864
|
+
get3DTileset(requestOptions) {
|
|
865
|
+
return this.transport.request({
|
|
866
|
+
method: "GET",
|
|
867
|
+
path: "/tiles/vector/v1/3dtiles/tileset.json",
|
|
868
|
+
requestOptions
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// src/client.ts
|
|
874
|
+
var OlaMapsClient = class {
|
|
875
|
+
places;
|
|
876
|
+
tiles;
|
|
877
|
+
routing;
|
|
878
|
+
roads;
|
|
879
|
+
geofencing;
|
|
880
|
+
elevation;
|
|
881
|
+
streetView;
|
|
882
|
+
auth;
|
|
883
|
+
transport;
|
|
884
|
+
staticAccessToken;
|
|
885
|
+
/**
|
|
886
|
+
* Create an Ola Maps client.
|
|
887
|
+
*
|
|
888
|
+
* Supports both the v1 shorthand (`new OlaMapsClient('YOUR_API_KEY')`) and the
|
|
889
|
+
* v2 configuration object supporting API Key, OAuth 2.0 (`client_credentials`),
|
|
890
|
+
* pre-issued Bearer `accessToken`, or Proxy Mode (`{ baseUrl: '/api/ola-maps' }`).
|
|
891
|
+
*/
|
|
892
|
+
constructor(configOrApiKey) {
|
|
893
|
+
let config;
|
|
894
|
+
if (typeof configOrApiKey === "string") {
|
|
895
|
+
if (!configOrApiKey.trim()) {
|
|
896
|
+
throw new OlaValidationError("API key is required.");
|
|
897
|
+
}
|
|
898
|
+
config = { apiKey: configOrApiKey };
|
|
899
|
+
} else if (configOrApiKey && typeof configOrApiKey === "object") {
|
|
900
|
+
config = configOrApiKey;
|
|
901
|
+
} else {
|
|
902
|
+
throw new OlaValidationError(
|
|
903
|
+
"OlaMapsClient requires an API key string or configuration object."
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
const fetchImpl = config.fetch ?? globalThis.fetch?.bind(globalThis);
|
|
907
|
+
if (!fetchImpl) {
|
|
908
|
+
throw new OlaValidationError(
|
|
909
|
+
"No global fetch implementation found. Use Node 18+ or pass a custom `fetch` in config."
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
this.auth = new AuthManager(config, fetchImpl);
|
|
913
|
+
this.transport = new HttpTransport(config, this.auth, fetchImpl);
|
|
914
|
+
this.staticAccessToken = typeof config.accessToken === "string" ? config.accessToken : void 0;
|
|
915
|
+
this.places = new Places(this.transport);
|
|
916
|
+
this.tiles = new Tiles(this.transport);
|
|
917
|
+
this.routing = new Routing(this.transport);
|
|
918
|
+
this.roads = new Roads(this.transport);
|
|
919
|
+
this.geofencing = new Geofencing(this.transport);
|
|
920
|
+
this.elevation = new Elevation(this.transport);
|
|
921
|
+
this.streetView = new StreetView(this.transport);
|
|
922
|
+
}
|
|
923
|
+
/** Active authentication mode (`'apiKey'`, `'oauth'`, `'accessToken'`, or `'proxy'`). */
|
|
924
|
+
get authMode() {
|
|
925
|
+
return this.auth.mode;
|
|
926
|
+
}
|
|
927
|
+
/** Configured API base URL. */
|
|
928
|
+
get baseUrl() {
|
|
929
|
+
return this.transport.baseUrl;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Fetch or return the cached OAuth 2.0 / Bearer access token.
|
|
933
|
+
*/
|
|
934
|
+
getAccessToken(forceRefresh = false) {
|
|
935
|
+
return this.auth.getAccessToken(forceRefresh);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Clear any cached in-memory GET responses.
|
|
939
|
+
*/
|
|
940
|
+
clearCache() {
|
|
941
|
+
this.transport.clearCache();
|
|
942
|
+
}
|
|
943
|
+
// ── MapLibre GL Convenience Helpers ───────────────────────────────
|
|
944
|
+
/**
|
|
945
|
+
* Get the full MapLibre style URL for a named Ola Maps style.
|
|
946
|
+
*/
|
|
947
|
+
getStyleURL(styleName = "default-light-standard") {
|
|
948
|
+
const styleBase = this.auth.mode === "proxy" ? this.transport.baseUrl : DEFAULT_BASE_URL;
|
|
949
|
+
return getStyleURL(styleName, styleBase);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Get a host-safe MapLibre `transformRequest` callback.
|
|
953
|
+
* Credentials are strictly restricted to `*.olamaps.io` hosts and never leak to third-party URLs.
|
|
954
|
+
*/
|
|
955
|
+
getTransformRequest() {
|
|
956
|
+
if (this.auth.mode === "proxy") {
|
|
957
|
+
return getTransformRequest({ proxyBaseUrl: this.transport.baseUrl });
|
|
958
|
+
}
|
|
959
|
+
return getTransformRequest({
|
|
960
|
+
apiKey: this.auth.getApiKey(),
|
|
961
|
+
accessToken: this.staticAccessToken
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Build a ready-to-use MapLibre GL `Map` options object.
|
|
966
|
+
*/
|
|
967
|
+
getMapOptions(options = {}) {
|
|
968
|
+
const authOpts = this.auth.mode === "proxy" ? { proxyBaseUrl: this.transport.baseUrl } : {
|
|
969
|
+
apiKey: this.auth.getApiKey(),
|
|
970
|
+
accessToken: this.staticAccessToken
|
|
971
|
+
};
|
|
972
|
+
return getMapOptions(authOpts, options);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
export { Elevation, Geofencing, OlaMapsClient, Places, Roads, Routing, StreetView, Tiles, formatCoordinateList, formatLatLng, normalizeCoordinate, parseLatLngPair };
|
|
977
|
+
//# sourceMappingURL=chunk-22747AE4.js.map
|
|
978
|
+
//# sourceMappingURL=chunk-22747AE4.js.map
|