Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(add applyEdits function): adds \
applyEdits()\
to feature-layer…
… for bulk crud transactions.
- Loading branch information
Showing
5 changed files
with
200 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { | ||
request, | ||
cleanUrl, | ||
appendCustomParams | ||
} from "@esri/arcgis-rest-request"; | ||
|
||
import { IFeature } from "@esri/arcgis-rest-types"; | ||
|
||
import { ISharedEditOptions, IApplyEditsResult } from "./helpers"; | ||
|
||
/** | ||
* Apply edits request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/apply-edits-feature-service-layer-.htm) for more information. | ||
* | ||
*/ | ||
export interface IApplyEditsOptions extends ISharedEditOptions { | ||
/** | ||
* Array of JSON features to add. | ||
*/ | ||
adds?: IFeature[]; | ||
/** | ||
* Array of JSON features to update. | ||
*/ | ||
updates?: IFeature[]; | ||
/** | ||
* Array of objectIds or globalIds to delete. | ||
*/ | ||
deletes?: number[] | string[]; | ||
/** | ||
* When set to true, the features and attachments in the adds, updates, deletes, and attachments parameters are identified by their globalIds. | ||
*/ | ||
useGlobalIds?: boolean; | ||
/** | ||
* Use the attachments parameter to add, update or delete attachments. Applies only when the useGlobalIds parameter is set to true. | ||
* See [attachment](https://developers.arcgis.com/rest/services-reference/apply-edits-feature-service-layer-.htm) param details. | ||
*/ | ||
attachments?: { | ||
adds?: any[]; | ||
updates?: any[]; | ||
deletes?: string[]; | ||
}; | ||
} | ||
|
||
/** | ||
* ```js | ||
* import { applyEdits } from '@esri/arcgis-rest-feature-layer'; | ||
* // | ||
* applyEdits({ | ||
* url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0", | ||
* adds: [{ | ||
* geometry: { x: -120, y: 45, spatialReference: { wkid: 4326 } }, | ||
* attributes: { status: "alive" } | ||
* }], | ||
* updates: [{ | ||
* attributes: { OBJECTID: 1004, status: "alive" } | ||
* }], | ||
* deletes: [862, 1548] | ||
* }) | ||
* .then(response) | ||
* ``` | ||
* Apply edits request. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/apply-edits-feature-service-layer-.htm) for more information. | ||
* | ||
* @param requestOptions - Options for the request. | ||
* @returns A Promise that will resolve with the applyEdits response. | ||
*/ | ||
export function applyEdits( | ||
requestOptions: IApplyEditsOptions | ||
): Promise<IApplyEditsResult> { | ||
const url = `${cleanUrl(requestOptions.url)}/applyEdits`; | ||
|
||
// edit operations are POST only | ||
const options = appendCustomParams<IApplyEditsOptions>( | ||
requestOptions, | ||
[ | ||
"adds", | ||
"updates", | ||
"deletes", | ||
"useGlobalIds", | ||
"attachments", | ||
"gdbVersion", | ||
"returnEditMoment", | ||
"rollbackOnFailure" | ||
], | ||
{ params: { ...requestOptions.params } } | ||
); | ||
|
||
return request(url, options); | ||
} |
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
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