UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.96 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../Graphic.js";import r from"../request.js";import o from"../core/Error.js";import{Loadable as s}from"../core/Loadable.js";import i from"../core/Logger.js";import{MultiOriginJSONSupportMixin as a}from"../core/MultiOriginJSONSupport.js";import{isAbortError as n}from"../core/promiseUtils.js";import{urlToObject as l}from"../core/urlUtils.js";import{generateUUID as d}from"../core/uuid.js";import{property as u,subclass as c}from"../core/accessorSupport/decorators.js";import p from"../geometry/Extent.js";import m from"../geometry/SpatialReference.js";import{fromJSON as h}from"../geometry/support/jsonUtils.js";import{versionMatches as y,onApplyEditsEvent as f,onUpdateMomentEvent as g,emitApplyEditsEvent as w}from"../layers/mixins/EditBusLayer.js";import{parse as v}from"../layers/support/arcgisLayerUrl.js";import S from"./support/TopologyValidationJobInfo.js";import{networkFromPortalItem as j}from"./support/utils.js";import{isVersionInEditSession as b,currentSessionId as I,isSafeToEditVersion as U}from"../versionManagement/support/versionManagementUtils.js";let k=class extends(a(s)){static fromPortalItem(e){return j(e)}constructor(e){super(e),this.id=d(),this.title=null,this.layerUrl=null,this.dataElement=null,this.fullExtent=null,this.spatialReference=null,this.type=null,this.sourceJSON=null,this._historicMoment=null,this._gdbVersion=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=>{b(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([f(this._applyEditsHandler),g(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 loaded(){return super.loaded}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}get gdbVersion(){return this._gdbVersion}set gdbVersion(e){this._gdbVersion=e}get historicMoment(){return this._historicMoment}set historicMoment(e){this._historicMoment=e}async load(e){return this.addResolvingPromise(this._load(e)),this}async _load(e){await Promise.all([this._fetchDataElement(this.featureServiceUrl,this.layerId.toString(),e),this._fetchLayerMetaData(this.layerUrl,e)])}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);b(this.featureServiceUrl,this.gdbVersion||null)?(i.sessionID=I,await U(this.featureServiceUrl,this.gdbVersion,!0)):i.sessionID=null,i.gdbVersion=this.gdbVersion;const a=this.networkServiceUrl,n=this.featureServiceUrl,l=w(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 m(r.spatialReference):null;e.push({layerId:t.layerId,editedFeatures:{adds:r?.adds?.map(e=>N(e,o))||[],updates:r?.updates?.map(e=>({original:N(e[0],o),current:N(e[1],o)}))||[],deletes:r?.deletes?.map(e=>N(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);b(this.featureServiceUrl,this.gdbVersion||null)?(n.sessionID=I,await U(this.featureServiceUrl,this.gdbVersion,!0)):n.sessionID=null,n.gdbVersion=this.gdbVersion||s;const l=this.networkServiceUrl,d=this.featureServiceUrl?w(this.featureServiceUrl,null,this.gdbVersion,!0):void 0,u=await i(l,n,{...t});return new S({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 N(e,r){return new t({attributes:e.attributes,geometry:h({...e.geometry,spatialReference:r})})}e([u({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}}},read:!1}})],k.prototype,"id",void 0),e([u({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}},service:{read:{source:"name"}}},read:!1}})],k.prototype,"title",void 0),e([u({type:String,nonNullable:!0,json:{origins:{"web-map":{read:{source:"url"},write:{target:"url",isRequired:!0}}},read:!1}})],k.prototype,"layerUrl",void 0),e([u({type:Object,json:{origins:{service:{read:!0}},read:!1}})],k.prototype,"dataElement",void 0),e([u({type:p,json:{origins:{service:{read:{source:"extent"}}},read:!1}})],k.prototype,"fullExtent",void 0),e([u({type:m,json:{origins:{service:{read:{source:"extent.spatialReference"}}},read:!1}})],k.prototype,"spatialReference",void 0),e([u({type:["utility","trace"],readOnly:!0,json:{read:!1,write:!1}})],k.prototype,"type",void 0),e([u({readOnly:!0})],k.prototype,"datasetName",null),e([u({readOnly:!0})],k.prototype,"owner",null),e([u({readOnly:!0})],k.prototype,"schemaGeneration",null),e([u({readOnly:!0})],k.prototype,"parsedUrl",null),e([u({readOnly:!0})],k.prototype,"featureServiceUrl",null),e([u({readOnly:!0})],k.prototype,"networkServiceUrl",null),e([u({readOnly:!0})],k.prototype,"layerId",null),e([u()],k.prototype,"sourceJSON",void 0),e([u({readOnly:!0})],k.prototype,"networkSystemLayers",null),e([u({type:String})],k.prototype,"gdbVersion",null),e([u({type:Date})],k.prototype,"historicMoment",null),e([u()],k.prototype,"_historicMoment",void 0),e([u()],k.prototype,"_gdbVersion",void 0),k=e([c("esri.networks.Network")],k);const V=k;export{V as default};