@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,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A ServiceError is an Error that includes the HTTP response details
|
|
3
|
-
*/
|
|
4
|
-
export class ServiceError extends Error {
|
|
5
|
-
constructor(
|
|
6
|
-
public res: Response,
|
|
7
|
-
customMessage = "",
|
|
8
|
-
) {
|
|
9
|
-
super(
|
|
10
|
-
`Call to enpoint ${res.url} failed with the status code ${res.status}. ${customMessage}`,
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { BBox, Position } from "geojson";
|
|
2
|
-
import { callFetch } from "../callFetch";
|
|
3
|
-
import { config } from "../config";
|
|
4
|
-
import { defaults } from "../defaults";
|
|
5
|
-
import { ServiceError } from "./ServiceError";
|
|
6
|
-
|
|
7
|
-
const customMessages = {
|
|
8
|
-
403: "Key is missing, invalid or restricted",
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type CoordinatesSearchOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* Custom MapTiler Cloud API key to use instead of the one in global `config`
|
|
14
|
-
*/
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Maximum number of results returned (default: 10)
|
|
19
|
-
*/
|
|
20
|
-
limit?: number;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Show detailed transformations for each CRS (default: false)
|
|
24
|
-
*/
|
|
25
|
-
transformations?: boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Show exports in WKT and Proj4 notations (default: false)
|
|
29
|
-
*/
|
|
30
|
-
exports?: boolean;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type CoordinateId = {
|
|
34
|
-
authority: string;
|
|
35
|
-
code: BigInteger;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type CoordinateExport = {
|
|
39
|
-
proj4: string;
|
|
40
|
-
wkt: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type CoordinateGrid = {
|
|
44
|
-
path: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type CoordinateTransformation = {
|
|
48
|
-
id: CoordinateId;
|
|
49
|
-
name: string;
|
|
50
|
-
reversible: boolean;
|
|
51
|
-
usable: boolean;
|
|
52
|
-
deprecated: boolean;
|
|
53
|
-
grids: Array<CoordinateGrid>;
|
|
54
|
-
accuracy?: number;
|
|
55
|
-
area?: string;
|
|
56
|
-
bbox?: BBox;
|
|
57
|
-
target_crs?: CoordinateId;
|
|
58
|
-
unit?: string;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export type CoordinateSearch = {
|
|
62
|
-
id: CoordinateId;
|
|
63
|
-
|
|
64
|
-
name: string;
|
|
65
|
-
|
|
66
|
-
kind: string;
|
|
67
|
-
|
|
68
|
-
deprecated: boolean;
|
|
69
|
-
|
|
70
|
-
transformations?: Array<CoordinateTransformation | number>;
|
|
71
|
-
|
|
72
|
-
accuracy?: number;
|
|
73
|
-
|
|
74
|
-
unit?: string;
|
|
75
|
-
|
|
76
|
-
area?: string;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Bounding box of the resource in [min_lon, min_lat, max_lon, max_lat] order.
|
|
80
|
-
*/
|
|
81
|
-
bbox?: BBox;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Most suitable transformation for this CRS.
|
|
85
|
-
*/
|
|
86
|
-
default_transformation?: DefaultTransformation;
|
|
87
|
-
|
|
88
|
-
exports: CoordinateExport;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export type DefaultTransformation = {
|
|
92
|
-
authority: string;
|
|
93
|
-
code: number;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export type CoordinateSearchResult = {
|
|
97
|
-
/**
|
|
98
|
-
* The coordinate search results
|
|
99
|
-
*/
|
|
100
|
-
results: Array<CoordinateSearch>;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The number of results
|
|
104
|
-
*/
|
|
105
|
-
total: number;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Search information about coordinate systems using MapTiler API.
|
|
110
|
-
* Learn more on the MapTiler API reference page: https://docs.maptiler.com/cloud/api/coordinates/#search-coordinate-systems
|
|
111
|
-
* @param query Can be any kind of CRS by name or code
|
|
112
|
-
* @param options
|
|
113
|
-
* @returns
|
|
114
|
-
*/
|
|
115
|
-
async function search(
|
|
116
|
-
query: string,
|
|
117
|
-
options: CoordinatesSearchOptions = {},
|
|
118
|
-
): Promise<CoordinateSearchResult> {
|
|
119
|
-
if (typeof query !== "string" || query.trim().length === 0) {
|
|
120
|
-
throw new Error("The query must be a non-empty string");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const endpoint = new URL(
|
|
124
|
-
`coordinates/search/${query}.json`,
|
|
125
|
-
defaults.maptilerApiURL,
|
|
126
|
-
);
|
|
127
|
-
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
128
|
-
|
|
129
|
-
if ("limit" in options) {
|
|
130
|
-
endpoint.searchParams.set("limit", options.limit.toString());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if ("transformations" in options) {
|
|
134
|
-
endpoint.searchParams.set(
|
|
135
|
-
"transformations",
|
|
136
|
-
options.transformations.toString(),
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if ("exports" in options) {
|
|
141
|
-
endpoint.searchParams.set("exports", options.exports.toString());
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const urlWithParams = endpoint.toString();
|
|
145
|
-
const res = await callFetch(urlWithParams);
|
|
146
|
-
|
|
147
|
-
if (!res.ok) {
|
|
148
|
-
throw new ServiceError(
|
|
149
|
-
res,
|
|
150
|
-
res.status in customMessages ? customMessages[res.status] : "",
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const obj = await res.json();
|
|
155
|
-
return obj as CoordinateSearchResult;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type XYZ = {
|
|
159
|
-
x?: number;
|
|
160
|
-
y?: number;
|
|
161
|
-
z?: number;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export type CoordinateTransformResult = {
|
|
165
|
-
results: Array<XYZ>;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Transformations are selected using given ops parameter.
|
|
169
|
-
* If no parameter is given, auto strategy is used.
|
|
170
|
-
* If given, it may try to use a listed transformation,
|
|
171
|
-
* then fallback to towgs84 patching, and finally boundcrs.
|
|
172
|
-
*/
|
|
173
|
-
transformer_selection_strategy: string;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Options that can be provided when transforming a coordinate from one CRS to another.
|
|
178
|
-
*/
|
|
179
|
-
export type CoordinatesTransformOptions = {
|
|
180
|
-
/**
|
|
181
|
-
* Custom MapTiler Cloud API key to use instead of the one in global `config`
|
|
182
|
-
*/
|
|
183
|
-
apiKey?: string;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Source coordinate reference system (default: 4326)
|
|
187
|
-
*/
|
|
188
|
-
sourceCrs?: number;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Target coordinate reference system (default: 4326)
|
|
192
|
-
*/
|
|
193
|
-
targetCrs?: number;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* List of codes of operations
|
|
197
|
-
*/
|
|
198
|
-
operations?: number | Array<number>;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Transforms coordinates from a source reference system to a target reference system using MapTiler API.
|
|
203
|
-
* Learn more on the MapTiler API reference page: https://docs.maptiler.com/cloud/api/coordinates/#transform-coordinates
|
|
204
|
-
* @param positions
|
|
205
|
-
* @param options
|
|
206
|
-
* @returns
|
|
207
|
-
*/
|
|
208
|
-
async function transform(
|
|
209
|
-
positions: Position | Array<Position>,
|
|
210
|
-
options: CoordinatesTransformOptions = {},
|
|
211
|
-
): Promise<CoordinateTransformResult> {
|
|
212
|
-
const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions])
|
|
213
|
-
.map((coord) => `${coord[0]},${coord[1]}`)
|
|
214
|
-
.join(";");
|
|
215
|
-
|
|
216
|
-
const endpoint = new URL(
|
|
217
|
-
`coordinates/transform/${coordinatesStr}.json`,
|
|
218
|
-
defaults.maptilerApiURL,
|
|
219
|
-
);
|
|
220
|
-
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
221
|
-
|
|
222
|
-
if ("sourceCrs" in options) {
|
|
223
|
-
endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if ("targetCrs" in options) {
|
|
227
|
-
endpoint.searchParams.set("t_srs", options.targetCrs.toString());
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if ("operations" in options) {
|
|
231
|
-
endpoint.searchParams.set(
|
|
232
|
-
"ops",
|
|
233
|
-
(Array.isArray(options.operations)
|
|
234
|
-
? options.operations
|
|
235
|
-
: [options.operations]
|
|
236
|
-
).join("|"),
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const urlWithParams = endpoint.toString();
|
|
241
|
-
const res = await callFetch(urlWithParams);
|
|
242
|
-
|
|
243
|
-
if (!res.ok) {
|
|
244
|
-
throw new ServiceError(
|
|
245
|
-
res,
|
|
246
|
-
res.status in customMessages ? customMessages[res.status] : "",
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const obj = await res.json();
|
|
251
|
-
return obj as CoordinateTransformResult;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* The **coordinate** namespace contains asynchronous functions to call the [MapTiler Coordinate API](https://docs.maptiler.com/cloud/api/coordinates/).
|
|
256
|
-
* The goal of the **Coordinate API* is query information about spatial coordinate reference system (CRS) as well as to transform coordinates from one CRS to another.
|
|
257
|
-
*/
|
|
258
|
-
const coordinates = {
|
|
259
|
-
search,
|
|
260
|
-
transform,
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
export { coordinates };
|
package/src/services/data.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { FeatureCollection } from "geojson";
|
|
2
|
-
import { callFetch } from "../callFetch";
|
|
3
|
-
import { config } from "../config";
|
|
4
|
-
import { defaults } from "../defaults";
|
|
5
|
-
import { ServiceError } from "./ServiceError";
|
|
6
|
-
|
|
7
|
-
const customMessages = {
|
|
8
|
-
403: "Key is missing, invalid or restricted",
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Options that can be provided to get user data.
|
|
13
|
-
*/
|
|
14
|
-
export type GetDataOptions = {
|
|
15
|
-
/**
|
|
16
|
-
* Custom MapTiler Cloud API key to use instead of the one in global `config`
|
|
17
|
-
*/
|
|
18
|
-
apiKey?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get user data and returns it as GeoJSON using the MapTiler API.
|
|
23
|
-
* Learn more on the MapTiler API reference page: https://docs.maptiler.com/cloud/api/data/#geojson
|
|
24
|
-
* @param dataId
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
async function get(
|
|
28
|
-
dataId: string,
|
|
29
|
-
options: GetDataOptions = {},
|
|
30
|
-
): Promise<FeatureCollection> {
|
|
31
|
-
if (typeof dataId !== "string" || dataId.trim().length === 0) {
|
|
32
|
-
throw new Error("The data ID must be a non-empty string");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const endpoint = new URL(
|
|
36
|
-
`data/${encodeURIComponent(dataId)}/features.json`,
|
|
37
|
-
defaults.maptilerApiURL,
|
|
38
|
-
);
|
|
39
|
-
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
40
|
-
const urlWithParams = endpoint.toString();
|
|
41
|
-
|
|
42
|
-
const res = await callFetch(urlWithParams);
|
|
43
|
-
|
|
44
|
-
if (!res.ok) {
|
|
45
|
-
throw new ServiceError(
|
|
46
|
-
res,
|
|
47
|
-
res.status in customMessages ? customMessages[res.status] : "",
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const obj = await res.json();
|
|
52
|
-
return obj;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The **data** namespace contains an asynchronous function to call the [MapTiler Data API](https://docs.maptiler.com/cloud/api/data/).
|
|
57
|
-
* The **Data API** provides a way to retrieve user data in GeoJSON format.
|
|
58
|
-
*/
|
|
59
|
-
const data = {
|
|
60
|
-
get,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { data };
|