@maptiler/client 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/maptiler-client.cjs +482 -309
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +114 -5
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +471 -309
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +483 -310
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/package.json +25 -18
  11. package/readme.md +1 -1
  12. package/rollup.config.js +3 -3
  13. package/src/callFetch.ts +2 -2
  14. package/src/config.ts +4 -1
  15. package/src/demProfiler/getElevation.ts +46 -0
  16. package/src/demProfiler/index.ts +240 -0
  17. package/src/demProfiler/tileCover.ts +96 -0
  18. package/src/geometry/area.ts +96 -0
  19. package/src/geometry/distance.ts +45 -0
  20. package/src/geometry/index.ts +3 -0
  21. package/src/geometry/util.ts +34 -0
  22. package/src/index.ts +3 -0
  23. package/src/language.ts +1 -1
  24. package/src/mapstyle.ts +5 -5
  25. package/src/services/ServiceError.ts +5 -2
  26. package/src/services/coordinates.ts +14 -9
  27. package/src/services/data.ts +3 -3
  28. package/src/services/geocoding.ts +17 -14
  29. package/src/services/geolocation.ts +2 -2
  30. package/src/services/simplify.ts +3 -3
  31. package/src/services/staticMaps.ts +9 -9
  32. package/tsconfig.json +1 -1
  33. package/docs/.nojekyll +0 -1
  34. package/docs/assets/custom.css +0 -118
  35. package/docs/assets/highlight.css +0 -85
  36. package/docs/assets/main.js +0 -58
  37. package/docs/assets/search.js +0 -1
  38. package/docs/assets/style.css +0 -1280
  39. package/docs/classes/config.ClientConfig.html +0 -132
  40. package/docs/classes/services_ServiceError.ServiceError.html +0 -103
  41. package/docs/functions/language.getAutoLanguageGeocoding.html +0 -60
  42. package/docs/functions/services_simplify.default.html +0 -65
  43. package/docs/images/JS-logo.svg +0 -4
  44. package/docs/images/TS-logo.svg +0 -6
  45. package/docs/images/maptiler-client-logo.afdesign +0 -0
  46. package/docs/images/maptiler-client-logo.svg +0 -75
  47. package/docs/images/maptiler-logo-256.png +0 -0
  48. package/docs/images/maptiler-logo.svg +0 -23
  49. package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
  50. package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
  51. package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  52. package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  53. package/docs/images/screenshots/static-with-path.png +0 -0
  54. package/docs/index.html +0 -340
  55. package/docs/modules/config.html +0 -71
  56. package/docs/modules/language.html +0 -71
  57. package/docs/modules/services_ServiceError.html +0 -61
  58. package/docs/modules/services_coordinates.html +0 -84
  59. package/docs/modules/services_data.html +0 -66
  60. package/docs/modules/services_geocoding.html +0 -82
  61. package/docs/modules/services_geolocation.html +0 -68
  62. package/docs/modules/services_simplify.html +0 -61
  63. package/docs/modules/services_staticMaps.html +0 -74
  64. package/docs/modules.html +0 -59
  65. package/docs/types/config.FetchFunction.html +0 -71
  66. package/docs/types/language.LanguageGeocodingString.html +0 -58
  67. package/docs/types/services_coordinates.CoordinateExport.html +0 -71
  68. package/docs/types/services_coordinates.CoordinateGrid.html +0 -69
  69. package/docs/types/services_coordinates.CoordinateId.html +0 -71
  70. package/docs/types/services_coordinates.CoordinateSearch.html +0 -93
  71. package/docs/types/services_coordinates.CoordinateSearchResult.html +0 -75
  72. package/docs/types/services_coordinates.CoordinateTransformResult.html +0 -76
  73. package/docs/types/services_coordinates.CoordinateTransformation.html +0 -89
  74. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +0 -83
  75. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +0 -85
  76. package/docs/types/services_coordinates.XYZ.html +0 -73
  77. package/docs/types/services_data.GetDataOptions.html +0 -64
  78. package/docs/types/services_geocoding.ByIdGeocodingOptions.html +0 -63
  79. package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +0 -63
  80. package/docs/types/services_geocoding.Coordinates.html +0 -63
  81. package/docs/types/services_geocoding.FeatureHierarchy.html +0 -63
  82. package/docs/types/services_geocoding.GeocodingFeature.html +0 -63
  83. package/docs/types/services_geocoding.GeocodingOptions.html +0 -63
  84. package/docs/types/services_geocoding.GeocodingSearchResult.html +0 -80
  85. package/docs/types/services_geocoding.LanguageGeocodingOptions.html +0 -70
  86. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +0 -63
  87. package/docs/types/services_geolocation.GeolocationInfoOptions.html +0 -65
  88. package/docs/types/services_geolocation.GeolocationResult.html +0 -128
  89. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +0 -61
  90. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +0 -61
  91. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +0 -61
  92. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +0 -157
  93. package/docs/types/services_staticMaps.StaticMapMarker.html +0 -61
  94. package/docs/variables/config.config.html +0 -58
  95. package/docs/variables/language.LanguageGeocoding.html +0 -171
  96. package/docs/variables/services_coordinates.coordinates.html +0 -110
  97. package/docs/variables/services_data.data.html +0 -80
  98. package/docs/variables/services_geocoding.geocoding.html +0 -265
  99. package/docs/variables/services_geolocation.geolocation.html +0 -79
  100. package/docs/variables/services_staticMaps.staticMaps.html +0 -128
  101. package/docsmd/.nojekyll +0 -1
  102. package/docsmd/README.md +0 -873
  103. package/docsmd/assets/custom.css +0 -118
  104. package/docsmd/classes/ClientConfig.md +0 -90
  105. package/docsmd/classes/MapStyleVariant.md +0 -234
  106. package/docsmd/classes/ReferenceMapStyle.md +0 -169
  107. package/docsmd/classes/ServiceError.md +0 -52
  108. package/images/JS-logo.svg +0 -4
  109. package/images/TS-logo.svg +0 -6
  110. package/images/maptiler-client-logo.afdesign +0 -0
  111. package/images/maptiler-client-logo.svg +0 -75
  112. package/images/maptiler-logo-256.png +0 -0
  113. package/images/maptiler-logo.svg +0 -23
  114. package/images/screenshots/static-bounded-europe-1024.png +0 -0
  115. package/images/screenshots/static-bounded-europe-2048.png +0 -0
  116. package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  117. package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  118. package/images/screenshots/static-with-path.png +0 -0
@@ -0,0 +1,96 @@
1
+ // ripped from https://github.com/Turfjs/turf/blob/master/packages/turf-area/index.ts
2
+ import { degToRad, earthRadius } from "./util";
3
+
4
+ /**
5
+ * Finds the area of a Polygon or MultiPolygon in square meters.
6
+ */
7
+ export function area(
8
+ area:
9
+ | GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>
10
+ | GeoJSON.Polygon
11
+ | GeoJSON.MultiPolygon,
12
+ ) {
13
+ const geometry = "geometry" in area ? area.geometry : area;
14
+ const type = geometry.type;
15
+ if (type === "MultiPolygon") {
16
+ return multiPolygonArea(geometry.coordinates);
17
+ }
18
+ return polygonArea(geometry.coordinates);
19
+ }
20
+
21
+ /**
22
+ * Finds the area of a MultiPolygon in square meters.
23
+ */
24
+ export function multiPolygonArea(
25
+ multiPoly: GeoJSON.MultiPolygon | GeoJSON.Position[][][],
26
+ ): number {
27
+ const coords = "coordinates" in multiPoly ? multiPoly.coordinates : multiPoly;
28
+ let total = 0;
29
+ for (const polygon of coords) {
30
+ total += polygonArea(polygon);
31
+ }
32
+ return total;
33
+ }
34
+
35
+ /**
36
+ * Finds the area of a Polygon in square meters.
37
+ */
38
+ export function polygonArea(
39
+ poly: GeoJSON.Polygon | GeoJSON.Position[][],
40
+ ): number {
41
+ const coords = "coordinates" in poly ? poly.coordinates : poly;
42
+ let total = 0;
43
+ for (const ring of coords) {
44
+ total += ringArea(ring);
45
+ }
46
+ return total;
47
+ }
48
+
49
+ /**
50
+ * Calculate the approximate area of the polygon were it projected onto the earth.
51
+ * Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.
52
+ *
53
+ * Reference:
54
+ * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for Polygons on a Sphere",
55
+ * JPL Publication 07-03, Jet Propulsion
56
+ * Laboratory, Pasadena, CA, June 2007 https://trs.jpl.nasa.gov/handle/2014/40409
57
+ */
58
+ function ringArea(coords: GeoJSON.Position[]): number {
59
+ let p1;
60
+ let p2;
61
+ let p3;
62
+ let lowerIndex;
63
+ let middleIndex;
64
+ let upperIndex;
65
+ let i;
66
+ let total = 0;
67
+ const coordsLength = coords.length;
68
+
69
+ if (coordsLength > 2) {
70
+ for (i = 0; i < coordsLength; i++) {
71
+ if (i === coordsLength - 2) {
72
+ // i = N-2
73
+ lowerIndex = coordsLength - 2;
74
+ middleIndex = coordsLength - 1;
75
+ upperIndex = 0;
76
+ } else if (i === coordsLength - 1) {
77
+ // i = N-1
78
+ lowerIndex = coordsLength - 1;
79
+ middleIndex = 0;
80
+ upperIndex = 1;
81
+ } else {
82
+ // i = 0 to N-3
83
+ lowerIndex = i;
84
+ middleIndex = i + 1;
85
+ upperIndex = i + 2;
86
+ }
87
+ p1 = coords[lowerIndex];
88
+ p2 = coords[middleIndex];
89
+ p3 = coords[upperIndex];
90
+ total += (degToRad(p3[0]) - degToRad(p1[0])) * Math.sin(degToRad(p2[1]));
91
+ }
92
+
93
+ total = (total * earthRadius * earthRadius) / 2;
94
+ }
95
+ return Math.abs(total);
96
+ }
@@ -0,0 +1,45 @@
1
+ import { earthRadius, degToRad } from "./util";
2
+
3
+ /** Get the distance of a LineString in meters */
4
+ export function lineDistance(
5
+ line:
6
+ | GeoJSON.Feature<GeoJSON.LineString>
7
+ | GeoJSON.LineString
8
+ | GeoJSON.Position[],
9
+ ) {
10
+ // grab the coordinates
11
+ const coordinates =
12
+ "geometry" in line
13
+ ? line.geometry.coordinates
14
+ : "coordinates" in line
15
+ ? line.coordinates
16
+ : line;
17
+ // iterate through the coordinates and calculate the distance
18
+ let distance = 0;
19
+ let prevCoord: GeoJSON.Position | undefined;
20
+ for (const coordinate of coordinates) {
21
+ if (prevCoord !== undefined) {
22
+ distance += pointDistance(prevCoord, coordinate);
23
+ }
24
+ prevCoord = coordinate;
25
+ }
26
+
27
+ return distance;
28
+ }
29
+
30
+ /** Get the distance between two lon-lat pairs in meters */
31
+ export function pointDistance(
32
+ from: GeoJSON.Position,
33
+ to: GeoJSON.Position,
34
+ ): number {
35
+ const { pow, sin, cos, sqrt, atan2 } = Math;
36
+ const dLat = degToRad(to[1] - from[1]);
37
+ const dLon = degToRad(to[0] - from[0]);
38
+ const lat1 = degToRad(from[1]);
39
+ const lat2 = degToRad(to[1]);
40
+
41
+ const a =
42
+ pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
43
+
44
+ return 2 * atan2(sqrt(a), sqrt(1 - a)) * earthRadius;
45
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./area";
2
+ export * from "./distance";
3
+ export * from "./util";
@@ -0,0 +1,34 @@
1
+ export const earthRadius = 6371008.8;
2
+
3
+ /** Convert meters to feet */
4
+ export function mToFt(m: number): number {
5
+ return m * 3.28084;
6
+ }
7
+
8
+ /** Convert degrees to Radians */
9
+ export function degToRad(degrees: number): number {
10
+ return ((degrees % 360) * Math.PI) / 180;
11
+ }
12
+
13
+ /** Convert radians to degrees */
14
+ export function radToDeg(radians: number): number {
15
+ return (radians * 180) / Math.PI;
16
+ }
17
+
18
+ /** Given a latitude and zoom level, determine the max distance each segment can be in meters */
19
+ export function getZoomLevelResolution(
20
+ latitude: number,
21
+ zoom: number,
22
+ tileSize = 512,
23
+ ): number {
24
+ return (
25
+ ((Math.cos((latitude * Math.PI) / 180.0) * 2 * Math.PI * 6378137) /
26
+ (tileSize * 2 ** zoom)) *
27
+ 3
28
+ );
29
+ }
30
+
31
+ /** Convert a tile's zoom-x-y to a number hash */
32
+ export function xyzToTileID(x: number, y: number, zoom: number): number {
33
+ return ((1 << zoom) * y + x) * 32 + zoom;
34
+ }
package/src/index.ts CHANGED
@@ -56,6 +56,9 @@ import {
56
56
  expandMapStyle,
57
57
  } from "./mapstyle";
58
58
 
59
+ export * from "./demProfiler";
60
+ export * from "./geometry";
61
+
59
62
  // Exporting types
60
63
  export type {
61
64
  Position,
package/src/language.ts CHANGED
@@ -76,7 +76,7 @@ function getAutoLanguageGeocoding(): LanguageGeocodingString {
76
76
  }
77
77
 
78
78
  const canditatelangs = Array.from(
79
- new Set(navigator.languages.map((l) => l.split("-")[0]))
79
+ new Set(navigator.languages.map((l) => l.split("-")[0])),
80
80
  ).filter((l) => languageCodeSet.has(l as LanguageGeocodingString));
81
81
 
82
82
  return canditatelangs.length
package/src/mapstyle.ts CHANGED
@@ -72,7 +72,7 @@ export class MapStyleVariant {
72
72
  /**
73
73
  * URL to an image describing the style variant
74
74
  */
75
- private imageURL: string
75
+ private imageURL: string,
76
76
  ) {}
77
77
 
78
78
  /**
@@ -186,7 +186,7 @@ export class ReferenceMapStyle {
186
186
  /**
187
187
  * ID of this reference style
188
188
  */
189
- private id: string
189
+ private id: string,
190
190
  ) {}
191
191
 
192
192
  /**
@@ -913,7 +913,7 @@ function buildMapStyles(): MapStyleType {
913
913
  const refStyleInfo = mapStylePresetList[i];
914
914
 
915
915
  const refStyle = makeReferenceStyleProxy(
916
- new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID)
916
+ new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID),
917
917
  );
918
918
 
919
919
  for (let j = 0; j < refStyleInfo.variants.length; j += 1) {
@@ -924,7 +924,7 @@ function buildMapStyles(): MapStyleType {
924
924
  variantInfo.id, // id
925
925
  refStyle, // referenceStyle
926
926
  variantInfo.description,
927
- variantInfo.imageURL // imageURL
927
+ variantInfo.imageURL, // imageURL
928
928
  );
929
929
 
930
930
  refStyle.addVariant(variant);
@@ -935,7 +935,7 @@ function buildMapStyles(): MapStyleType {
935
935
  }
936
936
 
937
937
  export function styleToStyle(
938
- style: string | ReferenceMapStyle | MapStyleVariant | null | undefined
938
+ style: string | ReferenceMapStyle | MapStyleVariant | null | undefined,
939
939
  ): string {
940
940
  if (!style) {
941
941
  return MapStyle[mapStylePresetList[0].referenceStyleID]
@@ -2,9 +2,12 @@
2
2
  * A ServiceError is an Error that includes the HTTP response details
3
3
  */
4
4
  export class ServiceError extends Error {
5
- constructor(public res: Response, customMessage = "") {
5
+ constructor(
6
+ public res: Response,
7
+ customMessage = "",
8
+ ) {
6
9
  super(
7
- `Call to enpoint ${res.url} failed with the status code ${res.status}. ${customMessage}`
10
+ `Call to enpoint ${res.url} failed with the status code ${res.status}. ${customMessage}`,
8
11
  );
9
12
  }
10
13
  }
@@ -83,11 +83,16 @@ export type CoordinateSearch = {
83
83
  /**
84
84
  * Most suitable transformation for this CRS.
85
85
  */
86
- default_transformation?: any;
86
+ default_transformation?: DefaultTransformation;
87
87
 
88
88
  exports: CoordinateExport;
89
89
  };
90
90
 
91
+ export type DefaultTransformation = {
92
+ authority: string;
93
+ code: number;
94
+ };
95
+
91
96
  export type CoordinateSearchResult = {
92
97
  /**
93
98
  * The coordinate search results
@@ -109,7 +114,7 @@ export type CoordinateSearchResult = {
109
114
  */
110
115
  async function search(
111
116
  query: string,
112
- options: CoordinatesSearchOptions = {}
117
+ options: CoordinatesSearchOptions = {},
113
118
  ): Promise<CoordinateSearchResult> {
114
119
  if (typeof query !== "string" || query.trim().length === 0) {
115
120
  throw new Error("The query must be a non-empty string");
@@ -117,7 +122,7 @@ async function search(
117
122
 
118
123
  const endpoint = new URL(
119
124
  `coordinates/search/${query}.json`,
120
- defaults.maptilerApiURL
125
+ defaults.maptilerApiURL,
121
126
  );
122
127
  endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
123
128
 
@@ -128,7 +133,7 @@ async function search(
128
133
  if ("transformations" in options) {
129
134
  endpoint.searchParams.set(
130
135
  "transformations",
131
- options.transformations.toString()
136
+ options.transformations.toString(),
132
137
  );
133
138
  }
134
139
 
@@ -142,7 +147,7 @@ async function search(
142
147
  if (!res.ok) {
143
148
  throw new ServiceError(
144
149
  res,
145
- res.status in customMessages ? customMessages[res.status] : ""
150
+ res.status in customMessages ? customMessages[res.status] : "",
146
151
  );
147
152
  }
148
153
 
@@ -202,7 +207,7 @@ export type CoordinatesTransformOptions = {
202
207
  */
203
208
  async function transform(
204
209
  positions: Position | Array<Position>,
205
- options: CoordinatesTransformOptions = {}
210
+ options: CoordinatesTransformOptions = {},
206
211
  ): Promise<CoordinateTransformResult> {
207
212
  const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions])
208
213
  .map((coord) => `${coord[0]},${coord[1]}`)
@@ -210,7 +215,7 @@ async function transform(
210
215
 
211
216
  const endpoint = new URL(
212
217
  `coordinates/transform/${coordinatesStr}.json`,
213
- defaults.maptilerApiURL
218
+ defaults.maptilerApiURL,
214
219
  );
215
220
  endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
216
221
 
@@ -228,7 +233,7 @@ async function transform(
228
233
  (Array.isArray(options.operations)
229
234
  ? options.operations
230
235
  : [options.operations]
231
- ).join("|")
236
+ ).join("|"),
232
237
  );
233
238
  }
234
239
 
@@ -238,7 +243,7 @@ async function transform(
238
243
  if (!res.ok) {
239
244
  throw new ServiceError(
240
245
  res,
241
- res.status in customMessages ? customMessages[res.status] : ""
246
+ res.status in customMessages ? customMessages[res.status] : "",
242
247
  );
243
248
  }
244
249
 
@@ -26,7 +26,7 @@ export type GetDataOptions = {
26
26
  */
27
27
  async function get(
28
28
  dataId: string,
29
- options: GetDataOptions = {}
29
+ options: GetDataOptions = {},
30
30
  ): Promise<FeatureCollection> {
31
31
  if (typeof dataId !== "string" || dataId.trim().length === 0) {
32
32
  throw new Error("The data ID must be a non-empty string");
@@ -34,7 +34,7 @@ async function get(
34
34
 
35
35
  const endpoint = new URL(
36
36
  `data/${encodeURIComponent(dataId)}/features.json`,
37
- defaults.maptilerApiURL
37
+ defaults.maptilerApiURL,
38
38
  );
39
39
  endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
40
40
  const urlWithParams = endpoint.toString();
@@ -44,7 +44,7 @@ async function get(
44
44
  if (!res.ok) {
45
45
  throw new ServiceError(
46
46
  res,
47
- res.status in customMessages ? customMessages[res.status] : ""
47
+ res.status in customMessages ? customMessages[res.status] : "",
48
48
  );
49
49
  }
50
50
 
@@ -85,7 +85,9 @@ export type GeocodingOptions = CommonForwardAndReverseGeocodingOptions & {
85
85
 
86
86
  export type ReverseGeocodingOptions = CommonForwardAndReverseGeocodingOptions;
87
87
 
88
- export type ByIdGeocodingOptions = LanguageGeocodingOptions;
88
+ export type ByIdGeocodingOptions = LanguageGeocodingOptions & {
89
+ apiKey?: string;
90
+ };
89
91
 
90
92
  export type Coordinates = Position;
91
93
 
@@ -231,7 +233,7 @@ export type GeocodingSearchResult = {
231
233
 
232
234
  function addLanguageGeocodingOptions(
233
235
  searchParams: URLSearchParams,
234
- options: LanguageGeocodingOptions
236
+ options: LanguageGeocodingOptions,
235
237
  ) {
236
238
  if (options.language == undefined) {
237
239
  return;
@@ -243,9 +245,9 @@ function addLanguageGeocodingOptions(
243
245
  ? options.language
244
246
  : [options.language]
245
247
  ).map((lang) =>
246
- lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
247
- )
248
- )
248
+ lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang,
249
+ ),
250
+ ),
249
251
  ).join(",");
250
252
 
251
253
  searchParams.set("language", languages);
@@ -253,7 +255,7 @@ function addLanguageGeocodingOptions(
253
255
 
254
256
  function addCommonForwardAndReverseGeocodingOptions(
255
257
  searchParams: URLSearchParams,
256
- options: CommonForwardAndReverseGeocodingOptions
258
+ options: CommonForwardAndReverseGeocodingOptions,
257
259
  ) {
258
260
  searchParams.set("key", options.apiKey ?? config.apiKey);
259
261
 
@@ -270,7 +272,7 @@ function addCommonForwardAndReverseGeocodingOptions(
270
272
 
271
273
  function addForwardGeocodingOptions(
272
274
  searchParams: URLSearchParams,
273
- options: GeocodingOptions
275
+ options: GeocodingOptions,
274
276
  ) {
275
277
  addCommonForwardAndReverseGeocodingOptions(searchParams, options);
276
278
 
@@ -306,7 +308,7 @@ function addForwardGeocodingOptions(
306
308
  */
307
309
  async function forward(
308
310
  query: string,
309
- options: GeocodingOptions = {}
311
+ options: GeocodingOptions = {},
310
312
  ): Promise<GeocodingSearchResult> {
311
313
  if (typeof query !== "string" || query.trim().length === 0) {
312
314
  throw new Error("The query must be a non-empty string");
@@ -314,7 +316,7 @@ async function forward(
314
316
 
315
317
  const endpoint = new URL(
316
318
  `geocoding/${encodeURIComponent(query)}.json`,
317
- defaults.maptilerApiURL
319
+ defaults.maptilerApiURL,
318
320
  );
319
321
 
320
322
  const { searchParams } = endpoint;
@@ -344,7 +346,7 @@ async function forward(
344
346
  */
345
347
  async function reverse(
346
348
  position: Position,
347
- options: ReverseGeocodingOptions = {}
349
+ options: ReverseGeocodingOptions = {},
348
350
  ): Promise<GeocodingSearchResult> {
349
351
  if (!Array.isArray(position) || position.length < 2) {
350
352
  throw new Error("The position must be an array of form [lng, lat].");
@@ -352,7 +354,7 @@ async function reverse(
352
354
 
353
355
  const endpoint = new URL(
354
356
  `geocoding/${position[0]},${position[1]}.json`,
355
- defaults.maptilerApiURL
357
+ defaults.maptilerApiURL,
356
358
  );
357
359
 
358
360
  addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
@@ -381,9 +383,10 @@ async function reverse(
381
383
  */
382
384
  async function byId(
383
385
  id: string,
384
- options: ByIdGeocodingOptions = {}
386
+ options: ByIdGeocodingOptions = {},
385
387
  ): Promise<GeocodingSearchResult> {
386
388
  const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
389
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
387
390
 
388
391
  addLanguageGeocodingOptions(endpoint.searchParams, options);
389
392
 
@@ -410,7 +413,7 @@ async function byId(
410
413
  */
411
414
  async function batch(
412
415
  queries: string[],
413
- options: GeocodingOptions = {}
416
+ options: GeocodingOptions = {},
414
417
  ): Promise<GeocodingSearchResult[]> {
415
418
  if (!queries.length) {
416
419
  return [];
@@ -422,7 +425,7 @@ async function batch(
422
425
 
423
426
  const endpoint = new URL(
424
427
  `geocoding/${joinedQuery}.json`,
425
- defaults.maptilerApiURL
428
+ defaults.maptilerApiURL,
426
429
  );
427
430
 
428
431
  const { searchParams } = endpoint;
@@ -109,7 +109,7 @@ export type GeolocationResult = {
109
109
  * @returns
110
110
  */
111
111
  async function info(
112
- options: GeolocationInfoOptions = {}
112
+ options: GeolocationInfoOptions = {},
113
113
  ): Promise<GeolocationResult> {
114
114
  const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
115
115
  endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
@@ -120,7 +120,7 @@ async function info(
120
120
  if (!res.ok) {
121
121
  throw new ServiceError(
122
122
  res,
123
- res.status in customMessages ? customMessages[res.status] : ""
123
+ res.status in customMessages ? customMessages[res.status] : "",
124
124
  );
125
125
  }
126
126
 
@@ -34,7 +34,7 @@ function simplifyDPStep(
34
34
  first: number,
35
35
  last: number,
36
36
  sqTolerance: number,
37
- simplified: Array<Position>
37
+ simplified: Array<Position>,
38
38
  ) {
39
39
  let maxSqDist = sqTolerance,
40
40
  index;
@@ -63,7 +63,7 @@ function simplifyDPStep(
63
63
  // simplification using Ramer-Douglas-Peucker algorithm
64
64
  function simplifyDouglasPeucker(
65
65
  points: Array<Position>,
66
- sqTolerance: number
66
+ sqTolerance: number,
67
67
  ): Array<Position> {
68
68
  const last = points.length - 1;
69
69
  const simplified = [points[0]];
@@ -75,7 +75,7 @@ function simplifyDouglasPeucker(
75
75
  // both algorithms combined for awesome performance
76
76
  export default function simplify(
77
77
  points: Array<Position>,
78
- tolerance: number
78
+ tolerance: number,
79
79
  ): Array<Position> {
80
80
  if (points.length <= 2) {
81
81
  return points;
@@ -155,12 +155,12 @@ export type StaticMapMarker = [
155
155
  /**
156
156
  * Color of the marker with CSS syntax. Applies only if a custom `markerIcon` is not provided.
157
157
  */
158
- string
158
+ string,
159
159
  ];
160
160
 
161
161
  function staticMapMarkerToString(
162
162
  marker: StaticMapMarker,
163
- includeColor = true
163
+ includeColor = true,
164
164
  ): string {
165
165
  let str = `${marker[0]},${marker[1]}`;
166
166
 
@@ -199,7 +199,7 @@ function simplifyAndStringify(path: Array<Position>, maxNbChar = 3000): string {
199
199
  function centered(
200
200
  center: Position,
201
201
  zoom: number,
202
- options: CenteredStaticMapOptions = {}
202
+ options: CenteredStaticMapOptions = {},
203
203
  ): string {
204
204
  const style = styleToStyle(options.style);
205
205
  const scale = options.hiDPI ? "@2x" : "";
@@ -216,7 +216,7 @@ function centered(
216
216
  `maps/${encodeURIComponent(style)}/static/${center[0]},${
217
217
  center[1]
218
218
  },${zoom}/${width}x${height}${scale}.${format}`,
219
- defaults.maptilerApiURL
219
+ defaults.maptilerApiURL,
220
220
  );
221
221
 
222
222
  if ("attribution" in options) {
@@ -283,7 +283,7 @@ function centered(
283
283
  */
284
284
  function bounded(
285
285
  boundingBox: BBox,
286
- options: BoundedStaticMapOptions = {}
286
+ options: BoundedStaticMapOptions = {},
287
287
  ): string {
288
288
  const style = styleToStyle(options.style);
289
289
  const scale = options.hiDPI ? "@2x" : "";
@@ -300,7 +300,7 @@ function bounded(
300
300
  `maps/${encodeURIComponent(style)}/static/${boundingBox[0]},${
301
301
  boundingBox[1]
302
302
  },${boundingBox[2]},${boundingBox[3]}/${width}x${height}${scale}.${format}`,
303
- defaults.maptilerApiURL
303
+ defaults.maptilerApiURL,
304
304
  );
305
305
 
306
306
  if ("attribution" in options) {
@@ -371,7 +371,7 @@ function bounded(
371
371
  function automatic(options: AutomaticStaticMapOptions = {}): string {
372
372
  if (!("markers" in options) && !("path" in options)) {
373
373
  throw new Error(
374
- "Automatic static maps require markers and/or path to be created."
374
+ "Automatic static maps require markers and/or path to be created.",
375
375
  );
376
376
  }
377
377
 
@@ -388,9 +388,9 @@ function automatic(options: AutomaticStaticMapOptions = {}): string {
388
388
 
389
389
  const endpoint = new URL(
390
390
  `maps/${encodeURIComponent(
391
- style
391
+ style,
392
392
  )}/static/auto/${width}x${height}${scale}.${format}`,
393
- defaults.maptilerApiURL
393
+ defaults.maptilerApiURL,
394
394
  );
395
395
 
396
396
  if ("attribution" in options) {
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "moduleResolution": "Node",
3
+ "moduleResolution": "Bundler",
4
4
  "target": "es6",
5
5
  "declaration": true,
6
6
  "allowSyntheticDefaultImports": true,
package/docs/.nojekyll DELETED
@@ -1 +0,0 @@
1
- TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.