@maptiler/client 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptiler-client.cjs +482 -309
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +177 -13
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +471 -309
- package/dist/maptiler-client.mjs.map +1 -1
- package/dist/maptiler-client.umd.js +483 -310
- package/dist/maptiler-client.umd.js.map +1 -1
- package/dist/maptiler-client.umd.min.js +1 -1
- package/examples/test-node.js +9 -9
- package/package.json +25 -18
- package/readme.md +1 -1
- package/rollup.config.js +3 -3
- package/src/callFetch.ts +2 -2
- package/src/config.ts +4 -1
- package/src/demProfiler/getElevation.ts +46 -0
- package/src/demProfiler/index.ts +240 -0
- package/src/demProfiler/tileCover.ts +96 -0
- package/src/geometry/area.ts +96 -0
- package/src/geometry/distance.ts +45 -0
- package/src/geometry/index.ts +3 -0
- package/src/geometry/util.ts +34 -0
- package/src/index.ts +3 -0
- package/src/language.ts +1 -1
- package/src/mapstyle.ts +5 -5
- package/src/services/ServiceError.ts +5 -2
- package/src/services/coordinates.ts +14 -9
- package/src/services/data.ts +3 -3
- package/src/services/geocoding.ts +113 -32
- package/src/services/geolocation.ts +2 -2
- package/src/services/simplify.ts +3 -3
- package/src/services/staticMaps.ts +9 -9
- package/tsconfig.json +1 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/custom.css +0 -118
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/config.ClientConfig.html +0 -132
- package/docs/classes/services_ServiceError.ServiceError.html +0 -103
- package/docs/functions/language.getAutoLanguageGeocoding.html +0 -60
- package/docs/functions/services_simplify.default.html +0 -65
- package/docs/images/JS-logo.svg +0 -4
- package/docs/images/TS-logo.svg +0 -6
- package/docs/images/maptiler-client-logo.afdesign +0 -0
- package/docs/images/maptiler-client-logo.svg +0 -75
- package/docs/images/maptiler-logo-256.png +0 -0
- package/docs/images/maptiler-logo.svg +0 -23
- package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/docs/images/screenshots/static-with-path.png +0 -0
- package/docs/index.html +0 -340
- package/docs/modules/config.html +0 -71
- package/docs/modules/language.html +0 -71
- package/docs/modules/services_ServiceError.html +0 -61
- package/docs/modules/services_coordinates.html +0 -84
- package/docs/modules/services_data.html +0 -66
- package/docs/modules/services_geocoding.html +0 -82
- package/docs/modules/services_geolocation.html +0 -68
- package/docs/modules/services_simplify.html +0 -61
- package/docs/modules/services_staticMaps.html +0 -74
- package/docs/modules.html +0 -59
- package/docs/types/config.FetchFunction.html +0 -71
- package/docs/types/language.LanguageGeocodingString.html +0 -58
- package/docs/types/services_coordinates.CoordinateExport.html +0 -71
- package/docs/types/services_coordinates.CoordinateGrid.html +0 -69
- package/docs/types/services_coordinates.CoordinateId.html +0 -71
- package/docs/types/services_coordinates.CoordinateSearch.html +0 -93
- package/docs/types/services_coordinates.CoordinateSearchResult.html +0 -75
- package/docs/types/services_coordinates.CoordinateTransformResult.html +0 -76
- package/docs/types/services_coordinates.CoordinateTransformation.html +0 -89
- package/docs/types/services_coordinates.CoordinatesSearchOptions.html +0 -83
- package/docs/types/services_coordinates.CoordinatesTransformOptions.html +0 -85
- package/docs/types/services_coordinates.XYZ.html +0 -73
- package/docs/types/services_data.GetDataOptions.html +0 -64
- package/docs/types/services_geocoding.ByIdGeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.Coordinates.html +0 -63
- package/docs/types/services_geocoding.FeatureHierarchy.html +0 -74
- package/docs/types/services_geocoding.GeocodingFeature.html +0 -63
- package/docs/types/services_geocoding.GeocodingOptions.html +0 -63
- package/docs/types/services_geocoding.GeocodingSearchResult.html +0 -80
- package/docs/types/services_geocoding.LanguageGeocodingOptions.html +0 -70
- package/docs/types/services_geocoding.ReverseGeocodingOptions.html +0 -63
- package/docs/types/services_geolocation.GeolocationInfoOptions.html +0 -65
- package/docs/types/services_geolocation.GeolocationResult.html +0 -128
- package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +0 -61
- package/docs/types/services_staticMaps.StaticMapBaseOptions.html +0 -157
- package/docs/types/services_staticMaps.StaticMapMarker.html +0 -61
- package/docs/variables/config.config.html +0 -58
- package/docs/variables/language.LanguageGeocoding.html +0 -171
- package/docs/variables/services_coordinates.coordinates.html +0 -110
- package/docs/variables/services_data.data.html +0 -80
- package/docs/variables/services_geocoding.geocoding.html +0 -265
- package/docs/variables/services_geolocation.geolocation.html +0 -79
- package/docs/variables/services_staticMaps.staticMaps.html +0 -128
- package/docsmd/.nojekyll +0 -1
- package/docsmd/README.md +0 -880
- package/docsmd/assets/custom.css +0 -118
- package/docsmd/classes/ClientConfig.md +0 -90
- package/docsmd/classes/MapStyleVariant.md +0 -234
- package/docsmd/classes/ReferenceMapStyle.md +0 -169
- package/docsmd/classes/ServiceError.md +0 -52
- package/images/JS-logo.svg +0 -4
- package/images/TS-logo.svg +0 -6
- package/images/maptiler-client-logo.afdesign +0 -0
- package/images/maptiler-client-logo.svg +0 -75
- package/images/maptiler-logo-256.png +0 -0
- package/images/maptiler-logo.svg +0 -23
- package/images/screenshots/static-bounded-europe-1024.png +0 -0
- package/images/screenshots/static-bounded-europe-2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
- package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
- package/images/screenshots/static-with-path.png +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { llToTile } from "web-merc-projection";
|
|
2
|
+
import {
|
|
3
|
+
pointDistance,
|
|
4
|
+
getZoomLevelResolution,
|
|
5
|
+
xyzToTileID,
|
|
6
|
+
} from "../geometry";
|
|
7
|
+
|
|
8
|
+
import type { Point } from "web-merc-projection";
|
|
9
|
+
|
|
10
|
+
export interface TileID {
|
|
11
|
+
id: number;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TileCoverCoordinates {
|
|
18
|
+
/** Store the coordinates as an ll-pair */
|
|
19
|
+
coordinate: Point;
|
|
20
|
+
/** Track the tile relative to the point */
|
|
21
|
+
tile: TileID;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TileCoverOutput {
|
|
25
|
+
coords: TileCoverCoordinates[];
|
|
26
|
+
tiles: TileID[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Given LineString coordinates, return the web mercator tiles that all the points contain.
|
|
31
|
+
* Breaks the coordinates down into points that are relative to the zoom.
|
|
32
|
+
*/
|
|
33
|
+
export default function tileCover(
|
|
34
|
+
coordinates: GeoJSON.Position[],
|
|
35
|
+
zoom: number,
|
|
36
|
+
tileSize: number,
|
|
37
|
+
): TileCoverOutput {
|
|
38
|
+
const tileHash = new Map<number, TileID>(); // tileHash => { id, x, y, z }
|
|
39
|
+
const tiles: TileID[] = [];
|
|
40
|
+
const coords: TileCoverCoordinates[] = [];
|
|
41
|
+
|
|
42
|
+
// get the resolution of the zoom level
|
|
43
|
+
const resolution = getZoomLevelResolution(coordinates[0][1], zoom, tileSize);
|
|
44
|
+
|
|
45
|
+
// migrate from coordinates to "samples" that are relative to the zoom
|
|
46
|
+
const samples = sampleProfileLine(coordinates, resolution);
|
|
47
|
+
|
|
48
|
+
for (const sample of samples) {
|
|
49
|
+
const coordinate = sample as unknown as [lon: number, lat: number];
|
|
50
|
+
// file the file that the coordinate is in
|
|
51
|
+
const [tileX, tileY] = llToTile(coordinate, zoom, tileSize);
|
|
52
|
+
// create the tile and store it
|
|
53
|
+
const id = xyzToTileID(tileX, tileY, zoom);
|
|
54
|
+
const tile: TileID = { id, x: tileX, y: tileY, z: zoom };
|
|
55
|
+
tileHash.set(id, tile);
|
|
56
|
+
// store the coordinates
|
|
57
|
+
coords.push({ coordinate, tile });
|
|
58
|
+
}
|
|
59
|
+
// store the tiles we've found
|
|
60
|
+
for (const tile of tileHash.values()) tiles.push(tile);
|
|
61
|
+
|
|
62
|
+
return { coords, tiles };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** convert coordinates to samples that have a max distance of the zoom level resolution */
|
|
66
|
+
function sampleProfileLine(
|
|
67
|
+
coordinates: GeoJSON.Position[],
|
|
68
|
+
resolution: number,
|
|
69
|
+
): GeoJSON.Position[] {
|
|
70
|
+
const samples: GeoJSON.Position[] = [];
|
|
71
|
+
|
|
72
|
+
let prevCoord: GeoJSON.Position | undefined;
|
|
73
|
+
for (const coord of coordinates) {
|
|
74
|
+
if (prevCoord !== undefined) {
|
|
75
|
+
const dist = pointDistance(
|
|
76
|
+
prevCoord as unknown as [lon: number, lat: number],
|
|
77
|
+
coord as unknown as [lon: number, lat: number],
|
|
78
|
+
);
|
|
79
|
+
const numSamples = Math.ceil(dist / resolution);
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i <= numSamples - 1; i++) {
|
|
82
|
+
const sample = [
|
|
83
|
+
prevCoord[0] + (coord[0] - prevCoord[0]) * (i / numSamples),
|
|
84
|
+
prevCoord[1] + (coord[1] - prevCoord[1]) * (i / numSamples),
|
|
85
|
+
];
|
|
86
|
+
samples.push(sample);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
samples.push(coord);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
prevCoord = coord;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return samples;
|
|
96
|
+
}
|
|
@@ -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,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
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(
|
|
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?:
|
|
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
|
|
package/src/services/data.ts
CHANGED
|
@@ -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
|
|