import { request , cleanUrl , appendCustomParams } from "@esri/arcgis-rest-request" ; import { ISpatialReference , IFeatureSet , IFeature , Units , IExtent , IStatisticDefinition } from "@esri/arcgis-rest-types" ; import { IGetLayerOptions , ISharedQueryOptions } from "./helpers" ; /**
 * Request options to fetch a feature by id.
 */ export interface IGetFeatureOptions extends IGetLayerOptions { /**
     * Unique identifier of the feature.
     */ id : number ; } /**
 * feature query request options. See [REST Documentation](https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm) for more information.
 */ export interface IQueryFeaturesOptions extends ISharedQueryOptions { objectIds ? : number [ ] ; relationParam ? : string ; time ? : number | number [ ] ; distance ? : number ; units ? : Units ; /**
     * Attribute fields to include in the response. Defaults to "*"
     */ outFields ? : "*" | string [ ] ; returnGeometry ? : boolean ; maxAllowableOffset ? : number ; geometryPrecision ? : number ; inSR ? : string | ISpatialReference ; outSR ? : string | ISpatialReference ; gdbVersion ? : string ; returnDistinctValues ? : boolean ; returnIdsOnly ? : boolean ; returnCountOnly ? : boolean ; returnExtentOnly ? : boolean ; orderByFields ? : string ; groupByFieldsForStatistics ? : string ; outStatistics ? : IStatisticDefinition [ ] ; returnZ ? : boolean ; returnM ? : boolean ; multipatchOption ? : "xyFootprint" ; resultOffset ? : number ; resultRecordCount ? : number ; quantizationParameters ? : any ; returnCentroid ? : boolean ; resultType ? : "none" | "standard" | "tile" ; historicMoment ? : number ; returnTrueCurves ? : false ; sqlFormat ? : "none" | "standard" | "native" ; returnExceededLimitFeatures ? : boolean ; /**
     * Response format. Defaults to "json"
     * NOTE: for "pbf" you must also supply `rawResponse: true`
     * and parse the response yourself using `response.arrayBuffer()`
     */ f ? : "json" | "geojson" | "pbf" ; } export interface IQueryFeaturesResponse extends IFeatureSet { exceededTransferLimit ? : boolean ; } export interface IQueryResponse { count ? : number ; extent ? : IExtent ; objectIdFieldName ? : string ; objectIds ? : number [ ] ; } param requestOptions returns export function getFeature ( requestOptions ) { const url = `${ cleanUrl ( requestOptions . url ) }/${ requestOptions . id }` ; const options = { ... { httpMethod : "GET" } , ... requestOptions } ; return request ( url , options ) . then ( ( response ) => { if ( options . rawResponse ) { return response ; } return response . feature ; } ) ; } param requestOptions returns export function queryFeatures ( requestOptions ) { const queryOptions = appendCustomParams < IQueryFeaturesOptions > ( requestOptions , [ "where" , "objectIds" , "relationParam" , "time" , "distance" , "units" , "outFields" , "geometry" , "geometryType" , "spatialRel" , "returnGeometry" , "maxAllowableOffset" , "geometryPrecision" , "inSR" , "outSR" , "gdbVersion" , "returnDistinctValues" , "returnIdsOnly" , "returnCountOnly" , "returnExtentOnly" , "orderByFields" , "groupByFieldsForStatistics" , "outStatistics" , "returnZ" , "returnM" , "multipatchOption" , "resultOffset" , "resultRecordCount" , "quantizationParameters" , "returnCentroid" , "resultType" , "historicMoment" , "returnTrueCurves" , "sqlFormat" , "returnExceededLimitFeatures" , "f" ] , { httpMethod : "GET" , params : { where : "1=1" , outFields : "*" , ... requestOptions . params } } ) ; return request ( `${ cleanUrl ( requestOptions . url ) }/query` , queryOptions ) ; }