import { IRequestOptions } from "@esri/arcgis-rest-request" ; import { IModel , cloneObject } from "@esri/hub-common" ; import geometryService from "./geometry" ; import { createItem , updateItem , IUpdateItemOptions , ICreateItemOptions , ICreateItemResponse } from "@esri/arcgis-rest-portal" ; export param { IModel } param { IRequestOptions } requestOptions returns { Promise < IModel > } export function saveModel ( model , requestOptions ) { const clone = cloneObject ( model ) as IModel ; const opts = createRequestOptions ( clone , requestOptions ) ; return createItem ( opts as ICreateItemOptions ) . then ( ( response ) => { clone . item . id = response . id ; return clone as IModel ; } ) ; } export param { IModel } param { IRequestOptions } requestOptions returns { Promise < IModel > } export function updateModel ( model , requestOptions ) { const clone = cloneObject ( model ) as IModel ; const opts = createRequestOptions ( clone , requestOptions ) ; return updateItem ( opts as IUpdateItemOptions ) . then ( ( ) => { return clone as IModel ; } ) ; } param { IModel } model param { IRequestOptions } requestOptions returns { * } function createRequestOptions ( model , requestOptions ) { const item = cloneObject ( model . item ) ; item . data = cloneObject ( model . data ) ; const opts = { item , ... requestOptions } ; return opts ; } export interface IProjectExtentOptions { extent : any ; portal ? : any ; } param orgExtent param portal returns { Promise < any > } export function getProjectedExtentAsBBOXString ( options , requestOptions ) { const url = geometryService . getUrl ( options . portal ) ; return geometryService . project ( url , options . extent . spatialReference . wkid , 4326 , "esriGeometryEnvelope" , [ options . extent ] , requestOptions ) . then ( ( response ) => { const ext4326 = response . geometries [ 0 ] ; return ( ext4326 . xmin + "," + ext4326 . ymin + "," + ext4326 . xmax + "," + ext4326 . ymax ) ; } ) ; }