@maptiler/client 1.5.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 +177 -13
- 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/examples/test-node.js +9 -9
- 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 +113 -32
- 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 -74
- 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 -880
- 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
|
@@ -120,40 +120,18 @@
|
|
|
120
120
|
return canditatelangs.length ? canditatelangs[0] : LanguageGeocoding.ENGLISH;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
} catch (e) {
|
|
136
|
-
reject(e);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
140
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
function callFetch(_0) {
|
|
144
|
-
return __async$4(this, arguments, function* (resource, options = {}) {
|
|
145
|
-
if (config.fetch === null) {
|
|
146
|
-
throw new Error(
|
|
147
|
-
"The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
if (new URL(resource).searchParams.get("key").trim() === "") {
|
|
151
|
-
throw new Error(
|
|
152
|
-
"The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
return config.fetch(resource, options);
|
|
156
|
-
});
|
|
123
|
+
async function callFetch(resource, options = {}) {
|
|
124
|
+
if (config.fetch === null) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
"The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (new URL(resource).searchParams.get("key").trim() === "") {
|
|
130
|
+
throw new Error(
|
|
131
|
+
"The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return config.fetch(resource, options);
|
|
157
135
|
}
|
|
158
136
|
|
|
159
137
|
const defaults = {
|
|
@@ -171,26 +149,6 @@
|
|
|
171
149
|
}
|
|
172
150
|
}
|
|
173
151
|
|
|
174
|
-
var __async$3 = (__this, __arguments, generator) => {
|
|
175
|
-
return new Promise((resolve, reject) => {
|
|
176
|
-
var fulfilled = (value) => {
|
|
177
|
-
try {
|
|
178
|
-
step(generator.next(value));
|
|
179
|
-
} catch (e) {
|
|
180
|
-
reject(e);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var rejected = (value) => {
|
|
184
|
-
try {
|
|
185
|
-
step(generator.throw(value));
|
|
186
|
-
} catch (e) {
|
|
187
|
-
reject(e);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
191
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
152
|
const customMessages$3 = {
|
|
195
153
|
400: "Query too long / Invalid parameters",
|
|
196
154
|
403: "Key is missing, invalid or restricted"
|
|
@@ -209,8 +167,7 @@
|
|
|
209
167
|
searchParams.set("language", languages);
|
|
210
168
|
}
|
|
211
169
|
function addCommonForwardAndReverseGeocodingOptions(searchParams, options) {
|
|
212
|
-
|
|
213
|
-
searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
|
|
170
|
+
searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
214
171
|
if (options.limit != void 0) {
|
|
215
172
|
searchParams.set("limit", String(options.limit));
|
|
216
173
|
}
|
|
@@ -237,82 +194,71 @@
|
|
|
237
194
|
searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
|
|
238
195
|
}
|
|
239
196
|
}
|
|
240
|
-
function forward(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const obj = yield res.json();
|
|
258
|
-
return obj;
|
|
259
|
-
});
|
|
197
|
+
async function forward(query, options = {}) {
|
|
198
|
+
if (typeof query !== "string" || query.trim().length === 0) {
|
|
199
|
+
throw new Error("The query must be a non-empty string");
|
|
200
|
+
}
|
|
201
|
+
const endpoint = new URL(
|
|
202
|
+
`geocoding/${encodeURIComponent(query)}.json`,
|
|
203
|
+
defaults.maptilerApiURL
|
|
204
|
+
);
|
|
205
|
+
const { searchParams } = endpoint;
|
|
206
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
207
|
+
const urlWithParams = endpoint.toString();
|
|
208
|
+
const res = await callFetch(urlWithParams);
|
|
209
|
+
if (!res.ok) {
|
|
210
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
211
|
+
}
|
|
212
|
+
const obj = await res.json();
|
|
213
|
+
return obj;
|
|
260
214
|
}
|
|
261
|
-
function reverse(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const obj = yield res.json();
|
|
278
|
-
return obj;
|
|
279
|
-
});
|
|
215
|
+
async function reverse(position, options = {}) {
|
|
216
|
+
if (!Array.isArray(position) || position.length < 2) {
|
|
217
|
+
throw new Error("The position must be an array of form [lng, lat].");
|
|
218
|
+
}
|
|
219
|
+
const endpoint = new URL(
|
|
220
|
+
`geocoding/${position[0]},${position[1]}.json`,
|
|
221
|
+
defaults.maptilerApiURL
|
|
222
|
+
);
|
|
223
|
+
addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
|
|
224
|
+
const urlWithParams = endpoint.toString();
|
|
225
|
+
const res = await callFetch(urlWithParams);
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
228
|
+
}
|
|
229
|
+
const obj = await res.json();
|
|
230
|
+
return obj;
|
|
280
231
|
}
|
|
281
|
-
function byId(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return obj;
|
|
293
|
-
});
|
|
232
|
+
async function byId(id, options = {}) {
|
|
233
|
+
const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
|
|
234
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
235
|
+
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
236
|
+
const urlWithParams = endpoint.toString();
|
|
237
|
+
const res = await callFetch(urlWithParams);
|
|
238
|
+
if (!res.ok) {
|
|
239
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
240
|
+
}
|
|
241
|
+
const obj = await res.json();
|
|
242
|
+
return obj;
|
|
294
243
|
}
|
|
295
|
-
function batch(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const obj = yield res.json();
|
|
314
|
-
return queries.length === 1 ? [obj] : obj;
|
|
315
|
-
});
|
|
244
|
+
async function batch(queries, options = {}) {
|
|
245
|
+
if (!queries.length) {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
|
|
249
|
+
const endpoint = new URL(
|
|
250
|
+
`geocoding/${joinedQuery}.json`,
|
|
251
|
+
defaults.maptilerApiURL
|
|
252
|
+
);
|
|
253
|
+
const { searchParams } = endpoint;
|
|
254
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
255
|
+
const urlWithParams = endpoint.toString();
|
|
256
|
+
const res = await callFetch(urlWithParams);
|
|
257
|
+
if (!res.ok) {
|
|
258
|
+
throw new ServiceError(res, customMessages$3[res.status] ?? "");
|
|
259
|
+
}
|
|
260
|
+
const obj = await res.json();
|
|
261
|
+
return queries.length === 1 ? [obj] : obj;
|
|
316
262
|
}
|
|
317
263
|
const geocoding = {
|
|
318
264
|
forward,
|
|
@@ -322,191 +268,119 @@
|
|
|
322
268
|
language: LanguageGeocoding
|
|
323
269
|
};
|
|
324
270
|
|
|
325
|
-
var __async$2 = (__this, __arguments, generator) => {
|
|
326
|
-
return new Promise((resolve, reject) => {
|
|
327
|
-
var fulfilled = (value) => {
|
|
328
|
-
try {
|
|
329
|
-
step(generator.next(value));
|
|
330
|
-
} catch (e) {
|
|
331
|
-
reject(e);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
var rejected = (value) => {
|
|
335
|
-
try {
|
|
336
|
-
step(generator.throw(value));
|
|
337
|
-
} catch (e) {
|
|
338
|
-
reject(e);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
342
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
271
|
const customMessages$2 = {
|
|
346
272
|
403: "Key is missing, invalid or restricted"
|
|
347
273
|
};
|
|
348
|
-
function info() {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const obj = yield res.json();
|
|
362
|
-
return obj;
|
|
363
|
-
});
|
|
274
|
+
async function info(options = {}) {
|
|
275
|
+
const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
|
|
276
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
277
|
+
const urlWithParams = endpoint.toString();
|
|
278
|
+
const res = await callFetch(urlWithParams);
|
|
279
|
+
if (!res.ok) {
|
|
280
|
+
throw new ServiceError(
|
|
281
|
+
res,
|
|
282
|
+
res.status in customMessages$2 ? customMessages$2[res.status] : ""
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
const obj = await res.json();
|
|
286
|
+
return obj;
|
|
364
287
|
}
|
|
365
288
|
const geolocation = {
|
|
366
289
|
info
|
|
367
290
|
};
|
|
368
291
|
|
|
369
|
-
var __async$1 = (__this, __arguments, generator) => {
|
|
370
|
-
return new Promise((resolve, reject) => {
|
|
371
|
-
var fulfilled = (value) => {
|
|
372
|
-
try {
|
|
373
|
-
step(generator.next(value));
|
|
374
|
-
} catch (e) {
|
|
375
|
-
reject(e);
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
var rejected = (value) => {
|
|
379
|
-
try {
|
|
380
|
-
step(generator.throw(value));
|
|
381
|
-
} catch (e) {
|
|
382
|
-
reject(e);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
386
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
292
|
const customMessages$1 = {
|
|
390
293
|
403: "Key is missing, invalid or restricted"
|
|
391
294
|
};
|
|
392
|
-
function search(
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
295
|
+
async function search(query, options = {}) {
|
|
296
|
+
if (typeof query !== "string" || query.trim().length === 0) {
|
|
297
|
+
throw new Error("The query must be a non-empty string");
|
|
298
|
+
}
|
|
299
|
+
const endpoint = new URL(
|
|
300
|
+
`coordinates/search/${query}.json`,
|
|
301
|
+
defaults.maptilerApiURL
|
|
302
|
+
);
|
|
303
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
304
|
+
if ("limit" in options) {
|
|
305
|
+
endpoint.searchParams.set("limit", options.limit.toString());
|
|
306
|
+
}
|
|
307
|
+
if ("transformations" in options) {
|
|
308
|
+
endpoint.searchParams.set(
|
|
309
|
+
"transformations",
|
|
310
|
+
options.transformations.toString()
|
|
401
311
|
);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const res = yield callFetch(urlWithParams);
|
|
417
|
-
if (!res.ok) {
|
|
418
|
-
throw new ServiceError(
|
|
419
|
-
res,
|
|
420
|
-
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
const obj = yield res.json();
|
|
424
|
-
return obj;
|
|
425
|
-
});
|
|
312
|
+
}
|
|
313
|
+
if ("exports" in options) {
|
|
314
|
+
endpoint.searchParams.set("exports", options.exports.toString());
|
|
315
|
+
}
|
|
316
|
+
const urlWithParams = endpoint.toString();
|
|
317
|
+
const res = await callFetch(urlWithParams);
|
|
318
|
+
if (!res.ok) {
|
|
319
|
+
throw new ServiceError(
|
|
320
|
+
res,
|
|
321
|
+
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const obj = await res.json();
|
|
325
|
+
return obj;
|
|
426
326
|
}
|
|
427
|
-
function transform(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
327
|
+
async function transform(positions, options = {}) {
|
|
328
|
+
const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
|
|
329
|
+
const endpoint = new URL(
|
|
330
|
+
`coordinates/transform/${coordinatesStr}.json`,
|
|
331
|
+
defaults.maptilerApiURL
|
|
332
|
+
);
|
|
333
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
334
|
+
if ("sourceCrs" in options) {
|
|
335
|
+
endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
|
|
336
|
+
}
|
|
337
|
+
if ("targetCrs" in options) {
|
|
338
|
+
endpoint.searchParams.set("t_srs", options.targetCrs.toString());
|
|
339
|
+
}
|
|
340
|
+
if ("operations" in options) {
|
|
341
|
+
endpoint.searchParams.set(
|
|
342
|
+
"ops",
|
|
343
|
+
(Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
|
|
434
344
|
);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
const urlWithParams = endpoint.toString();
|
|
449
|
-
const res = yield callFetch(urlWithParams);
|
|
450
|
-
if (!res.ok) {
|
|
451
|
-
throw new ServiceError(
|
|
452
|
-
res,
|
|
453
|
-
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
const obj = yield res.json();
|
|
457
|
-
return obj;
|
|
458
|
-
});
|
|
345
|
+
}
|
|
346
|
+
const urlWithParams = endpoint.toString();
|
|
347
|
+
const res = await callFetch(urlWithParams);
|
|
348
|
+
if (!res.ok) {
|
|
349
|
+
throw new ServiceError(
|
|
350
|
+
res,
|
|
351
|
+
res.status in customMessages$1 ? customMessages$1[res.status] : ""
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
const obj = await res.json();
|
|
355
|
+
return obj;
|
|
459
356
|
}
|
|
460
357
|
const coordinates = {
|
|
461
358
|
search,
|
|
462
359
|
transform
|
|
463
360
|
};
|
|
464
361
|
|
|
465
|
-
var __async = (__this, __arguments, generator) => {
|
|
466
|
-
return new Promise((resolve, reject) => {
|
|
467
|
-
var fulfilled = (value) => {
|
|
468
|
-
try {
|
|
469
|
-
step(generator.next(value));
|
|
470
|
-
} catch (e) {
|
|
471
|
-
reject(e);
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
var rejected = (value) => {
|
|
475
|
-
try {
|
|
476
|
-
step(generator.throw(value));
|
|
477
|
-
} catch (e) {
|
|
478
|
-
reject(e);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
482
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
483
|
-
});
|
|
484
|
-
};
|
|
485
362
|
const customMessages = {
|
|
486
363
|
403: "Key is missing, invalid or restricted"
|
|
487
364
|
};
|
|
488
|
-
function get(
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
365
|
+
async function get(dataId, options = {}) {
|
|
366
|
+
if (typeof dataId !== "string" || dataId.trim().length === 0) {
|
|
367
|
+
throw new Error("The data ID must be a non-empty string");
|
|
368
|
+
}
|
|
369
|
+
const endpoint = new URL(
|
|
370
|
+
`data/${encodeURIComponent(dataId)}/features.json`,
|
|
371
|
+
defaults.maptilerApiURL
|
|
372
|
+
);
|
|
373
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
374
|
+
const urlWithParams = endpoint.toString();
|
|
375
|
+
const res = await callFetch(urlWithParams);
|
|
376
|
+
if (!res.ok) {
|
|
377
|
+
throw new ServiceError(
|
|
378
|
+
res,
|
|
379
|
+
res.status in customMessages ? customMessages[res.status] : ""
|
|
497
380
|
);
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (!res.ok) {
|
|
502
|
-
throw new ServiceError(
|
|
503
|
-
res,
|
|
504
|
-
res.status in customMessages ? customMessages[res.status] : ""
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
const obj = yield res.json();
|
|
508
|
-
return obj;
|
|
509
|
-
});
|
|
381
|
+
}
|
|
382
|
+
const obj = await res.json();
|
|
383
|
+
return obj;
|
|
510
384
|
}
|
|
511
385
|
const data = {
|
|
512
386
|
get
|
|
@@ -1179,12 +1053,11 @@
|
|
|
1179
1053
|
return str;
|
|
1180
1054
|
}
|
|
1181
1055
|
function centered(center, zoom, options = {}) {
|
|
1182
|
-
var _a, _b, _c, _d, _e;
|
|
1183
1056
|
const style = styleToStyle(options.style);
|
|
1184
1057
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1185
|
-
const format =
|
|
1186
|
-
let width = ~~(
|
|
1187
|
-
let height = ~~(
|
|
1058
|
+
const format = options.format ?? "png";
|
|
1059
|
+
let width = ~~(options.width ?? 1024);
|
|
1060
|
+
let height = ~~(options.height ?? 1024);
|
|
1188
1061
|
if (options.hiDPI) {
|
|
1189
1062
|
width = ~~(width / 2);
|
|
1190
1063
|
height = ~~(height / 2);
|
|
@@ -1214,7 +1087,7 @@
|
|
|
1214
1087
|
}
|
|
1215
1088
|
if ("path" in options) {
|
|
1216
1089
|
let pathStr = "";
|
|
1217
|
-
pathStr += `fill:${
|
|
1090
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1218
1091
|
if ("pathStrokeColor" in options) {
|
|
1219
1092
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1220
1093
|
}
|
|
@@ -1225,16 +1098,15 @@
|
|
|
1225
1098
|
pathStr += simplifyAndStringify(options.path);
|
|
1226
1099
|
endpoint.searchParams.set("path", pathStr);
|
|
1227
1100
|
}
|
|
1228
|
-
endpoint.searchParams.set("key",
|
|
1101
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1229
1102
|
return endpoint.toString();
|
|
1230
1103
|
}
|
|
1231
1104
|
function bounded(boundingBox, options = {}) {
|
|
1232
|
-
var _a, _b, _c, _d, _e;
|
|
1233
1105
|
const style = styleToStyle(options.style);
|
|
1234
1106
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1235
|
-
const format =
|
|
1236
|
-
let width = ~~(
|
|
1237
|
-
let height = ~~(
|
|
1107
|
+
const format = options.format ?? "png";
|
|
1108
|
+
let width = ~~(options.width ?? 1024);
|
|
1109
|
+
let height = ~~(options.height ?? 1024);
|
|
1238
1110
|
if (options.hiDPI) {
|
|
1239
1111
|
width = ~~(width / 2);
|
|
1240
1112
|
height = ~~(height / 2);
|
|
@@ -1267,7 +1139,7 @@
|
|
|
1267
1139
|
}
|
|
1268
1140
|
if ("path" in options) {
|
|
1269
1141
|
let pathStr = "";
|
|
1270
|
-
pathStr += `fill:${
|
|
1142
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1271
1143
|
if ("pathStrokeColor" in options) {
|
|
1272
1144
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1273
1145
|
}
|
|
@@ -1278,11 +1150,10 @@
|
|
|
1278
1150
|
pathStr += simplifyAndStringify(options.path);
|
|
1279
1151
|
endpoint.searchParams.set("path", pathStr);
|
|
1280
1152
|
}
|
|
1281
|
-
endpoint.searchParams.set("key",
|
|
1153
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1282
1154
|
return endpoint.toString();
|
|
1283
1155
|
}
|
|
1284
1156
|
function automatic(options = {}) {
|
|
1285
|
-
var _a, _b, _c, _d, _e;
|
|
1286
1157
|
if (!("markers" in options) && !("path" in options)) {
|
|
1287
1158
|
throw new Error(
|
|
1288
1159
|
"Automatic static maps require markers and/or path to be created."
|
|
@@ -1290,9 +1161,9 @@
|
|
|
1290
1161
|
}
|
|
1291
1162
|
const style = styleToStyle(options.style);
|
|
1292
1163
|
const scale = options.hiDPI ? "@2x" : "";
|
|
1293
|
-
const format =
|
|
1294
|
-
let width = ~~(
|
|
1295
|
-
let height = ~~(
|
|
1164
|
+
const format = options.format ?? "png";
|
|
1165
|
+
let width = ~~(options.width ?? 1024);
|
|
1166
|
+
let height = ~~(options.height ?? 1024);
|
|
1296
1167
|
if (options.hiDPI) {
|
|
1297
1168
|
width = ~~(width / 2);
|
|
1298
1169
|
height = ~~(height / 2);
|
|
@@ -1327,7 +1198,7 @@
|
|
|
1327
1198
|
}
|
|
1328
1199
|
if ("path" in options) {
|
|
1329
1200
|
let pathStr = "";
|
|
1330
|
-
pathStr += `fill:${
|
|
1201
|
+
pathStr += `fill:${options.pathFillColor ?? "none"}|`;
|
|
1331
1202
|
if ("pathStrokeColor" in options) {
|
|
1332
1203
|
pathStr += `stroke:${options.pathStrokeColor}|`;
|
|
1333
1204
|
}
|
|
@@ -1338,7 +1209,7 @@
|
|
|
1338
1209
|
pathStr += simplifyAndStringify(options.path);
|
|
1339
1210
|
endpoint.searchParams.set("path", pathStr);
|
|
1340
1211
|
}
|
|
1341
|
-
endpoint.searchParams.set("key",
|
|
1212
|
+
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1342
1213
|
return endpoint.toString();
|
|
1343
1214
|
}
|
|
1344
1215
|
const staticMaps = {
|
|
@@ -1347,22 +1218,324 @@
|
|
|
1347
1218
|
automatic
|
|
1348
1219
|
};
|
|
1349
1220
|
|
|
1221
|
+
function d(n){return n*Math.PI/180}function _(n){return n%1!==0}var I={};function y(n,t){if(n<0||n>30)throw Error("Invalid zoom level");return _(n)?L(n,t):(I[t]===void 0&&(I[t]={}),Array.isArray(I[t][n])||(I[t][n]=L(n,t)),I[t][n])}function L(n,t){let r=t*Math.pow(2,n);return [r/360,r/(2*Math.PI),r/2,r]}function l(n,t,r=!1,u=512){let{min:o,max:e,sin:s,log:m,round:c}=Math,[a,p,A,i]=y(t,u),M=r?2:1,R=A,f=o(e(s(d(n[1])),-.9999),.9999),P=R+n[0]*a,b=R+.5*m((1+f)/(1-f))*-p;return _(t)||(P=c(P),b=c(b)),P>i*M&&(P=i*M),b>i&&(b=i),[P,b]}function g(n,t=512){let{floor:r}=Math,u=r(n[0]/t),o=r(n[1]/t);return [u,o]}function Z(n,t,r=512){let u=l(n,t,!1,r);return g(u,r)}function w(n,t,r=512){let[u,o,e]=t,s=l(n,u,!1,r),m=o*r,c=e*r;return [(s[0]-m)/r,(s[1]-c)/r]}
|
|
1222
|
+
|
|
1223
|
+
const earthRadius = 63710088e-1;
|
|
1224
|
+
function mToFt(m) {
|
|
1225
|
+
return m * 3.28084;
|
|
1226
|
+
}
|
|
1227
|
+
function degToRad(degrees) {
|
|
1228
|
+
return degrees % 360 * Math.PI / 180;
|
|
1229
|
+
}
|
|
1230
|
+
function radToDeg(radians) {
|
|
1231
|
+
return radians * 180 / Math.PI;
|
|
1232
|
+
}
|
|
1233
|
+
function getZoomLevelResolution(latitude, zoom, tileSize = 512) {
|
|
1234
|
+
return Math.cos(latitude * Math.PI / 180) * 2 * Math.PI * 6378137 / (tileSize * 2 ** zoom) * 3;
|
|
1235
|
+
}
|
|
1236
|
+
function xyzToTileID(x, y, zoom) {
|
|
1237
|
+
return ((1 << zoom) * y + x) * 32 + zoom;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
function area(area2) {
|
|
1241
|
+
const geometry = "geometry" in area2 ? area2.geometry : area2;
|
|
1242
|
+
const type = geometry.type;
|
|
1243
|
+
if (type === "MultiPolygon") {
|
|
1244
|
+
return multiPolygonArea(geometry.coordinates);
|
|
1245
|
+
}
|
|
1246
|
+
return polygonArea(geometry.coordinates);
|
|
1247
|
+
}
|
|
1248
|
+
function multiPolygonArea(multiPoly) {
|
|
1249
|
+
const coords = "coordinates" in multiPoly ? multiPoly.coordinates : multiPoly;
|
|
1250
|
+
let total = 0;
|
|
1251
|
+
for (const polygon of coords) {
|
|
1252
|
+
total += polygonArea(polygon);
|
|
1253
|
+
}
|
|
1254
|
+
return total;
|
|
1255
|
+
}
|
|
1256
|
+
function polygonArea(poly) {
|
|
1257
|
+
const coords = "coordinates" in poly ? poly.coordinates : poly;
|
|
1258
|
+
let total = 0;
|
|
1259
|
+
for (const ring of coords) {
|
|
1260
|
+
total += ringArea(ring);
|
|
1261
|
+
}
|
|
1262
|
+
return total;
|
|
1263
|
+
}
|
|
1264
|
+
function ringArea(coords) {
|
|
1265
|
+
let p1;
|
|
1266
|
+
let p2;
|
|
1267
|
+
let p3;
|
|
1268
|
+
let lowerIndex;
|
|
1269
|
+
let middleIndex;
|
|
1270
|
+
let upperIndex;
|
|
1271
|
+
let i;
|
|
1272
|
+
let total = 0;
|
|
1273
|
+
const coordsLength = coords.length;
|
|
1274
|
+
if (coordsLength > 2) {
|
|
1275
|
+
for (i = 0; i < coordsLength; i++) {
|
|
1276
|
+
if (i === coordsLength - 2) {
|
|
1277
|
+
lowerIndex = coordsLength - 2;
|
|
1278
|
+
middleIndex = coordsLength - 1;
|
|
1279
|
+
upperIndex = 0;
|
|
1280
|
+
} else if (i === coordsLength - 1) {
|
|
1281
|
+
lowerIndex = coordsLength - 1;
|
|
1282
|
+
middleIndex = 0;
|
|
1283
|
+
upperIndex = 1;
|
|
1284
|
+
} else {
|
|
1285
|
+
lowerIndex = i;
|
|
1286
|
+
middleIndex = i + 1;
|
|
1287
|
+
upperIndex = i + 2;
|
|
1288
|
+
}
|
|
1289
|
+
p1 = coords[lowerIndex];
|
|
1290
|
+
p2 = coords[middleIndex];
|
|
1291
|
+
p3 = coords[upperIndex];
|
|
1292
|
+
total += (degToRad(p3[0]) - degToRad(p1[0])) * Math.sin(degToRad(p2[1]));
|
|
1293
|
+
}
|
|
1294
|
+
total = total * earthRadius * earthRadius / 2;
|
|
1295
|
+
}
|
|
1296
|
+
return Math.abs(total);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
function lineDistance(line) {
|
|
1300
|
+
const coordinates = "geometry" in line ? line.geometry.coordinates : "coordinates" in line ? line.coordinates : line;
|
|
1301
|
+
let distance = 0;
|
|
1302
|
+
let prevCoord;
|
|
1303
|
+
for (const coordinate of coordinates) {
|
|
1304
|
+
if (prevCoord !== void 0) {
|
|
1305
|
+
distance += pointDistance(prevCoord, coordinate);
|
|
1306
|
+
}
|
|
1307
|
+
prevCoord = coordinate;
|
|
1308
|
+
}
|
|
1309
|
+
return distance;
|
|
1310
|
+
}
|
|
1311
|
+
function pointDistance(from, to) {
|
|
1312
|
+
const { pow, sin, cos, sqrt, atan2 } = Math;
|
|
1313
|
+
const dLat = degToRad(to[1] - from[1]);
|
|
1314
|
+
const dLon = degToRad(to[0] - from[0]);
|
|
1315
|
+
const lat1 = degToRad(from[1]);
|
|
1316
|
+
const lat2 = degToRad(to[1]);
|
|
1317
|
+
const a = pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
|
|
1318
|
+
return 2 * atan2(sqrt(a), sqrt(1 - a)) * earthRadius;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function tileCover(coordinates, zoom, tileSize) {
|
|
1322
|
+
const tileHash = /* @__PURE__ */ new Map();
|
|
1323
|
+
const tiles = [];
|
|
1324
|
+
const coords = [];
|
|
1325
|
+
const resolution = getZoomLevelResolution(coordinates[0][1], zoom, tileSize);
|
|
1326
|
+
const samples = sampleProfileLine(coordinates, resolution);
|
|
1327
|
+
for (const sample of samples) {
|
|
1328
|
+
const coordinate = sample;
|
|
1329
|
+
const [tileX, tileY] = Z(coordinate, zoom, tileSize);
|
|
1330
|
+
const id = xyzToTileID(tileX, tileY, zoom);
|
|
1331
|
+
const tile = { id, x: tileX, y: tileY, z: zoom };
|
|
1332
|
+
tileHash.set(id, tile);
|
|
1333
|
+
coords.push({ coordinate, tile });
|
|
1334
|
+
}
|
|
1335
|
+
for (const tile of tileHash.values())
|
|
1336
|
+
tiles.push(tile);
|
|
1337
|
+
return { coords, tiles };
|
|
1338
|
+
}
|
|
1339
|
+
function sampleProfileLine(coordinates, resolution) {
|
|
1340
|
+
const samples = [];
|
|
1341
|
+
let prevCoord;
|
|
1342
|
+
for (const coord of coordinates) {
|
|
1343
|
+
if (prevCoord !== void 0) {
|
|
1344
|
+
const dist = pointDistance(
|
|
1345
|
+
prevCoord,
|
|
1346
|
+
coord
|
|
1347
|
+
);
|
|
1348
|
+
const numSamples = Math.ceil(dist / resolution);
|
|
1349
|
+
for (let i = 0; i <= numSamples - 1; i++) {
|
|
1350
|
+
const sample = [
|
|
1351
|
+
prevCoord[0] + (coord[0] - prevCoord[0]) * (i / numSamples),
|
|
1352
|
+
prevCoord[1] + (coord[1] - prevCoord[1]) * (i / numSamples)
|
|
1353
|
+
];
|
|
1354
|
+
samples.push(sample);
|
|
1355
|
+
}
|
|
1356
|
+
} else {
|
|
1357
|
+
samples.push(coord);
|
|
1358
|
+
}
|
|
1359
|
+
prevCoord = coord;
|
|
1360
|
+
}
|
|
1361
|
+
return samples;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function getElevation(coord, tile, tileSize, tileImage, elevationParser = defaultElevationParser) {
|
|
1365
|
+
const { channels, image } = tileImage;
|
|
1366
|
+
let [x, y] = w(coord, tile, tileSize);
|
|
1367
|
+
x = clampPixel(x, tileSize);
|
|
1368
|
+
y = clampPixel(y, tileSize);
|
|
1369
|
+
const index = (y * tileSize + x) * channels;
|
|
1370
|
+
return elevationParser(
|
|
1371
|
+
image[index],
|
|
1372
|
+
image[index + 1],
|
|
1373
|
+
image[index + 2],
|
|
1374
|
+
channels === 4 ? image[index + 3] : 0
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
function clampPixel(n, tileSize) {
|
|
1378
|
+
return Math.max(0, Math.min(tileSize, Math.floor(n * tileSize)));
|
|
1379
|
+
}
|
|
1380
|
+
function defaultElevationParser(r, g, b) {
|
|
1381
|
+
return -1e4 + (r * 256 * 256 + g * 256 + b) * 0.1;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
async function profileLineString(path, options) {
|
|
1385
|
+
const coordinates = "geometry" in path ? path.geometry.coordinates : path.coordinates;
|
|
1386
|
+
const { coords, tiles } = tileCover(
|
|
1387
|
+
coordinates,
|
|
1388
|
+
options.zoom ?? 13,
|
|
1389
|
+
options.tileSize ?? 512
|
|
1390
|
+
);
|
|
1391
|
+
const tileCache = await getTiles(tiles, options.tileRequest);
|
|
1392
|
+
let points = getElevations(
|
|
1393
|
+
coords,
|
|
1394
|
+
tileCache,
|
|
1395
|
+
options.tileSize ?? 512,
|
|
1396
|
+
options.elevationParser
|
|
1397
|
+
);
|
|
1398
|
+
if (options.smooth === true)
|
|
1399
|
+
points = smoothElevation(points);
|
|
1400
|
+
let output = buildOutput(points);
|
|
1401
|
+
if (options.metric === "ft")
|
|
1402
|
+
output = toFeet(output);
|
|
1403
|
+
return output;
|
|
1404
|
+
}
|
|
1405
|
+
async function getTiles(tiles, tileRequest) {
|
|
1406
|
+
const tileCache = /* @__PURE__ */ new Map();
|
|
1407
|
+
const requests = [];
|
|
1408
|
+
for (const tile of tiles) {
|
|
1409
|
+
requests.push(
|
|
1410
|
+
tileRequest(tile.x, tile.y, tile.z).then((res) => {
|
|
1411
|
+
tileCache.set(tile.id, res);
|
|
1412
|
+
return res;
|
|
1413
|
+
}).catch((err) => {
|
|
1414
|
+
console.error(err);
|
|
1415
|
+
return void 0;
|
|
1416
|
+
})
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
await Promise.allSettled(requests);
|
|
1420
|
+
return tileCache;
|
|
1421
|
+
}
|
|
1422
|
+
function getElevations(coords, tileCache, tileSize, elevationParser) {
|
|
1423
|
+
const points = [];
|
|
1424
|
+
let curDistance = 0;
|
|
1425
|
+
let prevCoord;
|
|
1426
|
+
for (const { tile, coordinate } of coords) {
|
|
1427
|
+
const cTile = tileCache.get(tile.id);
|
|
1428
|
+
if (cTile === void 0)
|
|
1429
|
+
throw new Error(
|
|
1430
|
+
`Missing tile ${tile.id} (${tile.x}-${tile.y}-${tile.z})`
|
|
1431
|
+
);
|
|
1432
|
+
const elevation = getElevation(
|
|
1433
|
+
coordinate,
|
|
1434
|
+
[tile.z, tile.x, tile.y],
|
|
1435
|
+
tileSize,
|
|
1436
|
+
cTile,
|
|
1437
|
+
elevationParser
|
|
1438
|
+
);
|
|
1439
|
+
points.push({
|
|
1440
|
+
distance: curDistance,
|
|
1441
|
+
elevation,
|
|
1442
|
+
coordinate,
|
|
1443
|
+
tile
|
|
1444
|
+
});
|
|
1445
|
+
if (prevCoord !== void 0) {
|
|
1446
|
+
curDistance += pointDistance(prevCoord, coordinate);
|
|
1447
|
+
}
|
|
1448
|
+
prevCoord = coordinate;
|
|
1449
|
+
}
|
|
1450
|
+
return points;
|
|
1451
|
+
}
|
|
1452
|
+
function buildOutput(points) {
|
|
1453
|
+
let minElevation = Infinity;
|
|
1454
|
+
let maxElevation = -Infinity;
|
|
1455
|
+
let totalElevation = 0;
|
|
1456
|
+
for (const point of points) {
|
|
1457
|
+
if (point.elevation < minElevation)
|
|
1458
|
+
minElevation = point.elevation;
|
|
1459
|
+
if (point.elevation > maxElevation)
|
|
1460
|
+
maxElevation = point.elevation;
|
|
1461
|
+
totalElevation += point.elevation;
|
|
1462
|
+
}
|
|
1463
|
+
return {
|
|
1464
|
+
distance: points[points.length - 1].distance,
|
|
1465
|
+
minElevation,
|
|
1466
|
+
maxElevation,
|
|
1467
|
+
avgElevation: totalElevation / points.length,
|
|
1468
|
+
startElevation: points[0].elevation,
|
|
1469
|
+
endElevation: points[points.length - 1].elevation,
|
|
1470
|
+
points
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function smoothElevation(points) {
|
|
1474
|
+
const newPoints = [];
|
|
1475
|
+
let prevPoint;
|
|
1476
|
+
for (let i = 0; i < points.length; i++) {
|
|
1477
|
+
const point = points[i];
|
|
1478
|
+
const nextPoint = points[i + 1] ?? points[i];
|
|
1479
|
+
if (prevPoint === void 0) {
|
|
1480
|
+
newPoints.push(point);
|
|
1481
|
+
} else {
|
|
1482
|
+
const newPoint = {
|
|
1483
|
+
distance: point.distance,
|
|
1484
|
+
elevation: (prevPoint.elevation + point.elevation + nextPoint.elevation) / 3,
|
|
1485
|
+
coordinate: point.coordinate,
|
|
1486
|
+
tile: point.tile
|
|
1487
|
+
};
|
|
1488
|
+
newPoints.push(newPoint);
|
|
1489
|
+
}
|
|
1490
|
+
prevPoint = point;
|
|
1491
|
+
}
|
|
1492
|
+
return newPoints;
|
|
1493
|
+
}
|
|
1494
|
+
function toFeet(input) {
|
|
1495
|
+
const output = {
|
|
1496
|
+
distance: mToFt(input.distance),
|
|
1497
|
+
minElevation: mToFt(input.minElevation),
|
|
1498
|
+
maxElevation: mToFt(input.maxElevation),
|
|
1499
|
+
avgElevation: mToFt(input.avgElevation),
|
|
1500
|
+
startElevation: mToFt(input.startElevation),
|
|
1501
|
+
endElevation: mToFt(input.endElevation),
|
|
1502
|
+
points: input.points.map(({ distance, elevation, coordinate, tile }) => ({
|
|
1503
|
+
distance: mToFt(distance),
|
|
1504
|
+
elevation: mToFt(elevation),
|
|
1505
|
+
coordinate,
|
|
1506
|
+
tile
|
|
1507
|
+
}))
|
|
1508
|
+
};
|
|
1509
|
+
return output;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1350
1512
|
exports.ClientConfig = ClientConfig;
|
|
1351
1513
|
exports.LanguageGeocoding = LanguageGeocoding;
|
|
1352
1514
|
exports.MapStyle = MapStyle;
|
|
1353
1515
|
exports.MapStyleVariant = MapStyleVariant;
|
|
1354
1516
|
exports.ReferenceMapStyle = ReferenceMapStyle;
|
|
1355
1517
|
exports.ServiceError = ServiceError;
|
|
1518
|
+
exports.area = area;
|
|
1356
1519
|
exports.config = config;
|
|
1357
1520
|
exports.coordinates = coordinates;
|
|
1358
1521
|
exports.data = data;
|
|
1522
|
+
exports.defaultElevationParser = defaultElevationParser;
|
|
1523
|
+
exports.degToRad = degToRad;
|
|
1524
|
+
exports.earthRadius = earthRadius;
|
|
1359
1525
|
exports.expandMapStyle = expandMapStyle;
|
|
1360
1526
|
exports.geocoding = geocoding;
|
|
1361
1527
|
exports.geolocation = geolocation;
|
|
1528
|
+
exports.getZoomLevelResolution = getZoomLevelResolution;
|
|
1529
|
+
exports.lineDistance = lineDistance;
|
|
1530
|
+
exports.mToFt = mToFt;
|
|
1362
1531
|
exports.mapStylePresetList = mapStylePresetList;
|
|
1532
|
+
exports.multiPolygonArea = multiPolygonArea;
|
|
1533
|
+
exports.pointDistance = pointDistance;
|
|
1534
|
+
exports.polygonArea = polygonArea;
|
|
1535
|
+
exports.profileLineString = profileLineString;
|
|
1536
|
+
exports.radToDeg = radToDeg;
|
|
1363
1537
|
exports.staticMaps = staticMaps;
|
|
1364
|
-
|
|
1365
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1538
|
+
exports.xyzToTileID = xyzToTileID;
|
|
1366
1539
|
|
|
1367
1540
|
}));
|
|
1368
1541
|
//# sourceMappingURL=maptiler-client.umd.js.map
|