@maptiler/client 3.1.0-rc.2 → 3.1.0-rc.4
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/dist/maptiler-client.cjs
CHANGED
|
@@ -1315,29 +1315,43 @@ function addProfileOptions(search, profile, opts) {
|
|
|
1315
1315
|
search.set("pedestrian.walkingSpeed", String(o.walkingSpeed));
|
|
1316
1316
|
}
|
|
1317
1317
|
}
|
|
1318
|
+
function decodeLegGeometry(leg) {
|
|
1319
|
+
if (typeof leg.geometry === "string") {
|
|
1320
|
+
return decode(leg.geometry, 6).map(([lat, lon]) => [lon, lat]);
|
|
1321
|
+
}
|
|
1322
|
+
return leg.geometry;
|
|
1323
|
+
}
|
|
1318
1324
|
async function processDirectionsResponse(res) {
|
|
1319
1325
|
if (!res.ok) {
|
|
1320
1326
|
throw new ServiceError(res);
|
|
1321
1327
|
}
|
|
1322
1328
|
const response = await res.json();
|
|
1323
1329
|
for (const leg of response.route.legs) {
|
|
1324
|
-
|
|
1325
|
-
|
|
1330
|
+
leg.geometry = decodeLegGeometry(leg);
|
|
1331
|
+
}
|
|
1332
|
+
if (response.alternates) {
|
|
1333
|
+
for (const alternateRoute of response.alternates) {
|
|
1334
|
+
for (const leg of alternateRoute.legs) {
|
|
1335
|
+
leg.geometry = decodeLegGeometry(leg);
|
|
1336
|
+
}
|
|
1326
1337
|
}
|
|
1327
1338
|
}
|
|
1328
1339
|
return response;
|
|
1329
1340
|
}
|
|
1330
|
-
async function directionsPost(body) {
|
|
1341
|
+
async function directionsPost(body, fetchExtras) {
|
|
1331
1342
|
const url = new URL("routing/v1/directions", defaults.maptilerApiURL);
|
|
1332
1343
|
url.searchParams.set("key", config.apiKey);
|
|
1344
|
+
const headers = new Headers(fetchExtras?.headers);
|
|
1345
|
+
headers.set("content-type", "application/json");
|
|
1333
1346
|
const res = await callFetch(url.toString(), {
|
|
1347
|
+
...fetchExtras,
|
|
1334
1348
|
method: "POST",
|
|
1335
|
-
headers
|
|
1349
|
+
headers,
|
|
1336
1350
|
body: JSON.stringify(body)
|
|
1337
1351
|
});
|
|
1338
1352
|
return await processDirectionsResponse(res);
|
|
1339
1353
|
}
|
|
1340
|
-
async function directionsGet(req) {
|
|
1354
|
+
async function directionsGet(req, fetchExtras) {
|
|
1341
1355
|
const url = new URL("routing/v1/directions", defaults.maptilerApiURL);
|
|
1342
1356
|
const search = url.searchParams;
|
|
1343
1357
|
search.set("key", config.apiKey);
|
|
@@ -1348,7 +1362,11 @@ async function directionsGet(req) {
|
|
|
1348
1362
|
addLocations(search, req.locations);
|
|
1349
1363
|
addResponseOptions(search, req.response);
|
|
1350
1364
|
addProfileOptions(search, req.profile, req.profileOptions);
|
|
1351
|
-
const res = await callFetch(url.toString()
|
|
1365
|
+
const res = await callFetch(url.toString(), {
|
|
1366
|
+
...fetchExtras,
|
|
1367
|
+
method: "GET",
|
|
1368
|
+
body: null
|
|
1369
|
+
});
|
|
1352
1370
|
return await processDirectionsResponse(res);
|
|
1353
1371
|
}
|
|
1354
1372
|
const routing = {
|