-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from Esri/feat/get-feature
New arcgis-rest-features package w/ `getFeature()` to get a feature b…
- Loading branch information
Showing
10 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
[![npm version][npm-img]][npm-url] | ||
[![build status][travis-img]][travis-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-feature-service.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-feature-service | ||
[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js | ||
|
||
# @esri/arcgis-rest-feature-service | ||
|
||
> A module for working with ArcGIS feature services that runs in Node.js and modern browsers. | ||
### Example | ||
|
||
```bash | ||
npm install @esri/arcgis-rest-feature-service | ||
``` | ||
|
||
```js | ||
import { getFeature } from '@esri/arcgis-rest-feature-service'; | ||
|
||
const params = { | ||
url: | ||
"https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0", | ||
id: 42 | ||
}; | ||
|
||
getFeature(params) | ||
.then(feature => { | ||
console.log(feature.attributes.FID); // 42 | ||
}); | ||
``` | ||
|
||
### 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 <http://semver.org/>. | ||
|
||
### Contributing | ||
|
||
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md). | ||
|
||
### License | ||
|
||
Copyright 2018 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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@esri/arcgis-rest-feature-service", | ||
"version": "1.0.2", | ||
"description": "Feature service helpers for @esri/arcgis-rest-request", | ||
"main": "dist/node/index.js", | ||
"browser": "dist/umd/arcgis-rest-feature-service.umd.js", | ||
"module": "dist/esm/index.js", | ||
"js:next": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"tslib": "^1.7.1" | ||
}, | ||
"peerDependencies": { | ||
"@esri/arcgis-rest-common-types": "^1.0.3", | ||
"@esri/arcgis-rest-request": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"@esri/arcgis-rest-common-types": "^1.0.3", | ||
"@esri/arcgis-rest-request": "^1.0.3" | ||
}, | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "npm run build:node && npm run build:umd && npm run build:esm", | ||
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration", | ||
"build:umd": "rollup -c ../../rollup.config.umd.js", | ||
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Esri/arcgis-rest-js.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Tom Wayson", | ||
"email": "twayson@esri.com", | ||
"url": "http://tomwayson.com/" | ||
} | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Esri/arcgis-rest-js/issues" | ||
}, | ||
"homepage": "https://github.com/Esri/arcgis-rest-js#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
import { IFeature } from "@esri/arcgis-rest-common-types"; | ||
import { request, IRequestOptions } from "@esri/arcgis-rest-request"; | ||
|
||
/** | ||
* parameters required to get a feature by id | ||
* | ||
* @param url - layer service url | ||
* @param id - feature id | ||
*/ | ||
export interface IFeatureRequestOptions extends IRequestOptions { | ||
url: string; | ||
id: number; | ||
} | ||
|
||
/** | ||
* Get an feature by id | ||
* | ||
* @param requestOptions - Options for the request | ||
* @returns A Promise that will resolve with the feature. | ||
*/ | ||
export function getFeature( | ||
requestOptions: IFeatureRequestOptions | ||
): Promise<IFeature> { | ||
const url = `${requestOptions.url}/${requestOptions.id}`; | ||
|
||
// default to a GET request | ||
const options: IFeatureRequestOptions = { | ||
...{ httpMethod: "GET" }, | ||
...requestOptions | ||
}; | ||
return request(url, options).then((response: any) => response.feature); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./features"; |
26 changes: 26 additions & 0 deletions
26
packages/arcgis-rest-feature-service/test/features.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getFeature } from "../src/index"; | ||
|
||
import * as fetchMock from "fetch-mock"; | ||
|
||
import { featureResponse } from "./mocks/feature"; | ||
|
||
describe("feature", () => { | ||
afterEach(fetchMock.restore); | ||
|
||
it("should return a feature by id", done => { | ||
const params = { | ||
url: | ||
"https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0", | ||
id: 42 | ||
}; | ||
fetchMock.once("*", featureResponse); | ||
getFeature(params).then(response => { | ||
expect(fetchMock.called()).toBeTruthy(); | ||
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); | ||
expect(url).toEqual(`${params.url}/42?f=json`); | ||
expect(options.method).toBe("GET"); | ||
expect(response.attributes.FID).toEqual(42); | ||
done(); | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/arcgis-rest-feature-service/test/mocks/feature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IFeature } from "@esri/arcgis-rest-common-types"; | ||
|
||
export const featureResponse = { | ||
feature: { | ||
attributes: { | ||
FID: 42 | ||
}, | ||
geometry: { | ||
x: -9177311.62541634, | ||
y: 4247151.205222242 | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": [ | ||
"src/**/*.ts" | ||
] | ||
} |