@maptiler/client 1.7.0 → 1.8.1
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/.github/pull_request_template.md +11 -0
- package/.github/workflows/format-lint.yml +24 -0
- package/CHANGELOG.md +32 -0
- package/dist/maptiler-client.cjs +680 -306
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +270 -100
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +380 -294
- package/dist/maptiler-client.mjs.map +1 -1
- package/package.json +10 -8
- package/readme.md +133 -1
- package/rollup.config.js +3 -3
- package/dist/maptiler-client.umd.js +0 -1541
- package/dist/maptiler-client.umd.js.map +0 -1
- package/dist/maptiler-client.umd.min.js +0 -1
- package/examples/test-browser-es.html +0 -103
- package/examples/test-browser-umd.html +0 -90
- package/examples/test-node.js +0 -52
- package/src/callFetch.ts +0 -18
- package/src/config.ts +0 -68
- package/src/defaults.ts +0 -11
- package/src/demProfiler/getElevation.ts +0 -46
- package/src/demProfiler/index.ts +0 -240
- package/src/demProfiler/tileCover.ts +0 -96
- package/src/geometry/area.ts +0 -96
- package/src/geometry/distance.ts +0 -45
- package/src/geometry/index.ts +0 -3
- package/src/geometry/util.ts +0 -34
- package/src/index.ts +0 -114
- package/src/language.ts +0 -87
- package/src/mapstyle.ts +0 -968
- package/src/services/ServiceError.ts +0 -13
- package/src/services/coordinates.ts +0 -263
- package/src/services/data.ts +0 -63
- package/src/services/geocoding.ts +0 -461
- package/src/services/geolocation.ts +0 -139
- package/src/services/simplify.ts +0 -87
- package/src/services/staticMaps.ts +0 -463
|
@@ -1,6 +1,64 @@
|
|
|
1
|
-
import { BBox, Position, Feature, Geometry, FeatureCollection, LineString } from 'geojson';
|
|
2
|
-
export { BBox, Position } from 'geojson';
|
|
3
|
-
import
|
|
1
|
+
import { BBox, Position, Feature, Geometry, FeatureCollection, LineString, MultiLineString, GeoJsonObject } from 'geojson';
|
|
2
|
+
export { BBox, LineString, MultiLineString, Position } from 'geojson';
|
|
3
|
+
import QuickLRU from 'quick-lru';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Informations about an image
|
|
7
|
+
*/
|
|
8
|
+
type PixelData = {
|
|
9
|
+
/**
|
|
10
|
+
* The array of pixels as RGBRGB or RGBARGBA in a row-major order
|
|
11
|
+
*/
|
|
12
|
+
pixels: Uint8ClampedArray | Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* Width of the image in number of pixels
|
|
15
|
+
*/
|
|
16
|
+
width: number;
|
|
17
|
+
/**
|
|
18
|
+
* Height of the image in number of pixels
|
|
19
|
+
*/
|
|
20
|
+
height: number;
|
|
21
|
+
/**
|
|
22
|
+
* Number of components per pixel (3 if image is RGB, 4 if image is RGBA)
|
|
23
|
+
*/
|
|
24
|
+
components: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Type for the function that decodes an image file ArrayBuffer into valid pixel data
|
|
28
|
+
*/
|
|
29
|
+
type BufferToPixelDataFunction = (ArrayBuffer: any) => Promise<PixelData>;
|
|
30
|
+
/**
|
|
31
|
+
* Main properties necessary from a TileJSON
|
|
32
|
+
*/
|
|
33
|
+
type TileJSON = {
|
|
34
|
+
scale: string;
|
|
35
|
+
format: string;
|
|
36
|
+
maxzoom: number;
|
|
37
|
+
minzoom: number;
|
|
38
|
+
profile: string;
|
|
39
|
+
description: string;
|
|
40
|
+
attribution: string;
|
|
41
|
+
bounds: [number, number, number, number];
|
|
42
|
+
center: [number, number, number];
|
|
43
|
+
/**
|
|
44
|
+
* TileJSON version
|
|
45
|
+
*/
|
|
46
|
+
tilejson: string;
|
|
47
|
+
name: string;
|
|
48
|
+
crs: string;
|
|
49
|
+
crs_wkt: string;
|
|
50
|
+
extent: [number, number, number, number];
|
|
51
|
+
tiles: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Singleton-like function to access the tile cache
|
|
55
|
+
*/
|
|
56
|
+
declare function getTileCache(): QuickLRU<string, PixelData>;
|
|
57
|
+
/**
|
|
58
|
+
* Browser function to decode an image file buffer into valid pixel data
|
|
59
|
+
*/
|
|
60
|
+
declare function bufferToPixelDataBrowser(buff: ArrayBuffer): Promise<PixelData>;
|
|
61
|
+
declare function getBufferToPixelDataParser(): BufferToPixelDataFunction;
|
|
4
62
|
|
|
5
63
|
type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
6
64
|
/**
|
|
@@ -16,6 +74,11 @@ declare class ClientConfig {
|
|
|
16
74
|
* will be automatically resolved.
|
|
17
75
|
*/
|
|
18
76
|
private _fetch;
|
|
77
|
+
/**
|
|
78
|
+
* Number of tiles to keep in cache
|
|
79
|
+
*/
|
|
80
|
+
tileCacheSize: number;
|
|
81
|
+
bufferToPixelData: BufferToPixelDataFunction | null;
|
|
19
82
|
/**
|
|
20
83
|
* Set the MapTiler Cloud API key
|
|
21
84
|
*/
|
|
@@ -103,6 +166,7 @@ type Values<T> = T[keyof T];
|
|
|
103
166
|
* Built-in languages values as strings
|
|
104
167
|
*/
|
|
105
168
|
type LanguageGeocodingString = Values<typeof LanguageGeocoding>;
|
|
169
|
+
declare function getAutoLanguageGeocoding(): LanguageGeocodingString;
|
|
106
170
|
|
|
107
171
|
type LanguageGeocodingOptions = {
|
|
108
172
|
/**
|
|
@@ -120,9 +184,14 @@ type CommonForwardAndReverseGeocodingOptions = LanguageGeocodingOptions & {
|
|
|
120
184
|
*/
|
|
121
185
|
limit?: number;
|
|
122
186
|
/**
|
|
123
|
-
* Filter of feature types to return.
|
|
187
|
+
* Filter of feature types to return.
|
|
188
|
+
* If not specified, feature of all available types except `poi` are returned (`types = ["poi"]`, `excludeTypes = true`).
|
|
124
189
|
*/
|
|
125
190
|
types?: ("country" | "region" | "subregion" | "county" | "joint_municipality" | "joint_submunicipality" | "municipality" | "municipal_district" | "locality" | "neighbourhood" | "place" | "postal_code" | "address" | "poi")[];
|
|
191
|
+
/**
|
|
192
|
+
* Set to `true` to use all available feature types except those mentioned in `types`. Default value is `false` if `types` is specified.
|
|
193
|
+
*/
|
|
194
|
+
excludeTypes?: boolean;
|
|
126
195
|
};
|
|
127
196
|
type GeocodingOptions = CommonForwardAndReverseGeocodingOptions & {
|
|
128
197
|
/**
|
|
@@ -132,7 +201,7 @@ type GeocodingOptions = CommonForwardAndReverseGeocodingOptions & {
|
|
|
132
201
|
/**
|
|
133
202
|
* Prefer results close to a specific location.
|
|
134
203
|
*/
|
|
135
|
-
proximity?: Position;
|
|
204
|
+
proximity?: Position | "ip";
|
|
136
205
|
/**
|
|
137
206
|
* Limit search to specific country/countries specified as list of Alpha-2 ISO 3166-1 codes.
|
|
138
207
|
*/
|
|
@@ -142,8 +211,7 @@ type GeocodingOptions = CommonForwardAndReverseGeocodingOptions & {
|
|
|
142
211
|
*/
|
|
143
212
|
fuzzyMatch?: boolean;
|
|
144
213
|
/**
|
|
145
|
-
* Set to `true` to use autocomplete, `false` to disable it.
|
|
146
|
-
* Default (`undefined`) is to combine autocomplete with non-autocomplete results.
|
|
214
|
+
* Set to `true` to use autocomplete, `false` to disable it. Default is `true`.
|
|
147
215
|
*/
|
|
148
216
|
autocomplete?: boolean;
|
|
149
217
|
};
|
|
@@ -177,6 +245,10 @@ type FeatureProperties = {
|
|
|
177
245
|
* Array of POI categories. Only available for `poi` type.
|
|
178
246
|
*/
|
|
179
247
|
categories?: string[];
|
|
248
|
+
/**
|
|
249
|
+
* Wikidata identifier.
|
|
250
|
+
*/
|
|
251
|
+
wikidata?: string;
|
|
180
252
|
};
|
|
181
253
|
type FeatureBase = {
|
|
182
254
|
/**
|
|
@@ -297,7 +369,7 @@ declare function byId(id: string, options?: ByIdGeocodingOptions): Promise<Geoco
|
|
|
297
369
|
* @param options
|
|
298
370
|
* @returns
|
|
299
371
|
*/
|
|
300
|
-
declare function batch(queries: string[], options?: GeocodingOptions): Promise<GeocodingSearchResult[]>;
|
|
372
|
+
declare function batch$1(queries: string[], options?: GeocodingOptions): Promise<GeocodingSearchResult[]>;
|
|
301
373
|
/**
|
|
302
374
|
* The **geocoding** namespace contains asynchronous functions to call the [MapTiler Geocoding API](https://docs.maptiler.com/cloud/api/geocoding/).
|
|
303
375
|
* The **Geocoding API** provides ways to get geographic coordinates from a human-readable search query of a place (forward geocoding)
|
|
@@ -307,7 +379,7 @@ declare const geocoding: {
|
|
|
307
379
|
forward: typeof forward;
|
|
308
380
|
reverse: typeof reverse;
|
|
309
381
|
byId: typeof byId;
|
|
310
|
-
batch: typeof batch;
|
|
382
|
+
batch: typeof batch$1;
|
|
311
383
|
language: {
|
|
312
384
|
AUTO: string;
|
|
313
385
|
ALBANIAN: string;
|
|
@@ -1047,6 +1119,7 @@ type MapStyleType = {
|
|
|
1047
1119
|
};
|
|
1048
1120
|
};
|
|
1049
1121
|
declare const mapStylePresetList: Array<MapStylePreset>;
|
|
1122
|
+
declare function styleToStyle(style: string | ReferenceMapStyle | MapStyleVariant | null | undefined): string;
|
|
1050
1123
|
/**
|
|
1051
1124
|
* Contains all the reference map style created by MapTiler team as well as all the variants.
|
|
1052
1125
|
* For example, `MapStyle.STREETS` and the variants:
|
|
@@ -1232,106 +1305,203 @@ declare class ServiceError extends Error {
|
|
|
1232
1305
|
constructor(res: Response, customMessage?: string);
|
|
1233
1306
|
}
|
|
1234
1307
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
declare function
|
|
1308
|
+
/**
|
|
1309
|
+
* Convert a wgs84 longitude to web Mercator X (west-east axis), where westmost X is 0 and eastmost X is 1.
|
|
1310
|
+
*/
|
|
1311
|
+
declare function longitudeToMercatorX(lng: number): number;
|
|
1312
|
+
/**
|
|
1313
|
+
* Convert a wgs84 latitude to web Mercator Y (north-south axis), where northmost Y is 0 and southmost Y is 1.
|
|
1314
|
+
*/
|
|
1315
|
+
declare function latitudeToMercatorY(lat: number): number;
|
|
1316
|
+
/**
|
|
1317
|
+
* Convert a wgs84 position into a web Mercator position where north-west is [0, 0] and south-east is [1, 1]
|
|
1318
|
+
*/
|
|
1319
|
+
declare function wgs84ToMercator(position: Position): Position;
|
|
1320
|
+
/**
|
|
1321
|
+
* Converts a mercator X (west-east axis in [0, 1]) to wgs84 longitude
|
|
1322
|
+
*/
|
|
1323
|
+
declare function mercatorXToLongitude(x: number): number;
|
|
1324
|
+
/**
|
|
1325
|
+
* Converts a mercator Y (north-south axis in [0, 1]) to wgs84 latitude
|
|
1326
|
+
*/
|
|
1327
|
+
declare function mercatorYToLatitude(y: number): number;
|
|
1328
|
+
/**
|
|
1329
|
+
* Converts a web Mercator position where north-west is [0, 0] and south-east is [1, 1] into a wgs84
|
|
1330
|
+
*/
|
|
1331
|
+
declare function mercatorToWgs84(position: Position): Position;
|
|
1332
|
+
/**
|
|
1333
|
+
* Gives the distance in meters between two positions using the Haversine Formula.
|
|
1334
|
+
*/
|
|
1335
|
+
declare function haversineDistanceWgs84(from: Position, to: Position): number;
|
|
1336
|
+
/**
|
|
1337
|
+
* Compute the cumulated distance for each position of an array of positions.
|
|
1338
|
+
* For I positions, there are I-1 distance, hence the distance at i corresponds
|
|
1339
|
+
* to the distance from the (i-1)th position to ith
|
|
1340
|
+
*/
|
|
1341
|
+
declare function haversineCumulatedDistanceWgs84(positions: Position[]): number[];
|
|
1342
|
+
/**
|
|
1343
|
+
* Returns a position that has longitude in [-180, 180]
|
|
1344
|
+
*/
|
|
1345
|
+
declare function wrapWgs84(position: Position): Position;
|
|
1346
|
+
declare function circumferenceAtLatitude(latitude: number): number;
|
|
1347
|
+
/**
|
|
1348
|
+
* From a given mercator coordinate and a zoom level, computes the tile index
|
|
1349
|
+
*/
|
|
1350
|
+
declare function mercatorToTileIndex(
|
|
1351
|
+
/**
|
|
1352
|
+
* Mercator coordinates (north-west is [0, 0], sourth-east is [1, 1])
|
|
1353
|
+
*/
|
|
1354
|
+
position: Position,
|
|
1355
|
+
/**
|
|
1356
|
+
* Zoom level
|
|
1357
|
+
*/
|
|
1358
|
+
zoom: number,
|
|
1359
|
+
/**
|
|
1360
|
+
* Returns integer tile indices if `true` or floating-point values if `false`
|
|
1361
|
+
*/
|
|
1362
|
+
strict?: boolean): Position;
|
|
1363
|
+
/**
|
|
1364
|
+
* From a given wgs84 coordinate and a zoom level, computes the tile index
|
|
1365
|
+
*/
|
|
1366
|
+
declare function wgs84ToTileIndex(
|
|
1367
|
+
/**
|
|
1368
|
+
* Wgs84 coordinates
|
|
1369
|
+
*/
|
|
1370
|
+
position: Position,
|
|
1371
|
+
/**
|
|
1372
|
+
* Zoom level
|
|
1373
|
+
*/
|
|
1374
|
+
zoom: number,
|
|
1375
|
+
/**
|
|
1376
|
+
* Returns integer tile indices if `true` or floating-point values if `false`
|
|
1377
|
+
*/
|
|
1378
|
+
strict?: boolean): Position;
|
|
1379
|
+
/**
|
|
1380
|
+
* Converts a degree angle into a radian angle
|
|
1381
|
+
*/
|
|
1382
|
+
declare function toRadians(degrees: number): number;
|
|
1383
|
+
/**
|
|
1384
|
+
* Converts a radian angle to a degree angle
|
|
1385
|
+
*/
|
|
1386
|
+
declare function toDegrees(radians: number): number;
|
|
1387
|
+
/**
|
|
1388
|
+
* Compute an intermediate point between two reference points using the Haversine formula.
|
|
1389
|
+
* If ratio is `0`, the returned position is pos1.
|
|
1390
|
+
* If ratio is `1`, the returned position is pos2.
|
|
1391
|
+
* If ratio is `0.5`, the returned position is halfway pos1 pos2 in distance.
|
|
1392
|
+
*/
|
|
1393
|
+
declare function haversineIntermediateWgs84(pos1: Position, pos2: Position, ratio: number): Position;
|
|
1394
|
+
declare const math: {
|
|
1395
|
+
EARTH_RADIUS: number;
|
|
1396
|
+
EARTH_CIRCUMFERENCE: number;
|
|
1397
|
+
longitudeToMercatorX: typeof longitudeToMercatorX;
|
|
1398
|
+
latitudeToMercatorY: typeof latitudeToMercatorY;
|
|
1399
|
+
wgs84ToMercator: typeof wgs84ToMercator;
|
|
1400
|
+
mercatorXToLongitude: typeof mercatorXToLongitude;
|
|
1401
|
+
mercatorYToLatitude: typeof mercatorYToLatitude;
|
|
1402
|
+
mercatorToWgs84: typeof mercatorToWgs84;
|
|
1403
|
+
haversineDistanceWgs84: typeof haversineDistanceWgs84;
|
|
1404
|
+
wrapWgs84: typeof wrapWgs84;
|
|
1405
|
+
circumferenceAtLatitude: typeof circumferenceAtLatitude;
|
|
1406
|
+
mercatorToTileIndex: typeof mercatorToTileIndex;
|
|
1407
|
+
wgs84ToTileIndex: typeof wgs84ToTileIndex;
|
|
1408
|
+
toRadians: typeof toRadians;
|
|
1409
|
+
toDegrees: typeof toDegrees;
|
|
1410
|
+
haversineIntermediateWgs84: typeof haversineIntermediateWgs84;
|
|
1411
|
+
haversineCumulatedDistanceWgs84: typeof haversineCumulatedDistanceWgs84;
|
|
1412
|
+
};
|
|
1255
1413
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1414
|
+
type ElevationAtOptions = {
|
|
1415
|
+
/**
|
|
1416
|
+
* Custom MapTiler Cloud API key to use instead of the one in global `config`
|
|
1417
|
+
*/
|
|
1418
|
+
apiKey?: string;
|
|
1419
|
+
/**
|
|
1420
|
+
* Zoom level to use for the terrain RGB tileset.
|
|
1421
|
+
* If not provided, the highest zoom level will be used
|
|
1422
|
+
*/
|
|
1265
1423
|
zoom?: number;
|
|
1266
|
-
|
|
1267
|
-
tileSize?: number;
|
|
1268
|
-
/** Tile Request method */
|
|
1269
|
-
tileRequest: TileRequest;
|
|
1270
|
-
/** Elevation parser. Default: elevation = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1) */
|
|
1271
|
-
elevationParser?: ElevationParser;
|
|
1272
|
-
/** smooth out the elevation to make the visual aesthetic nicer */
|
|
1273
|
-
smooth?: boolean;
|
|
1274
|
-
}
|
|
1275
|
-
interface ElevPoint {
|
|
1276
|
-
/** Distance along path from the starting point in the metric defind by options */
|
|
1277
|
-
distance: number;
|
|
1278
|
-
/** Elevation of the point */
|
|
1279
|
-
elevation: number;
|
|
1280
|
-
/** Coordinates of the point in lat-lon */
|
|
1281
|
-
coordinate: [lon: number, lat: number];
|
|
1282
|
-
/** Tile that the point is in */
|
|
1283
|
-
tile: TileID;
|
|
1284
|
-
}
|
|
1285
|
-
interface Output {
|
|
1286
|
-
/** Total length of the path in the metric defined by options */
|
|
1287
|
-
distance: number;
|
|
1288
|
-
/** Minimum elevation of the path */
|
|
1289
|
-
minElevation: number;
|
|
1290
|
-
/** Maximum elevation of the path */
|
|
1291
|
-
maxElevation: number;
|
|
1292
|
-
/** Average elevation of the path */
|
|
1293
|
-
avgElevation: number;
|
|
1294
|
-
/** Elevation at the start of the path */
|
|
1295
|
-
startElevation: number;
|
|
1296
|
-
/** Elevation at the end of the path */
|
|
1297
|
-
endElevation: number;
|
|
1298
|
-
/** Array of points along the path */
|
|
1299
|
-
points: ElevPoint[];
|
|
1300
|
-
}
|
|
1424
|
+
};
|
|
1301
1425
|
/**
|
|
1302
|
-
*
|
|
1303
|
-
* This algorithm will automatically break the path into denser segments relative to the zoom level if necessary.
|
|
1426
|
+
* Options for batch elevation lookup
|
|
1304
1427
|
*/
|
|
1305
|
-
|
|
1306
|
-
|
|
1428
|
+
type ElevationBatchOptions = ElevationAtOptions & {
|
|
1429
|
+
/**
|
|
1430
|
+
* If provided, a median kernel of the given size will smooth the elevation
|
|
1431
|
+
* to reduce very small local variations
|
|
1432
|
+
*/
|
|
1433
|
+
smoothingKernelSize?: number;
|
|
1434
|
+
};
|
|
1307
1435
|
/**
|
|
1308
|
-
*
|
|
1436
|
+
* Get the elevation at a given position.
|
|
1437
|
+
* The returned position is of form [longitude, latitude, altitude]
|
|
1309
1438
|
*/
|
|
1310
|
-
declare function
|
|
1439
|
+
declare function at(
|
|
1311
1440
|
/**
|
|
1312
|
-
*
|
|
1441
|
+
* Wgs84 position as [longitude, latitude]
|
|
1313
1442
|
*/
|
|
1314
|
-
|
|
1443
|
+
position: Position,
|
|
1315
1444
|
/**
|
|
1316
|
-
*
|
|
1445
|
+
* Options
|
|
1317
1446
|
*/
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1447
|
+
options?: ElevationAtOptions): Promise<Position>;
|
|
1448
|
+
/**
|
|
1449
|
+
* Perform a batch elevation request
|
|
1450
|
+
*/
|
|
1451
|
+
declare function batch(
|
|
1452
|
+
/**
|
|
1453
|
+
* Wgs84 positions as [[lng0, lat0], [lng1, lat1], [lng2, lat2], ...]
|
|
1454
|
+
*/
|
|
1455
|
+
positions: Position[],
|
|
1456
|
+
/**
|
|
1457
|
+
* Options
|
|
1458
|
+
*/
|
|
1459
|
+
options?: ElevationBatchOptions): Promise<Position[]>;
|
|
1460
|
+
/**
|
|
1461
|
+
* Creates a clone of a GeoJSON LineString (deep copy with structuredClone) that contains the computed elevation
|
|
1462
|
+
* as the third element of each position array ([lng, lat, alt])
|
|
1463
|
+
*/
|
|
1464
|
+
declare function fromLineString(
|
|
1465
|
+
/**
|
|
1466
|
+
* A GeoJSON LineStriung feature
|
|
1467
|
+
*/
|
|
1468
|
+
ls: LineString,
|
|
1469
|
+
/**
|
|
1470
|
+
* Options
|
|
1471
|
+
*/
|
|
1472
|
+
options?: ElevationBatchOptions): Promise<LineString>;
|
|
1473
|
+
/**
|
|
1474
|
+
* Creates a clone of a MultiLineString (deep copy with structuredClone) that contains the computed elevation
|
|
1475
|
+
* as the third element of each position array ([lng, lat, alt])
|
|
1476
|
+
*/
|
|
1477
|
+
declare function fromMultiLineString(
|
|
1478
|
+
/**
|
|
1479
|
+
* A GeoJSON LineStriung feature
|
|
1480
|
+
*/
|
|
1481
|
+
ls: MultiLineString,
|
|
1482
|
+
/**
|
|
1483
|
+
* Options
|
|
1484
|
+
*/
|
|
1485
|
+
options?: ElevationBatchOptions): Promise<MultiLineString>;
|
|
1486
|
+
declare const elevation: {
|
|
1487
|
+
at: typeof at;
|
|
1488
|
+
batch: typeof batch;
|
|
1489
|
+
fromLineString: typeof fromLineString;
|
|
1490
|
+
fromMultiLineString: typeof fromMultiLineString;
|
|
1491
|
+
};
|
|
1324
1492
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
declare function
|
|
1330
|
-
/**
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
declare function
|
|
1334
|
-
|
|
1335
|
-
|
|
1493
|
+
/**
|
|
1494
|
+
* From a generic GeoJSON object extract thepossibly nested LineString and MultiLineString features
|
|
1495
|
+
* it contains. The result is a flat array made of LineString and MultiLineString.
|
|
1496
|
+
*/
|
|
1497
|
+
declare function extractLineStrings(geoJson: GeoJsonObject): Array<LineString | MultiLineString>;
|
|
1498
|
+
/**
|
|
1499
|
+
* Simplify a path made of a list of GeoJSON Positions, with a tolerance.
|
|
1500
|
+
*/
|
|
1501
|
+
declare function simplify(points: Array<Position>, tolerance: number): Array<Position>;
|
|
1502
|
+
declare const misc: {
|
|
1503
|
+
extractLineStrings: typeof extractLineStrings;
|
|
1504
|
+
simplify: typeof simplify;
|
|
1505
|
+
};
|
|
1336
1506
|
|
|
1337
|
-
export { type AutomaticStaticMapOptions, type BoundedStaticMapOptions, type CenteredStaticMapOptions, ClientConfig, type CommonForwardAndReverseGeocodingOptions, type CoordinateExport, type CoordinateGrid, type CoordinateId, type CoordinateSearch, type CoordinateSearchResult, type CoordinateTransformResult, type CoordinateTransformation, type Coordinates, type CoordinatesSearchOptions, type CoordinatesTransformOptions, type
|
|
1507
|
+
export { type AutomaticStaticMapOptions, type BoundedStaticMapOptions, type BufferToPixelDataFunction, type ByIdGeocodingOptions, type CenteredStaticMapOptions, ClientConfig, type CommonForwardAndReverseGeocodingOptions, type CoordinateExport, type CoordinateGrid, type CoordinateId, type CoordinateSearch, type CoordinateSearchResult, type CoordinateTransformResult, type CoordinateTransformation, type Coordinates, type CoordinatesSearchOptions, type CoordinatesTransformOptions, type DefaultTransformation, type ElevationAtOptions, type ElevationBatchOptions, type FeatureHierarchy, type FetchFunction, type GeocodingFeature, type GeocodingOptions, type GeocodingSearchResult, type GeolocationInfoOptions, type GeolocationResult, type GetDataOptions, LanguageGeocoding, type LanguageGeocodingOptions, type LanguageGeocodingString, MapStyle, type MapStylePreset, type MapStyleType, MapStyleVariant, type PixelData, ReferenceMapStyle, type ReverseGeocodingOptions, ServiceError, type StaticMapBaseOptions, type StaticMapMarker, type TileJSON, type XYZ, bufferToPixelDataBrowser, circumferenceAtLatitude, config, coordinates, data, elevation, expandMapStyle, geocoding, geolocation, getAutoLanguageGeocoding, getBufferToPixelDataParser, getTileCache, mapStylePresetList, math, misc, staticMaps, styleToStyle };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{llToTile as W,llToTilePx as _}from"web-merc-projection";function q(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class b{constructor(){this._apiKey="",this._fetch=q()}set apiKey(e){this._apiKey=e}get apiKey(){return this._apiKey}set fetch(e){this._fetch=e}get fetch(){return this._fetch}}const m=new b,v={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},Z=new Set(Object.values(v));function Y(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const t=Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).filter(e=>Z.has(e));return t.length?t[0]:v.ENGLISH}async function f(t,e={}){if(m.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(t).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return m.fetch(t,e)}const h={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(h);class u extends Error{constructor(e,n=""){super(`Call to enpoint ${e.url} failed with the status code ${e.status}. ${n}`),this.res=e}}const R={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function K(t,e){if(e.language==null)return;const n=Array.from(new Set((Array.isArray(e.language)?e.language:[e.language]).map(i=>i===v.AUTO?Y():i))).join(",");t.set("language",n)}function C(t,e){t.set("key",e.apiKey??m.apiKey),e.limit!=null&&t.set("limit",String(e.limit)),e.types!=null&&t.set("types",e.types.join(",")),K(t,e)}function O(t,e){C(t,e),e.bbox!=null&&t.set("bbox",e.bbox.join(",")),e.proximity!=null&&t.set("proximity",e.proximity.join(",")),e.country!=null&&t.set("country",e.country.join(",")),e.fuzzyMatch!=null&&t.set("fuzzyMatch",e.fuzzyMatch?"true":"false"),e.autocomplete!=null&&t.set("autocomplete",e.autocomplete?"true":"false")}async function J(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`geocoding/${encodeURIComponent(t)}.json`,h.maptilerApiURL),{searchParams:i}=n;O(i,e);const a=n.toString(),r=await f(a);if(!r.ok)throw new u(r,R[r.status]??"");return await r.json()}async function Q(t,e={}){if(!Array.isArray(t)||t.length<2)throw new Error("The position must be an array of form [lng, lat].");const n=new URL(`geocoding/${t[0]},${t[1]}.json`,h.maptilerApiURL);C(n.searchParams,e);const i=n.toString(),a=await f(i);if(!a.ok)throw new u(a,R[a.status]??"");return await a.json()}async function X(t,e={}){const n=new URL(`geocoding/${t}.json`,h.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),K(n.searchParams,e);const i=n.toString(),a=await f(i);if(!a.ok)throw new u(a,R[a.status]??"");return await a.json()}async function tt(t,e={}){if(!t.length)return[];const n=t.map(c=>encodeURIComponent(c)).join(";"),i=new URL(`geocoding/${n}.json`,h.maptilerApiURL),{searchParams:a}=i;O(a,e);const r=i.toString(),s=await f(r);if(!s.ok)throw new u(s,R[s.status]??"");const o=await s.json();return t.length===1?[o]:o}const et={forward:J,reverse:Q,byId:X,batch:tt,language:v},j={403:"Key is missing, invalid or restricted"};async function nt(t={}){const e=new URL("geolocation/ip.json",h.maptilerApiURL);e.searchParams.set("key",t.apiKey??m.apiKey);const n=e.toString(),i=await f(n);if(!i.ok)throw new u(i,i.status in j?j[i.status]:"");return await i.json()}const it={info:nt},L={403:"Key is missing, invalid or restricted"};async function at(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`coordinates/search/${t}.json`,h.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),"limit"in e&&n.searchParams.set("limit",e.limit.toString()),"transformations"in e&&n.searchParams.set("transformations",e.transformations.toString()),"exports"in e&&n.searchParams.set("exports",e.exports.toString());const i=n.toString(),a=await f(i);if(!a.ok)throw new u(a,a.status in L?L[a.status]:"");return await a.json()}async function rt(t,e={}){const n=(Array.isArray(t[0])?t:[t]).map(s=>`${s[0]},${s[1]}`).join(";"),i=new URL(`coordinates/transform/${n}.json`,h.maptilerApiURL);i.searchParams.set("key",e.apiKey??m.apiKey),"sourceCrs"in e&&i.searchParams.set("s_srs",e.sourceCrs.toString()),"targetCrs"in e&&i.searchParams.set("t_srs",e.targetCrs.toString()),"operations"in e&&i.searchParams.set("ops",(Array.isArray(e.operations)?e.operations:[e.operations]).join("|"));const a=i.toString(),r=await f(a);if(!r.ok)throw new u(r,r.status in L?L[r.status]:"");return await r.json()}const ot={search:at,transform:rt},M={403:"Key is missing, invalid or restricted"};async function st(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The data ID must be a non-empty string");const n=new URL(`data/${encodeURIComponent(t)}/features.json`,h.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey);const i=n.toString(),a=await f(i);if(!a.ok)throw new u(a,a.status in M?M[a.status]:"");return await a.json()}const ct={get:st};function H(t){const e=/^maptiler:\/\/(.*)/;let n;const i=t.trim();let a;return i.startsWith("http://")||i.startsWith("https://")?a=i:(n=e.exec(i))!==null?a=`https://api.maptiler.com/maps/${n[1]}/style.json`:a=`https://api.maptiler.com/maps/${i}/style.json`,a}class U{constructor(e,n,i,a,r,s){this.name=e,this.variantType=n,this.id=i,this.referenceStyle=a,this.description=r,this.imageURL=s}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(e){return this.referenceStyle.hasVariant(e)}getVariant(e){return this.referenceStyle.getVariant(e)}getVariants(){return this.referenceStyle.getVariants().filter(e=>e!==this)}getImageURL(){return this.imageURL}getExpandedStyleURL(){return H(this.getId())}}class D{constructor(e,n){this.name=e,this.id=n,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(e){this.variants[e.getType()]=e,this.orderedVariants.push(e)}hasVariant(e){return e in this.variants}getVariant(e){return e in this.variants?this.variants[e]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const I=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function lt(t){return new Proxy(t,{get(e,n,i){return e.hasVariant(n)?e.getVariant(n):n.toString().toUpperCase()===n?t.getDefaultVariant():Reflect.get(e,n,i)}})}function pt(){const t={};for(let e=0;e<I.length;e+=1){const n=I[e],i=lt(new D(n.name,n.referenceStyleID));for(let a=0;a<n.variants.length;a+=1){const r=n.variants[a],s=new U(r.name,r.variantType,r.id,i,r.description,r.imageURL);i.addVariant(s)}t[n.referenceStyleID]=i}return t}function E(t){if(!t)return x[I[0].referenceStyleID].getDefaultVariant().getId();if(typeof t=="string"||t instanceof String)return t.trim().toLowerCase();if(t instanceof U)return t.getId();if(t instanceof D)return t.getDefaultVariant().getId()}const x=pt();function mt(t,e,n){let i=e[0],a=e[1],r=n[0]-i,s=n[1]-a;if(r!==0||s!==0){const o=((t[0]-i)*r+(t[1]-a)*s)/(r*r+s*s);o>1?(i=n[0],a=n[1]):o>0&&(i+=r*o,a+=s*o)}return r=t[0]-i,s=t[1]-a,r*r+s*s}function k(t,e,n,i,a){let r=i,s;for(let o=e+1;o<n;o++){const c=mt(t[o],t[e],t[n]);c>r&&(s=o,r=c)}r>i&&(s-e>1&&k(t,e,s,i,a),a.push(t[s]),n-s>1&&k(t,s,n,i,a))}function ht(t,e){const n=t.length-1,i=[t[0]];return k(t,0,n,e,i),i.push(t[n]),i}function dt(t,e){if(t.length<=2)return t;const n=e!==void 0?e*e:1;return ht(t,n)}function w(t,e=!0){let n=`${t[0]},${t[1]}`;return t.length===3&&e&&(n+=`,${t[2]}`),n}function $(t,e=3e3){let n=t.map(r=>r.join(",")).join("|"),i=5e-6;const a=1e-5;for(;n.length>e;)n=dt(t,i).map(r=>`${r[0]},${r[1]}`).join("|"),i+=a;return n}function ut(t,e,n={}){const i=E(n.style),a=n.hiDPI?"@2x":"",r=n.format??"png";let s=~~(n.width??1024),o=~~(n.height??1024);n.hiDPI&&(s=~~(s/2),o=~~(o/2));const c=new URL(`maps/${encodeURIComponent(i)}/static/${t[0]},${t[1]},${e}/${s}x${o}${a}.${r}`,h.maptilerApiURL);if("attribution"in n&&c.searchParams.set("attribution",n.attribution.toString()),"markers"in n){let l="";const p="markerIcon"in n;p&&(l+=`icon:${n.markerIcon}|`),p&&"markerAnchor"in n&&(l+=`anchor:${n.markerAnchor}|`),p&&n.hiDPI&&(l+="scale:2|");const d=Array.isArray(n.markers[0])?n.markers:[n.markers];l+=d.map(A=>w(A,!p)).join("|"),c.searchParams.set("markers",l)}if("path"in n){let l="";if(l+=`fill:${n.pathFillColor??"none"}|`,"pathStrokeColor"in n&&(l+=`stroke:${n.pathStrokeColor}|`),"pathWidth"in n){const p=n.pathWidth/(n.hiDPI?2:1);l+=`width:${p.toString()}|`}l+=$(n.path),c.searchParams.set("path",l)}return c.searchParams.set("key",n.apiKey??m.apiKey),c.toString()}function gt(t,e={}){const n=E(e.style),i=e.hiDPI?"@2x":"",a=e.format??"png";let r=~~(e.width??1024),s=~~(e.height??1024);e.hiDPI&&(r=~~(r/2),s=~~(s/2));const o=new URL(`maps/${encodeURIComponent(n)}/static/${t[0]},${t[1]},${t[2]},${t[3]}/${r}x${s}${i}.${a}`,h.maptilerApiURL);if("attribution"in e&&o.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&o.searchParams.set("padding",e.padding.toString()),"markers"in e){let c="";const l="markerIcon"in e;l&&(c+=`icon:${e.markerIcon}|`),l&&"markerAnchor"in e&&(c+=`anchor:${e.markerAnchor}|`),l&&e.hiDPI&&(c+="scale:2|");const p=Array.isArray(e.markers[0])?e.markers:[e.markers];c+=p.map(d=>w(d,!l)).join("|"),o.searchParams.set("markers",c)}if("path"in e){let c="";if(c+=`fill:${e.pathFillColor??"none"}|`,"pathStrokeColor"in e&&(c+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const l=e.pathWidth/(e.hiDPI?2:1);c+=`width:${l.toString()}|`}c+=$(e.path),o.searchParams.set("path",c)}return o.searchParams.set("key",e.apiKey??m.apiKey),o.toString()}function ft(t={}){if(!("markers"in t)&&!("path"in t))throw new Error("Automatic static maps require markers and/or path to be created.");const e=E(t.style),n=t.hiDPI?"@2x":"",i=t.format??"png";let a=~~(t.width??1024),r=~~(t.height??1024);t.hiDPI&&(a=~~(a/2),r=~~(r/2));const s=new URL(`maps/${encodeURIComponent(e)}/static/auto/${a}x${r}${n}.${i}`,h.maptilerApiURL);if("attribution"in t&&s.searchParams.set("attribution",t.attribution.toString()),"padding"in t&&s.searchParams.set("padding",t.padding.toString()),"markers"in t){let o="";const c="markerIcon"in t;c&&(o+=`icon:${t.markerIcon}|`),c&&"markerAnchor"in t&&(o+=`anchor:${t.markerAnchor}|`),c&&t.hiDPI&&(o+="scale:2|");const l=Array.isArray(t.markers[0])?t.markers:[t.markers];o+=l.map(p=>w(p,!c)).join("|"),s.searchParams.set("markers",o)}if("path"in t){let o="";if(o+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(o+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const c=t.pathWidth/(t.hiDPI?2:1);o+=`width:${c.toString()}|`}o+=$(t.path),s.searchParams.set("path",o)}return s.searchParams.set("key",t.apiKey??m.apiKey),s.toString()}const yt={centered:ut,bounded:gt,automatic:ft},S=63710088e-1;function g(t){return t*3.28084}function y(t){return t%360*Math.PI/180}function vt(t){return t*180/Math.PI}function V(t,e,n=512){return Math.cos(t*Math.PI/180)*2*Math.PI*6378137/(n*2**e)*3}function G(t,e,n){return((1<<n)*e+t)*32+n}function At(t){const e="geometry"in t?t.geometry:t;return e.type==="MultiPolygon"?F(e.coordinates):P(e.coordinates)}function F(t){const e="coordinates"in t?t.coordinates:t;let n=0;for(const i of e)n+=P(i);return n}function P(t){const e="coordinates"in t?t.coordinates:t;let n=0;for(const i of e)n+=Rt(i);return n}function Rt(t){let e,n,i,a,r,s,o,c=0;const l=t.length;if(l>2){for(o=0;o<l;o++)o===l-2?(a=l-2,r=l-1,s=0):o===l-1?(a=l-1,r=0,s=1):(a=o,r=o+1,s=o+2),e=t[a],n=t[r],i=t[s],c+=(y(i[0])-y(e[0]))*Math.sin(y(n[1]));c=c*S*S/2}return Math.abs(c)}function Lt(t){const e="geometry"in t?t.geometry.coordinates:"coordinates"in t?t.coordinates:t;let n=0,i;for(const a of e)i!==void 0&&(n+=T(i,a)),i=a;return n}function T(t,e){const{pow:n,sin:i,cos:a,sqrt:r,atan2:s}=Math,o=y(e[1]-t[1]),c=y(e[0]-t[0]),l=y(t[1]),p=y(e[1]),d=n(i(o/2),2)+n(i(c/2),2)*a(l)*a(p);return 2*s(r(d),r(1-d))*S}function It(t,e,n){const i=new Map,a=[],r=[],s=V(t[0][1],e,n),o=St(t,s);for(const c of o){const l=c,[p,d]=W(l,e,n),A=G(p,d,e),N={id:A,x:p,y:d,z:e};i.set(A,N),r.push({coordinate:l,tile:N})}for(const c of i.values())a.push(c);return{coords:r,tiles:a}}function St(t,e){const n=[];let i;for(const a of t){if(i!==void 0){const r=T(i,a),s=Math.ceil(r/e);for(let o=0;o<=s-1;o++){const c=[i[0]+(a[0]-i[0])*(o/s),i[1]+(a[1]-i[1])*(o/s)];n.push(c)}}else n.push(a);i=a}return n}function Tt(t,e,n,i,a=B){const{channels:r,image:s}=i;let[o,c]=_(t,e,n);o=z(o,n),c=z(c,n);const l=(c*n+o)*r;return a(s[l],s[l+1],s[l+2],r===4?s[l+3]:0)}function z(t,e){return Math.max(0,Math.min(e,Math.floor(t*e)))}function B(t,e,n){return-1e4+(t*256*256+e*256+n)*.1}async function Ut(t,e){const n="geometry"in t?t.geometry.coordinates:t.coordinates,{coords:i,tiles:a}=It(n,e.zoom??13,e.tileSize??512),r=await Dt(a,e.tileRequest);let s=Et(i,r,e.tileSize??512,e.elevationParser);e.smooth===!0&&(s=wt(s));let o=kt(s);return e.metric==="ft"&&(o=$t(o)),o}async function Dt(t,e){const n=new Map,i=[];for(const a of t)i.push(e(a.x,a.y,a.z).then(r=>(n.set(a.id,r),r)).catch(r=>{console.error(r)}));return await Promise.allSettled(i),n}function Et(t,e,n,i){const a=[];let r=0,s;for(const{tile:o,coordinate:c}of t){const l=e.get(o.id);if(l===void 0)throw new Error(`Missing tile ${o.id} (${o.x}-${o.y}-${o.z})`);const p=Tt(c,[o.z,o.x,o.y],n,l,i);a.push({distance:r,elevation:p,coordinate:c,tile:o}),s!==void 0&&(r+=T(s,c)),s=c}return a}function kt(t){let e=1/0,n=-1/0,i=0;for(const a of t)a.elevation<e&&(e=a.elevation),a.elevation>n&&(n=a.elevation),i+=a.elevation;return{distance:t[t.length-1].distance,minElevation:e,maxElevation:n,avgElevation:i/t.length,startElevation:t[0].elevation,endElevation:t[t.length-1].elevation,points:t}}function wt(t){const e=[];let n;for(let i=0;i<t.length;i++){const a=t[i],r=t[i+1]??t[i];if(n===void 0)e.push(a);else{const s={distance:a.distance,elevation:(n.elevation+a.elevation+r.elevation)/3,coordinate:a.coordinate,tile:a.tile};e.push(s)}n=a}return e}function $t(t){return{distance:g(t.distance),minElevation:g(t.minElevation),maxElevation:g(t.maxElevation),avgElevation:g(t.avgElevation),startElevation:g(t.startElevation),endElevation:g(t.endElevation),points:t.points.map(({distance:e,elevation:n,coordinate:i,tile:a})=>({distance:g(e),elevation:g(n),coordinate:i,tile:a}))}}export{b as ClientConfig,v as LanguageGeocoding,x as MapStyle,U as MapStyleVariant,D as ReferenceMapStyle,u as ServiceError,At as area,m as config,ot as coordinates,ct as data,B as defaultElevationParser,y as degToRad,S as earthRadius,H as expandMapStyle,et as geocoding,it as geolocation,V as getZoomLevelResolution,Lt as lineDistance,g as mToFt,I as mapStylePresetList,F as multiPolygonArea,T as pointDistance,P as polygonArea,Ut as profileLineString,vt as radToDeg,yt as staticMaps,G as xyzToTileID};
|
|
1
|
+
import At from"quick-lru";function Lt(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class q{constructor(){this._apiKey="",this._fetch=Lt(),this.tileCacheSize=200}set apiKey(e){this._apiKey=e}get apiKey(){return this._apiKey}set fetch(e){this._fetch=e}get fetch(){return this._fetch}}const m=new q,k={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},Tt=new Set(Object.values(k));function Y(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const t=Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).filter(e=>Tt.has(e));return t.length?t[0]:k.ENGLISH}async function L(t,e={}){if(m.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(t).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return m.fetch(t,e)}const y={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(y);class A extends Error{constructor(e,n=""){super(`Call to enpoint ${e.url} failed with the status code ${e.status}. ${n}`),this.res=e}}const E={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function J(t,e){const{language:n}=e;if(n==null)return;const i=Array.from(new Set((Array.isArray(n)?n:[n]).map(a=>a===k.AUTO?Y():a))).join(",");t.set("language",i)}function Z(t,e){const{apiKey:n,limit:i,types:a,excludeTypes:r}=e;t.set("key",n??m.apiKey),i!=null&&t.set("limit",String(i)),a!=null&&t.set("types",a.join(",")),r!=null&&t.set("excludeTypes",String(r)),J(t,e)}function X(t,e){Z(t,e);const{bbox:n,proximity:i,country:a,fuzzyMatch:r,autocomplete:o}=e;n!=null&&t.set("bbox",n.join(",")),i!=null&&t.set("proximity",i==="ip"?i:i.join(",")),a!=null&&t.set("country",a.join(",")),r!=null&&t.set("fuzzyMatch",r?"true":"false"),o!=null&&t.set("autocomplete",o?"true":"false")}async function It(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`geocoding/${encodeURIComponent(t)}.json`,y.maptilerApiURL),{searchParams:i}=n;X(i,e);const a=n.toString(),r=await L(a);if(!r.ok)throw new A(r,E[r.status]??"");return await r.json()}async function wt(t,e={}){if(!Array.isArray(t)||t.length<2)throw new Error("The position must be an array of form [lng, lat].");const n=new URL(`geocoding/${t[0]},${t[1]}.json`,y.maptilerApiURL);Z(n.searchParams,e);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,E[a.status]??"");return await a.json()}async function Rt(t,e={}){const n=new URL(`geocoding/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),J(n.searchParams,e);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,E[a.status]??"");return await a.json()}async function vt(t,e={}){if(!t.length)return[];const n=t.map(c=>encodeURIComponent(c)).join(";"),i=new URL(`geocoding/${n}.json`,y.maptilerApiURL),{searchParams:a}=i;X(a,e);const r=i.toString(),o=await L(r);if(!o.ok)throw new A(o,E[o.status]??"");const s=await o.json();return t.length===1?[s]:s}const Ut={forward:It,reverse:wt,byId:Rt,batch:vt,language:k},Q={403:"Key is missing, invalid or restricted"};async function Dt(t={}){const e=new URL("geolocation/ip.json",y.maptilerApiURL);e.searchParams.set("key",t.apiKey??m.apiKey);const n=e.toString(),i=await L(n);if(!i.ok)throw new A(i,i.status in Q?Q[i.status]:"");return await i.json()}const kt={info:Dt},P={403:"Key is missing, invalid or restricted"};async function $t(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`coordinates/search/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),"limit"in e&&n.searchParams.set("limit",e.limit.toString()),"transformations"in e&&n.searchParams.set("transformations",e.transformations.toString()),"exports"in e&&n.searchParams.set("exports",e.exports.toString());const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,a.status in P?P[a.status]:"");return await a.json()}async function Et(t,e={}){const n=(Array.isArray(t[0])?t:[t]).map(o=>`${o[0]},${o[1]}`).join(";"),i=new URL(`coordinates/transform/${n}.json`,y.maptilerApiURL);i.searchParams.set("key",e.apiKey??m.apiKey),"sourceCrs"in e&&i.searchParams.set("s_srs",e.sourceCrs.toString()),"targetCrs"in e&&i.searchParams.set("t_srs",e.targetCrs.toString()),"operations"in e&&i.searchParams.set("ops",(Array.isArray(e.operations)?e.operations:[e.operations]).join("|"));const a=i.toString(),r=await L(a);if(!r.ok)throw new A(r,r.status in P?P[r.status]:"");return await r.json()}const Pt={search:$t,transform:Et},tt={403:"Key is missing, invalid or restricted"};async function Nt(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The data ID must be a non-empty string");const n=new URL(`data/${encodeURIComponent(t)}/features.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,a.status in tt?tt[a.status]:"");return await a.json()}const Mt={get:Nt};function et(t){const e=/^maptiler:\/\/(.*)/;let n;const i=t.trim();let a;return i.startsWith("http://")||i.startsWith("https://")?a=i:(n=e.exec(i))!==null?a=`https://api.maptiler.com/maps/${n[1]}/style.json`:a=`https://api.maptiler.com/maps/${i}/style.json`,a}class C{constructor(e,n,i,a,r,o){this.name=e,this.variantType=n,this.id=i,this.referenceStyle=a,this.description=r,this.imageURL=o}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(e){return this.referenceStyle.hasVariant(e)}getVariant(e){return this.referenceStyle.getVariant(e)}getVariants(){return this.referenceStyle.getVariants().filter(e=>e!==this)}getImageURL(){return this.imageURL}getExpandedStyleURL(){return et(this.getId())}}class K{constructor(e,n){this.name=e,this.id=n,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(e){this.variants[e.getType()]=e,this.orderedVariants.push(e)}hasVariant(e){return e in this.variants}getVariant(e){return e in this.variants?this.variants[e]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const N=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function bt(t){return new Proxy(t,{get(e,n,i){return e.hasVariant(n)?e.getVariant(n):n.toString().toUpperCase()===n?t.getDefaultVariant():Reflect.get(e,n,i)}})}function Ct(){const t={};for(let e=0;e<N.length;e+=1){const n=N[e],i=bt(new K(n.name,n.referenceStyleID));for(let a=0;a<n.variants.length;a+=1){const r=n.variants[a],o=new C(r.name,r.variantType,r.id,i,r.description,r.imageURL);i.addVariant(o)}t[n.referenceStyleID]=i}return t}function M(t){if(!t)return nt[N[0].referenceStyleID].getDefaultVariant().getId();if(typeof t=="string"||t instanceof String)return t.trim().toLowerCase();if(t instanceof C)return t.getId();if(t instanceof K)return t.getDefaultVariant().getId()}const nt=Ct();function Kt(t){const e=[];function n(r){(r.type==="LineString"||r.type==="MultiLineString")&&e.push(r)}function i(r){r.geometry&&n(r.geometry)}function a(r){for(const o of r.features)o.type==="Feature"?i(o):o.type==="FeatureCollection"&&a(o)}return t.type==="Feature"?i(t):t.type==="FeatureCollection"?a(t):n(t),e}function xt(t,e,n){let i=e[0],a=e[1],r=n[0]-i,o=n[1]-a;if(r!==0||o!==0){const s=((t[0]-i)*r+(t[1]-a)*o)/(r*r+o*o);s>1?(i=n[0],a=n[1]):s>0&&(i+=r*s,a+=o*s)}return r=t[0]-i,o=t[1]-a,r*r+o*o}function x(t,e,n,i,a){let r=i,o;for(let s=e+1;s<n;s++){const c=xt(t[s],t[e],t[n]);c>r&&(o=s,r=c)}r>i&&(o-e>1&&x(t,e,o,i,a),a.push(t[o]),n-o>1&&x(t,o,n,i,a))}function Ot(t,e){const n=t.length-1,i=[t[0]];return x(t,0,n,e,i),i.push(t[n]),i}function jt(t,e){if(t.length<=2)return t;const n=e!==void 0?e*e:1;return Ot(t,n)}const it={extractLineStrings:Kt,simplify:jt};function O(t,e=!0){let n=`${t[0]},${t[1]}`;return t.length===3&&e&&(n+=`,${t[2]}`),n}function j(t,e=3e3){let n=t.map(r=>r.join(",")).join("|"),i=5e-6;const a=1e-5;for(;n.length>e;)n=it.simplify(t,i).map(r=>`${r[0]},${r[1]}`).join("|"),i+=a;return n}function Ht(t,e,n={}){const i=M(n.style),a=n.hiDPI?"@2x":"",r=n.format??"png";let o=~~(n.width??1024),s=~~(n.height??1024);n.hiDPI&&(o=~~(o/2),s=~~(s/2));const c=new URL(`maps/${encodeURIComponent(i)}/static/${t[0]},${t[1]},${e}/${o}x${s}${a}.${r}`,y.maptilerApiURL);if("attribution"in n&&c.searchParams.set("attribution",n.attribution.toString()),"markers"in n){let h="";const l="markerIcon"in n;l&&(h+=`icon:${n.markerIcon}|`),l&&"markerAnchor"in n&&(h+=`anchor:${n.markerAnchor}|`),l&&n.hiDPI&&(h+="scale:2|");const S=Array.isArray(n.markers[0])?n.markers:[n.markers];h+=S.map(g=>O(g,!l)).join("|"),c.searchParams.set("markers",h)}if("path"in n){let h="";if(h+=`fill:${n.pathFillColor??"none"}|`,"pathStrokeColor"in n&&(h+=`stroke:${n.pathStrokeColor}|`),"pathWidth"in n){const l=n.pathWidth/(n.hiDPI?2:1);h+=`width:${l.toString()}|`}h+=j(n.path),c.searchParams.set("path",h)}return c.searchParams.set("key",n.apiKey??m.apiKey),c.toString()}function Vt(t,e={}){const n=M(e.style),i=e.hiDPI?"@2x":"",a=e.format??"png";let r=~~(e.width??1024),o=~~(e.height??1024);e.hiDPI&&(r=~~(r/2),o=~~(o/2));const s=new URL(`maps/${encodeURIComponent(n)}/static/${t[0]},${t[1]},${t[2]},${t[3]}/${r}x${o}${i}.${a}`,y.maptilerApiURL);if("attribution"in e&&s.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&s.searchParams.set("padding",e.padding.toString()),"markers"in e){let c="";const h="markerIcon"in e;h&&(c+=`icon:${e.markerIcon}|`),h&&"markerAnchor"in e&&(c+=`anchor:${e.markerAnchor}|`),h&&e.hiDPI&&(c+="scale:2|");const l=Array.isArray(e.markers[0])?e.markers:[e.markers];c+=l.map(S=>O(S,!h)).join("|"),s.searchParams.set("markers",c)}if("path"in e){let c="";if(c+=`fill:${e.pathFillColor??"none"}|`,"pathStrokeColor"in e&&(c+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const h=e.pathWidth/(e.hiDPI?2:1);c+=`width:${h.toString()}|`}c+=j(e.path),s.searchParams.set("path",c)}return s.searchParams.set("key",e.apiKey??m.apiKey),s.toString()}function Ft(t={}){if(!("markers"in t)&&!("path"in t))throw new Error("Automatic static maps require markers and/or path to be created.");const e=M(t.style),n=t.hiDPI?"@2x":"",i=t.format??"png";let a=~~(t.width??1024),r=~~(t.height??1024);t.hiDPI&&(a=~~(a/2),r=~~(r/2));const o=new URL(`maps/${encodeURIComponent(e)}/static/auto/${a}x${r}${n}.${i}`,y.maptilerApiURL);if("attribution"in t&&o.searchParams.set("attribution",t.attribution.toString()),"padding"in t&&o.searchParams.set("padding",t.padding.toString()),"markers"in t){let s="";const c="markerIcon"in t;c&&(s+=`icon:${t.markerIcon}|`),c&&"markerAnchor"in t&&(s+=`anchor:${t.markerAnchor}|`),c&&t.hiDPI&&(s+="scale:2|");const h=Array.isArray(t.markers[0])?t.markers:[t.markers];s+=h.map(l=>O(l,!c)).join("|"),o.searchParams.set("markers",s)}if("path"in t){let s="";if(s+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(s+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const c=t.pathWidth/(t.hiDPI?2:1);s+=`width:${c.toString()}|`}s+=j(t.path),o.searchParams.set("path",s)}return o.searchParams.set("key",t.apiKey??m.apiKey),o.toString()}const Gt={centered:Ht,bounded:Vt,automatic:Ft},b=63710088e-1,at=2*Math.PI*b;function rt(t){return(180+t)/360}function ot(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}function st(t){const e=ht(t);return[rt(e[0]),ot(e[1])]}function ct(t){return t*360-180}function pt(t){const e=180-t*360;return 360/Math.PI*Math.atan(Math.exp(e*Math.PI/180))-90}function Bt(t){return[ct(t[0]),pt(t[1])]}function H(t,e){const n=Math.PI/180,i=t[1]*n,a=e[1]*n,r=Math.sin(i)*Math.sin(a)+Math.cos(i)*Math.cos(a)*Math.cos((e[0]-t[0])*n);return b*Math.acos(Math.min(r,1))}function _t(t){const e=Array(t.length);e[0]=0;const n=e.length;for(let i=1;i<n;i++)e[i]=H(t[i-1],t[i])+e[i-1];return e}function ht(t){const e=t[0],n=t[1],i=360,a=((e+180)%i+i)%i-180;return[a===-180?180:a,n]}function lt(t){return at*Math.cos(t*Math.PI/180)}function mt(t,e,n=!0){const i=2**e,a=[t[0]*i,t[1]*i];return n?[~~a[0],~~a[1]]:a}function zt(t,e,n=!0){const i=st(t);return mt(i,e,n)}function $(t){return t*Math.PI/180}function V(t){return t*180/Math.PI}function Wt(t,e,n){const i=H(t,e),a=$(t[0]),r=$(t[1]),o=$(e[0]),s=$(e[1]),c=i/b,h=Math.sin((1-n)*c)/Math.sin(c),l=Math.sin(n*c)/Math.sin(c),S=h*Math.cos(r)*Math.cos(a)+l*Math.cos(s)*Math.cos(o),g=h*Math.cos(r)*Math.sin(a)+l*Math.cos(s)*Math.sin(o),w=h*Math.sin(r)+l*Math.sin(s),v=Math.atan2(w,Math.sqrt(S*S+g*g)),R=Math.atan2(g,S);return[V(R),V(v)]}const F={EARTH_RADIUS:b,EARTH_CIRCUMFERENCE:at,longitudeToMercatorX:rt,latitudeToMercatorY:ot,wgs84ToMercator:st,mercatorXToLongitude:ct,mercatorYToLatitude:pt,mercatorToWgs84:Bt,haversineDistanceWgs84:H,wrapWgs84:ht,circumferenceAtLatitude:lt,mercatorToTileIndex:mt,wgs84ToTileIndex:zt,toRadians:$,toDegrees:V,haversineIntermediateWgs84:Wt,haversineCumulatedDistanceWgs84:_t};let G=null;function B(){return G||(G=new At({maxSize:m.tileCacheSize})),G}async function ut(t){const e=new Blob([t]),n=await createImageBitmap(e),i=document.createElement("canvas"),a=i.getContext("2d");i.width=n.width,i.height=n.height,a.drawImage(n,0,0);const r=a.getImageData(0,0,i.width,i.height);return{pixels:r.data,width:i.width,height:i.height,components:r.data.length/(i.width*i.height)}}function _(){if(m.bufferToPixelData)return m.bufferToPixelData;if(typeof window<"u")return ut;throw new Error("An image file buffer to pixel data parser is necessary. Specify it in `config.bufferToPixelData`")}const qt="tiles/terrain-rgb-v2/tiles.json";let I=null;const z={403:"Key is missing, invalid or restricted"};async function gt(t){const e=new URL(qt,y.maptilerApiURL);e.searchParams.set("key",t);const n=e.toString(),i=await L(n);if(i.ok)return I=await i.json(),I;if(!i.ok)throw new A(i,z[i.status]??"")}async function Yt(t,e={}){const n=e.apiKey??m.apiKey;I||await gt(n);const i=I.maxzoom;let a=~~(e.zoom??i);(a>i||a<0)&&(a=i);const r=F.wgs84ToTileIndex(t,a,!1),o=~~r[0],s=~~r[1];if(!I.tiles.length)throw new Error("Terrain tileJSON tile list is empty.");const c=`terrain_${a.toString()}_${o.toString()}_${s.toString()}`;let h;const l=B();if(l.has(c))h=l.get(c);else{const T=I.tiles[0].replace("{x}",o.toString()).replace("{y}",s.toString()).replace("{z}",a.toString()),u=await L(T);if(!u.ok)throw new A(u,z[u.status]??"");const d=await u.arrayBuffer();h=await _()(d),l.set(c,h)}const S=~~(h.width*(r[0]%1)),g=(~~(h.height*(r[1]%1))*h.width+S)*h.components,w=h.pixels[g],v=h.pixels[g+1],R=h.pixels[g+2],p=-1e4+(w*256*256+v*256+R)*.1;return[t[0],t[1],p]}async function W(t,e={}){const n=e.apiKey??m.apiKey;I||await gt(n);const i=_(),a=I.tiles[0],r=B(),o=I.maxzoom;let s=~~(e.zoom??o);(s>o||s<0)&&(s=o);const c=t.map(p=>F.wgs84ToTileIndex(p,s,!1)),h=c.map(p=>[~~p[0],~~p[1]]).map(p=>`terrain_${s.toString()}_${p[0].toString()}_${p[1].toString()}`),l=Array.from(new Set(h.filter(p=>!r.has(p)))).map(p=>p.split("_").slice(1)),S=l.map(p=>a.replace("{x}",p[1].toString()).replace("{y}",p[2].toString()).replace("{z}",p[0].toString())).map(p=>L(p)),g=(await Promise.allSettled(S)).map(p=>p.status==="fulfilled"?p.value:null).filter(p=>p),w=g.filter(p=>!p.ok);if(g.length!==S.length)throw new Error("Some tiles could not be fetched.");if(w.length)throw new A(w[0],z[w[0].status]??"");const v=await Promise.all(g.map(p=>p.arrayBuffer()));if(!v.every(p=>p.byteLength>0))throw new Error("Some tiles are not available.");(await Promise.all(v.map(p=>i(p)))).forEach((p,T)=>{const u=l[T],d=`terrain_${u[0].toString()}_${u[1].toString()}_${u[2].toString()}`;r.set(d,p)});const R=t.map((p,T)=>{const u=h[T],d=c[T],f=r.get(u),U=Math.min(Math.round(f.width*(d[0]%1)),f.width-1),D=(Math.min(Math.round(f.height*(d[1]%1)),f.height-1)*f.width+U)*f.components,dt=f.pixels[D],ft=f.pixels[D+1],yt=f.pixels[D+2],St=-1e4+(dt*256*256+ft*256+yt)*.1;return[p[0],p[1],~~(St*1e3)/1e3]});if(e.smoothingKernelSize){const p=~~(e.smoothingKernelSize/2)*2+1,T=R.map(d=>d[2]),u=~~(p/2);for(let d=u;d<T.length-u-1;d+=1){let f=0;for(let U=0;U<p;U+=1){const D=T[d-u+U];f+=D}f/=p,R[d][2]=f}}return R}async function Jt(t,e={}){if(t.type!=="LineString")throw new Error("The provided object is not a GeoJSON LineString");const n=structuredClone(t),i=await W(n.coordinates,e);return n.coordinates=i,n}async function Zt(t,e={}){if(t.type!=="MultiLineString")throw new Error("The provided object is not a GeoJSON MultiLineString");const n=structuredClone(t),i=n.coordinates.map(c=>c.length),a=n.coordinates.flat(),r=await W(a,e),o=[];let s=0;for(const c of i)o.push(r.slice(s,s+c)),s+=c;return n.coordinates=o,n}const Xt={at:Yt,batch:W,fromLineString:Jt,fromMultiLineString:Zt};export{q as ClientConfig,k as LanguageGeocoding,nt as MapStyle,C as MapStyleVariant,K as ReferenceMapStyle,A as ServiceError,ut as bufferToPixelDataBrowser,lt as circumferenceAtLatitude,m as config,Pt as coordinates,Mt as data,Xt as elevation,et as expandMapStyle,Ut as geocoding,kt as geolocation,Y as getAutoLanguageGeocoding,_ as getBufferToPixelDataParser,B as getTileCache,N as mapStylePresetList,F as math,it as misc,Gt as staticMaps,M as styleToStyle};
|