Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update feature service to add layer(s) &| table(s) #317

Merged
merged 10 commits into from
Sep 14, 2018
4 changes: 4 additions & 0 deletions packages/arcgis-rest-common-types/src/webmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ export interface IPresentation {
* Root element in the web map specifying an array of table objects.
*/
export interface ITable {
/** Table name */
name?: string;
/** A comma-separated string listing which editing operations are allowed on an editable feature service. Available operations include: 'Create', 'Delete', 'Query', 'Update', and 'Editing'. */
capabilities?: string;
/** Object indicating the definitionEditor used as a layer's interactive filter. */
Expand Down Expand Up @@ -555,6 +557,8 @@ export interface IBaseMap {
export interface ILayer {
/** A unique identifying string for the layer. */
id: any;
/** Layer name */
name?: string;
/** Optional string containing the item ID of the service if it's registered on ArcGIS Online or your organization's portal. */
itemId?: string;
/** Indicates the layer type */
Expand Down
70 changes: 70 additions & 0 deletions packages/arcgis-rest-feature-service-admin/src/addTo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request } from "@esri/arcgis-rest-request";
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";
import { ILayer, ITable } from "@esri/arcgis-rest-common-types";

export interface IAddToServiceDefinitionRequestOptions
extends IUserRequestOptions {
/**
* Layers to add
*/
layers?: ILayer[];
/**
* Tables to add
*/
tables?: ITable[];
}

export interface IAddToServiceDefinitionItemSummary {
name: string;
id: any;
}

export interface IAddToServiceDefinitionResult {
layers?: IAddToServiceDefinitionItemSummary[];
tables?: IAddToServiceDefinitionItemSummary[];
success: boolean;
}

/**
* Add layer(s) and/or table(s) to a hosted feature service.
*
* ```js
* import { addToServiceDefinition } from '@esri/arcgis-rest-feature-service-admin';
*
* addToServiceDefinition(serviceurl, {
* authentication: userSession,
* layers: [],
* tables: []
* });
* ```
*
* @param url - URL of feature service
* @param requestOptions - Options for the request
* @returns A Promise that resolves with service layer and/or table details once the definition
* has been updated
*/
export function addToServiceDefinition(
url: string,
requestOptions: IAddToServiceDefinitionRequestOptions
): Promise<IAddToServiceDefinitionResult> {
const adminUrl =
url.replace("/rest/services", "/rest/admin/services") + "/addToDefinition";

requestOptions.params = {
addToDefinition: {},
...requestOptions.params
};

if (requestOptions.layers && requestOptions.layers.length > 0) {
requestOptions.params.addToDefinition.layers = requestOptions.layers;
}

if (requestOptions.tables && requestOptions.tables.length > 0) {
requestOptions.params.addToDefinition.tables = requestOptions.tables;
}

return request(adminUrl, requestOptions);
}
1 change: 1 addition & 0 deletions packages/arcgis-rest-feature-service-admin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./create";
export * from "./addTo";
Loading