diff --git a/demos/node-elevation-api/.gitignore b/demos/node-elevation-api/.gitignore new file mode 100644 index 000000000..1dcef2d9f --- /dev/null +++ b/demos/node-elevation-api/.gitignore @@ -0,0 +1,2 @@ +node_modules +.env \ No newline at end of file diff --git a/demos/node-elevation-api/atManyPointsDefault.mock.json b/demos/node-elevation-api/atManyPointsDefault.mock.json new file mode 100644 index 000000000..f3d50ccf1 --- /dev/null +++ b/demos/node-elevation-api/atManyPointsDefault.mock.json @@ -0,0 +1,25 @@ +{ + "result": { + "points": [ + { + "x": 1.2, + "y": 3.4, + "z": -4458, + "spatialReference": { + "wkid": 4326 + } + }, + { + "x": 1.23, + "y": 3.45, + "z": -4452, + "spatialReference": { + "wkid": 4326 + } + } + ] + }, + "elevationInfo": { + "relativeTo": "meanSeaLevel" + } +} \ No newline at end of file diff --git a/demos/node-elevation-api/atManyPointsEllipsoid.mock.json b/demos/node-elevation-api/atManyPointsEllipsoid.mock.json new file mode 100644 index 000000000..2a8f7a72c --- /dev/null +++ b/demos/node-elevation-api/atManyPointsEllipsoid.mock.json @@ -0,0 +1,25 @@ +{ + "result": { + "points": [ + { + "x": 1.2, + "y": 3.4, + "z": -4441, + "spatialReference": { + "wkid": 4326 + } + }, + { + "x": 1.23, + "y": 3.45, + "z": -4435, + "spatialReference": { + "wkid": 4326 + } + } + ] + }, + "elevationInfo": { + "relativeTo": "ellipsoid" + } +} \ No newline at end of file diff --git a/demos/node-elevation-api/atPoint.mock.json b/demos/node-elevation-api/atPoint.mock.json new file mode 100644 index 000000000..3606cdbe0 --- /dev/null +++ b/demos/node-elevation-api/atPoint.mock.json @@ -0,0 +1,15 @@ +{ + "result": { + "point": { + "x": -3.1883, + "y": 55.9533, + "z": 116, + "spatialReference": { + "wkid": 4326 + } + } + }, + "elevationInfo": { + "relativeTo": "ellipsoid" + } +} \ No newline at end of file diff --git a/demos/node-elevation-api/atPointDefault.mock.json b/demos/node-elevation-api/atPointDefault.mock.json new file mode 100644 index 000000000..6e637cc88 --- /dev/null +++ b/demos/node-elevation-api/atPointDefault.mock.json @@ -0,0 +1,15 @@ +{ + "result": { + "point": { + "x": -3.1883, + "y": 55.9533, + "z": 63, + "spatialReference": { + "wkid": 4326 + } + } + }, + "elevationInfo": { + "relativeTo": "meanSeaLevel" + } +} \ No newline at end of file diff --git a/demos/node-elevation-api/index.ts b/demos/node-elevation-api/index.ts new file mode 100644 index 000000000..cc1fb76aa --- /dev/null +++ b/demos/node-elevation-api/index.ts @@ -0,0 +1,78 @@ +import { ApiKeyManager } from "@esri/arcgis-rest-request"; +import { + findElevationAtPoint, + findElevationAtManyPoints +} from "@esri/arcgis-rest-elevation"; +import * as dotenv from "dotenv"; +import fs from "fs"; + +dotenv.config(); + +const authentication = ApiKeyManager.fromKey(process.env.API_KEY as string); + +const atPointResponse = await findElevationAtPoint({ + lon: -3.1883, + lat: 55.9533, + relativeTo: "ellipsoid", + authentication +}); + +fs.promises.writeFile( + "./atPoint.mock.json", + JSON.stringify(atPointResponse, null, 2) +); + +console.log("Found elevation for atPoint (ellipsoid):", atPointResponse); + +const atPointDefaultResponse = await findElevationAtPoint({ + lon: -3.1883, + lat: 55.9533, + authentication +}); + +fs.promises.writeFile( + "./atPointDefault.mock.json", + JSON.stringify(atPointDefaultResponse, null, 2) +); + +console.log( + "Found elevation for atPoint (mean sea level):", + atPointDefaultResponse +); + +const atManyPointsDefaultResponse = await findElevationAtManyPoints({ + coordinates: [ + [1.2, 3.4], + [1.23, 3.45] + ], + authentication +}); + +fs.promises.writeFile( + "./atManyPointsDefault.mock.json", + JSON.stringify(atManyPointsDefaultResponse, null, 2) +); + +console.log( + "Found elevation for atManyPoints (mean sea level):", + atManyPointsDefaultResponse +); + +const atManyPointsEllipsoidResponse = await findElevationAtManyPoints({ + coordinates: [ + [1.2, 3.4], + [1.23, 3.45] + ], + relativeTo: "ellipsoid", + authentication +}); + +fs.promises.writeFile( + "./atManyPointsEllipsoid.mock.json", + JSON.stringify(atManyPointsEllipsoidResponse, null, 2) +); + +console.log( + "Found elevation for atManyPoints (ellipsoid):", + atManyPointsEllipsoidResponse +); diff --git a/demos/node-elevation-api/package.json b/demos/node-elevation-api/package.json new file mode 100644 index 000000000..5faaf6a5a --- /dev/null +++ b/demos/node-elevation-api/package.json @@ -0,0 +1,26 @@ +{ + "private": true, + "name": "node-elevation-api", + "version": "1.0.0", + "description": "", + "license": "MIT", + "keywords": [], + "type": "module", + "main": "index.js", + "scripts": { + "start": "ts-node index.ts" + }, + "dependencies": { + "@esri/arcgis-rest-elevation": "^1.0.0-beta.1", + "@esri/arcgis-rest-request": "^4.0.0" + }, + "devDependencies": { + "ts-node": "^10.7.0", + "typescript": "^4.6.2" + }, + "author": "Sheryl Tania", + "volta": { + "node": "16.14.0", + "npm": "8.5.3" + } +} diff --git a/demos/node-elevation-api/readme.md b/demos/node-elevation-api/readme.md new file mode 100644 index 000000000..ebfe16002 --- /dev/null +++ b/demos/node-elevation-api/readme.md @@ -0,0 +1,9 @@ +# Basic demo of the Elevation API + +1. Copy `.env.template` to `.env` and add your own API key which has the elevation service privilege enabled. +2. Run the following commands: + +```bash +npm install +npm run start +``` diff --git a/demos/node-elevation-api/tsconfig.json b/demos/node-elevation-api/tsconfig.json new file mode 100644 index 000000000..ef1ce9817 --- /dev/null +++ b/demos/node-elevation-api/tsconfig.json @@ -0,0 +1,104 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "esnext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "ts-node": { + "esm": true + } +} diff --git a/package-lock.json b/package-lock.json index 26ecab397..fa6e8f634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "packages/arcgis-rest-request", "packages/arcgis-rest-auth", "packages/arcgis-rest-demographics", + "packages/arcgis-rest-elevation", "packages/arcgis-rest-feature-service", "packages/arcgis-rest-geocoding", "packages/arcgis-rest-portal", @@ -308,6 +309,31 @@ "@esri/arcgis-rest-request": "^4.0.0" } }, + "demos/node-elevation-api": { + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "@esri/arcgis-rest-portal": "^4.0.0", + "@esri/arcgis-rest-request": "^4.0.0" + }, + "devDependencies": { + "ts-node": "^10.7.0", + "typescript": "^4.6.2" + } + }, + "demos/node-elevation-api/node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "demos/node-es-modules": { "name": "arcgis-rest-js-node-es-modules-integration-test", "version": "1.0.0", @@ -2956,6 +2982,10 @@ "resolved": "packages/arcgis-rest-developer-credentials", "link": true }, + "node_modules/@esri/arcgis-rest-elevation": { + "resolved": "packages/arcgis-rest-elevation", + "link": true + }, "node_modules/@esri/arcgis-rest-feature-service": { "resolved": "packages/arcgis-rest-feature-service", "link": true @@ -25443,6 +25473,10 @@ "node": ">=10.5.0" } }, + "node_modules/node-elevation-api": { + "resolved": "demos/node-elevation-api", + "link": true + }, "node_modules/node-emoji": { "version": "1.11.0", "dev": true, @@ -41032,6 +41066,23 @@ "node": ">=12.20.0" } }, + "packages/arcgis-rest-elevation": { + "name": "@esri/arcgis-rest-elevation", + "version": "1.0.0", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.3.0" + }, + "devDependencies": { + "@esri/arcgis-rest-request": "^4.0.1" + }, + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "@esri/arcgis-rest-request": "^4.0.0" + } + }, "packages/arcgis-rest-feature-service": { "name": "@esri/arcgis-rest-feature-service", "version": "4.1.0", diff --git a/package.json b/package.json index 54414f86c..850f67db2 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,7 @@ "packages/arcgis-rest-request", "packages/arcgis-rest-auth", "packages/arcgis-rest-demographics", + "packages/arcgis-rest-elevation", "packages/arcgis-rest-feature-service", "packages/arcgis-rest-geocoding", "packages/arcgis-rest-portal", diff --git a/packages/arcgis-rest-elevation/README.md b/packages/arcgis-rest-elevation/README.md new file mode 100644 index 000000000..30d18915c --- /dev/null +++ b/packages/arcgis-rest-elevation/README.md @@ -0,0 +1,84 @@ +[![npm version][npm-img]][npm-url] +[![gzip bundle size][gzip-image]][npm-url] +[![Coverage Status][coverage-img]][coverage-url] +[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE) + +[npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-elevation.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-elevation +[gzip-image]: https://img.badgesize.io/https://unpkg.com/@esri/arcgis-rest-elevation/dist/bundled/elevation.umd.min.js?compression=gzip +[coverage-img]: https://codecov.io/gh/Esri/arcgis-rest-js/branch/master/graph/badge.svg +[coverage-url]: https://codecov.io/gh/Esri/arcgis-rest-js + +# @esri/arcgis-rest-places + +> A wrapper class to access the ArcGIS Elevation service for [`@esri/arcgis-rest-request`](https://github.com/Esri/arcgis-rest-js). + +### Example + +```bash +npm install @esri/arcgis-rest-request +npm install @esri/arcgis-rest-elevation +``` + +```js +import { findElevationAtPoint } from "@esri/arcgis-rest-elevation"; +import { ApiKeyManager } from "@esri/arcgis-rest-request"; + +const response = await findElevationAtPoint({ + lon: -179.99, + lat: -85.05, + authentication: ApiKeyManager.fromKey("YOUR_ACCESS_TOKEN"); +}); + +console.log(response.result.point.z) +``` + +### API Reference + +@TODO + +### Issues + +If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you. + +If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss). + +### Versioning + +For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible. + +For more information on SemVer, please visit . + +### Contributing + +Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md). + +### Generating Types from Open API + +The places service publishes an Open API definition. Eventually this will live at a public URL on the service itself. However for now it lives inside the Esri internal GitHub Enterprise installation. To generate the types view the raw file on GitHub Enterprise and replace the URL below. + +``` +npx openapi-typescript@5 URL_TO_RAW_SPEC_FILE --output packages/arcgis-rest-places/src/openapi-types.ts +``` + +The generated types are used in the interfaces for ArcGIS REST JS. + +### [Changelog](https://github.com/Esri/arcgis-rest-js/blob/master/CHANGELOG.md) + +### License + +Copyright © 2023 Esri + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +> http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +A copy of the license is available in the repository's [LICENSE](../../LICENSE) file. diff --git a/packages/arcgis-rest-elevation/package.json b/packages/arcgis-rest-elevation/package.json new file mode 100644 index 000000000..00805bedf --- /dev/null +++ b/packages/arcgis-rest-elevation/package.json @@ -0,0 +1,75 @@ +{ + "name": "@esri/arcgis-rest-elevation", + "version": "1.0.0-beta.1", + "description": "Wrapper for the elevation service for @esri/arcgis-rest-js", + "license": "Apache-2.0", + "keywords": [ + "ES6", + "arcgis", + "esri", + "fetch", + "promise", + "typescript" + ], + "type": "module", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "unpkg": "dist/bundled/elevation.umd.min.js", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, + "types": "dist/esm/index.d.ts", + "sideEffects": false, + "files": [ + "dist/**" + ], + "scripts": { + "build": "npm-run-all --parallel build:*", + "postbuild": "node ../../scripts/create-dist-package-jsons.js", + "build:bundled": "rollup -c ../../rollup.js", + "build:cjs": "tsc --outDir ./dist/cjs -m commonjs", + "postbuild:cjs": "node ../../scripts/create-dist-package-jsons.js", + "build:esm": "tsc --outDir ./dist/esm --declaration", + "postbuild:esm": "node ../../scripts/create-dist-package-jsons.js", + "dev": "npm-run-all --parallel dev:*", + "dev:bundled": "rollup -w -c ../../rollup.js", + "dev:cjs": "tsc -w --outDir ./dist/cjs -m commonjs", + "dev:esm": "tsc -w --outDir ./dist/esm --declaration" + }, + "engines": { + "node": ">=12.20.0" + }, + "dependencies": { + "tslib": "^2.3.0" + }, + "peerDependencies": { + "@esri/arcgis-rest-request": "^4.0.0" + }, + "devDependencies": { + "@esri/arcgis-rest-request": "^4.0.1" + }, + "contributors": [ + "Patrick Arlt (http://patrickarlt.com/)", + "Sheryl Tania (http://sheryltania.com/)" + ], + "homepage": "https://github.com/Esri/arcgis-rest-js#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/Esri/arcgis-rest-js.git", + "directory": "packages/arcgis-rest-places" + }, + "bugs": { + "url": "https://github.com/Esri/arcgis-rest-js/issues" + }, + "publishConfig": { + "access": "public" + }, + "esri": { + "keyExports": [ + "@TODO" + ] + } +} diff --git a/packages/arcgis-rest-elevation/src/findElevationAtManyPoints.ts b/packages/arcgis-rest-elevation/src/findElevationAtManyPoints.ts new file mode 100644 index 000000000..d1b0e9017 --- /dev/null +++ b/packages/arcgis-rest-elevation/src/findElevationAtManyPoints.ts @@ -0,0 +1,89 @@ +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["ElevationAtManyPointsPost"]["requestBody"]["content"]["application/json"], + "coordinates" | "relativeTo" +>; + +// get the correct type of the response format +type successResponse = + operations["ElevationAtManyPointsPost"]["responses"]["200"]["content"]["application/json"]; + +/** + * The response format for {@linkcode findElevationAtPoint}; + */ +export interface IFindElevationAtManyPointsResponse extends successResponse {} + +/** + * Options for {@linkcode findElevationAtPoint}. + */ +export interface IFindElevationAtManyPointsOptions + extends Omit, + queryParams {} + +/** + * This method returns elevations in meters at given longitudes and latitudes + * within the WGS84 coordinate system. The order of the points returned by this + * request will be the same as the order of the points passed in the coordinates + * parameter. + * + * If the distance between the furthest West and furthest East coordinate or + * the furthest North and furthest South coordinate exceeds 50km, the service + * will return a 400 HTTP response as the distance between these points is too + * large. + * + * 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 { findElevationAtManyPoints } from "@esri/arcgis-rest-elevation"; + * import { ApiKeyManager } from "@esri/arcgis-rest-request"; + * + * const results = await findElevationAtManyPoints({ + * coordinates: [[31.134167, 29.979167], [31.130833, 29.976111], [31.128333, 29.9725]], + * authentication: ApiKeyManager.fromKey("YOUR_ACCESS_TOKEN"); + * }); + * + * console.log(results) + * ``` + */ +export function findElevationAtManyPoints( + requestOptions: IFindElevationAtManyPointsOptions +): Promise { + const options: any = appendCustomParams( + requestOptions, + ["relativeTo"], + { + ...requestOptions + } + ); + + options.params.coordinates = JSON.stringify(requestOptions.coordinates); + + return ( + request(`${baseUrl}/elevation/at-many-points`, { + ...options + }) as Promise + ).then((response) => { + const r: IFindElevationAtManyPointsResponse = { + ...response + }; + + return r; + }); +} diff --git a/packages/arcgis-rest-elevation/src/findElevationAtPoint.ts b/packages/arcgis-rest-elevation/src/findElevationAtPoint.ts new file mode 100644 index 000000000..0111cfbf4 --- /dev/null +++ b/packages/arcgis-rest-elevation/src/findElevationAtPoint.ts @@ -0,0 +1,80 @@ +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 {} + +/** + * Options for {@linkcode findElevationAtPoint}. + */ +export interface IFindElevationAtPointOptions + extends Omit, + 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 { + const options = appendCustomParams( + requestOptions, + ["lon", "lat", "relativeTo"], + { + ...requestOptions + } + ); + + return ( + request(`${baseUrl}/elevation/at-point`, { + ...options, + httpMethod: "GET" + }) as Promise + ).then((response) => { + const r: IFindElevationAtPointResponse = { + ...response + }; + + return r; + }); +} diff --git a/packages/arcgis-rest-elevation/src/index.ts b/packages/arcgis-rest-elevation/src/index.ts new file mode 100644 index 000000000..dca91e04a --- /dev/null +++ b/packages/arcgis-rest-elevation/src/index.ts @@ -0,0 +1,9 @@ +/* Copyright (c) 2023 Environmental Systems Research Institute, Inc. + * Apache-2.0 */ + +// Types that are used in this package are re-exported for convenience and +// to make the links work correctly in the documentation pages. +export type {} from "@esri/arcgis-rest-request"; + +export * from "./findElevationAtPoint.js"; +export * from "./findElevationAtManyPoints.js"; diff --git a/packages/arcgis-rest-elevation/src/openapi-types.ts b/packages/arcgis-rest-elevation/src/openapi-types.ts new file mode 100644 index 000000000..6ed87c3a1 --- /dev/null +++ b/packages/arcgis-rest-elevation/src/openapi-types.ts @@ -0,0 +1,476 @@ +/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + +export interface paths { + "/elevation/at-point": { + /** + * 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. + * + * Note: You cannot permanently store elevations. Please see the [Terms of use](https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/terms-of-use/). + */ + get: operations["ElevationAtPointGet"]; + }; + "/elevation/at-many-points": { + /** + * Returns elevations in meters at given longitudes and latitudes within the WGS84 coordinate system. + * + * The order of the points returned by this request will be the same as the order of the points passed in the + * `coordinates` parameter. + * + * If the distance between the furthest West and furthest East coordinate exceeds 50km, the service will return a `400` HTTP response as the distance between these points is too large. + * + * If the distance between the furthest North and furthest South coordinate exceeds 50km, the service will return a `400` HTTP response as the distance between these points is too large. + * + * If any of the points are otherwise invalid, a `400` HTTP response will be returned. + * + * 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` parameter in the body 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. + * + * Note: You cannot permanently store elevations. Please see the [Terms of use](https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/terms-of-use/). + * + * The Post Body content type must be either: + * - JSON with content type of `application/json`, or + * - form URL encoded key-value pairs with content type `application/x-www-form-urlencoded`. + * + * The following parameters are used to fetch elevations for multiple coordinates: + * + * **coordinates** + * - (Required) Array of (longitude, latitude) pairs in the WGS84 spatial reference. Maximum size of 100 coordinates. The order of each pair must be + * - longitude in the range `-179.99` to `179.99` representing the east/west or x-axis + * - latitude in the range `-85.05` to `85.05` representing the north/south or y-axis + * - For example: `[[31.134167, 29.979167], [31.130833, 29.976111], [31.128333, 29.9725]]` + * + * **f** + * - (Optional) Case-sensitive parameter to specify the format in which responses are given. Can either be `json` or `pjson`. + * + * **relativeTo** + * - (Optional) The reference position (datum) from which to measure elevation. The valid values are: + * + * - **meanSeaLevel**: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. It takes into account the local variations in gravity and provides a consistent vertical reference. + * - **ellipsoid**: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + * + * **token** + * - (Optional) The authentication token, used to access the elevation service. Alternatively, you can supply a token in the request header with either the `Authorization` or `X-Esri-Authorization` key, using the "Bearer" scheme. + */ + post: operations["ElevationAtManyPointsPost"]; + }; +} + +export interface components { + schemas: { + /** @description A geometry point referring to a location on a map. */ + Point: { + /** @description The spatial reference system the point is relative to. */ + spatialReference: { + /** + * @description The Well-Known ID (WKID) value of the spatial reference. + * @example 4326 + */ + wkid: number; + }; + /** + * @description The X coordinate which is measured along the east/west axis. + * @example 86.925278 + */ + x: number; + /** + * @description The Y coordinate which is measured along the north/south axis. + * @example 27.988333 + */ + y: number; + /** + * @description The Z coordinate represents the vertical position of a point above or below a reference level, such as sea level (in meters, rounded to the nearest meter). + * @example 8744 + */ + z: number; + }; + /** @description A structure containing human readable metadata about the specified point. */ + ElevationInfo: { + /** + * @description The reference position (datum) from which to measure elevation. + * The valid values are: + * - meanSeaLevel: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. + * It takes into account the local variations in gravity and provides a consistent vertical reference. + * - ellipsoid: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + * + * @default meanSeaLevel + * @example meanSeaLevel + * @enum {string} + */ + relativeTo: "meanSeaLevel" | "ellipsoid"; + }; + /** @description A structure containing a point including an elevation value (defined as Z). */ + Elevation: { + /** @description The point containing the elevation. */ + point: components["schemas"]["Point"]; + }; + /** + * @description A structure containing a collection of points which contain elevation values (defined as Z). When returned from + * a request to the `/elevation/at-many-points` endpoint, the order of the points will match the order of the + * points in the request. + */ + Elevations: { + points: components["schemas"]["Point"][]; + }; + Error: { + /** @description Error information */ + error: { + /** + * @description A code identifying the type of error, either an HTTP error code, `498` (signifying invalid or expired token), or `499` (signifying missing token). + * @example 400 + * @enum {integer} + */ + code: 400 | 401 | 403 | 404 | 413 | 415 | 498 | 499 | 500; + /** @description A message describing the error. */ + message: string; + /** @description List of details about the error. */ + details?: string[]; + /** + * @description URL that provides the elevation service information. + * @example https://elevation-api.arcgis.com/arcgis/rest/info + */ + restInfoUrl?: string; + }; + }; + /** + * @description Optional, case-sensitive parameter to specify the format in which responses are given. Can either be `json` or `pjson`. + * @enum {string} + */ + Format: "json" | "pjson"; + }; + responses: { + /** Response to a request for the elevation at a specified point. */ + ElevationResponse: { + content: { + "application/json": { + elevationInfo: components["schemas"]["ElevationInfo"]; + result: components["schemas"]["Elevation"]; + }; + }; + }; + /** + * Response to a request for the elevations at specified points. There will be one response point for each point + * in the request. The order of these points will match the order of the points in the request. + */ + MultipleElevationsResponse: { + content: { + "application/json": { + elevationInfo: components["schemas"]["ElevationInfo"]; + result: components["schemas"]["Elevations"]; + }; + }; + }; + /** Authentication Error. The API key or token is missing, invalid or expired. */ + UnauthorizedErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** An error occurred on the server. */ + ServerErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** Invalid query parameters / Incorrect portal item type. */ + InvalidQueryErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** The supplied authentication information is valid but does not have permission to access the service. */ + PermissionMissingErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** The requested resource cannot be accessed because of incorrect sharing permissions. */ + ResourcePermissionErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** The request body was larger than limits defined by the service. */ + ContentTooLargeErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + /** The request's message content is of a media-type that the service does not support. */ + UnsupportedMediaTypeErrorResponse: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; + }; + parameters: { + /** @description Optional, case-sensitive parameter to specify the format in which responses are given. Can either be `json` or `pjson`. */ + FormatParam: components["schemas"]["Format"]; + /** + * @description The authentication token, used to access the elevation service. + * + * The `token` parameter can be either an API Key or short-lived token. + * + * Alternatively, you can supply a token in the request header with one of + * the following keys using the "Bearer" scheme: + * + * - `Authorization: Bearer ` + * - `X-Esri-Authorization: Bearer ` + * + * The provided `token` must be created from an ArcGIS Location Platform account and have the necessary `premium:user:elevation` privilege to use the elevation service. + * + * **Developer guide**: To learn more, go to [Security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/). + */ + TokenParam: string; + /** @description The longitude of the specified point. */ + LongitudeParam: number; + /** @description The latitude of the specified point. */ + LatitudeParam: number; + /** + * @description The reference position (datum) from which to measure elevation. + * The valid values are: + * - meanSeaLevel: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. + * It takes into account the local variations in gravity and provides a consistent vertical reference. + * - ellipsoid: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + */ + RelativeToParam: "meanSeaLevel" | "ellipsoid"; + }; +} + +export interface operations { + /** + * 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. + * + * Note: You cannot permanently store elevations. Please see the [Terms of use](https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/terms-of-use/). + */ + ElevationAtPointGet: { + parameters: { + query: { + /** The longitude of the specified point. */ + lon: components["parameters"]["LongitudeParam"]; + /** The latitude of the specified point. */ + lat: components["parameters"]["LatitudeParam"]; + /** + * The reference position (datum) from which to measure elevation. + * The valid values are: + * - meanSeaLevel: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. + * It takes into account the local variations in gravity and provides a consistent vertical reference. + * - ellipsoid: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + */ + relativeTo?: components["parameters"]["RelativeToParam"]; + /** + * The authentication token, used to access the elevation service. + * + * The `token` parameter can be either an API Key or short-lived token. + * + * Alternatively, you can supply a token in the request header with one of + * the following keys using the "Bearer" scheme: + * + * - `Authorization: Bearer ` + * - `X-Esri-Authorization: Bearer ` + * + * The provided `token` must be created from an ArcGIS Location Platform account and have the necessary `premium:user:elevation` privilege to use the elevation service. + * + * **Developer guide**: To learn more, go to [Security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/). + */ + token?: components["parameters"]["TokenParam"]; + /** Optional, case-sensitive parameter to specify the format in which responses are given. Can either be `json` or `pjson`. */ + f?: components["parameters"]["FormatParam"]; + }; + }; + responses: { + 200: components["responses"]["ElevationResponse"]; + 400: components["responses"]["InvalidQueryErrorResponse"]; + 401: components["responses"]["UnauthorizedErrorResponse"]; + 403: components["responses"]["ResourcePermissionErrorResponse"]; + "5XX": components["responses"]["ServerErrorResponse"]; + }; + }; + /** + * Returns elevations in meters at given longitudes and latitudes within the WGS84 coordinate system. + * + * The order of the points returned by this request will be the same as the order of the points passed in the + * `coordinates` parameter. + * + * If the distance between the furthest West and furthest East coordinate exceeds 50km, the service will return a `400` HTTP response as the distance between these points is too large. + * + * If the distance between the furthest North and furthest South coordinate exceeds 50km, the service will return a `400` HTTP response as the distance between these points is too large. + * + * If any of the points are otherwise invalid, a `400` HTTP response will be returned. + * + * 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` parameter in the body 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. + * + * Note: You cannot permanently store elevations. Please see the [Terms of use](https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/terms-of-use/). + * + * The Post Body content type must be either: + * - JSON with content type of `application/json`, or + * - form URL encoded key-value pairs with content type `application/x-www-form-urlencoded`. + * + * The following parameters are used to fetch elevations for multiple coordinates: + * + * **coordinates** + * - (Required) Array of (longitude, latitude) pairs in the WGS84 spatial reference. Maximum size of 100 coordinates. The order of each pair must be + * - longitude in the range `-179.99` to `179.99` representing the east/west or x-axis + * - latitude in the range `-85.05` to `85.05` representing the north/south or y-axis + * - For example: `[[31.134167, 29.979167], [31.130833, 29.976111], [31.128333, 29.9725]]` + * + * **f** + * - (Optional) Case-sensitive parameter to specify the format in which responses are given. Can either be `json` or `pjson`. + * + * **relativeTo** + * - (Optional) The reference position (datum) from which to measure elevation. The valid values are: + * + * - **meanSeaLevel**: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. It takes into account the local variations in gravity and provides a consistent vertical reference. + * - **ellipsoid**: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + * + * **token** + * - (Optional) The authentication token, used to access the elevation service. Alternatively, you can supply a token in the request header with either the `Authorization` or `X-Esri-Authorization` key, using the "Bearer" scheme. + */ + ElevationAtManyPointsPost: { + responses: { + 200: components["responses"]["MultipleElevationsResponse"]; + 400: components["responses"]["InvalidQueryErrorResponse"]; + 401: components["responses"]["UnauthorizedErrorResponse"]; + 403: components["responses"]["ResourcePermissionErrorResponse"]; + 413: components["responses"]["ContentTooLargeErrorResponse"]; + 415: components["responses"]["UnsupportedMediaTypeErrorResponse"]; + "5XX": components["responses"]["ServerErrorResponse"]; + }; + requestBody: { + content: { + "application/json": { + /** + * @description The authentication token, used to access the elevation service. + * + * The `token` parameter can be either an API Key or short-lived token. + * + * Alternatively, you can supply a token in the request header with one of + * the following keys using the "Bearer" scheme: + * + * - `Authorization: Bearer ` + * - `X-Esri-Authorization: Bearer ` + * + * The provided `token` must be created from an ArcGIS Location Platform account and have the necessary `premium:user:elevation` privilege to use the elevation service. + * + * **Developer guide**: To learn more, go to [Security and authentication](https://developers.arcgis.com/documentation/security-and-authentication/). + * + * @example My token + */ + token?: string; + /** + * @description The reference position (datum) from which to measure elevation. + * The valid values are: + * - meanSeaLevel: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. + * It takes into account the local variations in gravity and provides a consistent vertical reference. + * - ellipsoid: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + * + * @default meanSeaLevel + * @example meanSeaLevel + * @enum {string} + */ + relativeTo?: "meanSeaLevel" | "ellipsoid"; + f?: components["schemas"]["Format"]; + /** + * @description Array of (longitude, latitude) pairs in the WGS84 spatial reference. Maximum size of 100 coordinates. The order of each pair must be + * - longitude in the range `-179.99` to `179.99` representing the east/west or x-axis + * - latitude in the range `-85.05` to `85.05` representing the north/south or y-axis + * + * For example: `[[31.134167, 29.979167], [31.130833, 29.976111], [31.128333, 29.9725]]` + * + * @example [ + * [ + * 31.134167, + * 29.979167 + * ], + * [ + * 31.130833, + * 29.976111 + * ], + * [ + * 31.128333, + * 29.9725 + * ] + * ] + */ + coordinates: number[][]; + }; + "application/x-www-form-urlencoded": { + /** + * @description The authentication token, used to access the elevation service. + * + * The `token` parameter can be either an API Key or short-lived token. + * + * Alternatively, you can supply a token in the request header with one of + * the following keys using the "Bearer" scheme: + * + * - `Authorization: Bearer ` + * - `X-Esri-Authorization: Bearer ` + * + * The provided `token` must be created from an ArcGIS Location Platform account and have the necessary `premium:user:elevation` privilege to use the elevation service. + * + * **Developer guide**: To learn more, go to [Security and authentication](https://developers.arcgis.com/documentation/security-and-authentication/). + * + * @example My token + */ + token?: string; + /** + * @description The reference position (datum) from which to measure elevation. + * The valid values are: + * - meanSeaLevel: The elevation above or below the WGS84 geoid reference surface, which is approximately the mean sea level. + * It takes into account the local variations in gravity and provides a consistent vertical reference. + * - ellipsoid: Ellipsoidal height is measured with respect to an ellipsoid, which 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. + * + * @default meanSeaLevel + * @example meanSeaLevel + * @enum {string} + */ + relativeTo?: "meanSeaLevel" | "ellipsoid"; + f?: components["schemas"]["Format"]; + /** + * @description Array of (longitude, latitude) pairs in the WGS84 spatial reference. Maximum size of 100 coordinates. The order of each pair must be + * - longitude in the range `-179.99` to `179.99` representing the east/west or x-axis + * - latitude in the range `-85.05` to `85.05` representing the north/south or y-axis + * + * For example: `[[31.134167, 29.979167], [31.130833, 29.976111], [31.128333, 29.9725]]` + * + * @example [ + * [ + * 31.134167, + * 29.979167 + * ], + * [ + * 31.130833, + * 29.976111 + * ], + * [ + * 31.128333, + * 29.9725 + * ] + * ] + */ + coordinates: number[][]; + }; + }; + }; + }; +} + +export interface external {} diff --git a/packages/arcgis-rest-elevation/src/utils.ts b/packages/arcgis-rest-elevation/src/utils.ts new file mode 100644 index 000000000..1267b7806 --- /dev/null +++ b/packages/arcgis-rest-elevation/src/utils.ts @@ -0,0 +1,2 @@ +export const baseUrl = + "https://elevation-api.arcgis.com/arcgis/rest/services/elevation-service/v1"; diff --git a/packages/arcgis-rest-elevation/test/findElevationAtManyPoints.test.ts b/packages/arcgis-rest-elevation/test/findElevationAtManyPoints.test.ts new file mode 100644 index 000000000..fc562bf18 --- /dev/null +++ b/packages/arcgis-rest-elevation/test/findElevationAtManyPoints.test.ts @@ -0,0 +1,44 @@ +import { ApiKeyManager } from "@esri/arcgis-rest-request"; +import fetchMock from "fetch-mock"; +import { findElevationAtManyPoints } from "../src/index.js"; +import { atManyPointsDefaultResult } from "./mocks/atManyPointsDefault.mock.js"; +import { atManyPointsEllipsoidResult } from "./mocks/atManyPointsEllipsoid.mock.js"; + +describe("findElevationAtManyPoints()", () => { + afterEach(() => { + fetchMock.restore(); + }); + + it("should return elevation at points with mean sea level as the reference", async () => { + fetchMock.mock("*", atManyPointsDefaultResult); + + let response = await findElevationAtManyPoints({ + coordinates: [ + [1.2, 3.4], + [1.23, 3.45] + ], + authentication: ApiKeyManager.fromKey("MOCK_KEY") + }); + + const [url, options] = fetchMock.lastCall("*"); + + expect(response.result).toEqual(atManyPointsDefaultResult.result); + }); + + it("should return elevation at points with ellipsoid as the reference", async () => { + fetchMock.mock("*", atManyPointsEllipsoidResult); + + const response = await findElevationAtManyPoints({ + coordinates: [ + [1.2, 3.4], + [1.23, 3.45] + ], + relativeTo: "ellipsoid", + authentication: ApiKeyManager.fromKey("MOCK_KEY") + }); + + const [url, options] = fetchMock.lastCall("*"); + + expect(response.result).toEqual(atManyPointsEllipsoidResult.result); + }); +}); diff --git a/packages/arcgis-rest-elevation/test/findElevationAtPoint.test.ts b/packages/arcgis-rest-elevation/test/findElevationAtPoint.test.ts new file mode 100644 index 000000000..6bdcfddf3 --- /dev/null +++ b/packages/arcgis-rest-elevation/test/findElevationAtPoint.test.ts @@ -0,0 +1,46 @@ +import { ApiKeyManager } from "@esri/arcgis-rest-request"; +import fetchMock from "fetch-mock"; +import { findElevationAtPoint } from "../src/index.js"; +import { atPointDefaultResult } from "./mocks/atPointDefault.mock.js"; +import { atPointEllipsoidResult } from "./mocks/atPointEllipsoid.mock.js"; + +describe("findElevationAtPoint()", () => { + afterEach(() => { + fetchMock.restore(); + }); + + it("should return elevation at a point with mean sea level as the reference", async () => { + fetchMock.mock("*", atPointDefaultResult); + + const response = await findElevationAtPoint({ + lon: -3.1883, + lat: 55.9533, + authentication: ApiKeyManager.fromKey("MOCK_KEY") + }); + + const [url, options] = fetchMock.lastCall("*"); + + expect(response.result).toEqual(atPointDefaultResult.result); + expect(url).toContain("lon=-3.1883"); + expect(url).toContain("lat=55.9533"); + expect(url).toContain("token=MOCK_KEY"); + }); + + it("should return elevation at a point with ellipsoid as the reference", async () => { + fetchMock.mock("*", atPointEllipsoidResult); + + const response = await findElevationAtPoint({ + lon: -3.1883, + lat: 55.9533, + relativeTo: "ellipsoid", + authentication: ApiKeyManager.fromKey("MOCK_KEY") + }); + + const [url, options] = fetchMock.lastCall("*"); + + expect(response.result).toEqual(atPointEllipsoidResult.result); + expect(url).toContain("lon=-3.1883"); + expect(url).toContain("lat=55.9533"); + expect(url).toContain("token=MOCK_KEY"); + }); +}); diff --git a/packages/arcgis-rest-elevation/test/mocks/atManyPointsDefault.mock.ts b/packages/arcgis-rest-elevation/test/mocks/atManyPointsDefault.mock.ts new file mode 100644 index 000000000..c9aa26d7b --- /dev/null +++ b/packages/arcgis-rest-elevation/test/mocks/atManyPointsDefault.mock.ts @@ -0,0 +1,25 @@ +export const atManyPointsDefaultResult = { + elevationInfo: { + relativeTo: "meanSeaLevel" + }, + result: { + points: [ + { + spatialReference: { + wkid: 4326 + }, + x: 1.2, + y: 3.4, + z: -4458 + }, + { + spatialReference: { + wkid: 4326 + }, + x: 1.23, + y: 3.45, + z: -4452 + } + ] + } +}; diff --git a/packages/arcgis-rest-elevation/test/mocks/atManyPointsEllipsoid.mock.ts b/packages/arcgis-rest-elevation/test/mocks/atManyPointsEllipsoid.mock.ts new file mode 100644 index 000000000..0c58c8644 --- /dev/null +++ b/packages/arcgis-rest-elevation/test/mocks/atManyPointsEllipsoid.mock.ts @@ -0,0 +1,25 @@ +export const atManyPointsEllipsoidResult = { + elevationInfo: { + relativeTo: "ellipsoid" + }, + result: { + points: [ + { + spatialReference: { + wkid: 4326 + }, + x: 1.2, + y: 3.4, + z: -4441 + }, + { + spatialReference: { + wkid: 4326 + }, + x: 1.23, + y: 3.45, + z: -4435 + } + ] + } +}; diff --git a/packages/arcgis-rest-elevation/test/mocks/atPointDefault.mock.ts b/packages/arcgis-rest-elevation/test/mocks/atPointDefault.mock.ts new file mode 100644 index 000000000..b9942cd34 --- /dev/null +++ b/packages/arcgis-rest-elevation/test/mocks/atPointDefault.mock.ts @@ -0,0 +1,15 @@ +export const atPointDefaultResult = { + elevationInfo: { + relativeTo: "meanSeaLevel" + }, + result: { + point: { + spatialReference: { + wkid: 4326 + }, + x: -3.1883, + y: 55.9533, + z: 63 + } + } +}; diff --git a/packages/arcgis-rest-elevation/test/mocks/atPointEllipsoid.mock.ts b/packages/arcgis-rest-elevation/test/mocks/atPointEllipsoid.mock.ts new file mode 100644 index 000000000..b7dfe7760 --- /dev/null +++ b/packages/arcgis-rest-elevation/test/mocks/atPointEllipsoid.mock.ts @@ -0,0 +1,15 @@ +export const atPointEllipsoidResult = { + elevationInfo: { + relativeTo: "ellipsoid" + }, + result: { + point: { + spatialReference: { + wkid: 4326 + }, + x: -3.1883, + y: 55.9533, + z: 116 + } + } +}; diff --git a/packages/arcgis-rest-elevation/tsconfig.json b/packages/arcgis-rest-elevation/tsconfig.json new file mode 100644 index 000000000..400168ea9 --- /dev/null +++ b/packages/arcgis-rest-elevation/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.ts" + ] +} \ No newline at end of file diff --git a/typedoc.json b/typedoc.json index d93cb39e7..efb09fdec 100644 --- a/typedoc.json +++ b/typedoc.json @@ -7,6 +7,7 @@ "excludeExternals": true, "packages": [ "./packages/arcgis-rest-demographics/", + "./packages/arcgis-rest-elevation/", "./packages/arcgis-rest-feature-service/", "./packages/arcgis-rest-geocoding/", "./packages/arcgis-rest-portal/",