@maptiler/client 1.6.0 → 1.7.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/dist/maptiler-client.cjs +482 -309
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +114 -5
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +471 -309
- package/dist/maptiler-client.mjs.map +1 -1
- package/dist/maptiler-client.umd.js +483 -310
- package/dist/maptiler-client.umd.js.map +1 -1
- package/dist/maptiler-client.umd.min.js +1 -1
- package/package.json +25 -18
- package/readme.md +1 -1
- package/rollup.config.js +3 -3
- package/src/callFetch.ts +2 -2
- package/src/config.ts +4 -1
- package/src/demProfiler/getElevation.ts +46 -0
- package/src/demProfiler/index.ts +240 -0
- package/src/demProfiler/tileCover.ts +96 -0
- package/src/geometry/area.ts +96 -0
- package/src/geometry/distance.ts +45 -0
- package/src/geometry/index.ts +3 -0
- package/src/geometry/util.ts +34 -0
- package/src/index.ts +3 -0
- package/src/language.ts +1 -1
- package/src/mapstyle.ts +5 -5
- package/src/services/ServiceError.ts +5 -2
- package/src/services/coordinates.ts +14 -9
- package/src/services/data.ts +3 -3
- package/src/services/geocoding.ts +17 -14
- package/src/services/geolocation.ts +2 -2
- package/src/services/simplify.ts +3 -3
- package/src/services/staticMaps.ts +9 -9
- package/tsconfig.json +1 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/custom.css +0 -118
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/config.ClientConfig.html +0 -132
- package/docs/classes/services_ServiceError.ServiceError.html +0 -103
- package/docs/functions/language.getAutoLanguageGeocoding.html +0 -60
- package/docs/functions/services_simplify.default.html +0 -65
- package/docs/images/JS-logo.svg +0 -4
- package/docs/images/TS-logo.svg +0 -6
- package/docs/images/maptiler-client-logo.afdesign +0 -0
- package/docs/images/maptiler-client-logo.svg +0 -75
- package/docs/images/maptiler-logo-256.png +0 -0
- package/docs/images/maptiler-logo.svg +0 -23
- package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docs/images/screenshots/static-with-path.png +0 -0
- package/docs/index.html +0 -340
- package/docs/modules/config.html +0 -71
- package/docs/modules/language.html +0 -71
- package/docs/modules/services_ServiceError.html +0 -61
- package/docs/modules/services_coordinates.html +0 -84
- package/docs/modules/services_data.html +0 -66
- package/docs/modules/services_geocoding.html +0 -82
- package/docs/modules/services_geolocation.html +0 -68
- package/docs/modules/services_simplify.html +0 -61
- package/docs/modules/services_staticMaps.html +0 -74
- package/docs/modules.html +0 -59
- package/docs/types/config.FetchFunction.html +0 -71
- package/docs/types/language.LanguageGeocodingString.html +0 -58
- package/docs/types/services_coordinates.CoordinateExport.html +0 -71
- package/docs/types/services_coordinates.CoordinateGrid.html +0 -69
- package/docs/types/services_coordinates.CoordinateId.html +0 -71
- package/docs/types/services_coordinates.CoordinateSearch.html +0 -93
- package/docs/types/services_coordinates.CoordinateSearchResult.html +0 -75
- package/docs/types/services_coordinates.CoordinateTransformResult.html +0 -76
- package/docs/types/services_coordinates.CoordinateTransformation.html +0 -89
- package/docs/types/services_coordinates.CoordinatesSearchOptions.html +0 -83
- package/docs/types/services_coordinates.CoordinatesTransformOptions.html +0 -85
- package/docs/types/services_coordinates.XYZ.html +0 -73
- package/docs/types/services_data.GetDataOptions.html +0 -64
- package/docs/types/services_geocoding.ByIdGeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.Coordinates.html +0 -63
- package/docs/types/services_geocoding.FeatureHierarchy.html +0 -63
- package/docs/types/services_geocoding.GeocodingFeature.html +0 -63
- package/docs/types/services_geocoding.GeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.GeocodingSearchResult.html +0 -80
- package/docs/types/services_geocoding.LanguageGeocodingOptions.html +0 -70
- package/docs/types/services_geocoding.ReverseGeocodingOptions.html +0 -63
- package/docs/types/services_geolocation.GeolocationInfoOptions.html +0 -65
- package/docs/types/services_geolocation.GeolocationResult.html +0 -128
- package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.StaticMapBaseOptions.html +0 -157
- package/docs/types/services_staticMaps.StaticMapMarker.html +0 -61
- package/docs/variables/config.config.html +0 -58
- package/docs/variables/language.LanguageGeocoding.html +0 -171
- package/docs/variables/services_coordinates.coordinates.html +0 -110
- package/docs/variables/services_data.data.html +0 -80
- package/docs/variables/services_geocoding.geocoding.html +0 -265
- package/docs/variables/services_geolocation.geolocation.html +0 -79
- package/docs/variables/services_staticMaps.staticMaps.html +0 -128
- package/docsmd/.nojekyll +0 -1
- package/docsmd/README.md +0 -873
- package/docsmd/assets/custom.css +0 -118
- package/docsmd/classes/ClientConfig.md +0 -90
- package/docsmd/classes/MapStyleVariant.md +0 -234
- package/docsmd/classes/ReferenceMapStyle.md +0 -169
- package/docsmd/classes/ServiceError.md +0 -52
- package/images/JS-logo.svg +0 -4
- package/images/TS-logo.svg +0 -6
- package/images/maptiler-client-logo.afdesign +0 -0
- package/images/maptiler-client-logo.svg +0 -75
- package/images/maptiler-logo-256.png +0 -0
- package/images/maptiler-logo.svg +0 -23
- package/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/images/screenshots/static-with-path.png +0 -0
package/dist/maptiler-client.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { llToTile, llToTilePx } from 'web-merc-projection';
|
|
2
|
+
|
|
1
3
|
function tryGettingFetch() {
|
|
2
4
|
if (typeof self !== "undefined") {
|
|
3
5
|
return fetch.bind(self);
|
|
@@ -114,40 +116,18 @@ function getAutoLanguageGeocoding() {
|
|
|
114
116
|
return canditatelangs.length ? canditatelangs[0] : LanguageGeocoding.ENGLISH;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} catch (e) {
|
|
130
|
-
reject(e);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
134
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
function callFetch(_0) {
|
|
138
|
-
return __async$4(this, arguments, function* (resource, options = {}) {
|
|
139
|
-
if (config.fetch === null) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
"The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
if (new URL(resource).searchParams.get("key").trim() === "") {
|
|
145
|
-
throw new Error(
|
|
146
|
-
"The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
return config.fetch(resource, options);
|
|
150
|
-
});
|
|
119
|
+
async function callFetch(resource, options = {}) {
|
|
120
|
+
if (config.fetch === null) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
"The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (new URL(resource).searchParams.get("key").trim() === "") {
|
|
126
|
+
throw new Error(
|
|
127
|
+
"The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return config.fetch(resource, options);
|
|
151
131
|
}
|
|
152
132
|
|
|
153
133
|
const defaults = {
|
|
@@ -165,26 +145,6 @@ class ServiceError extends Error {
|
|
|
165
145
|
}
|
|
166
146
|
}
|
|
167
147
|
|
|
168
|
-
var __async$3 = (__this, __arguments, generator) => {
|
|
169
|
-
return new Promise((resolve, reject) => {
|
|
170
|
-
var fulfilled = (value) => {
|
|
171
|
-
try {
|
|
172
|
-
step(generator.next(value));
|
|
173
|
-
} catch (e) {
|
|
174
|
-
reject(e);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var rejected = (value) => {
|
|
178
|
-
try {
|
|
179
|
-
step(generator.throw(value));
|
|
180
|
-
} catch (e) {
|
|
181
|
-
reject(e);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
185
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
148
|
const customMessages$3 = {
|
|
189
149
|
400: "Query too long / Invalid parameters",
|
|
190
150
|
403: "Key is missing, invalid or restricted"
|
|
@@ -203,8 +163,7 @@ function addLanguageGeocodingOptions(searchParams, options) {
|
|
|
203
163
|
searchParams.set("language", languages);
|
|
204
164
|
}
|
|
205
165
|
function addCommonForwardAndReverseGeocodingOptions(searchParams, options) {
|
|
206
|
-
|
|
207
|
-
searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
|
|
166
|
+
searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
208
167
|
if (options.limit != void 0) {
|
|
209
168
|
searchParams.set("limit", String(options.limit));
|
|
210
169
|
}
|
|
@@ -231,82 +190,71 @@ function addForwardGeocodingOptions(searchParams, options) {
|
|
|
231
190
|
searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
|
|
232
191
|
}
|
|
233
192
|
}
|
|
234
|
-
function forward(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const obj = yield res.json();
|
|
252
|
-
return obj;
|
|
253
|
-
});
|
|
193
|
+
async function forward(query, options = {}) {
|
|
194
|
+
if (typeof query !== "string" || query.trim().length === 0) {
|
|
195
|
+
throw new Error("The query must be a non-empty string");
|
|
196
|
+
}
|
|
197
|
+
const endpoint = new URL(
|
|
198
|
+
`geocoding/${encodeURIComponent(query)}.json`,
|
|
199
|
+
defaults.maptilerApiURL
|
|
200
|
+
);
|
|
201
|
+
const { searchParams } = endpoint;
|
|
202
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
203
|
+
const urlWithParams = endpoint.toString();
|
|
204
|
+
const res = await callFetch(urlWithParams);
|
|
205
|
+
if (!res.ok) {
|
|
206
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
207
|
+
}
|
|
208
|
+
const obj = await res.json();
|
|
209
|
+
return obj;
|
|
254
210
|
}
|
|
255
|
-
function reverse(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const obj = yield res.json();
|
|
272
|
-
return obj;
|
|
273
|
-
});
|
|
211
|
+
async function reverse(position, options = {}) {
|
|
212
|
+
if (!Array.isArray(position) || position.length < 2) {
|
|
213
|
+
throw new Error("The position must be an array of form [lng, lat].");
|
|
214
|
+
}
|
|
215
|
+
const endpoint = new URL(
|
|
216
|
+
`geocoding/${position[0]},${position[1]}.json`,
|
|
217
|
+
defaults.maptilerApiURL
|
|
218
|
+
);
|
|
219
|
+
addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
|
|
220
|
+
const urlWithParams = endpoint.toString();
|
|
221
|
+
const res = await callFetch(urlWithParams);
|
|
222
|
+
if (!res.ok) {
|
|
223
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
224
|
+
}
|
|
225
|
+
const obj = await res.json();
|
|
226
|
+
return obj;
|
|
274
227
|
}
|
|
275
|
-
function byId(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return obj;
|
|
287
|
-
});
|
|
228
|
+
async function byId(id, options = {}) {
|
|
229
|
+
const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
|
|
230
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
231
|
+
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
232
|
+
const urlWithParams = endpoint.toString();
|
|
233
|
+
const res = await callFetch(urlWithParams);
|
|
234
|
+
if (!res.ok) {
|
|
235
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
236
|
+
}
|
|
237
|
+
const obj = await res.json();
|
|
238
|
+
return obj;
|
|
288
239
|
}
|
|
289
|
-
function batch(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const obj = yield res.json();
|
|
308
|
-
return queries.length === 1 ? [obj] : obj;
|
|
309
|
-
});
|
|
240
|
+
async function batch(queries, options = {}) {
|
|
241
|
+
if (!queries.length) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
|
|
245
|
+
const endpoint = new URL(
|
|
246
|
+
`geocoding/${joinedQuery}.json`,
|
|
247
|
+
defaults.maptilerApiURL
|
|
248
|
+
);
|
|
249
|
+
const { searchParams } = endpoint;
|
|
250
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
251
|
+
const urlWithParams = endpoint.toString();
|
|
252
|
+
const res = await callFetch(urlWithParams);
|
|
253
|
+
if (!res.ok) {
|
|
254
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
255
|
+
}
|
|
256
|
+
const obj = await res.json();
|
|
257
|
+
return queries.length === 1 ? [obj] : obj;
|
|
310
258
|
}
|
|
311
259
|
const geocoding = {
|
|
312
260
|
forward,
|
|
@@ -316,191 +264,119 @@ const geocoding = {
|
|
|
316
264
|
language: LanguageGeocoding
|
|
317
265
|
};
|
|
318
266
|
|
|
319
|
-
var __async$2 = (__this, __arguments, generator) => {
|
|
320
|
-
return new Promise((resolve, reject) => {
|
|
321
|
-
var fulfilled = (value) => {
|
|
322
|
-
try {
|
|
323
|
-
step(generator.next(value));
|
|
324
|
-
} catch (e) {
|
|
325
|
-
reject(e);
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
var rejected = (value) => {
|
|
329
|
-
try {
|
|
330
|
-
step(generator.throw(value));
|
|
331
|
-
} catch (e) {
|
|
332
|
-
reject(e);
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
336
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
267
|
const customMessages$2 = {
|
|
340
268
|
403: "Key is missing, invalid or restricted"
|
|
341
269
|
};
|
|
342
|
-
function info() {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const obj = yield res.json();
|
|
356
|
-
return obj;
|
|
357
|
-
});
|
|
270
|
+
async function info(options = {}) {
|
|
271
|
+
const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
|
|
272
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
273
|
+
const urlWithParams = endpoint.toString();
|
|
274
|
+
const res = await callFetch(urlWithParams);
|
|
275
|
+
if (!res.ok) {
|
|
276
|
+
throw new ServiceError(
|
|
277
|
+
res,
|
|
278
|
+
res.status in customMessages$2 ? customMessages$2[res.status] : ""
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
const obj = await res.json();
|
|
282
|
+
return obj;
|
|
358
283
|
}
|
|
359
284
|
const geolocation = {
|
|
360
285
|
info
|
|
361
286
|
};
|
|
362
287
|
|
|
363
|
-
var __async$1 = (__this, __arguments, generator) => {
|
|
364
|
-
return new Promise((resolve, reject) => {
|
|
365
|
-
var fulfilled = (value) => {
|
|
366
|
-
try {
|
|
367
|
-
step(generator.next(value));
|
|
368
|
-
} catch (e) {
|
|
369
|
-
reject(e);
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
var rejected = (value) => {
|
|
373
|
-
try {
|
|
374
|
-
step(generator.throw(value));
|
|
375
|
-
} catch (e) {
|
|
376
|
-
reject(e);
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
380
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
288
|
const customMessages$1 = {
|
|
384
289
|
403: "Key is missing, invalid or restricted"
|
|
385
290
|
};
|
|
386
|
-
function search(
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
291
|
+
async function search(query, options = {}) {
|
|
292
|
+
if (typeof query !== "string" || query.trim().length === 0) {
|
|
293
|
+
throw new Error("The query must be a non-empty string");
|
|
294
|
+
}
|
|
295
|
+
const endpoint = new URL(
|
|
296
|
+
`coordinates/search/${query}.json`,
|
|
297
|
+
defaults.maptilerApiURL
|
|
298
|
+
);
|
|
299
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
300
|
+
if ("limit" in options) {
|
|
301
|
+
endpoint.searchParams.set("limit", options.limit.toString());
|
|
302
|
+
}
|
|
303
|
+
if ("transformations" in options) {
|
|
304
|
+
endpoint.searchParams.set(
|
|
305
|
+
"transformations",
|
|
306
|
+
options.transformations.toString()
|
|
395
307
|
);
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const res = yield callFetch(urlWithParams);
|
|
411
|
-
if (!res.ok) {
|
|
412
|
-
throw new ServiceError(
|
|
413
|
-
res,
|
|
414
|
-
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
const obj = yield res.json();
|
|
418
|
-
return obj;
|
|
419
|
-
});
|
|
308
|
+
}
|
|
309
|
+
if ("exports" in options) {
|
|
310
|
+
endpoint.searchParams.set("exports", options.exports.toString());
|
|
311
|
+
}
|
|
312
|
+
const urlWithParams = endpoint.toString();
|
|
313
|
+
const res = await callFetch(urlWithParams);
|
|
314
|
+
if (!res.ok) {
|
|
315
|
+
throw new ServiceError(
|
|
316
|
+
res,
|
|
317
|
+
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
const obj = await res.json();
|
|
321
|
+
return obj;
|
|
420
322
|
}
|
|
421
|
-
function transform(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
323
|
+
async function transform(positions, options = {}) {
|
|
324
|
+
const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
|
|
325
|
+
const endpoint = new URL(
|
|
326
|
+
`coordinates/transform/${coordinatesStr}.json`,
|
|
327
|
+
defaults.maptilerApiURL
|
|
328
|
+
);
|
|
329
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
330
|
+
if ("sourceCrs" in options) {
|
|
331
|
+
endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
|
|
332
|
+
}
|
|
333
|
+
if ("targetCrs" in options) {
|
|
334
|
+
endpoint.searchParams.set("t_srs", options.targetCrs.toString());
|
|
335
|
+
}
|
|
336
|
+
if ("operations" in options) {
|
|
337
|
+
endpoint.searchParams.set(
|
|
338
|
+
"ops",
|
|
339
|
+
(Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
|
|
428
340
|
);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
const urlWithParams = endpoint.toString();
|
|
443
|
-
const res = yield callFetch(urlWithParams);
|
|
444
|
-
if (!res.ok) {
|
|
445
|
-
throw new ServiceError(
|
|
446
|
-
res,
|
|
447
|
-
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
const obj = yield res.json();
|
|
451
|
-
return obj;
|
|
452
|
-
});
|
|
341
|
+
}
|
|
342
|
+
const urlWithParams = endpoint.toString();
|
|
343
|
+
const res = await callFetch(urlWithParams);
|
|
344
|
+
if (!res.ok) {
|
|
345
|
+
throw new ServiceError(
|
|
346
|
+
res,
|
|
347
|
+
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
const obj = await res.json();
|
|
351
|
+
return obj;
|
|
453
352
|
}
|
|
454
353
|
const coordinates = {
|
|
455
354
|
search,
|
|
456
355
|
transform
|
|
457
356
|
};
|
|
458
357
|
|
|
459
|
-
var __async = (__this, __arguments, generator) => {
|
|
460
|
-
return new Promise((resolve, reject) => {
|
|
461
|
-
var fulfilled = (value) => {
|
|
462
|
-
try {
|
|
463
|
-
step(generator.next(value));
|
|
464
|
-
} catch (e) {
|
|
465
|
-
reject(e);
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
var rejected = (value) => {
|
|
469
|
-
try {
|
|
470
|
-
step(generator.throw(value));
|
|
471
|
-
} catch (e) {
|
|
472
|
-
reject(e);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
476
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
477
|
-
});
|
|
478
|
-
};
|
|
479
358
|
const customMessages = {
|
|
480
359
|
403: "Key is missing, invalid or restricted"
|
|
481
360
|
};
|
|
482
|
-
function get(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
361
|
+
async function get(dataId, options = {}) {
|
|
362
|
+
if (typeof dataId !== "string" || dataId.trim().length === 0) {
|
|
363
|
+
throw new Error("The data ID must be a non-empty string");
|
|
364
|
+
}
|
|
365
|
+
const endpoint = new URL(
|
|
366
|
+
`data/${encodeURIComponent(dataId)}/features.json`,
|
|
367
|
+
defaults.maptilerApiURL
|
|
368
|
+
);
|
|
369
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
370
|
+
const urlWithParams = endpoint.toString();
|
|
371
|
+
const res = await callFetch(urlWithParams);
|
|
372
|
+
if (!res.ok) {
|
|
373
|
+
throw new ServiceError(
|
|
374
|
+
res,
|
|
375
|
+
res.status in customMessages ? customMessages[res.status] : ""
|
|
491
376
|
);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (!res.ok) {
|
|
496
|
-
throw new ServiceError(
|
|
497
|
-
res,
|
|
498
|
-
res.status in customMessages ? customMessages[res.status] : ""
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
const obj = yield res.json();
|
|
502
|
-
return obj;
|
|
503
|
-
});
|
|
377
|
+
}
|
|
378
|
+
const obj = await res.json();
|
|
379
|
+
return obj;
|
|
504
380
|
}
|
|
505
381
|
const data = {
|
|
506
382
|
get
|
|
@@ -1173,12 +1049,11 @@ function simplifyAndStringify(path, maxNbChar = 3e3) {
|
|
|
1173
1049
|
return str;
|
|
1174
1050
|
}
|
|
1175
1051
|
function centered(center, zoom, options = {}) {
|
|
1176
|
-
var _a, _b, _c, _d, _e;
|
|
1177
1052
|
const style = styleToStyle(options.style);
|
|
1178
1053
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1179
|
-
const format =
|
|
1180
|
-
let width = ~~(
|
|
1181
|
-
let height = ~~(
|
|
1054
|
+
const format = options.format ?? "png";
|
|
1055
|
+
let width = ~~(options.width ?? 1024);
|
|
1056
|
+
let height = ~~(options.height ?? 1024);
|
|
1182
1057
|
if (options.hiDPI) {
|
|
1183
1058
|
width = ~~(width / 2);
|
|
1184
1059
|
height = ~~(height / 2);
|
|
@@ -1208,7 +1083,7 @@ function centered(center, zoom, options = {}) {
|
|
|
1208
1083
|
}
|
|
1209
1084
|
if ("path" in options) {
|
|
1210
1085
|
let pathStr = "";
|
|
1211
|
-
pathStr += `fill:${
|
|
1086
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1212
1087
|
if ("pathStrokeColor" in options) {
|
|
1213
1088
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1214
1089
|
}
|
|
@@ -1219,16 +1094,15 @@ function centered(center, zoom, options = {}) {
|
|
|
1219
1094
|
pathStr += simplifyAndStringify(options.path);
|
|
1220
1095
|
endpoint.searchParams.set("path", pathStr);
|
|
1221
1096
|
}
|
|
1222
|
-
endpoint.searchParams.set("key",
|
|
1097
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1223
1098
|
return endpoint.toString();
|
|
1224
1099
|
}
|
|
1225
1100
|
function bounded(boundingBox, options = {}) {
|
|
1226
|
-
var _a, _b, _c, _d, _e;
|
|
1227
1101
|
const style = styleToStyle(options.style);
|
|
1228
1102
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1229
|
-
const format =
|
|
1230
|
-
let width = ~~(
|
|
1231
|
-
let height = ~~(
|
|
1103
|
+
const format = options.format ?? "png";
|
|
1104
|
+
let width = ~~(options.width ?? 1024);
|
|
1105
|
+
let height = ~~(options.height ?? 1024);
|
|
1232
1106
|
if (options.hiDPI) {
|
|
1233
1107
|
width = ~~(width / 2);
|
|
1234
1108
|
height = ~~(height / 2);
|
|
@@ -1261,7 +1135,7 @@ function bounded(boundingBox, options = {}) {
|
|
|
1261
1135
|
}
|
|
1262
1136
|
if ("path" in options) {
|
|
1263
1137
|
let pathStr = "";
|
|
1264
|
-
pathStr += `fill:${
|
|
1138
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1265
1139
|
if ("pathStrokeColor" in options) {
|
|
1266
1140
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1267
1141
|
}
|
|
@@ -1272,11 +1146,10 @@ function bounded(boundingBox, options = {}) {
|
|
|
1272
1146
|
pathStr += simplifyAndStringify(options.path);
|
|
1273
1147
|
endpoint.searchParams.set("path", pathStr);
|
|
1274
1148
|
}
|
|
1275
|
-
endpoint.searchParams.set("key",
|
|
1149
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1276
1150
|
return endpoint.toString();
|
|
1277
1151
|
}
|
|
1278
1152
|
function automatic(options = {}) {
|
|
1279
|
-
var _a, _b, _c, _d, _e;
|
|
1280
1153
|
if (!("markers" in options) && !("path" in options)) {
|
|
1281
1154
|
throw new Error(
|
|
1282
1155
|
"Automatic static maps require markers and/or path to be created."
|
|
@@ -1284,9 +1157,9 @@ function automatic(options = {}) {
|
|
|
1284
1157
|
}
|
|
1285
1158
|
const style = styleToStyle(options.style);
|
|
1286
1159
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1287
|
-
const format =
|
|
1288
|
-
let width = ~~(
|
|
1289
|
-
let height = ~~(
|
|
1160
|
+
const format = options.format ?? "png";
|
|
1161
|
+
let width = ~~(options.width ?? 1024);
|
|
1162
|
+
let height = ~~(options.height ?? 1024);
|
|
1290
1163
|
if (options.hiDPI) {
|
|
1291
1164
|
width = ~~(width / 2);
|
|
1292
1165
|
height = ~~(height / 2);
|
|
@@ -1321,7 +1194,7 @@ function automatic(options = {}) {
|
|
|
1321
1194
|
}
|
|
1322
1195
|
if ("path" in options) {
|
|
1323
1196
|
let pathStr = "";
|
|
1324
|
-
pathStr += `fill:${
|
|
1197
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1325
1198
|
if ("pathStrokeColor" in options) {
|
|
1326
1199
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1327
1200
|
}
|
|
@@ -1332,7 +1205,7 @@ function automatic(options = {}) {
|
|
|
1332
1205
|
pathStr += simplifyAndStringify(options.path);
|
|
1333
1206
|
endpoint.searchParams.set("path", pathStr);
|
|
1334
1207
|
}
|
|
1335
|
-
endpoint.searchParams.set("key",
|
|
1208
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1336
1209
|
return endpoint.toString();
|
|
1337
1210
|
}
|
|
1338
1211
|
const staticMaps = {
|
|
@@ -1341,5 +1214,294 @@ const staticMaps = {
|
|
|
1341
1214
|
automatic
|
|
1342
1215
|
};
|
|
1343
1216
|
|
|
1344
|
-
|
|
1217
|
+
const earthRadius = 63710088e-1;
|
|
1218
|
+
function mToFt(m) {
|
|
1219
|
+
return m * 3.28084;
|
|
1220
|
+
}
|
|
1221
|
+
function degToRad(degrees) {
|
|
1222
|
+
return degrees % 360 * Math.PI / 180;
|
|
1223
|
+
}
|
|
1224
|
+
function radToDeg(radians) {
|
|
1225
|
+
return radians * 180 / Math.PI;
|
|
1226
|
+
}
|
|
1227
|
+
function getZoomLevelResolution(latitude, zoom, tileSize = 512) {
|
|
1228
|
+
return Math.cos(latitude * Math.PI / 180) * 2 * Math.PI * 6378137 / (tileSize * 2 ** zoom) * 3;
|
|
1229
|
+
}
|
|
1230
|
+
function xyzToTileID(x, y, zoom) {
|
|
1231
|
+
return ((1 << zoom) * y + x) * 32 + zoom;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
function area(area2) {
|
|
1235
|
+
const geometry = "geometry" in area2 ? area2.geometry : area2;
|
|
1236
|
+
const type = geometry.type;
|
|
1237
|
+
if (type === "MultiPolygon") {
|
|
1238
|
+
return multiPolygonArea(geometry.coordinates);
|
|
1239
|
+
}
|
|
1240
|
+
return polygonArea(geometry.coordinates);
|
|
1241
|
+
}
|
|
1242
|
+
function multiPolygonArea(multiPoly) {
|
|
1243
|
+
const coords = "coordinates" in multiPoly ? multiPoly.coordinates : multiPoly;
|
|
1244
|
+
let total = 0;
|
|
1245
|
+
for (const polygon of coords) {
|
|
1246
|
+
total += polygonArea(polygon);
|
|
1247
|
+
}
|
|
1248
|
+
return total;
|
|
1249
|
+
}
|
|
1250
|
+
function polygonArea(poly) {
|
|
1251
|
+
const coords = "coordinates" in poly ? poly.coordinates : poly;
|
|
1252
|
+
let total = 0;
|
|
1253
|
+
for (const ring of coords) {
|
|
1254
|
+
total += ringArea(ring);
|
|
1255
|
+
}
|
|
1256
|
+
return total;
|
|
1257
|
+
}
|
|
1258
|
+
function ringArea(coords) {
|
|
1259
|
+
let p1;
|
|
1260
|
+
let p2;
|
|
1261
|
+
let p3;
|
|
1262
|
+
let lowerIndex;
|
|
1263
|
+
let middleIndex;
|
|
1264
|
+
let upperIndex;
|
|
1265
|
+
let i;
|
|
1266
|
+
let total = 0;
|
|
1267
|
+
const coordsLength = coords.length;
|
|
1268
|
+
if (coordsLength > 2) {
|
|
1269
|
+
for (i = 0; i < coordsLength; i++) {
|
|
1270
|
+
if (i === coordsLength - 2) {
|
|
1271
|
+
lowerIndex = coordsLength - 2;
|
|
1272
|
+
middleIndex = coordsLength - 1;
|
|
1273
|
+
upperIndex = 0;
|
|
1274
|
+
} else if (i === coordsLength - 1) {
|
|
1275
|
+
lowerIndex = coordsLength - 1;
|
|
1276
|
+
middleIndex = 0;
|
|
1277
|
+
upperIndex = 1;
|
|
1278
|
+
} else {
|
|
1279
|
+
lowerIndex = i;
|
|
1280
|
+
middleIndex = i + 1;
|
|
1281
|
+
upperIndex = i + 2;
|
|
1282
|
+
}
|
|
1283
|
+
p1 = coords[lowerIndex];
|
|
1284
|
+
p2 = coords[middleIndex];
|
|
1285
|
+
p3 = coords[upperIndex];
|
|
1286
|
+
total += (degToRad(p3[0]) - degToRad(p1[0])) * Math.sin(degToRad(p2[1]));
|
|
1287
|
+
}
|
|
1288
|
+
total = total * earthRadius * earthRadius / 2;
|
|
1289
|
+
}
|
|
1290
|
+
return Math.abs(total);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function lineDistance(line) {
|
|
1294
|
+
const coordinates = "geometry" in line ? line.geometry.coordinates : "coordinates" in line ? line.coordinates : line;
|
|
1295
|
+
let distance = 0;
|
|
1296
|
+
let prevCoord;
|
|
1297
|
+
for (const coordinate of coordinates) {
|
|
1298
|
+
if (prevCoord !== void 0) {
|
|
1299
|
+
distance += pointDistance(prevCoord, coordinate);
|
|
1300
|
+
}
|
|
1301
|
+
prevCoord = coordinate;
|
|
1302
|
+
}
|
|
1303
|
+
return distance;
|
|
1304
|
+
}
|
|
1305
|
+
function pointDistance(from, to) {
|
|
1306
|
+
const { pow, sin, cos, sqrt, atan2 } = Math;
|
|
1307
|
+
const dLat = degToRad(to[1] - from[1]);
|
|
1308
|
+
const dLon = degToRad(to[0] - from[0]);
|
|
1309
|
+
const lat1 = degToRad(from[1]);
|
|
1310
|
+
const lat2 = degToRad(to[1]);
|
|
1311
|
+
const a = pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
|
|
1312
|
+
return 2 * atan2(sqrt(a), sqrt(1 - a)) * earthRadius;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function tileCover(coordinates, zoom, tileSize) {
|
|
1316
|
+
const tileHash = /* @__PURE__ */ new Map();
|
|
1317
|
+
const tiles = [];
|
|
1318
|
+
const coords = [];
|
|
1319
|
+
const resolution = getZoomLevelResolution(coordinates[0][1], zoom, tileSize);
|
|
1320
|
+
const samples = sampleProfileLine(coordinates, resolution);
|
|
1321
|
+
for (const sample of samples) {
|
|
1322
|
+
const coordinate = sample;
|
|
1323
|
+
const [tileX, tileY] = llToTile(coordinate, zoom, tileSize);
|
|
1324
|
+
const id = xyzToTileID(tileX, tileY, zoom);
|
|
1325
|
+
const tile = { id, x: tileX, y: tileY, z: zoom };
|
|
1326
|
+
tileHash.set(id, tile);
|
|
1327
|
+
coords.push({ coordinate, tile });
|
|
1328
|
+
}
|
|
1329
|
+
for (const tile of tileHash.values())
|
|
1330
|
+
tiles.push(tile);
|
|
1331
|
+
return { coords, tiles };
|
|
1332
|
+
}
|
|
1333
|
+
function sampleProfileLine(coordinates, resolution) {
|
|
1334
|
+
const samples = [];
|
|
1335
|
+
let prevCoord;
|
|
1336
|
+
for (const coord of coordinates) {
|
|
1337
|
+
if (prevCoord !== void 0) {
|
|
1338
|
+
const dist = pointDistance(
|
|
1339
|
+
prevCoord,
|
|
1340
|
+
coord
|
|
1341
|
+
);
|
|
1342
|
+
const numSamples = Math.ceil(dist / resolution);
|
|
1343
|
+
for (let i = 0; i <= numSamples - 1; i++) {
|
|
1344
|
+
const sample = [
|
|
1345
|
+
prevCoord[0] + (coord[0] - prevCoord[0]) * (i / numSamples),
|
|
1346
|
+
prevCoord[1] + (coord[1] - prevCoord[1]) * (i / numSamples)
|
|
1347
|
+
];
|
|
1348
|
+
samples.push(sample);
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
samples.push(coord);
|
|
1352
|
+
}
|
|
1353
|
+
prevCoord = coord;
|
|
1354
|
+
}
|
|
1355
|
+
return samples;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
function getElevation(coord, tile, tileSize, tileImage, elevationParser = defaultElevationParser) {
|
|
1359
|
+
const { channels, image } = tileImage;
|
|
1360
|
+
let [x, y] = llToTilePx(coord, tile, tileSize);
|
|
1361
|
+
x = clampPixel(x, tileSize);
|
|
1362
|
+
y = clampPixel(y, tileSize);
|
|
1363
|
+
const index = (y * tileSize + x) * channels;
|
|
1364
|
+
return elevationParser(
|
|
1365
|
+
image[index],
|
|
1366
|
+
image[index + 1],
|
|
1367
|
+
image[index + 2],
|
|
1368
|
+
channels === 4 ? image[index + 3] : 0
|
|
1369
|
+
);
|
|
1370
|
+
}
|
|
1371
|
+
function clampPixel(n, tileSize) {
|
|
1372
|
+
return Math.max(0, Math.min(tileSize, Math.floor(n * tileSize)));
|
|
1373
|
+
}
|
|
1374
|
+
function defaultElevationParser(r, g, b) {
|
|
1375
|
+
return -1e4 + (r * 256 * 256 + g * 256 + b) * 0.1;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
async function profileLineString(path, options) {
|
|
1379
|
+
const coordinates = "geometry" in path ? path.geometry.coordinates : path.coordinates;
|
|
1380
|
+
const { coords, tiles } = tileCover(
|
|
1381
|
+
coordinates,
|
|
1382
|
+
options.zoom ?? 13,
|
|
1383
|
+
options.tileSize ?? 512
|
|
1384
|
+
);
|
|
1385
|
+
const tileCache = await getTiles(tiles, options.tileRequest);
|
|
1386
|
+
let points = getElevations(
|
|
1387
|
+
coords,
|
|
1388
|
+
tileCache,
|
|
1389
|
+
options.tileSize ?? 512,
|
|
1390
|
+
options.elevationParser
|
|
1391
|
+
);
|
|
1392
|
+
if (options.smooth === true)
|
|
1393
|
+
points = smoothElevation(points);
|
|
1394
|
+
let output = buildOutput(points);
|
|
1395
|
+
if (options.metric === "ft")
|
|
1396
|
+
output = toFeet(output);
|
|
1397
|
+
return output;
|
|
1398
|
+
}
|
|
1399
|
+
async function getTiles(tiles, tileRequest) {
|
|
1400
|
+
const tileCache = /* @__PURE__ */ new Map();
|
|
1401
|
+
const requests = [];
|
|
1402
|
+
for (const tile of tiles) {
|
|
1403
|
+
requests.push(
|
|
1404
|
+
tileRequest(tile.x, tile.y, tile.z).then((res) => {
|
|
1405
|
+
tileCache.set(tile.id, res);
|
|
1406
|
+
return res;
|
|
1407
|
+
}).catch((err) => {
|
|
1408
|
+
console.error(err);
|
|
1409
|
+
return void 0;
|
|
1410
|
+
})
|
|
1411
|
+
);
|
|
1412
|
+
}
|
|
1413
|
+
await Promise.allSettled(requests);
|
|
1414
|
+
return tileCache;
|
|
1415
|
+
}
|
|
1416
|
+
function getElevations(coords, tileCache, tileSize, elevationParser) {
|
|
1417
|
+
const points = [];
|
|
1418
|
+
let curDistance = 0;
|
|
1419
|
+
let prevCoord;
|
|
1420
|
+
for (const { tile, coordinate } of coords) {
|
|
1421
|
+
const cTile = tileCache.get(tile.id);
|
|
1422
|
+
if (cTile === void 0)
|
|
1423
|
+
throw new Error(
|
|
1424
|
+
`Missing tile ${tile.id} (${tile.x}-${tile.y}-${tile.z})`
|
|
1425
|
+
);
|
|
1426
|
+
const elevation = getElevation(
|
|
1427
|
+
coordinate,
|
|
1428
|
+
[tile.z, tile.x, tile.y],
|
|
1429
|
+
tileSize,
|
|
1430
|
+
cTile,
|
|
1431
|
+
elevationParser
|
|
1432
|
+
);
|
|
1433
|
+
points.push({
|
|
1434
|
+
distance: curDistance,
|
|
1435
|
+
elevation,
|
|
1436
|
+
coordinate,
|
|
1437
|
+
tile
|
|
1438
|
+
});
|
|
1439
|
+
if (prevCoord !== void 0) {
|
|
1440
|
+
curDistance += pointDistance(prevCoord, coordinate);
|
|
1441
|
+
}
|
|
1442
|
+
prevCoord = coordinate;
|
|
1443
|
+
}
|
|
1444
|
+
return points;
|
|
1445
|
+
}
|
|
1446
|
+
function buildOutput(points) {
|
|
1447
|
+
let minElevation = Infinity;
|
|
1448
|
+
let maxElevation = -Infinity;
|
|
1449
|
+
let totalElevation = 0;
|
|
1450
|
+
for (const point of points) {
|
|
1451
|
+
if (point.elevation < minElevation)
|
|
1452
|
+
minElevation = point.elevation;
|
|
1453
|
+
if (point.elevation > maxElevation)
|
|
1454
|
+
maxElevation = point.elevation;
|
|
1455
|
+
totalElevation += point.elevation;
|
|
1456
|
+
}
|
|
1457
|
+
return {
|
|
1458
|
+
distance: points[points.length - 1].distance,
|
|
1459
|
+
minElevation,
|
|
1460
|
+
maxElevation,
|
|
1461
|
+
avgElevation: totalElevation / points.length,
|
|
1462
|
+
startElevation: points[0].elevation,
|
|
1463
|
+
endElevation: points[points.length - 1].elevation,
|
|
1464
|
+
points
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
function smoothElevation(points) {
|
|
1468
|
+
const newPoints = [];
|
|
1469
|
+
let prevPoint;
|
|
1470
|
+
for (let i = 0; i < points.length; i++) {
|
|
1471
|
+
const point = points[i];
|
|
1472
|
+
const nextPoint = points[i + 1] ?? points[i];
|
|
1473
|
+
if (prevPoint === void 0) {
|
|
1474
|
+
newPoints.push(point);
|
|
1475
|
+
} else {
|
|
1476
|
+
const newPoint = {
|
|
1477
|
+
distance: point.distance,
|
|
1478
|
+
elevation: (prevPoint.elevation + point.elevation + nextPoint.elevation) / 3,
|
|
1479
|
+
coordinate: point.coordinate,
|
|
1480
|
+
tile: point.tile
|
|
1481
|
+
};
|
|
1482
|
+
newPoints.push(newPoint);
|
|
1483
|
+
}
|
|
1484
|
+
prevPoint = point;
|
|
1485
|
+
}
|
|
1486
|
+
return newPoints;
|
|
1487
|
+
}
|
|
1488
|
+
function toFeet(input) {
|
|
1489
|
+
const output = {
|
|
1490
|
+
distance: mToFt(input.distance),
|
|
1491
|
+
minElevation: mToFt(input.minElevation),
|
|
1492
|
+
maxElevation: mToFt(input.maxElevation),
|
|
1493
|
+
avgElevation: mToFt(input.avgElevation),
|
|
1494
|
+
startElevation: mToFt(input.startElevation),
|
|
1495
|
+
endElevation: mToFt(input.endElevation),
|
|
1496
|
+
points: input.points.map(({ distance, elevation, coordinate, tile }) => ({
|
|
1497
|
+
distance: mToFt(distance),
|
|
1498
|
+
elevation: mToFt(elevation),
|
|
1499
|
+
coordinate,
|
|
1500
|
+
tile
|
|
1501
|
+
}))
|
|
1502
|
+
};
|
|
1503
|
+
return output;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
export { ClientConfig, LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, area, config, coordinates, data, defaultElevationParser, degToRad, earthRadius, expandMapStyle, geocoding, geolocation, getZoomLevelResolution, lineDistance, mToFt, mapStylePresetList, multiPolygonArea, pointDistance, polygonArea, profileLineString, radToDeg, staticMaps, xyzToTileID };
|
|
1345
1507
|
//# sourceMappingURL=maptiler-client.mjs.map
|