-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathfindElevationAtPoint.ts
More file actions
90 lines (81 loc) · 2.54 KB
/
Copy pathfindElevationAtPoint.ts
File metadata and controls
90 lines (81 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
request,
appendCustomParams,
IRequestOptions
} from "@esri/arcgis-rest-request";
import { operations } from "./openapi-types.js";
import { baseUrl } from "./utils.js";
// determine the list of allowed params we want to allow as options
// this should match the array given to appendCustomParams below
type queryParams = Pick<
operations["ElevationAtPointGet"]["parameters"]["query"],
"lon" | "lat" | "relativeTo"
>;
// get the correct type of the response format
type successResponse =
operations["ElevationAtPointGet"]["responses"]["200"]["content"]["application/json"];
/**
* The response format for {@linkcode findElevationAtPoint};
*/
export interface IFindElevationAtPointResponse extends successResponse {}
type IRequestOptionsWithoutHttpMethod = Omit<
IRequestOptions,
"fetchOptions"
> & {
fetchOptions?: Omit<RequestInit, "method">;
};
/**
* Options for {@linkcode findElevationAtPoint}.
*/
export interface IFindElevationAtPointOptions
extends IRequestOptionsWithoutHttpMethod,
queryParams {}
/**
* This method returns the elevation in meters at a given longitude and latitude
* within the WGS84 coordinate system. By default the elevation is measured with
* respect to the Earth's mean sea level. It takes into account the local
* variations in gravity and provides a consistent vertical reference.
*
* If the relativeTo query parameter is set to `ellipsoid`, the elevation will be
* measured with respect to the ellipsoid. This is a mathematical model that
* approximates the shape of the Earth. It does not consider local variations
* in gravity and is commonly used in GPS positioning.
*
* ```
* import { findElevationAtPoint } from "@esri/arcgis-rest-elevation";
* import { ApiKeyManager } from "@esri/arcgis-rest-request";
*
* const results = await findElevationAtPoint({
* lon: -179.99,
* lat: -85.05,
* authentication: ApiKeyManager.fromKey("YOUR_ACCESS_TOKEN");
* });
*
* console.log(results)
* ```
*/
export function findElevationAtPoint(
requestOptions: IFindElevationAtPointOptions
): Promise<IFindElevationAtPointResponse> {
const options = appendCustomParams<IFindElevationAtPointOptions>(
requestOptions,
["lon", "lat", "relativeTo"],
{
...requestOptions
}
);
return (
request(`${baseUrl}/elevation/at-point`, {
...options,
fetchOptions: {
...options.fetchOptions,
method: "GET"
}
}) as Promise<successResponse>
).then((response) => {
const r: IFindElevationAtPointResponse = {
...response
};
return r;
});
}