UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 8.81 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../Graphic.js";import r from"../request.js";import o from"../core/Error.js";import s from"../core/Loadable.js";import i from"../core/Logger.js";import{MultiOriginJSONMixin as a}from"../core/MultiOriginJSONSupport.js";import{isAbortError as n}from"../core/promiseUtils.js";import{urlToObject as l}from"../core/urlUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import c from"../geometry/Extent.js";import p from"../geometry/SpatialReference.js";import{fromJSON as m}from"../geometry/support/jsonUtils.js";import{versionMatches as y,onApplyEditsEvent as h,onUpdateMomentEvent as f,emitApplyEditsEvent as g}from"../layers/mixins/EditBusLayer.js";import{parse as v}from"../layers/support/arcgisLayerUrl.js";import w from"./support/TopologyValidationJobInfo.js";import{networkFromPortalItem as S}from"./support/utils.js";import{isVersionInEditSession as j,currentSessionId as I,isSafeToEditVersion as b}from"../versionManagement/support/versionManagementUtils.js";let U=class extends(a(s)){static fromPortalItem(e){return S(e)}constructor(e){super(e),this.id=null,this.title=null,this.layerUrl=null,this.dataElement=null,this.fullExtent=null,this.spatialReference=null,this.type=null,this.sourceJSON=null,this.gdbVersion=null,this.historicMoment=null,this._sourceIdByLayerId=new Map,this._layerIdBySourceId=new Map,this._applyEditsHandler=e=>{const{serviceUrl:t,gdbVersion:r,result:o}=e,s=t===this.featureServiceUrl,i=y(t,r,this.gdbVersion);s&&i&&o.then((e=>{j(t,r)&&(this.historicMoment=e.historicMoment)}))},this._updateMomentHandler=e=>{const{serviceUrl:t,gdbVersion:r,moment:o}=e,s=t===this.featureServiceUrl,i=y(t,r,this.gdbVersion);s&&i&&(this.historicMoment=o)},this.when().then((()=>{this.addHandles([h(this._applyEditsHandler),f(this._updateMomentHandler)])}),(()=>{}))}initialize(){this.when().catch((e=>{n(e)||i.getLogger(this).error("#load()",`Failed to load layer (title: '${this.title??"no title"}', id: '${this.id??"no id"}')`,{error:e})}))}get datasetName(){return this.dataElement?.name??null}get owner(){return this.dataElement?.userIdentity??null}get schemaGeneration(){return this.dataElement?.schemaGeneration??null}get parsedUrl(){return l(this.layerUrl)}get featureServiceUrl(){return v(this.parsedUrl.path).url.path}get networkServiceUrl(){return this.featureServiceUrl.replace(/\/FeatureServer/i,"/UtilityNetworkServer")}get layerId(){return v(this.parsedUrl.path).sublayer}get networkSystemLayers(){return null}async load(e){return this.addResolvingPromise(this._fetchDataElement(this.featureServiceUrl,this.layerId.toString(),e)),this.addResolvingPromise(this._fetchLayerMetaData(this.layerUrl,e)),this}getLayerIdBySourceId(e){if(!this.dataElement)return null;const t=this._layerIdBySourceId.get(e);if(null!=t)return t;const r=this.dataElement.domainNetworks,o=this._traverseNetworkSources(r,this._layerIdBySourceId,"sourceId","layerId",e);return o>=0?o:null}getSourceIdByLayerId(e){if(!this.dataElement)return null;const t=this._sourceIdByLayerId.get(e);if(null!=t)return t;const r=this.dataElement.domainNetworks,o=this._traverseNetworkSources(r,this._sourceIdByLayerId,"layerId","sourceId",e);return o>=0?o:null}getObjectIdsFromElements(e){const t=[],r=new Map;for(const s of e){const e=this.getLayerIdBySourceId(s.networkSourceId);if(null==e)continue;let t=r.get(e);void 0===t&&(t=[]),t.push(s.objectId),r.set(e,t)}const o=this.featureServiceUrl;return r.forEach(((e,r)=>t.push({layerUrl:`${o}/${r}`,objectIds:e}))),t}async queryNamedTraceConfigurations(e,t){const[{queryNamedTraceConfigurations:r},{default:o}]=await Promise.all([import("../rest/networks/queryNamedTraceConfigurations.js"),import("../rest/networks/support/QueryNamedTraceConfigurationsParameters.js")]),s=this.networkServiceUrl,i=o.from(e);return(await r(s,i,{...t}))?.namedTraceConfigurations}async validateTopology(e,t){if(!e.validateArea)throw new o("network:undefined-validateArea","the network must have validateArea defined in the validate network topology parameters.");const[{validateNetworkTopology:r},{default:s}]=await Promise.all([import("../rest/networks/validateNetworkTopology.js"),import("../rest/networks/support/ValidateNetworkTopologyParameters.js")]),i=s.from(e);j(this.featureServiceUrl,this.gdbVersion||null)?(i.sessionID=I,await b(this.featureServiceUrl,this.gdbVersion,!0)):i.sessionID=null,i.gdbVersion=this.gdbVersion;const a=this.networkServiceUrl,n=this.featureServiceUrl,l=g(n,null,this.gdbVersion,!0),d=await r(a,i,{...t});if(d?.serviceEdits){const e=[];for(const t of d.serviceEdits){const{editedFeatures:r}=t,o=r?.spatialReference?new p(r.spatialReference):null;e.push({layerId:t.layerId,editedFeatures:{adds:r?.adds?.map((e=>k(e,o)))||[],updates:r?.updates?.map((e=>({original:k(e[0],o),current:k(e[1],o)})))||[],deletes:r?.deletes?.map((e=>k(e,o)))||[],spatialReference:o}})}l.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],editedFeatures:e,exceededTransferLimit:!1,historicMoment:d.moment})}return d}async submitTopologyValidationJob(e,t){let s=null;if(!e.validateArea)throw new o("network:undefined-validateArea","the network must have validateArea defined in the validate network topology parameters.");if(!this.gdbVersion){const e=this.layerUrl.replace(/\/FeatureServer/i,"/VersionManagementServer").replace(/\/\d*$/,"");s=(await r(e,{responseType:"json",query:{f:"json"}})).data.defaultVersionName}const[{submitValidateNetworkTopologyJob:i},{default:a}]=await Promise.all([import("../rest/networks/validateNetworkTopology.js"),import("../rest/networks/support/ValidateNetworkTopologyParameters.js")]),n=a.from(e);j(this.featureServiceUrl,this.gdbVersion||null)?(n.sessionID=I,await b(this.featureServiceUrl,this.gdbVersion,!0)):n.sessionID=null,n.gdbVersion=this.gdbVersion||s;const l=this.networkServiceUrl,d=this.featureServiceUrl?g(this.featureServiceUrl,null,this.gdbVersion,!0):void 0,u=await i(l,n,{...t});return new w({statusUrl:u,editsResolver:d})}getSourceTypeById(e){if(!this.dataElement)return null;for(const t of this.dataElement.domainNetworks)for(const r of[t.edgeSources??[],t.junctionSources??[]])for(const o of r)if(o.sourceId===e)return r===t.edgeSources?"edge":"junction";return null}_traverseNetworkSources(e,t,r,o,s){for(const i of e)for(const e of[i.edgeSources??[],i.junctionSources??[]])for(const i of e)if(i[r]===s)return t.set(s,i[o]),i[o];return-1}async _fetchLayerMetaData(e,t){const o=await r(e,{responseType:"json",query:{f:"json"},...t});this.sourceJSON=o.data,this.read(o.data,{origin:"service"})}async _fetchDataElement(e,t,o){if(this.dataElement)return;const s=await r(`${e}/queryDataElements`,{responseType:"json",query:{layers:JSON.stringify([t]),f:"json"},...o}).then((e=>e.data.layerDataElements?.[0]));s&&this.read(s,{origin:"service"})}};function k(e,r){return new t({attributes:e.attributes,geometry:m({...e.geometry,spatialReference:r})})}e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}},service:{read:!0}},read:!1}})],U.prototype,"id",void 0),e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}},service:{read:{source:"name"}}},read:!1}})],U.prototype,"title",void 0),e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:{source:"url"},write:{target:"url",isRequired:!0}}},read:!1}})],U.prototype,"layerUrl",void 0),e([d({type:Object,json:{origins:{service:{read:!0}},read:!1}})],U.prototype,"dataElement",void 0),e([d({type:c,json:{origins:{service:{read:{source:"extent"}}},read:!1}})],U.prototype,"fullExtent",void 0),e([d({type:p,json:{origins:{service:{read:{source:"extent.spatialReference"}}},read:!1}})],U.prototype,"spatialReference",void 0),e([d({type:["utility","trace"],readOnly:!0,json:{read:!1,write:!1}})],U.prototype,"type",void 0),e([d({readOnly:!0})],U.prototype,"datasetName",null),e([d({readOnly:!0})],U.prototype,"owner",null),e([d({readOnly:!0})],U.prototype,"schemaGeneration",null),e([d({readOnly:!0})],U.prototype,"parsedUrl",null),e([d({readOnly:!0})],U.prototype,"featureServiceUrl",null),e([d({readOnly:!0})],U.prototype,"networkServiceUrl",null),e([d({readOnly:!0})],U.prototype,"layerId",null),e([d()],U.prototype,"sourceJSON",void 0),e([d({readOnly:!0})],U.prototype,"networkSystemLayers",null),e([d()],U.prototype,"gdbVersion",void 0),e([d({type:Date})],U.prototype,"historicMoment",void 0),U=e([u("esri.networks.Network")],U);const N=U;export{N as default};