UNPKG

@ngageoint/mage.arcgis.service

Version:

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

91 lines 5.27 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.FeatureQuerier = void 0; const arcgis_rest_feature_service_1 = require("@esri/arcgis-rest-feature-service"); /** * Performs various queries on observations for a specific arc feature layer. */ class FeatureQuerier { /** * Creates a new instance of FeatureQuerier. * @param {LayerInfo} layerInfo - Information about the ArcGIS feature layer. * @param {ArcGISPluginConfig} config - Configuration settings for the ArcGIS plugin. * @param {ArcGISIdentityManager} identityManager - ArcGIS identity manager for authentication. * @param {Console} console - Console instance for logging. */ constructor(layerInfo, config, identityManager, console) { this._identityManager = identityManager; this._url = new URL(layerInfo.url); this._console = console; this._config = config; } /** * Queries for an observation by id. * @param {string} observationId - The id of the observation to query for on the arc feature layer. * @param {function(QueryObjectResult): void} response - Callback function called with the query result. * @param {string[]} [fields] - Optional array of field names to query. If not provided, all fields are queried. * @param {boolean} [geometry] - Optional flag to include geometry in the query. Defaults to true. */ queryObservation(observationId, response, fields, geometry) { return __awaiter(this, void 0, void 0, function* () { const where = !this._config.eventIdField ? `${this._config.observationIdField} LIKE '${observationId}${this._config.idSeparator}%'` : `${this._config.observationIdField} = '${observationId}'`; this._console.info('ArcGIS query observation: ' + this._url.toString() + where); yield (0, arcgis_rest_feature_service_1.queryFeatures)({ url: this._url.toString(), authentication: this._identityManager, where, returnGeometry: geometry, outFields: (fields === null || fields === void 0 ? void 0 : fields.length) ? fields : '*' }).then((queryResponse) => response(queryResponse)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error)); }); } /** * Queries all observations. * @param {function(QueryObjectResult): void} response - Callback function called with the query result. * @param {string[]} [fields] - Optional array of field names to query. If not provided, all fields are queried. * @param {boolean} [geometry] - Optional flag to include geometry in the query. Defaults to true. */ queryObservations(response, fields, geometry) { return __awaiter(this, void 0, void 0, function* () { this._console.info('ArcGIS query observation: ' + this._url.toString()); yield (0, arcgis_rest_feature_service_1.queryFeatures)({ url: this._url.toString(), authentication: this._identityManager, where: `${this._config.observationIdField} IS NOT NULL`, returnGeometry: geometry, outFields: (fields === null || fields === void 0 ? void 0 : fields.length) ? fields : '*' }).then((queryResponse) => response(queryResponse)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error)); }); } /** * Queries for distinct non-null values in a specified field. * @param {function(QueryObjectResult): void} response - Callback function called with the query result. * @param {string} field - The field name to query for distinct values. */ queryDistinct(response, field) { return __awaiter(this, void 0, void 0, function* () { this._console.info('ArcGIS query observation: ' + this._url.toString()); yield (0, arcgis_rest_feature_service_1.queryFeatures)({ url: this._url.toString(), authentication: this._identityManager, where: `${field} IS NOT NULL`, returnGeometry: false, outFields: field ? [field] : '*', returnDistinctValues: true }).then((queryResponse) => response(queryResponse)).catch((error) => this._console.error('Error in FeatureQuerier.queryDistinct :: ' + error)); }); } } exports.FeatureQuerier = FeatureQuerier; //# sourceMappingURL=FeatureQuerier.js.map