@maptiler/client 3.0.2 → 3.1.0-rc.2
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 +174 -0
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +219 -2
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +101 -1
- package/dist/maptiler-client.mjs.map +1 -1
- package/package.json +2 -1
- package/readme.md +8 -28
package/dist/maptiler-client.cjs
CHANGED
|
@@ -1189,6 +1189,179 @@ const geolocation = {
|
|
|
1189
1189
|
info
|
|
1190
1190
|
};
|
|
1191
1191
|
|
|
1192
|
+
/**
|
|
1193
|
+
* Copyright 2020 Google LLC
|
|
1194
|
+
*
|
|
1195
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1196
|
+
* you may not use this file except in compliance with the License.
|
|
1197
|
+
* You may obtain a copy of the License at
|
|
1198
|
+
*
|
|
1199
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1200
|
+
*
|
|
1201
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1202
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1203
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1204
|
+
* See the License for the specific language governing permissions and
|
|
1205
|
+
* limitations under the License.
|
|
1206
|
+
*/
|
|
1207
|
+
/**
|
|
1208
|
+
* Decodes an encoded path string into a sequence of LatLngs.
|
|
1209
|
+
*
|
|
1210
|
+
* See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm}
|
|
1211
|
+
*
|
|
1212
|
+
* #### Example
|
|
1213
|
+
*
|
|
1214
|
+
* ```js
|
|
1215
|
+
* import { decode } from "@googlemaps/polyline-codec";
|
|
1216
|
+
*
|
|
1217
|
+
* const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
|
|
1218
|
+
* console.log(decode(encoded, 5));
|
|
1219
|
+
* // [
|
|
1220
|
+
* // [38.5, -120.2],
|
|
1221
|
+
* // [40.7, -120.95],
|
|
1222
|
+
* // [43.252, -126.453],
|
|
1223
|
+
* // ]
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
1226
|
+
var decode = function (encodedPath, precision) {
|
|
1227
|
+
var factor = Math.pow(10, precision);
|
|
1228
|
+
var len = encodedPath.length;
|
|
1229
|
+
// For speed we preallocate to an upper bound on the final length, then
|
|
1230
|
+
// truncate the array before returning.
|
|
1231
|
+
var path = new Array(Math.floor(encodedPath.length / 2));
|
|
1232
|
+
var index = 0;
|
|
1233
|
+
var lat = 0;
|
|
1234
|
+
var lng = 0;
|
|
1235
|
+
var pointIndex = 0;
|
|
1236
|
+
// This code has been profiled and optimized, so don't modify it without
|
|
1237
|
+
// measuring its performance.
|
|
1238
|
+
for (; index < len; ++pointIndex) {
|
|
1239
|
+
// Fully unrolling the following loops speeds things up about 5%.
|
|
1240
|
+
var result = 1;
|
|
1241
|
+
var shift = 0;
|
|
1242
|
+
var b = void 0;
|
|
1243
|
+
do {
|
|
1244
|
+
// Invariant: "result" is current partial result plus (1 << shift).
|
|
1245
|
+
// The following line effectively clears this bit by decrementing "b".
|
|
1246
|
+
b = encodedPath.charCodeAt(index++) - 63 - 1;
|
|
1247
|
+
result += b << shift;
|
|
1248
|
+
shift += 5;
|
|
1249
|
+
} while (b >= 0x1f); // See note above.
|
|
1250
|
+
lat += result & 1 ? ~(result >> 1) : result >> 1;
|
|
1251
|
+
result = 1;
|
|
1252
|
+
shift = 0;
|
|
1253
|
+
do {
|
|
1254
|
+
b = encodedPath.charCodeAt(index++) - 63 - 1;
|
|
1255
|
+
result += b << shift;
|
|
1256
|
+
shift += 5;
|
|
1257
|
+
} while (b >= 0x1f);
|
|
1258
|
+
lng += result & 1 ? ~(result >> 1) : result >> 1;
|
|
1259
|
+
path[pointIndex] = [lat / factor, lng / factor];
|
|
1260
|
+
}
|
|
1261
|
+
// truncate array
|
|
1262
|
+
path.length = pointIndex;
|
|
1263
|
+
return path;
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
function addLocations(search, locations) {
|
|
1267
|
+
for (const loc of locations) {
|
|
1268
|
+
search.append("location", `${loc.lon},${loc.lat}`);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function addResponseOptions(search, response) {
|
|
1272
|
+
if (!response) return;
|
|
1273
|
+
if (response.units) search.set("response.units", response.units);
|
|
1274
|
+
if (response.language) search.set("response.language", response.language);
|
|
1275
|
+
if (response.alternates !== void 0)
|
|
1276
|
+
search.set("alternates", String(response.alternates));
|
|
1277
|
+
if (response.additionalData?.detailLevel)
|
|
1278
|
+
search.set(
|
|
1279
|
+
"response.additionalData.detailLevel",
|
|
1280
|
+
response.additionalData.detailLevel
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
function addProfileOptions(search, profile, opts) {
|
|
1284
|
+
if (!opts) return;
|
|
1285
|
+
if (profile === "car") {
|
|
1286
|
+
const o = opts;
|
|
1287
|
+
if (o.mode) search.set("car.mode", o.mode);
|
|
1288
|
+
if (o.topSpeed) search.set("topSpeed", String(o.topSpeed));
|
|
1289
|
+
if (o.avoidances?.tolls !== void 0)
|
|
1290
|
+
search.set("avoidances.tolls", String(o.avoidances.tolls));
|
|
1291
|
+
if (o.avoidances?.ferry !== void 0)
|
|
1292
|
+
search.set("avoidances.ferry", String(o.avoidances.ferry));
|
|
1293
|
+
if (o.avoidances?.highway !== void 0)
|
|
1294
|
+
search.set("avoidances.highway", String(o.avoidances.highway));
|
|
1295
|
+
}
|
|
1296
|
+
if (profile === "truck") {
|
|
1297
|
+
const o = opts;
|
|
1298
|
+
if (o.height) search.set("truck.height", String(o.height));
|
|
1299
|
+
if (o.weight) search.set("truck.weight", String(o.weight));
|
|
1300
|
+
if (o.axleLoad) search.set("truck.axleLoad", String(o.axleLoad));
|
|
1301
|
+
if (o.hazmat !== void 0) search.set("truck.hazmat", String(o.hazmat));
|
|
1302
|
+
if (o.topSpeed) search.set("topSpeed", String(o.topSpeed));
|
|
1303
|
+
if (o.avoidances?.tolls !== void 0)
|
|
1304
|
+
search.set("avoidances.tolls", String(o.avoidances.tolls));
|
|
1305
|
+
}
|
|
1306
|
+
if (profile === "bicycle") {
|
|
1307
|
+
const o = opts;
|
|
1308
|
+
if (o.type) search.set("bicycle.type", o.type);
|
|
1309
|
+
if (o.cyclingSpeed)
|
|
1310
|
+
search.set("bicycle.cyclingSpeed", String(o.cyclingSpeed));
|
|
1311
|
+
}
|
|
1312
|
+
if (profile === "pedestrian") {
|
|
1313
|
+
const o = opts;
|
|
1314
|
+
if (o.walkingSpeed)
|
|
1315
|
+
search.set("pedestrian.walkingSpeed", String(o.walkingSpeed));
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
async function processDirectionsResponse(res) {
|
|
1319
|
+
if (!res.ok) {
|
|
1320
|
+
throw new ServiceError(res);
|
|
1321
|
+
}
|
|
1322
|
+
const response = await res.json();
|
|
1323
|
+
for (const leg of response.route.legs) {
|
|
1324
|
+
if (typeof leg.geometry === "string") {
|
|
1325
|
+
leg.geometry = decode(leg.geometry, 6).map(([lat, lon]) => [lon, lat]);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return response;
|
|
1329
|
+
}
|
|
1330
|
+
async function directionsPost(body) {
|
|
1331
|
+
const url = new URL("routing/v1/directions", defaults.maptilerApiURL);
|
|
1332
|
+
url.searchParams.set("key", config.apiKey);
|
|
1333
|
+
const res = await callFetch(url.toString(), {
|
|
1334
|
+
method: "POST",
|
|
1335
|
+
headers: { "content-type": "application/json" },
|
|
1336
|
+
body: JSON.stringify(body)
|
|
1337
|
+
});
|
|
1338
|
+
return await processDirectionsResponse(res);
|
|
1339
|
+
}
|
|
1340
|
+
async function directionsGet(req) {
|
|
1341
|
+
const url = new URL("routing/v1/directions", defaults.maptilerApiURL);
|
|
1342
|
+
const search = url.searchParams;
|
|
1343
|
+
search.set("key", config.apiKey);
|
|
1344
|
+
search.set("profile", req.profile);
|
|
1345
|
+
if (req.id) search.set("id", req.id);
|
|
1346
|
+
if (req.departureTime) search.set("departureTime", req.departureTime);
|
|
1347
|
+
if (req.arrivalTime) search.set("arrivalTime", req.arrivalTime);
|
|
1348
|
+
addLocations(search, req.locations);
|
|
1349
|
+
addResponseOptions(search, req.response);
|
|
1350
|
+
addProfileOptions(search, req.profile, req.profileOptions);
|
|
1351
|
+
const res = await callFetch(url.toString());
|
|
1352
|
+
return await processDirectionsResponse(res);
|
|
1353
|
+
}
|
|
1354
|
+
const routing = {
|
|
1355
|
+
/**
|
|
1356
|
+
* Get directions using POST request
|
|
1357
|
+
*/
|
|
1358
|
+
directionsPost,
|
|
1359
|
+
/**
|
|
1360
|
+
* Get directions using GET request
|
|
1361
|
+
*/
|
|
1362
|
+
directionsGet
|
|
1363
|
+
};
|
|
1364
|
+
|
|
1192
1365
|
const customMessages$2 = {
|
|
1193
1366
|
403: "Key is missing, invalid or restricted"
|
|
1194
1367
|
};
|
|
@@ -3336,6 +3509,7 @@ exports.isLanguageInfo = isLanguageInfo;
|
|
|
3336
3509
|
exports.mapStylePresetList = mapStylePresetList;
|
|
3337
3510
|
exports.math = math;
|
|
3338
3511
|
exports.misc = misc;
|
|
3512
|
+
exports.routing = routing;
|
|
3339
3513
|
exports.staticMaps = staticMaps;
|
|
3340
3514
|
exports.styleToStyle = styleToStyle;
|
|
3341
3515
|
exports.toLanguageInfo = toLanguageInfo;
|