UNPKG

@ngageoint/mage.arcgis.service

Version:

A mage service plugin that synchronizes mage observations to a configured ArcGIS feature layer.

143 lines 5.74 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeatureService = void 0; const arcgis_rest_feature_service_1 = require("@esri/arcgis-rest-feature-service"); // TODO: Migrate FeatureQuerier to use this class /** * Queries arc feature services and layers. */ class FeatureService { constructor(console, config, identityManager) { this._config = config; this._identityManager = identityManager; this._console = console; } /** * Gets features from the feature service using the given where clause. * @param {string} whereClause - The where clause to filter the features. * @returns {Promise<any>} - A promise that resolves to the query result. */ getFeatures(whereClause) { return __awaiter(this, void 0, void 0, function* () { const queryParams = { url: this._config.url, where: whereClause, authentication: this._identityManager }; this._console.info('Querying feature service with params: ', queryParams); return yield (0, arcgis_rest_feature_service_1.queryFeatures)(queryParams).catch((error) => { this._console.error('Error querying feature service:', error); throw new Error(`Error querying feature service: ${error}`); }); }); } /** * Gets a specific layer from the feature service. * @param {string | number} layerId - The ID of the layer to query. * @returns {Promise<any>} - A promise that resolves to the layer info. */ getLayer(layerId) { return __awaiter(this, void 0, void 0, function* () { const url = `${this._config.url}/${layerId}`; try { return yield (0, arcgis_rest_feature_service_1.getLayer)({ url, authentication: this._identityManager }); } catch (error) { throw new Error(`Error querying layer info: ${error}`); } }); } getService() { return __awaiter(this, void 0, void 0, function* () { try { return yield (0, arcgis_rest_feature_service_1.getService)({ url: this._config.url, authentication: this._identityManager, }); } catch (error) { throw new Error(`Error getting service: ${error}`); } }); } // Add feature using applyEdits addFeature(feature) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield (0, arcgis_rest_feature_service_1.applyEdits)({ url: this._config.url, adds: [feature], authentication: this._identityManager, }); return response; } catch (error) { throw new Error(`Error adding feature: ${error}`); } }); } // Update feature using applyEdits updateFeature(feature) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield (0, arcgis_rest_feature_service_1.applyEdits)({ url: this._config.url, updates: [feature], authentication: this._identityManager, }); return response; } catch (error) { throw new Error(`Error updating feature: ${error}`); } }); } // Delete feature using applyEdits deleteFeature(objectId) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield (0, arcgis_rest_feature_service_1.applyEdits)({ url: this._config.url, deletes: [typeof objectId === 'number' ? objectId : parseInt(objectId, 10)], authentication: this._identityManager, }); return response; } catch (error) { throw new Error(`Error deleting feature: ${error}`); } }); } // Batch operation using applyEdits applyEditsBatch(edits) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield (0, arcgis_rest_feature_service_1.applyEdits)({ url: this._config.url, adds: edits.add || [], updates: edits.update || [], deletes: edits.delete || [], authentication: this._identityManager, }); return response; } catch (error) { throw new Error(`Error applying edits: ${error}`); } }); } } exports.FeatureService = FeatureService; //# sourceMappingURL=FeatureService.js.map