@arcgis/core 4.33.0-next.20250331 → 4.33.0-next.20250401
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/0297e55a49ca0d1231ef.js +1 -0
- package/assets/esri/core/workers/chunks/{98da74243df03e0cc70d.js → 067dda58592fbf4fb812.js} +1 -1
- package/assets/esri/core/workers/chunks/093421648cc61afdeb3c.js +1 -0
- package/assets/esri/core/workers/chunks/0db4c0071282dd94f3b2.js +1 -0
- package/assets/esri/core/workers/chunks/1072b4f37eacbbfda2c8.js +1 -0
- package/assets/esri/core/workers/chunks/{4d95cc85f4b73e857b1f.js → 11badb73d43059374ad8.js} +1 -1
- package/assets/esri/core/workers/chunks/{dcb043986fb065de0366.js → 16607e71804eff64c0e1.js} +1 -1
- package/assets/esri/core/workers/chunks/18f8b41bd761e9ab60d0.js +1 -0
- package/assets/esri/core/workers/chunks/{ed831e51c2a03ee95879.js → 19e83b184d8b4d0b3007.js} +1 -1
- package/assets/esri/core/workers/chunks/{5de3aee547113bfd59df.js → 1b87fa15470cce26feea.js} +1 -1
- package/assets/esri/core/workers/chunks/{dde03a893f9cef8e0f45.js → 1d322685016263f86cf5.js} +1 -1
- package/assets/esri/core/workers/chunks/{e4b80c8f4c45fd78bde1.js → 23de8aeed5b82c682cbe.js} +1 -1
- package/assets/esri/core/workers/chunks/269531e770376ed9e4fd.js +1 -0
- package/assets/esri/core/workers/chunks/2791f1f2791087d0217f.js +1 -0
- package/assets/esri/core/workers/chunks/{48ad7beb48dcc2693cc3.js → 2ab7d36409e9af3ac3da.js} +1 -1
- package/assets/esri/core/workers/chunks/{a7a1832274892e99c388.js → 30a047bd66f333bb7d2d.js} +1 -1
- package/assets/esri/core/workers/chunks/{94292c7afff18694d55e.js → 322cb1b1871d03b69f0a.js} +37 -37
- package/assets/esri/core/workers/chunks/{b52a3a48d2d3ff22542d.js → 3577909b8e84959d415b.js} +1 -1
- package/assets/esri/core/workers/chunks/37e49d1a1407c193dcd0.js +1 -0
- package/assets/esri/core/workers/chunks/3b7284516a0e34a9e85e.js +1 -0
- package/assets/esri/core/workers/chunks/{6cb5ce0a6bb85c624a21.js → 400f95295bbfced31076.js} +1 -1
- package/assets/esri/core/workers/chunks/401ff3c83789c72e9ac9.js +1 -0
- package/assets/esri/core/workers/chunks/{6339a24874c698594101.js → 40b33c9bd271cddbd837.js} +1 -1
- package/assets/esri/core/workers/chunks/4ba34124054752b363c0.js +1 -0
- package/assets/esri/core/workers/chunks/4cc77769009901a112ec.js +39 -0
- package/assets/esri/core/workers/chunks/5aae4e127e888f69435a.js +1 -0
- package/assets/esri/core/workers/chunks/{0943695a1dcd21c45e83.js → 5b32c2a1b276352593dc.js} +1 -1
- package/assets/esri/core/workers/chunks/{087a09b4c41abef6b516.js → 5c757e20c0543e6a49b3.js} +1 -1
- package/assets/esri/core/workers/chunks/6280e1fe944ea4a71b91.js +1 -0
- package/assets/esri/core/workers/chunks/{9c59fc2df8081e65a128.js → 628395830c78b95b46dc.js} +1 -1
- package/assets/esri/core/workers/chunks/{edcc0fefd57323d2cb67.js → 6828e4936db0121a9638.js} +1 -1
- package/assets/esri/core/workers/chunks/{1cd9b5ef62582b25df9b.js → 69b5d0ef14fb521b0fd7.js} +1 -1
- package/assets/esri/core/workers/chunks/6e679703b5d6fc1b91a5.js +1 -0
- package/assets/esri/core/workers/chunks/6f3731f19497cbc6ea74.js +1 -0
- package/assets/esri/core/workers/chunks/72d7e45e7eb28f2cc0b0.js +1 -0
- package/assets/esri/core/workers/chunks/7649d59b0b7d53818a29.js +1 -0
- package/assets/esri/core/workers/chunks/{fe3ed029b07bb1e4aef3.js → 77ae11dbd3e1eeacd7ee.js} +1 -1
- package/assets/esri/core/workers/chunks/7978b66cdfe078960ddd.js +1 -0
- package/assets/esri/core/workers/chunks/7b8f0b63b968ff40d00d.js +1 -0
- package/assets/esri/core/workers/chunks/7e00122014d0a55363a8.js +319 -0
- package/assets/esri/core/workers/chunks/{f452ca61842dbe8de9af.js → 7ea5bbb52e84be9a608e.js} +1 -1
- package/assets/esri/core/workers/chunks/{eb9d2bb8b44a93347274.js → 7ef9bcd58af499a14a08.js} +1 -1
- package/assets/esri/core/workers/chunks/{b2f8702a9f54fff23ad9.js → 7f31dbe0ca8974a10be8.js} +1 -1
- package/assets/esri/core/workers/chunks/80427cd9f0c2e07f21c3.js +1 -0
- package/assets/esri/core/workers/chunks/{77199b4b39ee8b4303de.js → 82a58a405332d43a328f.js} +1 -1
- package/assets/esri/core/workers/chunks/8725580f6d2a495051b5.js +1 -0
- package/assets/esri/core/workers/chunks/{626db8488f9d931cf55c.js → 899f197556b6ced6eddf.js} +2 -2
- package/assets/esri/core/workers/chunks/8aae03e347ab18ae6ee2.js +1 -0
- package/assets/esri/core/workers/chunks/8d49c79e549e90371303.js +1 -0
- package/assets/esri/core/workers/chunks/{a9b6377f1fef5826f28d.js → 8f35416a5036897d6289.js} +1 -1
- package/assets/esri/core/workers/chunks/91439b59260b0fb04be9.js +1 -0
- package/assets/esri/core/workers/chunks/{a01c86910fe4984eb788.js → 9574896c90b39fa7ecb4.js} +1 -1
- package/assets/esri/core/workers/chunks/96978d039f183565bffa.js +1 -0
- package/assets/esri/core/workers/chunks/9a641fb94819574e48f6.js +1 -0
- package/assets/esri/core/workers/chunks/{72c7126dbd27fa48fcdb.js → a3421383e48379012c9c.js} +1 -1
- package/assets/esri/core/workers/chunks/{f8d1c7df671733c3325c.js → b64f708f821dd2bb51cd.js} +1 -1
- package/assets/esri/core/workers/chunks/{3e4204502f6e09483c60.js → b7a1185ac49480fc1410.js} +1 -1
- package/assets/esri/core/workers/chunks/{aa712f850fd129ca5ed8.js → bba6d7615d8f3862fe70.js} +1 -1
- package/assets/esri/core/workers/chunks/{1cf8a431e5da946c7d27.js → bd0dbad694ce5531deab.js} +1 -1
- package/assets/esri/core/workers/chunks/c1bd47cde53918f454ca.js +1 -0
- package/assets/esri/core/workers/chunks/{1d0473dd43c88ab5776d.js → c589d32f8efcca6bf712.js} +1 -1
- package/assets/esri/core/workers/chunks/{081699532b183db1e7c2.js → cda6ae4c5cb67e22b454.js} +1 -1
- package/assets/esri/core/workers/chunks/{460afde071df9f35182d.js → e14449f07ed3386f4f2b.js} +1 -1
- package/assets/esri/core/workers/chunks/{d0fbd4c6bffe0cb98d14.js → e592731ac12b9bc646ff.js} +1 -1
- package/assets/esri/core/workers/chunks/e5aff9b10877fb04d6de.js +1 -0
- package/assets/esri/core/workers/chunks/e6469173c65531d6524a.js +1 -0
- package/assets/esri/core/workers/chunks/e6544e966f14fb410157.js +1 -0
- package/assets/esri/core/workers/chunks/e8312c999b3f0c9ef09e.js +1 -0
- package/assets/esri/core/workers/chunks/{cb386923200272cf26a9.js → e9e517a2141e504eec64.js} +1 -1
- package/assets/esri/core/workers/chunks/eb011e8b14db37ddb110.js +1 -0
- package/assets/esri/core/workers/chunks/{f809cbfb744adb4fad29.js → efb0f3ec2344adcb24f3.js} +1 -1
- package/assets/esri/core/workers/chunks/{999e8dbe6f4d0665b3ab.js → f5fcba6ca6f43bf1d65d.js} +1 -1
- package/assets/esri/core/workers/chunks/fa9ef9e8eae505371965.js +1 -0
- package/assets/esri/core/workers/chunks/fb5b852d0f72df014377.js +1 -0
- package/assets/esri/core/workers/chunks/ff62b813fff4a015a8a6.js +1 -0
- package/core/has.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/TemplateDefinitionBase.js +1 -1
- package/geometry/asserts.js +1 -1
- package/geometry/support/normalizeUtils.js +1 -1
- package/identity/IdentityManagerBase.js +1 -1
- package/interfaces.d.ts +7 -2
- package/layers/TileLayer.js +1 -1
- package/layers/graphics/applyEditsUtils.js +1 -1
- package/layers/graphics/featureConversionUtils.js +1 -1
- package/layers/graphics/sources/GeoJSONSource.js +1 -1
- package/layers/graphics/sources/MemorySource.js +1 -1
- package/layers/graphics/sources/connections/GeoEventConnection.js +1 -1
- package/layers/graphics/sources/support/sourceUtils.js +1 -1
- package/layers/support/ElevationQuery.js +1 -1
- package/layers/support/SubtypeSublayer.js +1 -1
- package/layers/support/wmtsUtils.js +1 -1
- package/networks/support/UtilityNetworkLookupHelper.js +1 -1
- package/package.json +3 -3
- package/portal/support/geometryServiceUtils.js +1 -1
- package/renderers/support/DictionaryScriptEvaluator.js +1 -1
- package/rest/support/printTaskUtils.js +1 -1
- package/smartMapping/support/adapters/InMemoryLayerAdapter.js +1 -1
- package/support/revision.js +1 -1
- package/undoredo/support/Services.js +1 -1
- package/versionManagement/VersioningState.js +1 -1
- package/views/2d/engine/webgl/Mesh2D.js +1 -1
- package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
- package/views/2d/layers/features/layerAdapters/InMemoryLayerAdapter.js +1 -1
- package/views/2d/layers/features/support/FeatureSetReaderPBFHeader.js +1 -1
- package/views/3d/layers/graphics/pipeline/Feature3DPipeline.js +1 -1
- package/views/3d/layers/graphics/pipeline/Feature3DPipelineWorker.js +1 -1
- package/views/3d/layers/graphics/pipeline/Feature3DPipelineWorkerHandle.js +1 -1
- package/views/3d/layers/graphics/pipeline/rendering/FeaturePipelineRenderManager.js +1 -1
- package/views/3d/layers/graphics/pipeline/rendering/RenderCommandContext.js +1 -1
- package/views/3d/layers/graphics/pipeline/symbolization/TestObjectSymbol.js +1 -1
- package/views/3d/layers/graphics/pipeline/symbolization/TestSymbol.js +1 -1
- package/views/3d/layers/i3s/I3SClientMaterialUtil.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/layers/i3s/I3SUtil.js +1 -1
- package/views/3d/support/engineContent/sdfPrimitives.js +1 -1
- package/views/3d/webgl-engine/core/FBOCache.js +1 -1
- package/views/3d/webgl-engine/core/shaderTechnique/ShaderTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/core/shaderTechnique/ShaderTechniqueRepository.js +1 -1
- package/views/3d/webgl-engine/lib/Texture.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/textureUtils.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/View.js +1 -1
- package/views/ViewAnimation.js +1 -1
- package/views/webgl/ShaderBuilder.js +1 -1
- package/views/webgl/Texture.js +1 -1
- package/views/webgl/textureUtils.js +1 -1
- package/widgets/Editor/AddAssociationWorkflow.js +1 -1
- package/widgets/Editor/UpdateFeaturesWorkflow.js +5 -0
- package/widgets/Editor/UpdateFeaturesWorkflowData.js +5 -0
- package/widgets/Editor/UpdateRecordWorkflow.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Feature/support/relatedFeatureUtils.js +1 -1
- package/widgets/FeatureForm/FieldInput.js +1 -1
- package/widgets/FloorFilter/FloorFilterViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/dataCaptureUtils.js +1 -1
- package/widgets/Slider.js +1 -1
- package/widgets/UtilityNetworkTraceAnalysis/UtilityNetworkTraceAnalysisViewModel.js +1 -1
- package/widgets/VersionManagement/VersionManagementViewModel.js +1 -1
- package/widgets/support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/028e2e0fa6971aaaaae8.js +0 -1
- package/assets/esri/core/workers/chunks/0e82365be7d9257e7cb2.js +0 -1
- package/assets/esri/core/workers/chunks/1322096a72e910f23167.js +0 -1
- package/assets/esri/core/workers/chunks/186387a561364a11e574.js +0 -1
- package/assets/esri/core/workers/chunks/3808f10747cecc8a1a9b.js +0 -1
- package/assets/esri/core/workers/chunks/3f7c57d5f3bdefa74d18.js +0 -1
- package/assets/esri/core/workers/chunks/424e2058228e5f6a183d.js +0 -1
- package/assets/esri/core/workers/chunks/4aa0a58ded4465ea28bd.js +0 -1
- package/assets/esri/core/workers/chunks/4bb65ef7b3a02ebe416e.js +0 -1
- package/assets/esri/core/workers/chunks/4d798da25a726f179089.js +0 -319
- package/assets/esri/core/workers/chunks/4ffdff269aae8c293cb4.js +0 -1
- package/assets/esri/core/workers/chunks/564cc81c232c97646833.js +0 -1
- package/assets/esri/core/workers/chunks/5820808c7659460969d4.js +0 -1
- package/assets/esri/core/workers/chunks/5d01f0b86566d08ba29d.js +0 -1
- package/assets/esri/core/workers/chunks/6c378e7a6ca29d530880.js +0 -1
- package/assets/esri/core/workers/chunks/7d1c39c2a80e20a0595f.js +0 -1
- package/assets/esri/core/workers/chunks/86ee278919038260696e.js +0 -39
- package/assets/esri/core/workers/chunks/8752f807c05d1ec215e8.js +0 -1
- package/assets/esri/core/workers/chunks/8ef5e6f1c606e5e41002.js +0 -1
- package/assets/esri/core/workers/chunks/921b41b101957cfc1cfd.js +0 -1
- package/assets/esri/core/workers/chunks/9ef509e0853ad41f7690.js +0 -1
- package/assets/esri/core/workers/chunks/9f18de17fbcad0e5c140.js +0 -1
- package/assets/esri/core/workers/chunks/a53e9f5092de715da025.js +0 -1
- package/assets/esri/core/workers/chunks/aa3a45e8228216c1739b.js +0 -1
- package/assets/esri/core/workers/chunks/ab0113d1269675dcd520.js +0 -1
- package/assets/esri/core/workers/chunks/b23d16745674486ddd6c.js +0 -1
- package/assets/esri/core/workers/chunks/b3c126e8a0a722c03efc.js +0 -1
- package/assets/esri/core/workers/chunks/c7aa4a8263e21f631004.js +0 -1
- package/assets/esri/core/workers/chunks/cc441051a52bfbda9caf.js +0 -1
- package/assets/esri/core/workers/chunks/ccc6f6f7052985bebdab.js +0 -1
- package/assets/esri/core/workers/chunks/d3912886ac2910290f43.js +0 -1
- package/assets/esri/core/workers/chunks/d8b903b4147b090576f2.js +0 -1
- package/assets/esri/core/workers/chunks/da8a002d18544def5383.js +0 -1
- package/assets/esri/core/workers/chunks/f28eaf1d3a7f12788bcf.js +0 -1
- package/assets/esri/core/workers/chunks/f9bedb421d4e115a888f.js +0 -1
- package/assets/esri/core/workers/chunks/faed301a25252c619cff.js +0 -1
- package/assets/esri/core/workers/chunks/fc9758006a7135c7d9c3.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import t from"../config.js";import{id as r}from"../kernel.js";import s from"../request.js";import i from"../core/Error.js";import o from"../core/Evented.js";import{on as n}from"../core/events.js";import{fixJson as a}from"../core/lang.js";import{getDeepValue as h}from"../core/object.js";import{createResolver as l,onAbort as c,isAborted as d}from"../core/promiseUtils.js";import{urlToObject as u,hasSameOrigin as p,Url as _,queryToObject as f,base64UrlEncode as g,objectToQuery as m,normalize as v,getProxyRule as S,makeAbsolute as w,addQueryParameters as I}from"../core/urlUtils.js";import{property as A}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as k}from"../core/accessorSupport/decorators/subclass.js";import y from"./IdentityModal.js";import U from"./OAuthCredential.js";import T from"./OAuthInfo.js";import x from"./ServerInfo.js";import{isSecureProxyService as O,normalizeArcGISOnlineOrgDomain as P}from"../portal/support/urlUtils.js";const R={},C=e=>{const t=new _(e.owningSystemUrl).host,r=new _(e.server).host,s=/.+\.arcgis\.com$/i;return s.test(t)&&s.test(r)},D=(e,t)=>!!(C(e)&&t&&t.some((t=>t.test(e.server))));let b=null,q=null;try{b=window.localStorage,q=window.sessionStorage}catch{}class j extends o{constructor(){super(),this._portalConfig=globalThis.esriGeowConfig,this.serverInfos=[],this.oAuthInfos=[],this.credentials=[],this._soReqs=[],this._xoReqs=[],this._portals=[],this._defaultOAuthInfo=null,this._defaultTokenValidity=60,this.dialog=null,this.tokenValidity=null,this.normalizeWebTierAuth=!1,this._appOrigin="null"!==window.origin?window.origin:window.location.origin,this._appUrlObj=u(window.location.href),this._busy=null,this._rejectOnPersistedPageShow=!1,this._oAuthLocationParams=null,this._gwTokenUrl="/sharing/rest/generateToken",this._agsRest="/rest/services",this._agsPortal=/\/sharing(\/|$)/i,this._agsAdmin=/(https?:\/\/[^/]+\/[^/]+)\/admin\/?(\/.*)?$/i,this._adminSvcs=/\/rest\/admin\/services(\/|$)/i,this._gwDomains=[{regex:/^https?:\/\/www\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:dev|[a-z\d-]+\.mapsdev)\.arcgis\.com/i,customBaseUrl:"mapsdev.arcgis.com",tokenServiceUrl:"https://dev.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:devext|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,customBaseUrl:"mapsdevext.arcgis.com",tokenServiceUrl:"https://devext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:qaext|[a-z\d-]+\.mapsqa)\.arcgis\.com/i,customBaseUrl:"mapsqa.arcgis.com",tokenServiceUrl:"https://qaext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/[a-z\d-]+\.maps\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"}],this._legacyFed=[],this._regexSDirUrl=/http.+\/rest\/services\/?/gi,this._regexServerType=/(\/(FeatureServer|GPServer|GeoDataServer|GeocodeServer|GeoenrichmentServer|GeometryServer|GlobeServer|ImageServer|KnowledgeGraphServer|MapServer|MissionServer|MobileServer|NAServer|NetworkDiagramServer|OGCFeatureServer|ParcelFabricServer|RelationalCatalogServer|SceneServer|StreamServer|UtilityNetworkServer|ValidationServer|VectorTileServer|VersionManagementServer|VideoServer)).*/gi,this._gwUser=/http.+\/users\/([^/]+).*/i,this._gwItem=/http.+\/items\/([^/]+).*/i,this._gwGroup=/http.+\/groups\/([^/]+).*/i,this._rePortalTokenSvc=/\/sharing(\/rest)?\/generatetoken/i,this._createDefaultOAuthInfo=!0,this._hasTestedIfAppIsOnPortal=!1,this._getPlatformSelfError=null,this._getOAuthLocationParams(),window.addEventListener("pageshow",(e=>{this._pageShowHandler(e)}))}registerServers(e){const t=this.serverInfos;t?(e=e.filter((e=>!this.findServerInfo(e.server))),this.serverInfos=t.concat(e)):this.serverInfos=e,e.forEach((e=>{e.owningSystemUrl&&this._portals.push(e.owningSystemUrl),e.hasPortal&&this._portals.push(e.server)}))}registerOAuthInfos(e){const t=this.oAuthInfos;if(t){for(const r of e){const e=this.findOAuthInfo(r.portalUrl);e&&t.splice(t.indexOf(e),1)}this.oAuthInfos=t.concat(e)}else this.oAuthInfos=e}registerToken(e){e={...e};const t=this._sanitizeUrl(e.server),r=this._isServerRsrc(t);let s,i=this.findServerInfo(t),o=!0;i||(i=new x,i.server=this._getServerInstanceRoot(t),r?i.hasServer=!0:(i.tokenServiceUrl=this._getTokenSvcUrl(t),i.hasPortal=!0),this.registerServers([i])),s=this._findCredential(t),s?(delete e.server,Object.assign(s,e),o=!1):(s=new E({userId:e.userId,server:i.server??void 0,token:e.token,expires:e.expires,ssl:e.ssl,scope:r?"server":"portal"}),s.resources=[t],this.credentials.push(s)),s.emitTokenChange(!1),o||s.refreshServerTokens()}toJSON(){return a({serverInfos:this.serverInfos.map((e=>e.toJSON())),oAuthInfos:this.oAuthInfos.map((e=>e.toJSON())),credentials:this.credentials.map((e=>e.toJSON()))})}initialize(e){if(!e)return;"string"==typeof e&&(e=JSON.parse(e));const t=e.serverInfos,r=e.oAuthInfos,s=e.credentials;if(t){const e=[];t.forEach((t=>{t.server&&t.tokenServiceUrl&&e.push(t.declaredClass?t:new x(t))})),e.length&&this.registerServers(e)}if(r){const e=[];r.forEach((t=>{t.appId&&e.push(t.declaredClass?t:new T(t))})),e.length&&this.registerOAuthInfos(e)}s&&s.forEach((e=>{e.server&&e.token&&e.expires&&e.expires>Date.now()&&((e=e.declaredClass?e:new E(e)).emitTokenChange(),this.credentials.push(e))}))}findServerInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.serverInfos)if(this._hasSameServerInstance(r.server,e)){t=r;break}return t}findOAuthInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.oAuthInfos)if(this._hasSameServerInstance(r.portalUrl,e)){t=r;break}return t}findCredential(e,t){if(!e)return;let r;e=this._sanitizeUrl(e);const s=this._isServerRsrc(e)?"server":"portal";if(t){for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&t===i.userId&&i.scope===s){r=i;break}}else for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&-1!==this._getIdenticalSvcIdx(e,i)&&i.scope===s){r=i;break}return r}getCredential(e,t){let r,s,o=!0;t&&(r=!!t.token,s=t.error,o=!1!==t.prompt),t={...t},e=this._sanitizeUrl(e);const n=new AbortController,a=l();if(t.signal&&c(t.signal,(()=>{n.abort()})),c(n,(()=>{a.reject(new i("identity-manager:user-aborted","ABORTED"))})),d(n))return a.promise;t.signal=n.signal;const h=this._isAdminResource(e),u=r?this.findCredential(e):null;let _;if(u&&s&&s.details&&498===s.details.httpStatus)u.destroy();else if(u)return _=new i("identity-manager:not-authorized","You are currently signed in as: '"+u.userId+"'. You do not have access to this resource: "+e,{error:s}),a.reject(_),a.promise;const f=this._findCredential(e,t);if(f)return a.resolve(f),a.promise;let g=this.findServerInfo(e);if(g)!g.hasPortal&&g.server&&g.owningSystemUrl&&this._hasSameServerInstance(g.server,g.owningSystemUrl)&&(g.hasPortal=!0),!g.hasServer&&this._isServerRsrc(e)&&(g._restInfoPms=this._getTokenSvcUrl(e),g.hasServer=!0);else{const t=this._getTokenSvcUrl(e);if(!t)return _=new i("identity-manager:unknown-resource","Unknown resource - could not find token service endpoint."),a.reject(_),a.promise;g=new x,g.server=this._getServerInstanceRoot(e),"string"==typeof t?(g.tokenServiceUrl=t,g.hasPortal=!0):(g._restInfoPms=t,g.hasServer=!0),this.registerServers([g])}return g.hasPortal&&void 0===g._selfReq&&(o||p(g.tokenServiceUrl,this._appOrigin)||this._gwDomains.some((e=>e.tokenServiceUrl===g.tokenServiceUrl)))&&(g._selfReq={owningTenant:t?.owningTenant,selfDfd:this._getPortalSelf(g.tokenServiceUrl.replace(this._rePortalTokenSvc,"/sharing/rest/portals/self"),e)}),this._enqueue(e,g,t,a,h)}getResourceName(e){return this._isRESTService(e)?e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"")||"":this._gwUser.test(e)&&e.replace(this._gwUser,"$1")||this._gwItem.test(e)&&e.replace(this._gwItem,"$1")||this._gwGroup.test(e)&&e.replace(this._gwGroup,"$1")||""}generateToken(e,t,r){const o=this._rePortalTokenSvc.test(e.tokenServiceUrl),n=new _(this._appOrigin),a=e.shortLivedTokenValidity;let h,l,c,d,u,f,g,m;t&&(m=this.tokenValidity||a||this._defaultTokenValidity,m>a&&a>0&&(m=a)),r&&(h=r.isAdmin,l=r.serverUrl,c=r.token,f=r.signal,g=r.ssl,e.customParameters=r.customParameters),h?d=e.adminTokenServiceUrl:(d=e.tokenServiceUrl,u=new _(d.toLowerCase()),e.webTierAuth&&r?.serverUrl&&!g&&"http"===n.scheme&&(p(n.uri,d,!0)||"https"===u.scheme&&n.host===u.host&&"7080"===n.port&&"7443"===u.port)&&(d=d.replace(/^https:/i,"http:").replace(/:7443/i,":7080")));const v={query:{request:"getToken",username:t?.username,password:t?.password,serverUrl:l,token:c,expiration:m,referer:h||o?this._appOrigin:null,client:h?"referer":null,f:"json",...e.customParameters},method:"post",authMode:"anonymous",useProxy:this._useProxy(e,r),signal:f,...r?.ioArgs};o||(v.withCredentials=!1);return s(d,v).then((r=>{const s=r.data;if(!s?.token)return new i("identity-manager:authentication-failed","Unable to generate token");const o=e.server;return R[o]||(R[o]={}),t&&(R[o][t.username]=t.password),s.validity=m,s}))}isBusy(){return!!this._busy}async checkSignInStatus(e){return(await this.checkAppAccess(e,"")).credential}checkAppAccess(e,t,r){let o=!1;return this.getCredential(e,{prompt:!1}).then((n=>{let a;const h={f:"json"};if("portal"===n.scope)if(t&&(this._doPortalSignIn(e)||r?.force))a=n.server+"/sharing/rest/oauth2/validateAppAccess",h.client_id=t;else{if(!n.token)return{credential:n};a=n.server+"/sharing/rest"}else{if(!n.token)return{credential:n};a=n.server+"/rest/services"}return n.token&&(h.token=n.token),s(a,{query:h,authMode:"anonymous"}).then((e=>{if(!1===e.data.valid)throw new i("identity-manager:not-authorized",`You are currently signed in as: '${n.userId}'.`,e.data);return o=!!e.data.viewOnlyUserTypeApp,{credential:n}})).catch((e=>{if("identity-manager:not-authorized"===e.name)throw e;const t=e.details?.httpStatus;if(498===t)throw n.destroy(),new i("identity-manager:not-authenticated","User is not signed in.");if(400===t)throw new i("identity-manager:invalid-request");return{credential:n}}))})).then((e=>({credential:e.credential,viewOnly:o})))}setOAuthResponseHash(e){e&&("#"===e.charAt(0)&&(e=e.slice(1)),this._processOAuthPopupParams(f(e)))}setOAuthRedirectionHandler(e){this._oAuthRedirectFunc=e}setProtocolErrorHandler(e){this._protocolFunc=e}signIn(e,t,r={}){const s=l(),o=()=>{h?.remove(),d?.remove(),this.dialog?.destroy(),this.dialog=h=d=null},n=()=>{o(),this._oAuthDfd=null,s.reject(new i("identity-manager:user-aborted","ABORTED"))};r.signal&&c(r.signal,(()=>{n()}));const a=new y({open:!0,resource:this.getResourceName(e),server:t.server});this.dialog=a,this.emit("dialog-create");let h=a.on("cancel",n),d=a.on("submit",(e=>{this.generateToken(t,e,{isAdmin:r.isAdmin,signal:r.signal}).then((i=>{o();const n=new E({userId:e.username,server:t.server??void 0,token:i.token,expires:null!=i.expires?Number(i.expires):null,ssl:!!i.ssl,isAdmin:r.isAdmin,validity:i.validity});s.resolve(n)})).catch((e=>{a.error=e,a.signingIn=!1}))}));return s.promise}oAuthSignIn(e,t,r,s){this._oAuthDfd=l();const o=this._oAuthDfd;let n;s?.signal&&c(s.signal,(()=>{const e=this._oAuthDfd&&this._oAuthDfd.oAuthWin_;e&&!e.closed?e.close():this.dialog&&u()})),o.resUrl_=e,o.sinfo_=t,o.oinfo_=r;const a=r._oAuthCred;if(a.storage&&("authorization-code"===r.flowType||"auto"===r.flowType&&t.currentVersion>=8.4)){let e=crypto.getRandomValues(new Uint8Array(32));n=g(e),a.codeVerifier=n,e=crypto.getRandomValues(new Uint8Array(32)),a.stateUID=g(e),a.save()||(a.codeVerifier=n=null)}else a.codeVerifier=null;let h,d;this._getCodeChallenge(n).then((i=>{const o=!s||!1!==s.oAuthPopupConfirmation;if(!r.popup||!o)return void this._doOAuthSignIn(e,t,r,i);const n=new y({oAuthPrompt:!0,server:t.server,open:!0});this.dialog=n,this.emit("dialog-create"),h=n.on("cancel",u),d=n.on("submit",(()=>{p(),this._doOAuthSignIn(e,t,r,i)}))}));const u=()=>{p(),this._oAuthDfd=null,o.reject(new i("identity-manager:user-aborted","ABORTED"))},p=()=>{h?.remove(),d?.remove(),this.dialog?.destroy(),this.dialog=null};return o.promise}destroyCredentials(){if(this.credentials){this.credentials.slice().forEach((e=>{e.destroy()}))}this.emit("credentials-destroy")}enablePostMessageAuth(e="https://www.arcgis.com/sharing/rest"){this._postMessageAuthHandle&&this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=n(window,"message",(t=>{if((t.origin===this._appOrigin||t.origin.endsWith(".arcgis.com"))&&"arcgis:auth:requestCredential"===t.data?.type){const r=t.source;this.getCredential(e).then((e=>{r.postMessage({type:"arcgis:auth:credential",credential:{expires:e.expires,server:e.server,ssl:e.ssl,token:e.token,userId:e.userId}},t.origin)})).catch((e=>{r.postMessage({type:"arcgis:auth:error",error:{name:e.name,message:e.message}},t.origin)}))}}))}disablePostMessageAuth(){this._postMessageAuthHandle&&(this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=null)}_getOAuthLocationParams(){let e=window.location.hash;if(e){"#"===e.charAt(0)&&(e=e.slice(1));const t=f(e);let r=!1;if(t.access_token&&t.expires_in&&t.state&&t.hasOwnProperty("username"))try{t.state=JSON.parse(t.state),t.state.portalUrl&&(this._oAuthLocationParams=t,r=!0)}catch{}else if(t.error&&t.error_description&&(console.log("IdentityManager OAuth Error: ",t.error," - ",t.error_description),"access_denied"===t.error&&(r=!0,t.state)))try{t.state=JSON.parse(t.state)}catch{}r&&(window.location.hash=t.state?.hash||"")}let t=window.location.search;if(t){"?"===t.charAt(0)&&(t=t.slice(1));const e=f(t);let r=!1;if(e.code&&e.state)try{e.state=JSON.parse(e.state),e.state.portalUrl&&e.state.uid&&(this._oAuthLocationParams=e,r=!0)}catch{}else if(e.error&&e.error_description&&(console.log("IdentityManager OAuth Error: ",e.error," - ",e.error_description),"access_denied"===e.error&&(r=!0,e.state)))try{e.state=JSON.parse(e.state)}catch{}if(r){const t={...e};["code","error","error_description","message_code","persist","state"].forEach((e=>{delete t[e]}));const r=m(t),s=window.location.pathname+(r?`?${r}`:"")+(e.state?.hash||"");window.history.replaceState(window.history.state,"",s)}}}_getOAuthToken(e,t,r,i,o){return e=e.replace(/^http:/i,"https:"),s(`${e}/sharing/rest/oauth2/token`,{authMode:"anonymous",method:"post",query:i&&o?{grant_type:"authorization_code",code:t,redirect_uri:i,client_id:r,code_verifier:o}:{grant_type:"refresh_token",refresh_token:t,client_id:r}}).then((e=>e.data))}async _getCodeChallenge(e){if(e&&globalThis.isSecureContext){const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-256",t);return g(new Uint8Array(r))}return null}_pageShowHandler(e){if(e.persisted&&this.isBusy()&&this._rejectOnPersistedPageShow){const e=new i("identity-manager:user-aborted","ABORTED");this._errbackFunc(e)}}_findCredential(e,t){let r,s,i,o,n=-1;const a=t?.token,h=t?.resource,l=this._isServerRsrc(e)?"server":"portal",c=this.credentials.filter((t=>this._hasSameServerInstance(t.server,e)&&t.scope===l));if(e=h||e,c.length)if(1===c.length){if(r=c[0],i=this.findServerInfo(r.server),s=i?.owningSystemUrl,o=s?this.findCredential(s,r.userId):void 0,n=this._getIdenticalSvcIdx(e,r),!a)return-1===n&&r.resources.push(e),this._addResource(e,o),r;-1!==n&&(r.resources.splice(n,1),this._removeResource(e,o))}else{let t,r;if(c.some((a=>(r=this._getIdenticalSvcIdx(e,a),-1!==r&&(t=a,i=this.findServerInfo(t.server),s=i?.owningSystemUrl,o=s?this.findCredential(s,t.userId):void 0,n=r,!0)))),a)t&&(t.resources.splice(n,1),this._removeResource(e,o));else if(t)return this._addResource(e,o),t}}_findOAuthInfo(e){let t=this.findOAuthInfo(e);if(!t)for(const r of this.oAuthInfos)if(this._isIdProvider(r.portalUrl,e)){t=r;break}return t}_addResource(e,t){t&&-1===this._getIdenticalSvcIdx(e,t)&&t.resources.push(e)}_removeResource(e,t){let r=-1;t&&(r=this._getIdenticalSvcIdx(e,t),r>-1&&t.resources.splice(r,1))}_useProxy(e,t){return t?.isAdmin&&!p(e.adminTokenServiceUrl,this._appOrigin)||!this._isPortalDomain(e.tokenServiceUrl)&&"10.1"===String(e.currentVersion)&&!p(e.tokenServiceUrl,this._appOrigin)}_getOrigin(e){const t=new _(e);return t.scheme+"://"+t.host+(null!=t.port?":"+t.port:"")}_getServerInstanceRoot(e){const t=e.toLowerCase();let r=t.indexOf(this._agsRest);return-1===r&&this._isAdminResource(e)&&(r=this._agsAdmin.test(e)?e.replace(this._agsAdmin,"$1").length:e.search(this._adminSvcs)),-1!==r||O(t)||(r=t.indexOf("/sharing")),-1===r&&t.endsWith("/")&&(r=t.length-1),r>-1?e.slice(0,r):e}_hasSameServerInstance(e,t){return e.endsWith("/")&&(e=e.slice(0,-1)),e=e.toLowerCase(),t=this._getServerInstanceRoot(t).toLowerCase(),e=P(e),t=P(t),(e=e.slice(Math.max(0,e.indexOf(":"))))===(t=t.slice(Math.max(0,t.indexOf(":"))))}_sanitizeUrl(e){const r=(t.request.proxyUrl||"").toLowerCase(),s=r?e.toLowerCase().indexOf(r+"?"):-1;return-1!==s&&(e=e.slice(s+r.length+1)),e=v(e),u(e).path}_isRESTService(e){return e.includes(this._agsRest)}_isAdminResource(e){return this._agsAdmin.test(e)||this._adminSvcs.test(e)}_isServerRsrc(e){return this._isRESTService(e)||this._isAdminResource(e)}_isIdenticalService(e,t){let r=!1;if(this._isRESTService(e)&&this._isRESTService(t)){const s=this._getSuffix(e).toLowerCase(),i=this._getSuffix(t).toLowerCase();if(r=s===i,!r){const e=/(.*)\/(MapServer|FeatureServer|UtilityNetworkServer).*/gi;r=s.replaceAll(e,"$1")===i.replaceAll(e,"$1")}}else this._isAdminResource(e)&&this._isAdminResource(t)?r=!0:this._isServerRsrc(e)||this._isServerRsrc(t)||!this._isPortalDomain(e)||(r=!0);return r}_isPortalDomain(e){const r=new _(e.toLowerCase()),s=this._portalConfig;let i=this._gwDomains.some((e=>e.regex.test(r.uri)));return!i&&s&&(i=this._hasSameServerInstance(this._getServerInstanceRoot(s.restBaseUrl),r.uri)),i||t.portalUrl&&(i=p(r,t.portalUrl,!0)),i||(i=this._portals.some((e=>this._hasSameServerInstance(e,r.uri)))),i=i||this._agsPortal.test(r.path),i}_isIdProvider(e,t){let r=-1,s=-1;this._gwDomains.forEach(((i,o)=>{-1===r&&i.regex.test(e)&&(r=o),-1===s&&i.regex.test(t)&&(s=o)}));let i=!1;if(r>-1&&s>-1&&(0===r||4===r?0!==s&&4!==s||(i=!0):1===r?1!==s&&2!==s||(i=!0):2===r?2===s&&(i=!0):3===r&&3===s&&(i=!0)),!i){const r=this.findServerInfo(t),s=r?.owningSystemUrl;s&&C(r)&&this._isPortalDomain(s)&&this._isIdProvider(e,s)&&(i=!0)}return i}_getIdenticalSvcIdx(e,t){let r=-1;for(let s=0;s<t.resources.length;s++){const i=t.resources[s];if(this._isIdenticalService(e,i)){r=s;break}}return r}_getSuffix(e){return e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"$1")}_getTokenSvcUrl(e){let t,r,i;if(this._isRESTService(e)||this._isAdminResource(e)){const i=this._getServerInstanceRoot(e);return t=i+"/admin/generateToken",r=s(e=i+"/rest/info",{query:{f:"json"}}).then((e=>e.data)),{adminUrl:t,promise:r}}if(this._isPortalDomain(e)){let t="";if(this._gwDomains.some((r=>(r.regex.test(e)&&(t=r.tokenServiceUrl),!!t))),t||this._portals.some((r=>(this._hasSameServerInstance(r,e)&&(t=r+this._gwTokenUrl),!!t))),t||(i=e.toLowerCase().indexOf("/sharing"),-1!==i&&(t=e.slice(0,i)+this._gwTokenUrl)),t||(t=this._getOrigin(e)+this._gwTokenUrl),t){const r=new _(e).port;/^http:\/\//i.test(e)&&"7080"===r&&(t=t.replace(/:7080/i,":7443")),t=t.replace(/http:/i,"https:")}return t}}_processOAuthResponseParams(e,t,r){const s=t._oAuthCred;if(e.code){const i=s.codeVerifier;return s.codeVerifier=null,s.stateUID=null,s.save(),this._getOAuthToken(r.server,e.code,t.appId,this._getRedirectURI(t,!0),i).then((i=>{const o=new E({userId:i.username,server:r.server??void 0,token:i.access_token,expires:Date.now()+1e3*i.expires_in,ssl:i.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=o.userId,s.storage=i.persist?b:q,s.refreshToken=i.refresh_token,s.token=null,s.expires=i.refresh_token_expires_in?Date.now()+1e3*i.refresh_token_expires_in:null,s.userId=o.userId,s.ssl=o.ssl,s.save(),o}))}const i=new E({userId:e.username,server:r.server??void 0,token:e.access_token,expires:Date.now()+1e3*Number(e.expires_in),ssl:"true"===e.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=i.userId,s.storage=e.persist?b:q,s.refreshToken=null,s.token=i.token,s.expires=i.expires,s.userId=i.userId,s.ssl=i.ssl,s.save(),Promise.resolve(i)}_processOAuthPopupParams(e){const t=this._oAuthDfd;if(this._oAuthDfd=null,t)if(clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle?.remove(),e.error){const r="access_denied"===e.error,s=new i(r?"identity-manager:user-aborted":"identity-manager:authentication-failed",r?"ABORTED":"OAuth: "+e.error+" - "+e.error_description);t.reject(s)}else this._processOAuthResponseParams(e,t.oinfo_,t.sinfo_).then((e=>{t.resolve(e)})).catch((e=>{t.reject(e)}))}_setOAuthResponseQueryString(e){e&&("?"===e.charAt(0)&&(e=e.slice(1)),this._processOAuthPopupParams(f(e)))}async _exchangeToken(e,t,r){return(await s(`${e}/sharing/rest/oauth2/exchangeToken`,{authMode:"anonymous",method:"post",query:{f:"json",client_id:t,token:r}})).data.token}async _getPlatformSelf(e,t){if(this._getPlatformSelfError&&Date.now()-this._getPlatformSelfError[1]<1e3)throw this._getPlatformSelfError[0];e=e.replace(/^http:/i,"https:");try{const r=await s(`${e}/sharing/rest/oauth2/platformSelf`,{authMode:"anonymous",headers:{"X-Esri-Auth-Client-Id":t,"X-Esri-Auth-Redirect-Uri":window.location.href.replace(/#.*$/,"")},method:"post",query:{f:"json",expiration:30},withCredentials:!0});return this._getPlatformSelfError=null,r.data}catch(r){throw"OAUTH_0066"===r.details?.messageCode&&(this._getPlatformSelfError=[r,Date.now()]),r}}_getPortalSelf(e,t){let r;if(this._gwDomains.some((t=>(t.regex.test(e)&&(r=t.customBaseUrl),!!r))),r)return Promise.resolve({allSSL:!0,currentVersion:"8.4",customBaseUrl:r,portalMode:"multitenant",supportsOAuth:!0});this._appOrigin.startsWith("https:")?e=e.replace(/^http:/i,"https:").replace(/:7080/i,":7443"):/^http:/i.test(t)&&(e=e.replace(/^https:/i,"http:").replace(/:7443/i,":7080"));return s(e,{query:{f:"json"},authMode:"anonymous",withCredentials:!0}).then((e=>e.data))}_doPortalSignIn(e){const t=this._portalConfig,r=window.location.href,s=this.findServerInfo(e);return!(!t&&!this._isPortalDomain(r)||!(s?s.hasPortal||s.owningSystemUrl&&this._isPortalDomain(s.owningSystemUrl):this._isPortalDomain(e))||!(this._isIdProvider(r,e)||t&&(this._hasSameServerInstance(this._getServerInstanceRoot(t.restBaseUrl),e)||this._isIdProvider(t.restBaseUrl,e))||p(r,e,!0)))}_checkProtocol(e,t,r,s){let o=!0;const n=s?t.adminTokenServiceUrl:t.tokenServiceUrl;if(n.trim().toLowerCase().startsWith("https:")&&!this._appOrigin.startsWith("https:")&&S(n)&&(o=!!this._protocolFunc&&!!this._protocolFunc({resourceUrl:e,serverInfo:t}),!o)){r(new i("identity-manager:aborted","Aborted the Sign-In process to avoid sending password over insecure connection."))}return o}_enqueue(e,t,r,s,i,o){return s||(s=l()),s.resUrl_=e,s.sinfo_=t,s.options_=r,s.admin_=i,s.refresh_=o,this._busy?this._hasSameServerInstance(this._getServerInstanceRoot(e),this._busy.resUrl_)?(this._oAuthDfd&&this._oAuthDfd.oAuthWin_&&this._oAuthDfd.oAuthWin_.focus(),this._soReqs.push(s)):this._xoReqs.push(s):this._doSignIn(s),s.promise}_doSignIn(e){this._busy=e,this._rejectOnPersistedPageShow=!1;const t=t=>{const r=e.options_?.resource,s=e.resUrl_,i=e.refresh_;let o=!1;this.credentials.includes(t)||(i&&this.credentials.includes(i)?(i.userId=t.userId,i.token=t.token,i.expires=t.expires,i.validity=t.validity,i.ssl=t.ssl,i.creationTime=t.creationTime,o=!0,t=i):this.credentials.push(t)),t.resources||(t.resources=[]),t.resources.includes(r||s)||t.resources.push(r||s),t.scope=this._isServerRsrc(s)?"server":"portal",t.emitTokenChange();const n=this._soReqs,a={};this._soReqs=[],n.forEach((e=>{if(!this._isIdenticalService(s,e.resUrl_)){const r=this._getSuffix(e.resUrl_);a[r]||(a[r]=!0,t.resources.push(e.resUrl_))}})),e.resolve(t),n.forEach((e=>{this._hasSameServerInstance(this._getServerInstanceRoot(s),e.resUrl_)?e.resolve(t):this._soReqs.push(e)})),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,o||this.emit("credential-create",{credential:t}),this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},r=t=>{e.reject(t),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},s=(o,a,h,l)=>{const d=e.sinfo_,u=!e.options_||!1!==e.options_.prompt,_=d.hasPortal&&this._findOAuthInfo(e.resUrl_);let f,g;if(o)t(new E({userId:o,server:d.server??void 0,token:h??void 0,expires:null!=l?Number(l):null,ssl:!!a}));else if(window!==window.parent&&this._appUrlObj.query?.["arcgis-auth-origin"]&&this._appUrlObj.query?.["arcgis-auth-portal"]&&this._hasSameServerInstance(this._getServerInstanceRoot(this._appUrlObj.query["arcgis-auth-portal"]),e.resUrl_)){window.parent.postMessage({type:"arcgis:auth:requestCredential"},this._appUrlObj.query["arcgis-auth-origin"]);const s=n(window,"message",(e=>{e.source===window.parent&&e.data&&("arcgis:auth:credential"===e.data.type?(s.remove(),e.data.credential.expires<Date.now()?r(new i("identity-manager:credential-request-failed","Parent application's token has expired.")):t(new E(e.data.credential))):"arcgis:auth:error"===e.data.type&&(s.remove(),"tokenExpiredError"===e.data.error.name?r(new i("identity-manager:credential-request-failed","Parent application's token has expired.")):r(i.fromJSON(e.data.error))))}));c(e.options_?.signal,(()=>{s.remove()}))}else if(_){let o=_._oAuthCred;if(!o){const e=new U(_,b),t=new U(_,q);e.isValid()&&t.isValid()?e.expires>t.expires?(o=e,t.destroy()):(o=t,e.destroy()):o=e.isValid()?e:t,_._oAuthCred=o}if(o.isValid()){f=new E({userId:o.userId??void 0,server:d.server??void 0,token:o.token??void 0,expires:o.expires,ssl:o.ssl??void 0,_oAuthCred:o});const i=_.appId!==o.appId&&this._doPortalSignIn(e.resUrl_);i||o.refreshToken?(e._pendingDfd=o.refreshToken?this._getOAuthToken(d.server,o.refreshToken,o.appId).then((e=>(f.expires=Date.now()+1e3*e.expires_in,f.token=e.access_token,f))):Promise.resolve(f),e._pendingDfd.then((e=>i?this._exchangeToken(e.server,_.appId,e.token).then((t=>(e.token=t,e))).catch((()=>e)):e)).then((e=>{t(e)})).catch((e=>{const t=e.details?.httpStatus;t>0&&404!==t?(o.destroy(),s()):r(e)}))):t(f)}else if(this._oAuthLocationParams&&this._hasSameServerInstance(_.portalUrl,this._oAuthLocationParams.state.portalUrl)&&(this._oAuthLocationParams.access_token||this._oAuthLocationParams.code&&this._oAuthLocationParams.state.uid===o.stateUID&&o.codeVerifier)){const s=this._oAuthLocationParams;this._oAuthLocationParams=null,e._pendingDfd=this._processOAuthResponseParams(s,_,d).then((e=>{t(e)})).catch(r)}else{const s=()=>{u?e._pendingDfd=this.oAuthSignIn(e.resUrl_,d,_,e.options_).then(t,r):(g=new i("identity-manager:not-authenticated","User is not signed in."),r(g))};this._doPortalSignIn(e.resUrl_)?e._pendingDfd=this._getPlatformSelf(d.server,_.appId).then((e=>{p(e.portalUrl,this._appOrigin,!0)?(f=new E({userId:e.username,server:d.server??void 0,expires:Date.now()+1e3*e.expires_in,token:e.token}),t(f)):s()})).catch(s):s()}}else if(u){if(this._checkProtocol(e.resUrl_,d,r,e.admin_)){let s=e.options_;e.admin_&&(s=s||{},s.isAdmin=!0),e._pendingDfd=this.signIn(e.resUrl_,d,s).then(t,r)}}else g=new i("identity-manager:not-authenticated","User is not signed in."),r(g)},o=()=>{const s=e.sinfo_,i=s.owningSystemUrl,o=e.options_;let n,a,h,l;if(o&&(n=o.token,a=o.error,h=o.prompt),l=this._findCredential(i,{token:n,resource:e.resUrl_}),!l)for(const e of this.credentials)if(this._isIdProvider(i,e.server)){l=e;break}if(l){const i=this.findCredential(e.resUrl_,l.userId);if(i)t(i);else if(D(s,this._legacyFed)){const e=l.toJSON();e.server=s.server,e.resources=null,t(new E(e))}else{(e._pendingDfd=this.generateToken(this.findServerInfo(l.server),null,{serverUrl:e.resUrl_,token:l.token,signal:e.options_.signal,ssl:l.ssl})).then((r=>{t(new E({userId:l?.userId,server:s.server??void 0,token:r.token,expires:null!=r.expires?Number(r.expires):null,ssl:!!r.ssl,isAdmin:e.admin_,validity:r.validity}))}),r)}}else{this._busy=null,n&&(e.options_.token=null);(e._pendingDfd=this.getCredential(i.replace(/\/?$/,"/sharing"),{resource:e.resUrl_,owningTenant:s.owningTenant,signal:e.options_.signal,token:n,error:a,prompt:h})).then((()=>{this._enqueue(e.resUrl_,e.sinfo_,e.options_,e,e.admin_)}),(t=>{e.resUrl_=e.sinfo_=e.refresh_=null,e.reject(t)}))}};this._errbackFunc=r;const a=e.sinfo_.owningSystemUrl,l=this._isServerRsrc(e.resUrl_),d=e.sinfo_._restInfoPms;d?d.promise.then((t=>{const r=e.sinfo_;if(r._restInfoPms){r.adminTokenServiceUrl=r._restInfoPms.adminUrl,r._restInfoPms=null,r.tokenServiceUrl=(h("authInfo.tokenServicesUrl",t)||h("authInfo.tokenServiceUrl",t)||h("tokenServiceUrl",t))??null,r.shortLivedTokenValidity=h("authInfo.shortLivedTokenValidity",t)??null,r.currentVersion=t.currentVersion,r.owningTenant=t.owningTenant;const e=r.owningSystemUrl=t.owningSystemUrl;e&&this._portals.push(e)}l&&r.owningSystemUrl?o():s()}),(()=>{e.sinfo_._restInfoPms=null;const t=new i("identity-manager:server-identification-failed","Unknown resource - could not find token service endpoint.");r(t)})):l&&a?o():e.sinfo_._selfReq?e.sinfo_._selfReq.selfDfd.then((t=>{const r={};let s,i,o,n;return t&&(s=t.user?.username,r.username=s,r.allSSL=t.allSSL,i=t.supportsOAuth,n=parseFloat(t.currentVersion),"multitenant"===t.portalMode&&(o=t.customBaseUrl),e.sinfo_.currentVersion=n),e.sinfo_.webTierAuth=!!s,s&&this.normalizeWebTierAuth?this.generateToken(e.sinfo_,null,{ssl:r.allSSL}).catch((()=>null)).then((e=>(r.portalToken=e?.token,r.tokenExpiration=e?.expires,r))):!s&&i&&n>=4.4&&!this._findOAuthInfo(e.resUrl_)?this._generateOAuthInfo({portalUrl:e.sinfo_.server,customBaseUrl:o,owningTenant:e.sinfo_._selfReq.owningTenant}).catch((()=>null)).then((()=>r)):r})).catch((()=>null)).then((t=>{e.sinfo_._selfReq=null,t?s(t.username,t.allSSL,t.portalToken,t.tokenExpiration):s()})):s()}_generateOAuthInfo(e){let t,r=null,i=e.portalUrl;const o=e.customBaseUrl,n=e.owningTenant,a=!this._defaultOAuthInfo&&this._createDefaultOAuthInfo&&!this._hasTestedIfAppIsOnPortal;if(a){r=window.location.href;let e=r.indexOf("?");e>-1&&(r=r.slice(0,e)),e=r.search(/\/(apps|home)\//),r=e>-1?r.slice(0,e):null}return a&&r?(this._hasTestedIfAppIsOnPortal=!0,t=s(r+"/sharing/rest",{query:{f:"json"}}).then((()=>{this._defaultOAuthInfo=new T({appId:"arcgisonline",popupCallbackUrl:r+"/home/oauth-callback.html"})}))):t=Promise.resolve(),t.then((()=>{if(this._defaultOAuthInfo)return i=i.replace(/^http:/i,"https:"),s(i+"/sharing/rest/oauth2/validateRedirectUri",{query:{accountId:n,client_id:this._defaultOAuthInfo.appId,redirect_uri:w(this._defaultOAuthInfo.popupCallbackUrl),f:"json"}}).then((e=>{if(e.data.valid){const t=this._defaultOAuthInfo.clone();e.data.urlKey&&o?t.portalUrl="https://"+e.data.urlKey.toLowerCase()+"."+o:t.portalUrl=i,t.popup=window!==window.top||!(p(i,this._appOrigin)||this._gwDomains.some((e=>e.regex.test(i)&&e.regex.test(this._appOrigin)))),this.oAuthInfos.push(t)}}))}))}_doOAuthSignIn(e,t,r,s){const o=r._oAuthCred,a={portalUrl:r.portalUrl};!r.popup&&r.preserveUrlHash&&window.location.hash&&(a.hash=window.location.hash),o.stateUID&&(a.uid=o.stateUID);const h={client_id:r.appId,response_type:o.codeVerifier?"code":"token",state:JSON.stringify(a),expiration:r.expiration,locale:r.locale,redirect_uri:this._getRedirectURI(r,!!o.codeVerifier)};r.forceLogin&&(h.force_login=!0),r.forceUserId&&r.userId&&(h.prepopulatedusername=r.userId),!r.popup&&this._doPortalSignIn(e)&&(h.redirectToUserOrgUrl=!0),o.codeVerifier&&(h.code_challenge=s||o.codeVerifier,h.code_challenge_method=s?"S256":"plain");const l=r.portalUrl.replace(/^http:/i,"https:")+"/sharing/oauth2/authorize",c=l+"?"+m(h);if(r.popup){const e=window.open(c,"esriJSAPIOAuth",r.popupWindowFeatures);if(e)e.focus(),this._oAuthDfd.oAuthWin_=e,this._oAuthIntervalId=setInterval((()=>{if(e.closed){clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle.remove();const e=this._oAuthDfd;if(e){const t=new i("identity-manager:user-aborted","ABORTED");e.reject(t)}}}),500),this._oAuthOnPopupHandle=n(window,["arcgis:auth:hash","arcgis:auth:location:search"],(e=>{"arcgis:auth:hash"===e.type?this.setOAuthResponseHash(e.detail):this._setOAuthResponseQueryString(e.detail)}));else{const e=new i("identity-manager:popup-blocked","ABORTED");this._oAuthDfd.reject(e)}}else this._rejectOnPersistedPageShow=!0,this._oAuthRedirectFunc?this._oAuthRedirectFunc({authorizeParams:h,authorizeUrl:l,resourceUrl:e,serverInfo:t,oAuthInfo:r}):window.location.href=c}_getRedirectURI(e,t){const r=window.location.href.replace(/#.*$/,"");if(e.popup)return w(e.popupCallbackUrl);if(t){const e=u(r);return e.query&&["code","error","error_description","message_code","persist","state"].forEach((t=>{delete e.query[t]})),I(e.path,e.query)}return r}}j.prototype.declaredClass="esri.identity.IdentityManagerBase";let E=class extends o.EventedAccessor{constructor(e){super(e),this._oAuthCred=null,this.tokenRefreshBuffer=2,e?._oAuthCred&&(this._oAuthCred=e._oAuthCred)}initialize(){this.resources=this.resources||[],null==this.creationTime&&(this.creationTime=Date.now())}refreshToken(){const e=r,t=e.findServerInfo(this.server),s=t?.owningSystemUrl,i=!!s&&"server"===this.scope,o=i&&D(t,e._legacyFed),n=t.webTierAuth,a=n&&e.normalizeWebTierAuth,h=R[this.server],l=h?.[this.userId];let c,d=this.resources&&this.resources[0],u=i?e.findServerInfo(s):null,p={username:this.userId,password:l};if(n&&!a)return;i&&!u&&e.serverInfos.some((t=>(e._isIdProvider(s,t.server)&&(u=t),!!u)));const _=u?e.findCredential(u.server,this.userId):null;if(!i||_){if(!o){if(i)c={serverUrl:d,token:_?.token,ssl:_?.ssl};else if(a)p=null,c={ssl:this.ssl};else{if(!l){let r;return d&&(d=e._sanitizeUrl(d),this._enqueued=1,r=e._enqueue(d,t,null,null,this.isAdmin,this),r.then((()=>{this._enqueued=0,this.refreshServerTokens()})).catch((()=>{this._enqueued=0}))),r}this.isAdmin&&(c={isAdmin:!0})}return e.generateToken(i?u:t,i?null:p,c).then((e=>{this.token=e.token,this.expires=null!=e.expires?Number(e.expires):null,this.creationTime=Date.now(),this.validity=e.validity,this.emitTokenChange(),this.refreshServerTokens()})).catch((()=>{}))}_?.refreshToken()}}refreshServerTokens(){if("portal"===this.scope){const e=r;e.credentials.forEach((t=>{const r=e.findServerInfo(t.server),s=r?.owningSystemUrl;t!==this&&t.userId===this.userId&&s&&"server"===t.scope&&(e._hasSameServerInstance(this.server,s)||e._isIdProvider(s,this.server))&&(D(r,e._legacyFed)?(t.token=this.token,t.expires=this.expires,t.creationTime=this.creationTime,t.validity=this.validity,t.emitTokenChange()):t.refreshToken())}))}}emitTokenChange(e){clearTimeout(this._refreshTimer);const t=r,s=this.server?t.findServerInfo(this.server):null,i=s?.owningSystemUrl,o=i?t.findServerInfo(i):null;!1===e||i&&"portal"!==this.scope&&(!o?.webTierAuth||t.normalizeWebTierAuth)||null==this.expires&&null==this.validity||this._startRefreshTimer(),this.emit("token-change")}destroy(){this.userId=this.server=this.token=this.expires=this.validity=this.resources=this.creationTime=null,this._oAuthCred&&(this._oAuthCred.destroy(),this._oAuthCred=null);const e=r,t=e.credentials.indexOf(this);t>-1&&e.credentials.splice(t,1),this.emitTokenChange(),this.emit("destroy")}toJSON(){const e=a({userId:this.userId,server:this.server,token:this.token,expires:this.expires,validity:this.validity,ssl:this.ssl,isAdmin:this.isAdmin,creationTime:this.creationTime,scope:this.scope}),t=this.resources;return t&&t.length>0&&(e.resources=t.slice()),e}_startRefreshTimer(){clearTimeout(this._refreshTimer);const e=6e4*this.tokenRefreshBuffer,t=2**31-1;let r=(this.validity?this.creationTime+6e4*this.validity:this.expires)-Date.now();r<0?r=0:r>t&&(r=t),this._refreshTimer=setTimeout(this.refreshToken.bind(this),r>e?r-e:r)}};e([A()],E.prototype,"creationTime",void 0),e([A()],E.prototype,"expires",void 0),e([A()],E.prototype,"isAdmin",void 0),e([A()],E.prototype,"oAuthState",void 0),e([A()],E.prototype,"resources",void 0),e([A()],E.prototype,"scope",void 0),e([A()],E.prototype,"server",void 0),e([A()],E.prototype,"ssl",void 0),e([A()],E.prototype,"token",void 0),e([A()],E.prototype,"tokenRefreshBuffer",void 0),e([A()],E.prototype,"userId",void 0),e([A()],E.prototype,"validity",void 0),E=e([k("esri.identity.Credential")],E);export{E as Credential,j as IdentityManagerBase};
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import t from"../config.js";import{id as r}from"../kernel.js";import s from"../request.js";import i from"../core/Error.js";import o from"../core/Evented.js";import{on as n}from"../core/events.js";import{fixJson as a}from"../core/lang.js";import{getDeepValue as h}from"../core/object.js";import{createResolver as l,onAbort as c,isAborted as d}from"../core/promiseUtils.js";import{urlToObject as u,hasSameOrigin as p,Url as _,queryToObject as f,base64UrlEncode as g,objectToQuery as m,normalize as v,getProxyRule as S,makeAbsolute as w,addQueryParameters as I}from"../core/urlUtils.js";import{property as A}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as k}from"../core/accessorSupport/decorators/subclass.js";import y from"./IdentityModal.js";import U from"./OAuthCredential.js";import T from"./OAuthInfo.js";import x from"./ServerInfo.js";import{isSecureProxyService as O,normalizeArcGISOnlineOrgDomain as P}from"../portal/support/urlUtils.js";const R={},C=e=>{const t=new _(e.owningSystemUrl).host,r=new _(e.server).host,s=/.+\.arcgis\.com$/i;return s.test(t)&&s.test(r)},D=(e,t)=>!!(C(e)&&t&&t.some((t=>t.test(e.server))));let b=null,q=null;try{b=window.localStorage,q=window.sessionStorage}catch{}class j extends o{constructor(){super(),this._portalConfig=globalThis.esriGeowConfig,this.serverInfos=[],this.oAuthInfos=[],this.credentials=[],this._soReqs=[],this._xoReqs=[],this._portals=[],this._defaultOAuthInfo=null,this._defaultTokenValidity=60,this.dialog=null,this.tokenValidity=null,this.normalizeWebTierAuth=!1,this._appOrigin="null"!==window.origin?window.origin:window.location.origin,this._appUrlObj=u(window.location.href),this._busy=null,this._rejectOnPersistedPageShow=!1,this._oAuthLocationParams=null,this._gwTokenUrl="/sharing/rest/generateToken",this._agsRest="/rest/services",this._agsPortal=/\/sharing(\/|$)/i,this._agsAdmin=/(https?:\/\/[^/]+\/[^/]+)\/admin\/?(\/.*)?$/i,this._adminSvcs=/\/rest\/admin\/services(\/|$)/i,this._gwDomains=[{regex:/^https?:\/\/www\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:dev|[a-z\d-]+\.mapsdev)\.arcgis\.com/i,customBaseUrl:"mapsdev.arcgis.com",tokenServiceUrl:"https://dev.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:devext|[a-z\d-]+\.mapsdevext)\.arcgis\.com/i,customBaseUrl:"mapsdevext.arcgis.com",tokenServiceUrl:"https://devext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/(?:qaext|[a-z\d-]+\.mapsqa)\.arcgis\.com/i,customBaseUrl:"mapsqa.arcgis.com",tokenServiceUrl:"https://qaext.arcgis.com/sharing/rest/generateToken"},{regex:/^https?:\/\/[a-z\d-]+\.maps\.arcgis\.com/i,customBaseUrl:"maps.arcgis.com",tokenServiceUrl:"https://www.arcgis.com/sharing/rest/generateToken"}],this._legacyFed=[],this._regexSDirUrl=/http.+\/rest\/services\/?/gi,this._regexServerType=/(\/(FeatureServer|GPServer|GeoDataServer|GeocodeServer|GeoenrichmentServer|GeometryServer|GlobeServer|ImageServer|KnowledgeGraphServer|MapServer|MissionServer|MobileServer|NAServer|NetworkDiagramServer|OGCFeatureServer|ParcelFabricServer|RelationalCatalogServer|SceneServer|StreamServer|UtilityNetworkServer|ValidationServer|VectorTileServer|VersionManagementServer|VideoServer)).*/gi,this._gwUser=/http.+\/users\/([^/]+).*/i,this._gwItem=/http.+\/items\/([^/]+).*/i,this._gwGroup=/http.+\/groups\/([^/]+).*/i,this._rePortalTokenSvc=/\/sharing(\/rest)?\/generatetoken/i,this._createDefaultOAuthInfo=!0,this._hasTestedIfAppIsOnPortal=!1,this._getPlatformSelfError=null,this._getOAuthLocationParams(),window.addEventListener("pageshow",(e=>{this._pageShowHandler(e)}))}registerServers(e){const t=this.serverInfos;t?(e=e.filter((e=>!this.findServerInfo(e.server))),this.serverInfos=t.concat(e)):this.serverInfos=e,e.forEach((e=>{e.owningSystemUrl&&this._portals.push(e.owningSystemUrl),e.hasPortal&&this._portals.push(e.server)}))}registerOAuthInfos(e){const t=this.oAuthInfos;if(t){for(const r of e){const e=this.findOAuthInfo(r.portalUrl);e&&t.splice(t.indexOf(e),1)}this.oAuthInfos=t.concat(e)}else this.oAuthInfos=e}registerToken(e){e={...e};const t=this._sanitizeUrl(e.server),r=this._isServerRsrc(t);let s,i=this.findServerInfo(t),o=!0;i||(i=new x,i.server=this._getServerInstanceRoot(t),r?i.hasServer=!0:(i.tokenServiceUrl=this._getTokenSvcUrl(t),i.hasPortal=!0),this.registerServers([i])),s=this._findCredential(t),s?(delete e.server,Object.assign(s,e),o=!1):(s=new E({userId:e.userId,server:i.server??void 0,token:e.token,expires:e.expires,ssl:e.ssl,scope:r?"server":"portal"}),s.resources=[t],this.credentials.push(s)),s.emitTokenChange(!1),o||s.refreshServerTokens()}toJSON(){return a({serverInfos:this.serverInfos.map((e=>e.toJSON())),oAuthInfos:this.oAuthInfos.map((e=>e.toJSON())),credentials:this.credentials.map((e=>e.toJSON()))})}initialize(e){if(!e)return;"string"==typeof e&&(e=JSON.parse(e));const t=e.serverInfos,r=e.oAuthInfos,s=e.credentials;if(t){const e=[];t.forEach((t=>{t.server&&t.tokenServiceUrl&&e.push(t.declaredClass?t:new x(t))})),e.length&&this.registerServers(e)}if(r){const e=[];r.forEach((t=>{t.appId&&e.push(t.declaredClass?t:new T(t))})),e.length&&this.registerOAuthInfos(e)}s&&s.forEach((e=>{e.server&&e.token&&e.expires&&e.expires>Date.now()&&((e=e.declaredClass?e:new E(e)).emitTokenChange(),this.credentials.push(e))}))}findServerInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.serverInfos)if(this._hasSameServerInstance(r.server,e)){t=r;break}return t}findOAuthInfo(e){let t;e=this._sanitizeUrl(e);for(const r of this.oAuthInfos)if(this._hasSameServerInstance(r.portalUrl,e)){t=r;break}return t}findCredential(e,t){if(!e)return;let r;e=this._sanitizeUrl(e);const s=this._isServerRsrc(e)?"server":"portal";if(t){for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&t===i.userId&&i.scope===s){r=i;break}}else for(const i of this.credentials)if(this._hasSameServerInstance(i.server,e)&&-1!==this._getIdenticalSvcIdx(e,i)&&i.scope===s){r=i;break}return r}getCredential(e,t){let r,s,o=!0;t&&(r=!!t.token,s=t.error,o=!1!==t.prompt),t={...t},e=this._sanitizeUrl(e);const n=new AbortController,a=l();if(t.signal&&c(t.signal,(()=>{n.abort()})),c(n,(()=>{a.reject(new i("identity-manager:user-aborted","ABORTED"))})),d(n))return a.promise;t.signal=n.signal;const h=this._isAdminResource(e),u=r?this.findCredential(e):null;let _;if(u&&s&&s.details&&498===s.details.httpStatus)u.destroy();else if(u)return _=new i("identity-manager:not-authorized","You are currently signed in as: '"+u.userId+"'. You do not have access to this resource: "+e,{error:s}),a.reject(_),a.promise;const f=this._findCredential(e,t);if(f)return a.resolve(f),a.promise;let g=this.findServerInfo(e);if(g)!g.hasPortal&&g.server&&g.owningSystemUrl&&this._hasSameServerInstance(g.server,g.owningSystemUrl)&&(g.hasPortal=!0),!g.hasServer&&this._isServerRsrc(e)&&(g._restInfoPms=this._getTokenSvcUrl(e),g.hasServer=!0);else{const t=this._getTokenSvcUrl(e);if(!t)return _=new i("identity-manager:unknown-resource","Unknown resource - could not find token service endpoint."),a.reject(_),a.promise;g=new x,g.server=this._getServerInstanceRoot(e),"string"==typeof t?(g.tokenServiceUrl=t,g.hasPortal=!0):(g._restInfoPms=t,g.hasServer=!0),this.registerServers([g])}return g.hasPortal&&void 0===g._selfReq&&(o||p(g.tokenServiceUrl,this._appOrigin)||this._gwDomains.some((e=>e.tokenServiceUrl===g.tokenServiceUrl)))&&(g._selfReq={owningTenant:t?.owningTenant,selfDfd:this._getPortalSelf(g.tokenServiceUrl.replace(this._rePortalTokenSvc,"/sharing/rest/portals/self"),e)}),this._enqueue(e,g,t,a,h)}getResourceName(e){return this._isRESTService(e)?e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"")||"":this._gwUser.test(e)&&e.replace(this._gwUser,"$1")||this._gwItem.test(e)&&e.replace(this._gwItem,"$1")||this._gwGroup.test(e)&&e.replace(this._gwGroup,"$1")||""}generateToken(e,t,r){const o=this._rePortalTokenSvc.test(e.tokenServiceUrl),n=new _(this._appOrigin),a=e.shortLivedTokenValidity;let h,l,c,d,u,f,g,m;t&&(m=this.tokenValidity||a||this._defaultTokenValidity,m>a&&a>0&&(m=a)),r&&(h=r.isAdmin,l=r.serverUrl,c=r.token,f=r.signal,g=r.ssl,e.customParameters=r.customParameters),h?d=e.adminTokenServiceUrl:(d=e.tokenServiceUrl,u=new _(d.toLowerCase()),e.webTierAuth&&r?.serverUrl&&!g&&"http"===n.scheme&&(p(n.uri,d,!0)||"https"===u.scheme&&n.host===u.host&&"7080"===n.port&&"7443"===u.port)&&(d=d.replace(/^https:/i,"http:").replace(/:7443/i,":7080")));const v={query:{request:"getToken",username:t?.username,password:t?.password,serverUrl:l,token:c,expiration:m,referer:h||o?this._appOrigin:null,client:h?"referer":null,f:"json",...e.customParameters},method:"post",authMode:"anonymous",useProxy:this._useProxy(e,r),signal:f,...r?.ioArgs};o||(v.withCredentials=!1);return s(d,v).then((r=>{const s=r.data;if(!s?.token)return new i("identity-manager:authentication-failed","Unable to generate token");const o=e.server;return R[o]||(R[o]={}),t&&(R[o][t.username]=t.password),s.validity=m,s}))}isBusy(){return!!this._busy}async checkSignInStatus(e){return(await this.checkAppAccess(e,"")).credential}checkAppAccess(e,t,r){let o=!1;return this.getCredential(e,{prompt:!1}).then((n=>{let a;const h={f:"json"};if("portal"===n.scope)if(t&&(this._doPortalSignIn(e)||r?.force))a=n.server+"/sharing/rest/oauth2/validateAppAccess",h.client_id=t;else{if(!n.token)return{credential:n};a=n.server+"/sharing/rest"}else{if(!n.token)return{credential:n};a=n.server+"/rest/services"}return n.token&&(h.token=n.token),s(a,{query:h,authMode:"anonymous"}).then((e=>{if(!1===e.data.valid)throw new i("identity-manager:not-authorized",`You are currently signed in as: '${n.userId}'.`,e.data);return o=!!e.data.viewOnlyUserTypeApp,{credential:n}})).catch((e=>{if("identity-manager:not-authorized"===e.name)throw e;const t=e.details?.httpStatus;if(498===t)throw n.destroy(),new i("identity-manager:not-authenticated","User is not signed in.");if(400===t)throw new i("identity-manager:invalid-request","Bad request");return{credential:n}}))})).then((e=>({credential:e.credential,viewOnly:o})))}setOAuthResponseHash(e){e&&("#"===e.charAt(0)&&(e=e.slice(1)),this._processOAuthPopupParams(f(e)))}setOAuthRedirectionHandler(e){this._oAuthRedirectFunc=e}setProtocolErrorHandler(e){this._protocolFunc=e}signIn(e,t,r={}){const s=l(),o=()=>{h?.remove(),d?.remove(),this.dialog?.destroy(),this.dialog=h=d=null},n=()=>{o(),this._oAuthDfd=null,s.reject(new i("identity-manager:user-aborted","ABORTED"))};r.signal&&c(r.signal,(()=>{n()}));const a=new y({open:!0,resource:this.getResourceName(e),server:t.server});this.dialog=a,this.emit("dialog-create");let h=a.on("cancel",n),d=a.on("submit",(e=>{this.generateToken(t,e,{isAdmin:r.isAdmin,signal:r.signal}).then((i=>{o();const n=new E({userId:e.username,server:t.server??void 0,token:i.token,expires:null!=i.expires?Number(i.expires):null,ssl:!!i.ssl,isAdmin:r.isAdmin,validity:i.validity});s.resolve(n)})).catch((e=>{a.error=e,a.signingIn=!1}))}));return s.promise}oAuthSignIn(e,t,r,s){this._oAuthDfd=l();const o=this._oAuthDfd;let n;s?.signal&&c(s.signal,(()=>{const e=this._oAuthDfd&&this._oAuthDfd.oAuthWin_;e&&!e.closed?e.close():this.dialog&&u()})),o.resUrl_=e,o.sinfo_=t,o.oinfo_=r;const a=r._oAuthCred;if(a.storage&&("authorization-code"===r.flowType||"auto"===r.flowType&&t.currentVersion>=8.4)){let e=crypto.getRandomValues(new Uint8Array(32));n=g(e),a.codeVerifier=n,e=crypto.getRandomValues(new Uint8Array(32)),a.stateUID=g(e),a.save()||(a.codeVerifier=n=null)}else a.codeVerifier=null;let h,d;this._getCodeChallenge(n).then((i=>{const o=!s||!1!==s.oAuthPopupConfirmation;if(!r.popup||!o)return void this._doOAuthSignIn(e,t,r,i);const n=new y({oAuthPrompt:!0,server:t.server,open:!0});this.dialog=n,this.emit("dialog-create"),h=n.on("cancel",u),d=n.on("submit",(()=>{p(),this._doOAuthSignIn(e,t,r,i)}))}));const u=()=>{p(),this._oAuthDfd=null,o.reject(new i("identity-manager:user-aborted","ABORTED"))},p=()=>{h?.remove(),d?.remove(),this.dialog?.destroy(),this.dialog=null};return o.promise}destroyCredentials(){if(this.credentials){this.credentials.slice().forEach((e=>{e.destroy()}))}this.emit("credentials-destroy")}enablePostMessageAuth(e="https://www.arcgis.com/sharing/rest"){this._postMessageAuthHandle&&this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=n(window,"message",(t=>{if((t.origin===this._appOrigin||t.origin.endsWith(".arcgis.com"))&&"arcgis:auth:requestCredential"===t.data?.type){const r=t.source;this.getCredential(e).then((e=>{r.postMessage({type:"arcgis:auth:credential",credential:{expires:e.expires,server:e.server,ssl:e.ssl,token:e.token,userId:e.userId}},t.origin)})).catch((e=>{r.postMessage({type:"arcgis:auth:error",error:{name:e.name,message:e.message}},t.origin)}))}}))}disablePostMessageAuth(){this._postMessageAuthHandle&&(this._postMessageAuthHandle.remove(),this._postMessageAuthHandle=null)}_getOAuthLocationParams(){let e=window.location.hash;if(e){"#"===e.charAt(0)&&(e=e.slice(1));const t=f(e);let r=!1;if(t.access_token&&t.expires_in&&t.state&&t.hasOwnProperty("username"))try{t.state=JSON.parse(t.state),t.state.portalUrl&&(this._oAuthLocationParams=t,r=!0)}catch{}else if(t.error&&t.error_description&&(console.log("IdentityManager OAuth Error: ",t.error," - ",t.error_description),"access_denied"===t.error&&(r=!0,t.state)))try{t.state=JSON.parse(t.state)}catch{}r&&(window.location.hash=t.state?.hash||"")}let t=window.location.search;if(t){"?"===t.charAt(0)&&(t=t.slice(1));const e=f(t);let r=!1;if(e.code&&e.state)try{e.state=JSON.parse(e.state),e.state.portalUrl&&e.state.uid&&(this._oAuthLocationParams=e,r=!0)}catch{}else if(e.error&&e.error_description&&(console.log("IdentityManager OAuth Error: ",e.error," - ",e.error_description),"access_denied"===e.error&&(r=!0,e.state)))try{e.state=JSON.parse(e.state)}catch{}if(r){const t={...e};["code","error","error_description","message_code","persist","state"].forEach((e=>{delete t[e]}));const r=m(t),s=window.location.pathname+(r?`?${r}`:"")+(e.state?.hash||"");window.history.replaceState(window.history.state,"",s)}}}_getOAuthToken(e,t,r,i,o){return e=e.replace(/^http:/i,"https:"),s(`${e}/sharing/rest/oauth2/token`,{authMode:"anonymous",method:"post",query:i&&o?{grant_type:"authorization_code",code:t,redirect_uri:i,client_id:r,code_verifier:o}:{grant_type:"refresh_token",refresh_token:t,client_id:r}}).then((e=>e.data))}async _getCodeChallenge(e){if(e&&globalThis.isSecureContext){const t=(new TextEncoder).encode(e),r=await crypto.subtle.digest("SHA-256",t);return g(new Uint8Array(r))}return null}_pageShowHandler(e){if(e.persisted&&this.isBusy()&&this._rejectOnPersistedPageShow){const e=new i("identity-manager:user-aborted","ABORTED");this._errbackFunc(e)}}_findCredential(e,t){let r,s,i,o,n=-1;const a=t?.token,h=t?.resource,l=this._isServerRsrc(e)?"server":"portal",c=this.credentials.filter((t=>this._hasSameServerInstance(t.server,e)&&t.scope===l));if(e=h||e,c.length)if(1===c.length){if(r=c[0],i=this.findServerInfo(r.server),s=i?.owningSystemUrl,o=s?this.findCredential(s,r.userId):void 0,n=this._getIdenticalSvcIdx(e,r),!a)return-1===n&&r.resources.push(e),this._addResource(e,o),r;-1!==n&&(r.resources.splice(n,1),this._removeResource(e,o))}else{let t,r;if(c.some((a=>(r=this._getIdenticalSvcIdx(e,a),-1!==r&&(t=a,i=this.findServerInfo(t.server),s=i?.owningSystemUrl,o=s?this.findCredential(s,t.userId):void 0,n=r,!0)))),a)t&&(t.resources.splice(n,1),this._removeResource(e,o));else if(t)return this._addResource(e,o),t}}_findOAuthInfo(e){let t=this.findOAuthInfo(e);if(!t)for(const r of this.oAuthInfos)if(this._isIdProvider(r.portalUrl,e)){t=r;break}return t}_addResource(e,t){t&&-1===this._getIdenticalSvcIdx(e,t)&&t.resources.push(e)}_removeResource(e,t){let r=-1;t&&(r=this._getIdenticalSvcIdx(e,t),r>-1&&t.resources.splice(r,1))}_useProxy(e,t){return t?.isAdmin&&!p(e.adminTokenServiceUrl,this._appOrigin)||!this._isPortalDomain(e.tokenServiceUrl)&&"10.1"===String(e.currentVersion)&&!p(e.tokenServiceUrl,this._appOrigin)}_getOrigin(e){const t=new _(e);return t.scheme+"://"+t.host+(null!=t.port?":"+t.port:"")}_getServerInstanceRoot(e){const t=e.toLowerCase();let r=t.indexOf(this._agsRest);return-1===r&&this._isAdminResource(e)&&(r=this._agsAdmin.test(e)?e.replace(this._agsAdmin,"$1").length:e.search(this._adminSvcs)),-1!==r||O(t)||(r=t.indexOf("/sharing")),-1===r&&t.endsWith("/")&&(r=t.length-1),r>-1?e.slice(0,r):e}_hasSameServerInstance(e,t){return e.endsWith("/")&&(e=e.slice(0,-1)),e=e.toLowerCase(),t=this._getServerInstanceRoot(t).toLowerCase(),e=P(e),t=P(t),(e=e.slice(Math.max(0,e.indexOf(":"))))===(t=t.slice(Math.max(0,t.indexOf(":"))))}_sanitizeUrl(e){const r=(t.request.proxyUrl||"").toLowerCase(),s=r?e.toLowerCase().indexOf(r+"?"):-1;return-1!==s&&(e=e.slice(s+r.length+1)),e=v(e),u(e).path}_isRESTService(e){return e.includes(this._agsRest)}_isAdminResource(e){return this._agsAdmin.test(e)||this._adminSvcs.test(e)}_isServerRsrc(e){return this._isRESTService(e)||this._isAdminResource(e)}_isIdenticalService(e,t){let r=!1;if(this._isRESTService(e)&&this._isRESTService(t)){const s=this._getSuffix(e).toLowerCase(),i=this._getSuffix(t).toLowerCase();if(r=s===i,!r){const e=/(.*)\/(MapServer|FeatureServer|UtilityNetworkServer).*/gi;r=s.replaceAll(e,"$1")===i.replaceAll(e,"$1")}}else this._isAdminResource(e)&&this._isAdminResource(t)?r=!0:this._isServerRsrc(e)||this._isServerRsrc(t)||!this._isPortalDomain(e)||(r=!0);return r}_isPortalDomain(e){const r=new _(e.toLowerCase()),s=this._portalConfig;let i=this._gwDomains.some((e=>e.regex.test(r.uri)));return!i&&s&&(i=this._hasSameServerInstance(this._getServerInstanceRoot(s.restBaseUrl),r.uri)),i||t.portalUrl&&(i=p(r,t.portalUrl,!0)),i||(i=this._portals.some((e=>this._hasSameServerInstance(e,r.uri)))),i=i||this._agsPortal.test(r.path),i}_isIdProvider(e,t){let r=-1,s=-1;this._gwDomains.forEach(((i,o)=>{-1===r&&i.regex.test(e)&&(r=o),-1===s&&i.regex.test(t)&&(s=o)}));let i=!1;if(r>-1&&s>-1&&(0===r||4===r?0!==s&&4!==s||(i=!0):1===r?1!==s&&2!==s||(i=!0):2===r?2===s&&(i=!0):3===r&&3===s&&(i=!0)),!i){const r=this.findServerInfo(t),s=r?.owningSystemUrl;s&&C(r)&&this._isPortalDomain(s)&&this._isIdProvider(e,s)&&(i=!0)}return i}_getIdenticalSvcIdx(e,t){let r=-1;for(let s=0;s<t.resources.length;s++){const i=t.resources[s];if(this._isIdenticalService(e,i)){r=s;break}}return r}_getSuffix(e){return e.replace(this._regexSDirUrl,"").replace(this._regexServerType,"$1")}_getTokenSvcUrl(e){let t,r,i;if(this._isRESTService(e)||this._isAdminResource(e)){const i=this._getServerInstanceRoot(e);return t=i+"/admin/generateToken",r=s(e=i+"/rest/info",{query:{f:"json"}}).then((e=>e.data)),{adminUrl:t,promise:r}}if(this._isPortalDomain(e)){let t="";if(this._gwDomains.some((r=>(r.regex.test(e)&&(t=r.tokenServiceUrl),!!t))),t||this._portals.some((r=>(this._hasSameServerInstance(r,e)&&(t=r+this._gwTokenUrl),!!t))),t||(i=e.toLowerCase().indexOf("/sharing"),-1!==i&&(t=e.slice(0,i)+this._gwTokenUrl)),t||(t=this._getOrigin(e)+this._gwTokenUrl),t){const r=new _(e).port;/^http:\/\//i.test(e)&&"7080"===r&&(t=t.replace(/:7080/i,":7443")),t=t.replace(/http:/i,"https:")}return t}}_processOAuthResponseParams(e,t,r){const s=t._oAuthCred;if(e.code){const i=s.codeVerifier;return s.codeVerifier=null,s.stateUID=null,s.save(),this._getOAuthToken(r.server,e.code,t.appId,this._getRedirectURI(t,!0),i).then((i=>{const o=new E({userId:i.username,server:r.server??void 0,token:i.access_token,expires:Date.now()+1e3*i.expires_in,ssl:i.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=o.userId,s.storage=i.persist?b:q,s.refreshToken=i.refresh_token,s.token=null,s.expires=i.refresh_token_expires_in?Date.now()+1e3*i.refresh_token_expires_in:null,s.userId=o.userId,s.ssl=o.ssl,s.save(),o}))}const i=new E({userId:e.username,server:r.server??void 0,token:e.access_token,expires:Date.now()+1e3*Number(e.expires_in),ssl:"true"===e.ssl,oAuthState:e.state,_oAuthCred:s});return t.userId=i.userId,s.storage=e.persist?b:q,s.refreshToken=null,s.token=i.token,s.expires=i.expires,s.userId=i.userId,s.ssl=i.ssl,s.save(),Promise.resolve(i)}_processOAuthPopupParams(e){const t=this._oAuthDfd;if(this._oAuthDfd=null,t)if(clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle?.remove(),e.error){const r="access_denied"===e.error,s=new i(r?"identity-manager:user-aborted":"identity-manager:authentication-failed",r?"ABORTED":"OAuth: "+e.error+" - "+e.error_description);t.reject(s)}else this._processOAuthResponseParams(e,t.oinfo_,t.sinfo_).then((e=>{t.resolve(e)})).catch((e=>{t.reject(e)}))}_setOAuthResponseQueryString(e){e&&("?"===e.charAt(0)&&(e=e.slice(1)),this._processOAuthPopupParams(f(e)))}async _exchangeToken(e,t,r){return(await s(`${e}/sharing/rest/oauth2/exchangeToken`,{authMode:"anonymous",method:"post",query:{f:"json",client_id:t,token:r}})).data.token}async _getPlatformSelf(e,t){if(this._getPlatformSelfError&&Date.now()-this._getPlatformSelfError[1]<1e3)throw this._getPlatformSelfError[0];e=e.replace(/^http:/i,"https:");try{const r=await s(`${e}/sharing/rest/oauth2/platformSelf`,{authMode:"anonymous",headers:{"X-Esri-Auth-Client-Id":t,"X-Esri-Auth-Redirect-Uri":window.location.href.replace(/#.*$/,"")},method:"post",query:{f:"json",expiration:30},withCredentials:!0});return this._getPlatformSelfError=null,r.data}catch(r){throw"OAUTH_0066"===r.details?.messageCode&&(this._getPlatformSelfError=[r,Date.now()]),r}}_getPortalSelf(e,t){let r;if(this._gwDomains.some((t=>(t.regex.test(e)&&(r=t.customBaseUrl),!!r))),r)return Promise.resolve({allSSL:!0,currentVersion:"8.4",customBaseUrl:r,portalMode:"multitenant",supportsOAuth:!0});this._appOrigin.startsWith("https:")?e=e.replace(/^http:/i,"https:").replace(/:7080/i,":7443"):/^http:/i.test(t)&&(e=e.replace(/^https:/i,"http:").replace(/:7443/i,":7080"));return s(e,{query:{f:"json"},authMode:"anonymous",withCredentials:!0}).then((e=>e.data))}_doPortalSignIn(e){const t=this._portalConfig,r=window.location.href,s=this.findServerInfo(e);return!(!t&&!this._isPortalDomain(r)||!(s?s.hasPortal||s.owningSystemUrl&&this._isPortalDomain(s.owningSystemUrl):this._isPortalDomain(e))||!(this._isIdProvider(r,e)||t&&(this._hasSameServerInstance(this._getServerInstanceRoot(t.restBaseUrl),e)||this._isIdProvider(t.restBaseUrl,e))||p(r,e,!0)))}_checkProtocol(e,t,r,s){let o=!0;const n=s?t.adminTokenServiceUrl:t.tokenServiceUrl;if(n.trim().toLowerCase().startsWith("https:")&&!this._appOrigin.startsWith("https:")&&S(n)&&(o=!!this._protocolFunc&&!!this._protocolFunc({resourceUrl:e,serverInfo:t}),!o)){r(new i("identity-manager:aborted","Aborted the Sign-In process to avoid sending password over insecure connection."))}return o}_enqueue(e,t,r,s,i,o){return s||(s=l()),s.resUrl_=e,s.sinfo_=t,s.options_=r,s.admin_=i,s.refresh_=o,this._busy?this._hasSameServerInstance(this._getServerInstanceRoot(e),this._busy.resUrl_)?(this._oAuthDfd&&this._oAuthDfd.oAuthWin_&&this._oAuthDfd.oAuthWin_.focus(),this._soReqs.push(s)):this._xoReqs.push(s):this._doSignIn(s),s.promise}_doSignIn(e){this._busy=e,this._rejectOnPersistedPageShow=!1;const t=t=>{const r=e.options_?.resource,s=e.resUrl_,i=e.refresh_;let o=!1;this.credentials.includes(t)||(i&&this.credentials.includes(i)?(i.userId=t.userId,i.token=t.token,i.expires=t.expires,i.validity=t.validity,i.ssl=t.ssl,i.creationTime=t.creationTime,o=!0,t=i):this.credentials.push(t)),t.resources||(t.resources=[]),t.resources.includes(r||s)||t.resources.push(r||s),t.scope=this._isServerRsrc(s)?"server":"portal",t.emitTokenChange();const n=this._soReqs,a={};this._soReqs=[],n.forEach((e=>{if(!this._isIdenticalService(s,e.resUrl_)){const r=this._getSuffix(e.resUrl_);a[r]||(a[r]=!0,t.resources.push(e.resUrl_))}})),e.resolve(t),n.forEach((e=>{this._hasSameServerInstance(this._getServerInstanceRoot(s),e.resUrl_)?e.resolve(t):this._soReqs.push(e)})),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,o||this.emit("credential-create",{credential:t}),this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},r=t=>{e.reject(t),this._busy=e.resUrl_=e.sinfo_=e.refresh_=null,this._soReqs.length?this._doSignIn(this._soReqs.shift()):this._xoReqs.length&&this._doSignIn(this._xoReqs.shift())},s=(o,a,h,l)=>{const d=e.sinfo_,u=!e.options_||!1!==e.options_.prompt,_=d.hasPortal&&this._findOAuthInfo(e.resUrl_);let f,g;if(o)t(new E({userId:o,server:d.server??void 0,token:h??void 0,expires:null!=l?Number(l):null,ssl:!!a}));else if(window!==window.parent&&this._appUrlObj.query?.["arcgis-auth-origin"]&&this._appUrlObj.query?.["arcgis-auth-portal"]&&this._hasSameServerInstance(this._getServerInstanceRoot(this._appUrlObj.query["arcgis-auth-portal"]),e.resUrl_)){window.parent.postMessage({type:"arcgis:auth:requestCredential"},this._appUrlObj.query["arcgis-auth-origin"]);const s=n(window,"message",(e=>{e.source===window.parent&&e.data&&("arcgis:auth:credential"===e.data.type?(s.remove(),e.data.credential.expires<Date.now()?r(new i("identity-manager:credential-request-failed","Parent application's token has expired.")):t(new E(e.data.credential))):"arcgis:auth:error"===e.data.type&&(s.remove(),"tokenExpiredError"===e.data.error.name?r(new i("identity-manager:credential-request-failed","Parent application's token has expired.")):r(i.fromJSON(e.data.error))))}));c(e.options_?.signal,(()=>{s.remove()}))}else if(_){let o=_._oAuthCred;if(!o){const e=new U(_,b),t=new U(_,q);e.isValid()&&t.isValid()?e.expires>t.expires?(o=e,t.destroy()):(o=t,e.destroy()):o=e.isValid()?e:t,_._oAuthCred=o}if(o.isValid()){f=new E({userId:o.userId??void 0,server:d.server??void 0,token:o.token??void 0,expires:o.expires,ssl:o.ssl??void 0,_oAuthCred:o});const i=_.appId!==o.appId&&this._doPortalSignIn(e.resUrl_);i||o.refreshToken?(e._pendingDfd=o.refreshToken?this._getOAuthToken(d.server,o.refreshToken,o.appId).then((e=>(f.expires=Date.now()+1e3*e.expires_in,f.token=e.access_token,f))):Promise.resolve(f),e._pendingDfd.then((e=>i?this._exchangeToken(e.server,_.appId,e.token).then((t=>(e.token=t,e))).catch((()=>e)):e)).then((e=>{t(e)})).catch((e=>{const t=e.details?.httpStatus;t>0&&404!==t?(o.destroy(),s()):r(e)}))):t(f)}else if(this._oAuthLocationParams&&this._hasSameServerInstance(_.portalUrl,this._oAuthLocationParams.state.portalUrl)&&(this._oAuthLocationParams.access_token||this._oAuthLocationParams.code&&this._oAuthLocationParams.state.uid===o.stateUID&&o.codeVerifier)){const s=this._oAuthLocationParams;this._oAuthLocationParams=null,e._pendingDfd=this._processOAuthResponseParams(s,_,d).then((e=>{t(e)})).catch(r)}else{const s=()=>{u?e._pendingDfd=this.oAuthSignIn(e.resUrl_,d,_,e.options_).then(t,r):(g=new i("identity-manager:not-authenticated","User is not signed in."),r(g))};this._doPortalSignIn(e.resUrl_)?e._pendingDfd=this._getPlatformSelf(d.server,_.appId).then((e=>{p(e.portalUrl,this._appOrigin,!0)?(f=new E({userId:e.username,server:d.server??void 0,expires:Date.now()+1e3*e.expires_in,token:e.token}),t(f)):s()})).catch(s):s()}}else if(u){if(this._checkProtocol(e.resUrl_,d,r,e.admin_)){let s=e.options_;e.admin_&&(s=s||{},s.isAdmin=!0),e._pendingDfd=this.signIn(e.resUrl_,d,s).then(t,r)}}else g=new i("identity-manager:not-authenticated","User is not signed in."),r(g)},o=()=>{const s=e.sinfo_,i=s.owningSystemUrl,o=e.options_;let n,a,h,l;if(o&&(n=o.token,a=o.error,h=o.prompt),l=this._findCredential(i,{token:n,resource:e.resUrl_}),!l)for(const e of this.credentials)if(this._isIdProvider(i,e.server)){l=e;break}if(l){const i=this.findCredential(e.resUrl_,l.userId);if(i)t(i);else if(D(s,this._legacyFed)){const e=l.toJSON();e.server=s.server,e.resources=null,t(new E(e))}else{(e._pendingDfd=this.generateToken(this.findServerInfo(l.server),null,{serverUrl:e.resUrl_,token:l.token,signal:e.options_.signal,ssl:l.ssl})).then((r=>{t(new E({userId:l?.userId,server:s.server??void 0,token:r.token,expires:null!=r.expires?Number(r.expires):null,ssl:!!r.ssl,isAdmin:e.admin_,validity:r.validity}))}),r)}}else{this._busy=null,n&&(e.options_.token=null);(e._pendingDfd=this.getCredential(i.replace(/\/?$/,"/sharing"),{resource:e.resUrl_,owningTenant:s.owningTenant,signal:e.options_.signal,token:n,error:a,prompt:h})).then((()=>{this._enqueue(e.resUrl_,e.sinfo_,e.options_,e,e.admin_)}),(t=>{e.resUrl_=e.sinfo_=e.refresh_=null,e.reject(t)}))}};this._errbackFunc=r;const a=e.sinfo_.owningSystemUrl,l=this._isServerRsrc(e.resUrl_),d=e.sinfo_._restInfoPms;d?d.promise.then((t=>{const r=e.sinfo_;if(r._restInfoPms){r.adminTokenServiceUrl=r._restInfoPms.adminUrl,r._restInfoPms=null,r.tokenServiceUrl=(h("authInfo.tokenServicesUrl",t)||h("authInfo.tokenServiceUrl",t)||h("tokenServiceUrl",t))??null,r.shortLivedTokenValidity=h("authInfo.shortLivedTokenValidity",t)??null,r.currentVersion=t.currentVersion,r.owningTenant=t.owningTenant;const e=r.owningSystemUrl=t.owningSystemUrl;e&&this._portals.push(e)}l&&r.owningSystemUrl?o():s()}),(()=>{e.sinfo_._restInfoPms=null;const t=new i("identity-manager:server-identification-failed","Unknown resource - could not find token service endpoint.");r(t)})):l&&a?o():e.sinfo_._selfReq?e.sinfo_._selfReq.selfDfd.then((t=>{const r={};let s,i,o,n;return t&&(s=t.user?.username,r.username=s,r.allSSL=t.allSSL,i=t.supportsOAuth,n=parseFloat(t.currentVersion),"multitenant"===t.portalMode&&(o=t.customBaseUrl),e.sinfo_.currentVersion=n),e.sinfo_.webTierAuth=!!s,s&&this.normalizeWebTierAuth?this.generateToken(e.sinfo_,null,{ssl:r.allSSL}).catch((()=>null)).then((e=>(r.portalToken=e?.token,r.tokenExpiration=e?.expires,r))):!s&&i&&n>=4.4&&!this._findOAuthInfo(e.resUrl_)?this._generateOAuthInfo({portalUrl:e.sinfo_.server,customBaseUrl:o,owningTenant:e.sinfo_._selfReq.owningTenant}).catch((()=>null)).then((()=>r)):r})).catch((()=>null)).then((t=>{e.sinfo_._selfReq=null,t?s(t.username,t.allSSL,t.portalToken,t.tokenExpiration):s()})):s()}_generateOAuthInfo(e){let t,r=null,i=e.portalUrl;const o=e.customBaseUrl,n=e.owningTenant,a=!this._defaultOAuthInfo&&this._createDefaultOAuthInfo&&!this._hasTestedIfAppIsOnPortal;if(a){r=window.location.href;let e=r.indexOf("?");e>-1&&(r=r.slice(0,e)),e=r.search(/\/(apps|home)\//),r=e>-1?r.slice(0,e):null}return a&&r?(this._hasTestedIfAppIsOnPortal=!0,t=s(r+"/sharing/rest",{query:{f:"json"}}).then((()=>{this._defaultOAuthInfo=new T({appId:"arcgisonline",popupCallbackUrl:r+"/home/oauth-callback.html"})}))):t=Promise.resolve(),t.then((()=>{if(this._defaultOAuthInfo)return i=i.replace(/^http:/i,"https:"),s(i+"/sharing/rest/oauth2/validateRedirectUri",{query:{accountId:n,client_id:this._defaultOAuthInfo.appId,redirect_uri:w(this._defaultOAuthInfo.popupCallbackUrl),f:"json"}}).then((e=>{if(e.data.valid){const t=this._defaultOAuthInfo.clone();e.data.urlKey&&o?t.portalUrl="https://"+e.data.urlKey.toLowerCase()+"."+o:t.portalUrl=i,t.popup=window!==window.top||!(p(i,this._appOrigin)||this._gwDomains.some((e=>e.regex.test(i)&&e.regex.test(this._appOrigin)))),this.oAuthInfos.push(t)}}))}))}_doOAuthSignIn(e,t,r,s){const o=r._oAuthCred,a={portalUrl:r.portalUrl};!r.popup&&r.preserveUrlHash&&window.location.hash&&(a.hash=window.location.hash),o.stateUID&&(a.uid=o.stateUID);const h={client_id:r.appId,response_type:o.codeVerifier?"code":"token",state:JSON.stringify(a),expiration:r.expiration,locale:r.locale,redirect_uri:this._getRedirectURI(r,!!o.codeVerifier)};r.forceLogin&&(h.force_login=!0),r.forceUserId&&r.userId&&(h.prepopulatedusername=r.userId),!r.popup&&this._doPortalSignIn(e)&&(h.redirectToUserOrgUrl=!0),o.codeVerifier&&(h.code_challenge=s||o.codeVerifier,h.code_challenge_method=s?"S256":"plain");const l=r.portalUrl.replace(/^http:/i,"https:")+"/sharing/oauth2/authorize",c=l+"?"+m(h);if(r.popup){const e=window.open(c,"esriJSAPIOAuth",r.popupWindowFeatures);if(e)e.focus(),this._oAuthDfd.oAuthWin_=e,this._oAuthIntervalId=setInterval((()=>{if(e.closed){clearInterval(this._oAuthIntervalId),this._oAuthOnPopupHandle.remove();const e=this._oAuthDfd;if(e){const t=new i("identity-manager:user-aborted","ABORTED");e.reject(t)}}}),500),this._oAuthOnPopupHandle=n(window,["arcgis:auth:hash","arcgis:auth:location:search"],(e=>{"arcgis:auth:hash"===e.type?this.setOAuthResponseHash(e.detail):this._setOAuthResponseQueryString(e.detail)}));else{const e=new i("identity-manager:popup-blocked","ABORTED");this._oAuthDfd.reject(e)}}else this._rejectOnPersistedPageShow=!0,this._oAuthRedirectFunc?this._oAuthRedirectFunc({authorizeParams:h,authorizeUrl:l,resourceUrl:e,serverInfo:t,oAuthInfo:r}):window.location.href=c}_getRedirectURI(e,t){const r=window.location.href.replace(/#.*$/,"");if(e.popup)return w(e.popupCallbackUrl);if(t){const e=u(r);return e.query&&["code","error","error_description","message_code","persist","state"].forEach((t=>{delete e.query[t]})),I(e.path,e.query)}return r}}j.prototype.declaredClass="esri.identity.IdentityManagerBase";let E=class extends o.EventedAccessor{constructor(e){super(e),this._oAuthCred=null,this.tokenRefreshBuffer=2,e?._oAuthCred&&(this._oAuthCred=e._oAuthCred)}initialize(){this.resources=this.resources||[],null==this.creationTime&&(this.creationTime=Date.now())}refreshToken(){const e=r,t=e.findServerInfo(this.server),s=t?.owningSystemUrl,i=!!s&&"server"===this.scope,o=i&&D(t,e._legacyFed),n=t.webTierAuth,a=n&&e.normalizeWebTierAuth,h=R[this.server],l=h?.[this.userId];let c,d=this.resources&&this.resources[0],u=i?e.findServerInfo(s):null,p={username:this.userId,password:l};if(n&&!a)return;i&&!u&&e.serverInfos.some((t=>(e._isIdProvider(s,t.server)&&(u=t),!!u)));const _=u?e.findCredential(u.server,this.userId):null;if(!i||_){if(!o){if(i)c={serverUrl:d,token:_?.token,ssl:_?.ssl};else if(a)p=null,c={ssl:this.ssl};else{if(!l){let r;return d&&(d=e._sanitizeUrl(d),this._enqueued=1,r=e._enqueue(d,t,null,null,this.isAdmin,this),r.then((()=>{this._enqueued=0,this.refreshServerTokens()})).catch((()=>{this._enqueued=0}))),r}this.isAdmin&&(c={isAdmin:!0})}return e.generateToken(i?u:t,i?null:p,c).then((e=>{this.token=e.token,this.expires=null!=e.expires?Number(e.expires):null,this.creationTime=Date.now(),this.validity=e.validity,this.emitTokenChange(),this.refreshServerTokens()})).catch((()=>{}))}_?.refreshToken()}}refreshServerTokens(){if("portal"===this.scope){const e=r;e.credentials.forEach((t=>{const r=e.findServerInfo(t.server),s=r?.owningSystemUrl;t!==this&&t.userId===this.userId&&s&&"server"===t.scope&&(e._hasSameServerInstance(this.server,s)||e._isIdProvider(s,this.server))&&(D(r,e._legacyFed)?(t.token=this.token,t.expires=this.expires,t.creationTime=this.creationTime,t.validity=this.validity,t.emitTokenChange()):t.refreshToken())}))}}emitTokenChange(e){clearTimeout(this._refreshTimer);const t=r,s=this.server?t.findServerInfo(this.server):null,i=s?.owningSystemUrl,o=i?t.findServerInfo(i):null;!1===e||i&&"portal"!==this.scope&&(!o?.webTierAuth||t.normalizeWebTierAuth)||null==this.expires&&null==this.validity||this._startRefreshTimer(),this.emit("token-change")}destroy(){this.userId=this.server=this.token=this.expires=this.validity=this.resources=this.creationTime=null,this._oAuthCred&&(this._oAuthCred.destroy(),this._oAuthCred=null);const e=r,t=e.credentials.indexOf(this);t>-1&&e.credentials.splice(t,1),this.emitTokenChange(),this.emit("destroy")}toJSON(){const e=a({userId:this.userId,server:this.server,token:this.token,expires:this.expires,validity:this.validity,ssl:this.ssl,isAdmin:this.isAdmin,creationTime:this.creationTime,scope:this.scope}),t=this.resources;return t&&t.length>0&&(e.resources=t.slice()),e}_startRefreshTimer(){clearTimeout(this._refreshTimer);const e=6e4*this.tokenRefreshBuffer,t=2**31-1;let r=(this.validity?this.creationTime+6e4*this.validity:this.expires)-Date.now();r<0?r=0:r>t&&(r=t),this._refreshTimer=setTimeout(this.refreshToken.bind(this),r>e?r-e:r)}};e([A()],E.prototype,"creationTime",void 0),e([A()],E.prototype,"expires",void 0),e([A()],E.prototype,"isAdmin",void 0),e([A()],E.prototype,"oAuthState",void 0),e([A()],E.prototype,"resources",void 0),e([A()],E.prototype,"scope",void 0),e([A()],E.prototype,"server",void 0),e([A()],E.prototype,"ssl",void 0),e([A()],E.prototype,"token",void 0),e([A()],E.prototype,"tokenRefreshBuffer",void 0),e([A()],E.prototype,"userId",void 0),e([A()],E.prototype,"validity",void 0),E=e([k("esri.identity.Credential")],E);export{E as Credential,j as IdentityManagerBase};
|
package/interfaces.d.ts
CHANGED
|
@@ -3297,7 +3297,7 @@ declare namespace __esri {
|
|
|
3297
3297
|
* {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Error.html#name Read more...}
|
|
3298
3298
|
*/
|
|
3299
3299
|
name: string;
|
|
3300
|
-
constructor(name: string, message
|
|
3300
|
+
constructor(name: string, message: string, details?: any);
|
|
3301
3301
|
}
|
|
3302
3302
|
|
|
3303
3303
|
export class Evented {
|
|
@@ -110865,7 +110865,12 @@ declare namespace __esri {
|
|
|
110865
110865
|
*
|
|
110866
110866
|
* {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Editor-Workflow.html#type Read more...}
|
|
110867
110867
|
*/
|
|
110868
|
-
readonly type: "add-association"
|
|
110868
|
+
readonly type: | "add-association"
|
|
110869
|
+
| "create-features"
|
|
110870
|
+
| "update"
|
|
110871
|
+
| "update-feature"
|
|
110872
|
+
| "update-features"
|
|
110873
|
+
| "update-table-record";
|
|
110869
110874
|
/**
|
|
110870
110875
|
* The read-only `Workflow` class helps manage different stages of an {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Editor.html editing} workflow.
|
|
110871
110876
|
*
|
package/layers/TileLayer.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import r from"../request.js";import t from"../core/Error.js";import{loadAll as s}from"../core/loadAll.js";import{MultiOriginJSONMixin as i}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as o}from"../core/promiseUtils.js";import{urlToObject as a,objectToQuery as l,makeAbsolute as n}from"../core/urlUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{cast as c}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{reader as u}from"../core/accessorSupport/decorators/reader.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{writer as h}from"../core/accessorSupport/decorators/writer.js";import d from"../geometry/SpatialReference.js";import y from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISCachedService as v}from"./mixins/ArcGISCachedService.js";import{ArcGISMapService as g}from"./mixins/ArcGISMapService.js";import{ArcGISService as S}from"./mixins/ArcGISService.js";import{BlendLayer as _}from"./mixins/BlendLayer.js";import{CustomParametersMixin as j}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as b}from"./mixins/OperationalLayer.js";import{PortalLayer as T}from"./mixins/PortalLayer.js";import{RefreshableLayer as w}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as O}from"./mixins/ScaleRangeLayer.js";import{SublayersOwner as L}from"./mixins/SublayersOwner.js";import{parse as R,isHostedAgolService as U,isArcGISUrl as P}from"./support/arcgisLayerUrl.js";import{url as x}from"./support/commonProperties.js";import{createTileBitmap as A}from"./support/imageBitmapUtils.js";import I from"./support/Sublayer.js";import M from"../symbols/support/ElevationInfo.js";var W;const B=["Canvas/World_Dark_Gray_Base","Canvas/World_Dark_Gray_Reference","Canvas/World_Light_Gray_Base","Canvas/World_Light_Gray_Reference","Elevation/World_Hillshade","Elevation/World_Hillshade_Dark","Ocean/World_Ocean_Base","Ocean/World_Ocean_Reference","Ocean_Basemap","Reference/World_Boundaries_and_Places","Reference/World_Boundaries_and_Places_Alternate","Reference/World_Transportation","World_Imagery","World_Street_Map","World_Topo_Map"];let C=W=class extends(_(O(L(v(g(b(T(S(i(w(f(j(y))))))))))))){constructor(...e){super(...e),this.listMode="show",this.elevationInfo=new M({mode:"on-the-ground"}),this.isReference=null,this.operationalLayerType="ArcGISTiledMapServiceLayer",this.resampling=!0,this.sourceJSON=null,this.spatialReference=null,this.path=null,this.sublayers=null,this.type="tile",this.url=null}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}load(e){const r=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Map Service"]},e).catch(o).then((()=>this._fetchService(r)))),Promise.resolve(this)}get attributionDataUrl(){const e=this.parsedUrl?.path.toLowerCase();return e?this._getDefaultAttribution(this._getMapName(e)):null}readSpatialReference(e,r){return(e=e||r.tileInfo?.spatialReference)&&d.fromJSON(e)}writeSublayers(e,r,t,s){if(!this.loaded||!e)return;const i=e.slice().reverse().flatten((({sublayers:e})=>e&&e.toArray().reverse())).toArray(),o=[],a={writeSublayerStructure:!1,...s};i.forEach((e=>{const r=e.write({},a);o.push(r)}));o.some((e=>Object.keys(e).length>1))&&(r.layers=o)}get tileServers(){return this._getDefaultTileServers(this.parsedUrl?.path)}castTileServers(e){return Array.isArray(e)?e.map((e=>a(e).path)):null}fetchTile(e,t,s,i={}){const{signal:o}=i,a=this.getTileUrl(e,t,s),l={responseType:"image",signal:o,query:{...this.refreshParameters}};return r(a,l).then((e=>e.data))}async fetchImageBitmapTile(e,t,s,i={}){const{signal:o}=i;if(this.fetchTile!==W.prototype.fetchTile){const r=await this.fetchTile(e,t,s,i);return A(r,e,t,s,o)}const a=this.getTileUrl(e,t,s),l={responseType:"blob",signal:o,query:{...this.refreshParameters}},{data:n}=await r(a,l);return A(n,e,t,s,o)}getTileUrl(e,r,t){const s=!this.capabilities.operations.supportsTileMap&&this.supportsBlankTile,i=l({...this.parsedUrl?.query,blankTile:!s&&null,...this.customParameters,token:this.apiKey}),o=this.tileServers;return`${o&&o.length?o[r%o.length]:this.parsedUrl?.path}/tile/${e}/${r}/${t}${i?"?"+i:""}`}loadAll(){return s(this,(e=>{e(this.allSublayers)}))}_fetchService(e){return new Promise(((s,i)=>{if(this.sourceJSON){if(null!=this.sourceJSON.bandCount&&null!=this.sourceJSON.pixelSizeX)throw new t("tile-layer:unsupported-url","use ImageryTileLayer to open a tiled image service");return void s({data:this.sourceJSON})}if(!this.parsedUrl)throw new t("tile-layer:undefined-url","layer's url is not defined");const o=R(this.parsedUrl.path);if(null!=o&&"ImageServer"===o.serverType)throw new t("tile-layer:unsupported-url","use ImageryTileLayer to open a tiled image service");r(this.parsedUrl.path,{query:{f:"json",...this.parsedUrl.query,...this.customParameters,token:this.apiKey},responseType:"json",signal:e}).then(s,i)})).then((r=>{let t=this.url;if(r.ssl&&(t=this.url=t.replace(/^http:/i,"https:")),this.sourceJSON=r.data,this.read(r.data,{origin:"service",url:this.parsedUrl}),10.1===this.version&&!U(t))return this._fetchServerVersion(t,e).then((e=>{this.read({currentVersion:e})})).catch((()=>{}))}))}_fetchServerVersion(e,s){if(!P(e))return Promise.reject();const i=e.replace(/(.*\/rest)\/.*/i,"$1")+"/info";return r(i,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:s}).then((e=>{if(e.data
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import r from"../request.js";import t from"../core/Error.js";import{loadAll as s}from"../core/loadAll.js";import{MultiOriginJSONMixin as i}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as o}from"../core/promiseUtils.js";import{urlToObject as a,objectToQuery as l,makeAbsolute as n}from"../core/urlUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{cast as c}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{reader as u}from"../core/accessorSupport/decorators/reader.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{writer as h}from"../core/accessorSupport/decorators/writer.js";import d from"../geometry/SpatialReference.js";import y from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISCachedService as v}from"./mixins/ArcGISCachedService.js";import{ArcGISMapService as g}from"./mixins/ArcGISMapService.js";import{ArcGISService as S}from"./mixins/ArcGISService.js";import{BlendLayer as _}from"./mixins/BlendLayer.js";import{CustomParametersMixin as j}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as b}from"./mixins/OperationalLayer.js";import{PortalLayer as T}from"./mixins/PortalLayer.js";import{RefreshableLayer as w}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as O}from"./mixins/ScaleRangeLayer.js";import{SublayersOwner as L}from"./mixins/SublayersOwner.js";import{parse as R,isHostedAgolService as U,isArcGISUrl as P}from"./support/arcgisLayerUrl.js";import{url as x}from"./support/commonProperties.js";import{createTileBitmap as A}from"./support/imageBitmapUtils.js";import I from"./support/Sublayer.js";import M from"../symbols/support/ElevationInfo.js";var W;const B=["Canvas/World_Dark_Gray_Base","Canvas/World_Dark_Gray_Reference","Canvas/World_Light_Gray_Base","Canvas/World_Light_Gray_Reference","Elevation/World_Hillshade","Elevation/World_Hillshade_Dark","Ocean/World_Ocean_Base","Ocean/World_Ocean_Reference","Ocean_Basemap","Reference/World_Boundaries_and_Places","Reference/World_Boundaries_and_Places_Alternate","Reference/World_Transportation","World_Imagery","World_Street_Map","World_Topo_Map"];let C=W=class extends(_(O(L(v(g(b(T(S(i(w(f(j(y))))))))))))){constructor(...e){super(...e),this.listMode="show",this.elevationInfo=new M({mode:"on-the-ground"}),this.isReference=null,this.operationalLayerType="ArcGISTiledMapServiceLayer",this.resampling=!0,this.sourceJSON=null,this.spatialReference=null,this.path=null,this.sublayers=null,this.type="tile",this.url=null}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}load(e){const r=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Map Service"]},e).catch(o).then((()=>this._fetchService(r)))),Promise.resolve(this)}get attributionDataUrl(){const e=this.parsedUrl?.path.toLowerCase();return e?this._getDefaultAttribution(this._getMapName(e)):null}readSpatialReference(e,r){return(e=e||r.tileInfo?.spatialReference)&&d.fromJSON(e)}writeSublayers(e,r,t,s){if(!this.loaded||!e)return;const i=e.slice().reverse().flatten((({sublayers:e})=>e&&e.toArray().reverse())).toArray(),o=[],a={writeSublayerStructure:!1,...s};i.forEach((e=>{const r=e.write({},a);o.push(r)}));o.some((e=>Object.keys(e).length>1))&&(r.layers=o)}get tileServers(){return this._getDefaultTileServers(this.parsedUrl?.path)}castTileServers(e){return Array.isArray(e)?e.map((e=>a(e).path)):null}fetchTile(e,t,s,i={}){const{signal:o}=i,a=this.getTileUrl(e,t,s),l={responseType:"image",signal:o,query:{...this.refreshParameters}};return r(a,l).then((e=>e.data))}async fetchImageBitmapTile(e,t,s,i={}){const{signal:o}=i;if(this.fetchTile!==W.prototype.fetchTile){const r=await this.fetchTile(e,t,s,i);return A(r,e,t,s,o)}const a=this.getTileUrl(e,t,s),l={responseType:"blob",signal:o,query:{...this.refreshParameters}},{data:n}=await r(a,l);return A(n,e,t,s,o)}getTileUrl(e,r,t){const s=!this.capabilities.operations.supportsTileMap&&this.supportsBlankTile,i=l({...this.parsedUrl?.query,blankTile:!s&&null,...this.customParameters,token:this.apiKey}),o=this.tileServers;return`${o&&o.length?o[r%o.length]:this.parsedUrl?.path}/tile/${e}/${r}/${t}${i?"?"+i:""}`}loadAll(){return s(this,(e=>{e(this.allSublayers)}))}_fetchService(e){return new Promise(((s,i)=>{if(this.sourceJSON){if(null!=this.sourceJSON.bandCount&&null!=this.sourceJSON.pixelSizeX)throw new t("tile-layer:unsupported-url","use ImageryTileLayer to open a tiled image service");return void s({data:this.sourceJSON})}if(!this.parsedUrl)throw new t("tile-layer:undefined-url","layer's url is not defined");const o=R(this.parsedUrl.path);if(null!=o&&"ImageServer"===o.serverType)throw new t("tile-layer:unsupported-url","use ImageryTileLayer to open a tiled image service");r(this.parsedUrl.path,{query:{f:"json",...this.parsedUrl.query,...this.customParameters,token:this.apiKey},responseType:"json",signal:e}).then(s,i)})).then((r=>{let t=this.url;if(r.ssl&&(t=this.url=t.replace(/^http:/i,"https:")),this.sourceJSON=r.data,this.read(r.data,{origin:"service",url:this.parsedUrl}),10.1===this.version&&!U(t))return this._fetchServerVersion(t,e).then((e=>{this.read({currentVersion:e})})).catch((()=>{}))}))}_fetchServerVersion(e,s){if(!P(e))return Promise.reject();const i=e.replace(/(.*\/rest)\/.*/i,"$1")+"/info";return r(i,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:s}).then((e=>{if(e.data?.currentVersion)return e.data.currentVersion;throw new t("tile-layer:version-not-available","Server did not provide a version")}))}_getMapName(e){const r=e.match(/^(?:https?:)?\/\/(server\.arcgisonline\.com|services\.arcgisonline\.com|ibasemaps-api\.arcgis\.com)\/arcgis\/rest\/services\/([^/]+(\/[^/]+)*)\/mapserver/i);return r?r[2]:void 0}_getDefaultAttribution(e){if(null==e)return null;let r;e=e.toLowerCase();for(let t=0,s=B.length;t<s;t++)if(r=B[t],r.toLowerCase().includes(e))return n("//static.arcgis.com/attribution/"+r);return null}_getDefaultTileServers(e){if(null==e)return[];const r=-1!==e.search(/^(?:https?:)?\/\/server\.arcgisonline\.com/i),t=-1!==e.search(/^(?:https?:)?\/\/services\.arcgisonline\.com/i);return r||t?[e,e.replace(r?/server\.arcgisonline/i:/services\.arcgisonline/i,r?"services.arcgisonline":"server.arcgisonline")]:[]}get hasOverriddenFetchTile(){return!this.fetchTile[N]}};e([p({readOnly:!0})],C.prototype,"attributionDataUrl",null),e([p({type:["show","hide","hide-children"]})],C.prototype,"listMode",void 0),e([p({json:{read:!0,write:!0}})],C.prototype,"blendMode",void 0),e([p()],C.prototype,"elevationInfo",void 0),e([p({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],C.prototype,"isReference",void 0),e([p({readOnly:!0,type:["ArcGISTiledMapServiceLayer"]})],C.prototype,"operationalLayerType",void 0),e([p({type:Boolean})],C.prototype,"resampling",void 0),e([p()],C.prototype,"sourceJSON",void 0),e([p({type:d})],C.prototype,"spatialReference",void 0),e([u("spatialReference",["spatialReference","tileInfo"])],C.prototype,"readSpatialReference",null),e([p({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],C.prototype,"path",void 0),e([p({readOnly:!0})],C.prototype,"sublayers",void 0),e([h("sublayers",{layers:{type:[I]}})],C.prototype,"writeSublayers",null),e([p({json:{read:!1,write:!1}})],C.prototype,"popupEnabled",void 0),e([p()],C.prototype,"tileServers",null),e([c("tileServers")],C.prototype,"castTileServers",null),e([p({readOnly:!0,json:{read:!1}})],C.prototype,"type",void 0),e([p(x)],C.prototype,"url",void 0),C=W=e([m("esri.layers.TileLayer")],C);const N=Symbol("default-fetch-tile");C.prototype.fetchTile[N]=!0;const k=C;export{k as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import e from"../../Graphic.js";import t from"../../core/Error.js";import r from"../../core/Logger.js";import{getMetersPerCartesianUnitForSR as a}from"../../core/unitUtils.js";import{parseData as s}from"../../core/urlUtils.js";import{isEqualBaseGCS as o,canProjectWithoutEngine as n,projectWithoutEngine as l}from"../../geometry/projection.js";import{fromJSON as i}from"../../geometry/support/jsonUtils.js";import u from"../../geometry/support/MeshTransform.js";import{equals as d}from"../../geometry/support/spatialReferenceUtils.js";import{isFeatureIdentifierArrayWithGlobalId as c,isFeatureIdentifierArrayWithObjectId as p}from"./editingSupport.js";async function m(e,t,r){const{geometry:s}=t,i={...t.attributes};if(null!=r&&"mesh"===s?.type){const{transformFieldRoles:t}=r,{origin:c,spatialReference:p,vertexSpace:m}=s,f=s.transform??new u,g="local"===m.type,b=e.spatialReference,y=b.isGeographic,R=d(b,p),h=o(p,b)&&n(p,b);if(!(g&&y&&h||!g&&!y&&R))return null;const I=l(c,p,b);if(null==I)return null;if(i[t.originX]=I.x,i[t.originY]=I.y,i[t.originZ]=I.z??0,null!=f){const{translation:e,scale:r,rotation:s}=f,o=g?1:a(p)/a(b);i[t.translationX]=e[0]*o,i[t.translationY]=e[2]*o,i[t.translationZ]=-e[1]*o,i[t.scaleX]=r[0],i[t.scaleY]=r[2],i[t.scaleZ]=r[1],i[t.rotationX]=s[0],i[t.rotationY]=s[2],i[t.rotationZ]=-s[1],i[t.rotationDeg]=s[3]}return{attributes:i}}return null==s?{attributes:i}:"mesh"===s.type||"extent"===s.type?null:{geometry:s.toJSON(),attributes:i}}async function f(e,t){const r=await Promise.all((t.addAttachments??[]).map((t=>g(e,t)))),a=await Promise.all((t.updateAttachments??[]).map((t=>g(e,t)))),s=t.deleteAttachments??[];return r.length||a.length||s.length?{adds:r,updates:a,deletes:[...s]}:null}async function g(e,t){const{feature:r,attachment:a}=t,{globalId:o,name:n,contentType:l,data:i,uploadId:u}=a,d={globalId:o};if(r&&("attributes"in r?d.parentGlobalId=r.attributes?.[e.globalIdField]:r.globalId&&(d.parentGlobalId=r.globalId)),u)d.uploadId=u;else if(i){const e=await s(i);e&&(d.contentType=e.mediaType,d.data=e.data),i instanceof File&&(d.name=i.name)}return n&&(d.name=n),l&&(d.contentType=l),d}function b(e,t,r){if(!t||0===t.length)return[];if(r&&c(t))return t.map((e=>e.globalId));if(p(t))return t.map((e=>e.objectId));const a=r?e.globalIdField:e.objectIdField;return a?t.map((e=>e.getAttribute(a))):[]}function y(e){const t=e?.assetMaps;if(t){for(const e of t.addResults)e.success||r.getLogger("esri.layers.graphics.sources.support.sourceUtils").error(`Failed to map asset to feature with globalId ${e.globalId}.`);for(const e of t.updateResults)e.success||r.getLogger("esri.layers.graphics.sources.support.sourceUtils").error(`Failed to map asset to feature with globalId ${e.globalId}.`)}const a=e?.attachments,s={addFeatureResults:e?.addResults?.map(R)??[],updateFeatureResults:e?.updateResults?.map(R)??[],deleteFeatureResults:e?.deleteResults?.map(R)??[],addAttachmentResults:a?.addResults?a.addResults.map(R):[],updateAttachmentResults:a?.updateResults?a.updateResults.map(R):[],deleteAttachmentResults:a?.deleteResults?a.deleteResults.map(R):[]};return e?.editMoment&&(s.editMoment=e.editMoment),s}function R(e){const r=!0===e.success?null:e.error||{code:void 0,description:"Feature edit failed"};return{objectId:e.objectId,globalId:e.globalId,error:r?new t("feature-layer-source:edit-failure",r.description,{code:r.code}):null}}function h(t,r){return new e({attributes:t.attributes,geometry:i({...t.geometry,spatialReference:r})})}function I(e,t){return{adds:e?.adds?.map((e=>h(e,t)))||[],updates:e?.updates?.map((e=>({original:h(e[0],t),current:h(e[1],t)})))||[],deletes:e?.deletes?.map((e=>h(e,t)))||[],spatialReference:t}}function j(e){const t=e.details.raw,r=+t.code,a=+t.extendedCode;return 500===r&&(-2147217144===a||-2147467261===a)}export{I as createEditedFeatures,R as createFeatureEditResult,f as getAttachmentEditsJSON,b as getFeatureIds,m as getFeatureJSON,j as isProtectedOrPrivateVersionError,y as unpackEditResultData};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{assertIsSome as o}from"../../core/maybe.js";import{is as n,fromRectValues as r}from"../../geometry/support/aaBoundingBox.js";import{fromValues as s}from"../../geometry/support/aaBoundingRect.js";import{isPoint as u,isPolygon as l,isPolyline as c,isMultipoint as i}from"../../geometry/support/jsonUtils.js";import{OptimizedFeature as f}from"./OptimizedFeature.js";import a from"./OptimizedFeatureSet.js";import h from"./OptimizedGeometry.js";function d(t,e){return t?e?4:3:e?3:2}const m=()=>e.getLogger("esri.layers.graphics.featureConversionUtils"),g={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0,esriGeometryMultiPatch:3,esriGeometryEnvelope:0},y=(t,e,o,n,r,s)=>{t[o]=r,t[o+1]=s},p=(t,e,o,n,r,s)=>{t[o]=r,t[o+1]=s,t[o+2]=e[n+2]},I=(t,e,o,n,r,s)=>{t[o]=r,t[o+1]=s,t[o+2]=e[n+3]},M=(t,e,o,n,r,s)=>{t[o]=r,t[o+1]=s,t[o+2]=e[n+2],t[o+3]=e[n+3]};function b(t,e,o,n){if(t){if(o)return e&&n?M:p;if(e&&n)return I}else if(e&&n)return p;return y}function w({scale:t,translate:e},o){return Math.round((o-e[0])/t[0])}function N({scale:t,translate:e},o){return Math.round((e[1]-o)/t[1])}function G({scale:t,translate:e},o){return Math.round((o-e[0])/t[0])}function T({scale:t,translate:e},o){return Math.round((o-e[1])/t[1])}function F(t,e){return x(t,e,0)}function P(t,e){return x(t,-e,1)}function x({scale:t,translate:e},o,n){return o*t[n]+e[n]}function j(t,e,o){return t?e?o?Y(t):v(t):o?k(t):Z(t):null}function Z(t){const e=t.coords;return{x:e[0],y:e[1]}}function E(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t}function v(t){const e=t.coords;return{x:e[0],y:e[1],z:e[2]}}function z(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.z,t}function k(t){const e=t.coords;return{x:e[0],y:e[1],m:e[2]}}function V(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.m,t}function Y(t){const e=t.coords;return{x:e[0],y:e[1],z:e[2],m:e[3]}}function _(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.z,t.coords[3]=e.m,t}function L(t,e,o,n){let r=Z;o&&n?r=Y:o?r=v:n&&(r=k);for(const s of e){const{geometry:e,attributes:o}=s,n=null!=e?r(e):null;t.push({attributes:o,geometry:n})}return t}function O(t,e){return t&&e?_:t?z:e?V:E}function S(t,e,o,n,r){const s=O(o,n);for(const{geometry:u,attributes:l}of e){const e=null!=u?s(new h,u):null;t.push(new f(e,l,null,r?l[r]:void 0))}return t}function U(t,e,o=O(null!=e.z,null!=e.m)){return o(t,e)}function q(t,e,o,n){for(const{geometry:r,attributes:s}of e)t.push({attributes:s,geometry:null!=r?R(r,o,n):null});return t}function R(t,e,o){if(null==t)return null;const n=d(e,o),r=[];for(let s=0;s<t.coords.length;s+=n){const e=[];for(let o=0;o<n;o++)e.push(t.coords[s+o]);r.push(e)}return e?o?{points:r,hasZ:e,hasM:o}:{points:r,hasZ:e}:o?{points:r,hasM:o}:{points:r}}function A(t,e,o,n,r){const s=d(o,n);for(const{geometry:u,attributes:l}of e){const e=null!=u?$(new h,u,s):null;t.push(new f(e,l,null,r?l[r]:void 0))}return t}function $(t,e,o=d(e.hasZ,e.hasM)){t.lengths[0]=e.points.length;const n=t.coords;let r=0;for(const s of e.points)for(let t=0;t<o;t++)n[r++]=s[t];return t}function B(t,e,o,n){for(const{geometry:r,attributes:s}of e)t.push({attributes:s,geometry:null!=r?C(r,o,n):null});return t}function C(t,e,o){if(!t)return null;const n=d(e,o),{coords:r,lengths:s}=t,u=[];let l=0;for(const c of s){const t=[];for(let e=0;e<c;e++){const e=[];for(let t=0;t<n;t++)e.push(r[l++]);t.push(e)}u.push(t)}return e?o?{paths:u,hasZ:e,hasM:o}:{paths:u,hasZ:e}:o?{paths:u,hasM:o}:{paths:u}}function D(t,e,o,n,r){const s=d(o,n);for(const{geometry:u,attributes:l,centroid:c}of e){const e=null!=u?H(new h,u,s):null,o=null!=c?U(new h,c):null;t.push(new f(e,l,o,r?l[r]:void 0))}return t}function H(t,e,o=d(e.hasZ,e.hasM)){const{lengths:n,coords:r}=t;let s=0;for(const u of e.paths){for(const t of u)for(let e=0;e<o;e++)r[s++]=t[e];n.push(u.length)}return t}function J(t,e,o,n){for(const{geometry:r,attributes:s,centroid:u}of e){const e=null!=r?K(r,o,n):null;if(null!=u){const o=Z(u);t.push({attributes:s,centroid:o,geometry:e})}else t.push({attributes:s,geometry:e})}return t}function K(t,e,o){if(!t)return null;const n=d(e,o),{coords:r,lengths:s}=t,u=[];let l=0;for(const c of s){const t=[];for(let e=0;e<c;e++){const e=[];for(let t=0;t<n;t++)e.push(r[l++]);t.push(e)}u.push(t)}return e?o?{rings:u,hasZ:e,hasM:o}:{rings:u,hasZ:e}:o?{rings:u,hasM:o}:{rings:u}}function Q(t,e,o,n,r){for(const{geometry:s,centroid:u,attributes:l}of e){const e=null!=s?W(new h,s,o,n):null,c=r?l[r]:void 0;null!=u?t.push(new f(e,l,E(new h,u),c)):t.push(new f(e,l,null,c))}return t}function W(t,e,o=e.hasZ,n=e.hasM){return X(t,e.rings,o,n)}function X(t,e,o,n){const r=d(o,n),{lengths:s,coords:u}=t;let l=0;Pt(t);for(const c of e){for(const t of c)for(let e=0;e<r;e++)u[l++]=t[e];s.push(c.length)}return t}const tt=[],et=[];function ot(t,e,o,n,r){tt[0]=t;const[s]=nt(et,tt,e,o,n,r);return xt(tt),xt(et),s}function nt(e,o,n,r,s,u){if(xt(e),!n){for(const t of o){const o=u?t.attributes[u]:void 0;e.push(new f(null,t.attributes,null,o))}return e}switch(n){case"esriGeometryPoint":return S(e,o,r,s,u);case"esriGeometryMultipoint":return A(e,o,r,s,u);case"esriGeometryPolyline":return D(e,o,r,s,u);case"esriGeometryPolygon":case"esriGeometryMultiPatch":return Q(e,o,r,s,u);default:m().error("convertToFeatureSet:unknown-geometry",new t(`Unable to parse unknown geometry type '${n}'`)),xt(e)}return e}function rt(t,e,o,n){et[0]=t,ct(tt,et,e,o,n);const r=tt[0];return xt(tt),xt(et),r}function st(e,o,n){if(null==e)return null;const r=new h;if("hasZ"in e&&null==o&&(o=e.hasZ),"hasM"in e&&null==n&&(n=e.hasM),u(e)){return O(null!=o?o:null!=e.z,null!=n?n:null!=e.m)(r,e)}return l(e)?W(r,e,o,n):c(e)?H(r,e,d(o,n)):i(e)?$(r,e,d(o,n)):void m().error("convertFromGeometry:unknown-geometry",new t(`Unable to parse unknown geometry type '${e}'`))}function ut(e,o,n,r){const s=e&&("coords"in e?e:e.geometry);if(null==s)return null;switch(o){case"esriGeometryPoint":{let t=Z;return n&&r?t=Y:n?t=v:r&&(t=k),t(s)}case"esriGeometryMultipoint":return R(s,n,r);case"esriGeometryPolyline":return C(s,n,r);case"esriGeometryPolygon":return K(s,n,r);default:return m().error("convertToGeometry:unknown-geometry",new t(`Unable to parse unknown geometry type '${o}'`)),null}}function lt(t,e){for(const o of e)t.push({attributes:o.attributes});return t}function ct(e,o,n,r,s){if(xt(e),null==n)return lt(e,o);switch(n){case"esriGeometryPoint":return L(e,o,r,s);case"esriGeometryMultipoint":return q(e,o,r,s);case"esriGeometryPolyline":return B(e,o,r,s);case"esriGeometryPolygon":return J(e,o,r,s);default:m().error("convertToFeatureSet:unknown-geometry",new t(`Unable to parse unknown geometry type '${n}'`))}return e}function it(t){const{objectIdFieldName:e,spatialReference:o,transform:n,fields:r,hasM:s,hasZ:u,features:l,geometryType:c,exceededTransferLimit:i,uniqueIdField:f,queryGeometry:a,queryGeometryType:h}=t,d={features:ct([],l,c,u,s),fields:r,geometryType:c,objectIdFieldName:e,spatialReference:o,uniqueIdField:f,queryGeometry:ut(a,h,!1,!1)};return n&&(d.transform=n),i&&(d.exceededTransferLimit=i),s&&(d.hasM=s),u&&(d.hasZ=u),d}function ft(e,o){const n=new a,{hasM:r,hasZ:s,features:u,objectIdFieldName:l,spatialReference:c,geometryType:i,exceededTransferLimit:f,transform:h,fields:d}=e;return d&&(n.fields=d),n.geometryType=i??null,n.objectIdFieldName=l??o??null,n.spatialReference=c??null,n.objectIdFieldName?(u&&nt(n.features,u,i,s,r,n.objectIdFieldName),f&&(n.exceededTransferLimit=f),r&&(n.hasM=r),s&&(n.hasZ=s),h&&(n.transform=h),n):(m().error(new t("optimized-features:invalid-objectIdFieldName","objectIdFieldName is missing")),n)}function at(t){const{transform:e,features:o,hasM:n,hasZ:r}=t;if(!e)return t;for(const s of o)null!=s.geometry&&Mt(s.geometry,s.geometry,n,r,e),null!=s.centroid&&Mt(s.centroid,s.centroid,n,r,e);return t.transform=null,t}function ht(t,e){const{geometryType:o,features:n,hasM:r,hasZ:s}=e;if(!t)return e;for(let u=0;u<n.length;u++){const e=n[u],l=e.weakClone();l.geometry=new h,dt(l.geometry,e.geometry,r,s,o,t),e.centroid&&(l.centroid=new h,dt(l.centroid,e.centroid,r,s,"esriGeometryPoint",t)),n[u]=l}return e.transform=t,e}function dt(t,e,o,n,r,s,u=o,l=n){if(Pt(t),!e?.coords.length)return null;const c=g[r],{coords:i,lengths:f}=e,a=d(o,n),h=d(o&&u,n&&l),m=b(o,n,u,l);if(!f.length)return m(t.coords,i,0,0,w(s,i[0]),N(s,i[1])),Pt(t,a,0),t;let y,p,I,M,G=0,T=0,F=T;for(const d of f){if(d<c)continue;let e=0;T=F,I=y=w(s,i[G]),M=p=N(s,i[G+1]),m(t.coords,i,T,G,I,M),e++,G+=a,T+=h;for(let o=1;o<d;o++,G+=a)I=w(s,i[G]),M=N(s,i[G+1]),I===y&&M===p||(m(t.coords,i,T,G,I-y,M-p),T+=h,e++,y=I,p=M);e>=c&&(t.lengths.push(e),F=T)}return xt(t.coords,F),t.coords.length?t:null}function mt(t,e,o,n,r,s,u=o,l=n){if(Pt(t),!e?.coords.length)return null;const c=g[r],{coords:i,lengths:f}=e,a=d(o,n),h=d(o&&u,n&&l),m=b(o,n,u,l);if(!f.length)return m(t.coords,i,0,0,i[0],i[1]),Pt(t,a,0),t;let y=0;const p=s*s;for(const d of f){if(d<c){y+=d*a;continue}const e=t.coords.length/h,o=y,n=y+(d-1)*a;m(t.coords,i,t.coords.length,o,i[o],i[o+1]),yt(t.coords,i,a,p,m,o,n),m(t.coords,i,t.coords.length,n,i[n],i[n+1]);const r=t.coords.length/h-e;r>=c?t.lengths.push(r):xt(t.coords,e*h),y+=d*a}return t.coords.length?t:null}function gt(t,e,o,n){const r=t[e],s=t[e+1],u=t[o],l=t[o+1],c=t[n],i=t[n+1];let f=u,a=l,h=c-f,d=i-a;if(0!==h||0!==d){const t=((r-f)*h+(s-a)*d)/(h*h+d*d);t>1?(f=c,a=i):t>0&&(f+=h*t,a+=d*t)}return h=r-f,d=s-a,h*h+d*d}function yt(t,e,o,n,r,s,u){let l,c=n,i=0;for(let f=s+o;f<u;f+=o)l=gt(e,f,s,u),l>c&&(i=f,c=l);c>n&&(i-s>o&&yt(t,e,o,n,r,s,i),r(t,e,t.length,i,e[i],e[i+1]),u-i>o&&yt(t,e,o,n,r,i,u))}function pt(t,e,o,u){if(!e?.coords?.length)return null;const l=d(o,u);let c=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;if(e&&e.coords){const t=e.coords;for(let e=0;e<t.length;e+=l){const o=t[e],n=t[e+1];c=Math.min(c,o),f=Math.max(f,o),i=Math.min(i,n),a=Math.max(a,n)}}return n(t)?r(t,c,i,f,a):s(c,i,f,a,t),t}function It(t,e,o,n){const r=d(o,n),{lengths:s,coords:u}=e;let l=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY,a=0;for(const h of s){let t=u[a],e=u[a+1];l=Math.min(t,l),c=Math.min(e,c),i=Math.max(t,i),f=Math.max(e,f),a+=r;for(let o=1;o<h;o++,a+=r){const o=u[a],n=u[a+1];t+=o,e+=n,o<0&&(l=Math.min(l,t)),o>0&&(i=Math.max(i,t)),n<0?c=Math.min(c,e):n>0&&(f=Math.max(f,e))}}return t[0]=l,t[1]=c,t[2]=i,t[3]=f,t}function Mt(t,e,n,r,s){const{coords:u,lengths:l}=e,c=d(n,r);if(!u.length)return t!==e&&Pt(t),t;o(s);const{originPosition:i,scale:f,translate:a}=s,h=jt;h.originPosition=i;const m=h.scale;m[0]=f[0]??1,m[1]=-(f[1]??1),m[2]=f[2]??1,m[3]=f[3]??1;const g=h.translate;if(g[0]=a[0]??0,g[1]=a[1]??0,g[2]=a[2]??0,g[3]=a[3]??0,!l.length){for(let e=0;e<c;++e)t.coords[e]=x(h,u[e],e);return t!==e&&Pt(t,c,0),t}let y=0;for(let o=0;o<l.length;o++){const e=l[o];t.lengths[o]=e;for(let o=0;o<c;++o)t.coords[y+o]=x(h,u[y+o],o);let n=t.coords[y],r=t.coords[y+1];y+=c;for(let o=1;o<e;o++,y+=c){n+=u[y]*m[0],r+=u[y+1]*m[1],t.coords[y]=n,t.coords[y+1]=r;for(let e=2;e<c;++e)t.coords[y+e]=x(h,u[y+e],e)}}return t!==e&&Pt(t,u.length,l.length),t}function bt(t,e,o,n,r,s){if(Pt(t),t.lengths.push(...e.lengths),o===r&&n===s)for(let u=0;u<e.coords.length;u++)t.coords.push(e.coords[u]);else{const u=d(o,n),l=b(o,n,r,s),c=e.coords;for(let e=0;e<c.length;e+=u)l(t.coords,c,t.coords.length,e,c[e],c[e+1])}return t}function wt(t,e,o,n,r){if(!e?.coords?.length)return null;const s=g[o],{coords:u,lengths:l}=e,c=b(n,r,n,r),i=d(n,r);let f=0,a=0,h=0,m=0;for(const d of l){a=m,c(t.coords,u,a,f,u[f],u[f+1]),f+=i;let e=u[f],o=u[f+1],n=e,r=o,l=o/e;a+=i,c(t.coords,u,a,f,n,r),f+=i;for(let s=2;s<d;s++){e=u[f],o=u[f+1];const s=o/e,h=l===s||!isFinite(l)&&!isFinite(s),d=h&&isFinite(s)?l>=0&&s>=0||l<=0&&s<=0:r>=0&&o>=0||r<=0&&o<=0;h&&d?(n+=e,r+=o):(n=e,r=o,a+=i),c(t.coords,u,a,f,n,r),f+=i,l=s}a+=i;const g=(a-m)/i;g>=s&&(t.lengths[h]=g,m=a,h++)}return t.coords.length>m&&(t.coords.length=m),t.lengths.length>h&&(t.lengths.length=h),t.coords.length&&t.lengths.length?t:null}function Nt(t,e,o,n){let r=0,s=t[n*e],u=t[n*(e+1)];for(let l=1;l<o;l++){const o=s+t[n*(e+l)],c=u+t[n*(e+l)+1],i=(o-s)*(c+u);s=o,u=c,r+=i}return.5*r}function Gt(t,e){const{coords:o,lengths:n}=t;let r=0,s=0;for(let u=0;u<n.length;u++){const t=n[u];s+=Nt(o,r,t,e),r+=t}return Math.abs(s)}function Tt(t,e,o,n){return 0===t*n-o*e&&t*o+e*n>0}function Ft(t,e,o,n,r){const s=d(n,r);if(!t.lengths.length){if(t.coords.length<2)return null;const[o,n]=t.coords,r=G(e,o),s=T(e,n);return new h([],[r,s])}const u=new h([],[0,0]),l=g[o],c="esriGeometryPolygon"===o||"esriGeometryPolyline"===o;let i=0,f=0;for(let a=0;a<t.lengths.length;a++){const o=t.lengths[a],n=f;let r=G(e,t.coords[s*i]),h=T(e,t.coords[s*i+1]);u.coords[f++]=r,u.coords[f++]=h;let d=0,m=0,g=1;for(let l=1;l<o;l++){const o=G(e,t.coords[s*(l+i)]),n=T(e,t.coords[s*(l+i)+1]);if(o!==r||n!==h){const t=o-r,e=n-h;c&&Tt(d,m,t,e)?(u.coords[f-2]+=t,u.coords[f-1]+=e,r+=t,h+=e):(u.coords[f++]=o,u.coords[f++]=n,r=o,h=n,d=t,m=e,g+=1)}}g<l?f=n:u.lengths.push(g),i+=o}return 0===u.lengths.length?null:u}function Pt(t,e=0,o=0){xt(t.lengths,o),xt(t.coords,e)}function xt(t,e=0){t.length!==e&&(t.length=e)}const jt={originPosition:"lowerLeft",scale:[1,1,1,1],translate:[0,0,0,0]};export{ot as convertFromFeature,ft as convertFromFeatureSet,nt as convertFromFeatures,st as convertFromGeometry,$ as convertFromMultipoint,A as convertFromMultipointFeatures,X as convertFromNestedArray,U as convertFromPoint,S as convertFromPointFeatures,W as convertFromPolygon,H as convertFromPolyline,D as convertFromPolylineFeatures,rt as convertToFeature,it as convertToFeatureSet,ct as convertToFeatures,ut as convertToGeometry,R as convertToMultipoint,q as convertToMultipointFeatures,j as convertToPoint,K as convertToPolygon,C as convertToPolyline,mt as generalizeOptimizedGeometry,pt as getBoundsOptimizedGeometry,Gt as getQuantizedArea,It as getQuantizedBoundsOptimizedGeometry,Nt as getSignedQuantizedRingArea,Ft as quantizeForDisplay,ht as quantizeOptimizedFeatureSet,dt as quantizeOptimizedGeometry,w as quantizeX,N as quantizeY,wt as removeCollinearVertices,bt as removeZMValues,at as unquantizeOptimizedFeatureSet,Mt as unquantizeOptimizedGeometry,x as unquantizeValue,F as unquantizeX,P as unquantizeY};
|
|
5
|
+
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{assertIsSome as n}from"../../core/maybe.js";import{is as o,fromRectValues as r}from"../../geometry/support/aaBoundingBox.js";import{fromValues as s}from"../../geometry/support/aaBoundingRect.js";import{isPoint as u,isPolygon as l,isPolyline as c,isMultipoint as i}from"../../geometry/support/jsonUtils.js";import{OptimizedFeature as f}from"./OptimizedFeature.js";import a from"./OptimizedFeatureSet.js";import h from"./OptimizedGeometry.js";function d(t,e){return t?e?4:3:e?3:2}const m=()=>e.getLogger("esri.layers.graphics.featureConversionUtils"),g={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0,esriGeometryMultiPatch:3,esriGeometryEnvelope:0},y=(t,e,n,o,r,s)=>{t[n]=r,t[n+1]=s},p=(t,e,n,o,r,s)=>{t[n]=r,t[n+1]=s,t[n+2]=e[o+2]},I=(t,e,n,o,r,s)=>{t[n]=r,t[n+1]=s,t[n+2]=e[o+3]},M=(t,e,n,o,r,s)=>{t[n]=r,t[n+1]=s,t[n+2]=e[o+2],t[n+3]=e[o+3]};function b(t,e,n,o){if(t){if(n)return e&&o?M:p;if(e&&o)return I}else if(e&&o)return p;return y}function w({scale:t,translate:e},n){return Math.round((n-e[0])/t[0])}function N({scale:t,translate:e},n){return Math.round((e[1]-n)/t[1])}function G({scale:t,translate:e},n){return Math.round((n-e[0])/t[0])}function T({scale:t,translate:e},n){return Math.round((n-e[1])/t[1])}function F(t,e){return x(t,e,0)}function P(t,e){return x(t,-e,1)}function x({scale:t,translate:e},n,o){return n*t[o]+e[o]}function j(t,e,n){return t?e?n?Y(t):v(t):n?k(t):Z(t):null}function Z(t){const e=t.coords;return{x:e[0],y:e[1]}}function E(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t}function v(t){const e=t.coords;return{x:e[0],y:e[1],z:e[2]}}function z(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.z,t}function k(t){const e=t.coords;return{x:e[0],y:e[1],m:e[2]}}function V(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.m,t}function Y(t){const e=t.coords;return{x:e[0],y:e[1],z:e[2],m:e[3]}}function _(t,e){return t.coords[0]=e.x,t.coords[1]=e.y,t.coords[2]=e.z,t.coords[3]=e.m,t}function L(t,e,n,o){let r=Z;n&&o?r=Y:n?r=v:o&&(r=k);for(const s of e){const{geometry:e,attributes:n}=s,o=null!=e?r(e):null;t.push({attributes:n,geometry:o})}return t}function O(t,e){return t&&e?_:t?z:e?V:E}function S(t,e,n,o,r){const s=O(n,o);for(const{geometry:u,attributes:l}of e){const e=null!=u?s(new h,u):null;t.push(new f(e,l,null,r?l[r]:void 0))}return t}function U(t,e,n=O(null!=e.z,null!=e.m)){return n(t,e)}function q(t,e,n,o){for(const{geometry:r,attributes:s}of e)t.push({attributes:s,geometry:null!=r?R(r,n,o):null});return t}function R(t,e,n){if(null==t)return null;const o=d(e,n),r=[];for(let s=0;s<t.coords.length;s+=o){const e=[];for(let n=0;n<o;n++)e.push(t.coords[s+n]);r.push(e)}return e?n?{points:r,hasZ:e,hasM:n}:{points:r,hasZ:e}:n?{points:r,hasM:n}:{points:r}}function A(t,e,n,o,r){const s=d(n,o);for(const{geometry:u,attributes:l}of e){const e=null!=u?$(new h,u,s):null;t.push(new f(e,l,null,r?l[r]:void 0))}return t}function $(t,e,n=d(e.hasZ,e.hasM)){t.lengths[0]=e.points.length;const o=t.coords;let r=0;for(const s of e.points)for(let t=0;t<n;t++)o[r++]=s[t];return t}function B(t,e,n,o){for(const{geometry:r,attributes:s}of e)t.push({attributes:s,geometry:null!=r?C(r,n,o):null});return t}function C(t,e,n){if(!t)return null;const o=d(e,n),{coords:r,lengths:s}=t,u=[];let l=0;for(const c of s){const t=[];for(let e=0;e<c;e++){const e=[];for(let t=0;t<o;t++)e.push(r[l++]);t.push(e)}u.push(t)}return e?n?{paths:u,hasZ:e,hasM:n}:{paths:u,hasZ:e}:n?{paths:u,hasM:n}:{paths:u}}function D(t,e,n,o,r){const s=d(n,o);for(const{geometry:u,attributes:l,centroid:c}of e){const e=null!=u?H(new h,u,s):null,n=null!=c?U(new h,c):null;t.push(new f(e,l,n,r?l[r]:void 0))}return t}function H(t,e,n=d(e.hasZ,e.hasM)){const{lengths:o,coords:r}=t;let s=0;for(const u of e.paths){for(const t of u)for(let e=0;e<n;e++)r[s++]=t[e];o.push(u.length)}return t}function J(t,e,n,o){for(const{geometry:r,attributes:s,centroid:u}of e){const e=null!=r?K(r,n,o):null;if(null!=u){const n=Z(u);t.push({attributes:s,centroid:n,geometry:e})}else t.push({attributes:s,geometry:e})}return t}function K(t,e,n){if(!t)return null;const o=d(e,n),{coords:r,lengths:s}=t,u=[];let l=0;for(const c of s){const t=[];for(let e=0;e<c;e++){const e=[];for(let t=0;t<o;t++)e.push(r[l++]);t.push(e)}u.push(t)}return e?n?{rings:u,hasZ:e,hasM:n}:{rings:u,hasZ:e}:n?{rings:u,hasM:n}:{rings:u}}function Q(t,e,n,o,r){for(const{geometry:s,centroid:u,attributes:l}of e){const e=null!=s?W(new h,s,n,o):null,c=r?l[r]:void 0;null!=u?t.push(new f(e,l,E(new h,u),c)):t.push(new f(e,l,null,c))}return t}function W(t,e,n=e.hasZ,o=e.hasM){return X(t,e.rings,n,o)}function X(t,e,n,o){const r=d(n,o),{lengths:s,coords:u}=t;let l=0;Pt(t);for(const c of e){for(const t of c)for(let e=0;e<r;e++)u[l++]=t[e];s.push(c.length)}return t}const tt=[],et=[];function nt(t,e,n,o,r){tt[0]=t;const[s]=ot(et,tt,e,n,o,r);return xt(tt),xt(et),s}function ot(e,n,o,r,s,u){if(xt(e),!o){for(const t of n){const n=u?t.attributes[u]:void 0;e.push(new f(null,t.attributes,null,n))}return e}switch(o){case"esriGeometryPoint":return S(e,n,r,s,u);case"esriGeometryMultipoint":return A(e,n,r,s,u);case"esriGeometryPolyline":return D(e,n,r,s,u);case"esriGeometryPolygon":case"esriGeometryMultiPatch":return Q(e,n,r,s,u);default:m().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${o}'`)),xt(e)}return e}function rt(t,e,n,o){et[0]=t,ct(tt,et,e,n,o);const r=tt[0];return xt(tt),xt(et),r}function st(e,n,o){if(null==e)return null;const r=new h;if("hasZ"in e&&null==n&&(n=e.hasZ),"hasM"in e&&null==o&&(o=e.hasM),u(e)){return O(null!=n?n:null!=e.z,null!=o?o:null!=e.m)(r,e)}return l(e)?W(r,e,n,o):c(e)?H(r,e,d(n,o)):i(e)?$(r,e,d(n,o)):void m().error("convertFromGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${e}'`))}function ut(e,n,o,r){const s=e&&("coords"in e?e:e.geometry);if(null==s)return null;switch(n){case"esriGeometryPoint":{let t=Z;return o&&r?t=Y:o?t=v:r&&(t=k),t(s)}case"esriGeometryMultipoint":return R(s,o,r);case"esriGeometryPolyline":return C(s,o,r);case"esriGeometryPolygon":return K(s,o,r);default:return m().error("convertToGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${n}'`)),null}}function lt(t,e){for(const n of e)t.push({attributes:n.attributes});return t}function ct(e,n,o,r,s){if(xt(e),null==o)return lt(e,n);switch(o){case"esriGeometryPoint":return L(e,n,r,s);case"esriGeometryMultipoint":return q(e,n,r,s);case"esriGeometryPolyline":return B(e,n,r,s);case"esriGeometryPolygon":return J(e,n,r,s);default:m().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${o}'`))}return e}function it(t){const{objectIdFieldName:e,spatialReference:n,transform:o,fields:r,hasM:s,hasZ:u,features:l,geometryType:c,exceededTransferLimit:i,uniqueIdField:f,queryGeometry:a,queryGeometryType:h}=t,d={features:ct([],l,c,u,s),fields:r,geometryType:c,objectIdFieldName:e,spatialReference:n,uniqueIdField:f,queryGeometry:ut(a,h,!1,!1)};return o&&(d.transform=o),i&&(d.exceededTransferLimit=i),s&&(d.hasM=s),u&&(d.hasZ=u),d}function ft(e,n){const o=new a,{hasM:r,hasZ:s,features:u,objectIdFieldName:l,spatialReference:c,geometryType:i,exceededTransferLimit:f,transform:h,fields:d}=e;return d&&(o.fields=d),o.geometryType=i??null,o.objectIdFieldName=l??n??null,o.spatialReference=c??null,o.objectIdFieldName?(u&&ot(o.features,u,i,s,r,o.objectIdFieldName),f&&(o.exceededTransferLimit=f),r&&(o.hasM=r),s&&(o.hasZ=s),h&&(o.transform=h),o):(m().error(new t("optimized-features:invalid-objectIdFieldName","objectIdFieldName is missing")),o)}function at(t){const{transform:e,features:n,hasM:o,hasZ:r}=t;if(!e)return t;for(const s of n)null!=s.geometry&&Mt(s.geometry,s.geometry,o,r,e),null!=s.centroid&&Mt(s.centroid,s.centroid,o,r,e);return t.transform=null,t}function ht(t,e){const{geometryType:n,features:o,hasM:r,hasZ:s}=e;if(!t)return e;for(let u=0;u<o.length;u++){const e=o[u],l=e.weakClone();l.geometry=new h,dt(l.geometry,e.geometry,r,s,n,t),e.centroid&&(l.centroid=new h,dt(l.centroid,e.centroid,r,s,"esriGeometryPoint",t)),o[u]=l}return e.transform=t,e}function dt(t,e,n,o,r,s,u=n,l=o){if(Pt(t),!e?.coords.length)return null;const c=g[r],{coords:i,lengths:f}=e,a=d(n,o),h=d(n&&u,o&&l),m=b(n,o,u,l);if(!f.length)return m(t.coords,i,0,0,w(s,i[0]),N(s,i[1])),Pt(t,a,0),t;let y,p,I,M,G=0,T=0,F=T;for(const d of f){if(d<c)continue;let e=0;T=F,I=y=w(s,i[G]),M=p=N(s,i[G+1]),m(t.coords,i,T,G,I,M),e++,G+=a,T+=h;for(let n=1;n<d;n++,G+=a)I=w(s,i[G]),M=N(s,i[G+1]),I===y&&M===p||(m(t.coords,i,T,G,I-y,M-p),T+=h,e++,y=I,p=M);e>=c&&(t.lengths.push(e),F=T)}return xt(t.coords,F),t.coords.length?t:null}function mt(t,e,n,o,r,s,u=n,l=o){if(Pt(t),!e?.coords.length)return null;const c=g[r],{coords:i,lengths:f}=e,a=d(n,o),h=d(n&&u,o&&l),m=b(n,o,u,l);if(!f.length)return m(t.coords,i,0,0,i[0],i[1]),Pt(t,a,0),t;let y=0;const p=s*s;for(const d of f){if(d<c){y+=d*a;continue}const e=t.coords.length/h,n=y,o=y+(d-1)*a;m(t.coords,i,t.coords.length,n,i[n],i[n+1]),yt(t.coords,i,a,p,m,n,o),m(t.coords,i,t.coords.length,o,i[o],i[o+1]);const r=t.coords.length/h-e;r>=c?t.lengths.push(r):xt(t.coords,e*h),y+=d*a}return t.coords.length?t:null}function gt(t,e,n,o){const r=t[e],s=t[e+1],u=t[n],l=t[n+1],c=t[o],i=t[o+1];let f=u,a=l,h=c-f,d=i-a;if(0!==h||0!==d){const t=((r-f)*h+(s-a)*d)/(h*h+d*d);t>1?(f=c,a=i):t>0&&(f+=h*t,a+=d*t)}return h=r-f,d=s-a,h*h+d*d}function yt(t,e,n,o,r,s,u){let l,c=o,i=0;for(let f=s+n;f<u;f+=n)l=gt(e,f,s,u),l>c&&(i=f,c=l);c>o&&(i-s>n&&yt(t,e,n,o,r,s,i),r(t,e,t.length,i,e[i],e[i+1]),u-i>n&&yt(t,e,n,o,r,i,u))}function pt(t,e,n,u){if(!e?.coords?.length)return null;const l=d(n,u);let c=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;if(e&&e.coords){const t=e.coords;for(let e=0;e<t.length;e+=l){const n=t[e],o=t[e+1];c=Math.min(c,n),f=Math.max(f,n),i=Math.min(i,o),a=Math.max(a,o)}}return o(t)?r(t,c,i,f,a):s(c,i,f,a,t),t}function It(t,e,n,o){const r=d(n,o),{lengths:s,coords:u}=e;let l=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY,a=0;for(const h of s){let t=u[a],e=u[a+1];l=Math.min(t,l),c=Math.min(e,c),i=Math.max(t,i),f=Math.max(e,f),a+=r;for(let n=1;n<h;n++,a+=r){const n=u[a],o=u[a+1];t+=n,e+=o,n<0&&(l=Math.min(l,t)),n>0&&(i=Math.max(i,t)),o<0?c=Math.min(c,e):o>0&&(f=Math.max(f,e))}}return t[0]=l,t[1]=c,t[2]=i,t[3]=f,t}function Mt(t,e,o,r,s){const{coords:u,lengths:l}=e,c=d(o,r);if(!u.length)return t!==e&&Pt(t),t;n(s);const{originPosition:i,scale:f,translate:a}=s,h=jt;h.originPosition=i;const m=h.scale;m[0]=f[0]??1,m[1]=-(f[1]??1),m[2]=f[2]??1,m[3]=f[3]??1;const g=h.translate;if(g[0]=a[0]??0,g[1]=a[1]??0,g[2]=a[2]??0,g[3]=a[3]??0,!l.length){for(let e=0;e<c;++e)t.coords[e]=x(h,u[e],e);return t!==e&&Pt(t,c,0),t}let y=0;for(let n=0;n<l.length;n++){const e=l[n];t.lengths[n]=e;for(let n=0;n<c;++n)t.coords[y+n]=x(h,u[y+n],n);let o=t.coords[y],r=t.coords[y+1];y+=c;for(let n=1;n<e;n++,y+=c){o+=u[y]*m[0],r+=u[y+1]*m[1],t.coords[y]=o,t.coords[y+1]=r;for(let e=2;e<c;++e)t.coords[y+e]=x(h,u[y+e],e)}}return t!==e&&Pt(t,u.length,l.length),t}function bt(t,e,n,o,r,s){if(Pt(t),t.lengths.push(...e.lengths),n===r&&o===s)for(let u=0;u<e.coords.length;u++)t.coords.push(e.coords[u]);else{const u=d(n,o),l=b(n,o,r,s),c=e.coords;for(let e=0;e<c.length;e+=u)l(t.coords,c,t.coords.length,e,c[e],c[e+1])}return t}function wt(t,e,n,o,r){if(!e?.coords?.length)return null;const s=g[n],{coords:u,lengths:l}=e,c=b(o,r,o,r),i=d(o,r);let f=0,a=0,h=0,m=0;for(const d of l){a=m,c(t.coords,u,a,f,u[f],u[f+1]),f+=i;let e=u[f],n=u[f+1],o=e,r=n,l=n/e;a+=i,c(t.coords,u,a,f,o,r),f+=i;for(let s=2;s<d;s++){e=u[f],n=u[f+1];const s=n/e,h=l===s||!isFinite(l)&&!isFinite(s),d=h&&isFinite(s)?l>=0&&s>=0||l<=0&&s<=0:r>=0&&n>=0||r<=0&&n<=0;h&&d?(o+=e,r+=n):(o=e,r=n,a+=i),c(t.coords,u,a,f,o,r),f+=i,l=s}a+=i;const g=(a-m)/i;g>=s&&(t.lengths[h]=g,m=a,h++)}return t.coords.length>m&&(t.coords.length=m),t.lengths.length>h&&(t.lengths.length=h),t.coords.length&&t.lengths.length?t:null}function Nt(t,e,n,o){let r=0,s=t[o*e],u=t[o*(e+1)];for(let l=1;l<n;l++){const n=s+t[o*(e+l)],c=u+t[o*(e+l)+1],i=(n-s)*(c+u);s=n,u=c,r+=i}return.5*r}function Gt(t,e){const{coords:n,lengths:o}=t;let r=0,s=0;for(let u=0;u<o.length;u++){const t=o[u];s+=Nt(n,r,t,e),r+=t}return Math.abs(s)}function Tt(t,e,n,o){return 0===t*o-n*e&&t*n+e*o>0}function Ft(t,e,n,o,r){const s=d(o,r);if(!t.lengths.length){if(t.coords.length<2)return null;const[n,o]=t.coords,r=G(e,n),s=T(e,o);return new h([],[r,s])}const u=new h([],[0,0]),l=g[n],c="esriGeometryPolygon"===n||"esriGeometryPolyline"===n;let i=0,f=0;for(let a=0;a<t.lengths.length;a++){const n=t.lengths[a],o=f;let r=G(e,t.coords[s*i]),h=T(e,t.coords[s*i+1]);u.coords[f++]=r,u.coords[f++]=h;let d=0,m=0,g=1;for(let l=1;l<n;l++){const n=G(e,t.coords[s*(l+i)]),o=T(e,t.coords[s*(l+i)+1]);if(n!==r||o!==h){const t=n-r,e=o-h;c&&Tt(d,m,t,e)?(u.coords[f-2]+=t,u.coords[f-1]+=e,r+=t,h+=e):(u.coords[f++]=n,u.coords[f++]=o,r=n,h=o,d=t,m=e,g+=1)}}g<l?f=o:u.lengths.push(g),i+=n}return 0===u.lengths.length?null:u}function Pt(t,e=0,n=0){xt(t.lengths,n),xt(t.coords,e)}function xt(t,e=0){t.length!==e&&(t.length=e)}const jt={originPosition:"lowerLeft",scale:[1,1,1,1],translate:[0,0,0,0]};export{nt as convertFromFeature,ft as convertFromFeatureSet,ot as convertFromFeatures,st as convertFromGeometry,$ as convertFromMultipoint,A as convertFromMultipointFeatures,X as convertFromNestedArray,U as convertFromPoint,S as convertFromPointFeatures,W as convertFromPolygon,H as convertFromPolyline,D as convertFromPolylineFeatures,rt as convertToFeature,it as convertToFeatureSet,ct as convertToFeatures,ut as convertToGeometry,R as convertToMultipoint,q as convertToMultipointFeatures,j as convertToPoint,K as convertToPolygon,C as convertToPolyline,mt as generalizeOptimizedGeometry,pt as getBoundsOptimizedGeometry,Gt as getQuantizedArea,It as getQuantizedBoundsOptimizedGeometry,Nt as getSignedQuantizedRingArea,Ft as quantizeForDisplay,ht as quantizeOptimizedFeatureSet,dt as quantizeOptimizedGeometry,w as quantizeX,N as quantizeY,wt as removeCollinearVertices,bt as removeZMValues,at as unquantizeOptimizedFeatureSet,Mt as unquantizeOptimizedGeometry,x as unquantizeValue,F as unquantizeX,P as unquantizeY};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import has from"../../../core/has.js";import r from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import{debounce as s}from"../../../core/promiseUtils.js";import{open as i}from"../../../core/workers/workers.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/RandomLCG.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import u from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as c}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import h from"../../../rest/support/FeatureSet.js";let p=class extends r{constructor(){super(...arguments),this.type="geojson",this.refresh=s((async e=>{await this.load();const{extent:t,timeExtent:r}=await this._connection.invoke("refresh",e);return this.sourceJSON.extent=t,r&&(this.sourceJSON.timeInfo.timeExtent=[r.start,r.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}}))}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then((()=>this._applyEdits(e)))}openPorts(){return this.load().then((()=>this._connection.openPorts()))}queryFeatures(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatures",e?e.toJSON():null,t))).then((e=>h.fromJSON(e)))}queryFeaturesJSON(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatures",e?e.toJSON():null,t)))}queryFeatureCount(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatureCount",e?e.toJSON():null,t)))}queryObjectIds(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryObjectIds",e?e.toJSON():null,t)))}queryExtent(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryExtent",e?e.toJSON():null,t))).then((e=>({count:e.count,extent:u.fromJSON(e.extent)})))}querySnapping(e,t={}){return this.load(t).then((()=>this._connection.invoke("querySnapping",e,t)))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke("queryAttributeBins",e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t("geojson-layer-source:edit-failure","Memory source not loaded");const r=this.layer.objectIdField,o=[],s=[],i=[];if(e.addFeatures)for(const t of e.addFeatures)o.push(this._serializeFeature(t));if(e.deleteFeatures)for(const t of e.deleteFeatures)"objectId"in t&&null!=t.objectId?s.push(t.objectId):"attributes"in t&&null!=t.attributes[r]&&s.push(t.attributes[r]);if(e.updateFeatures)for(const t of e.updateFeatures)i.push(this._serializeFeature(t));return this._connection.invoke("applyEdits",{adds:o,updates:i,deletes:s}).then((({extent:e,timeExtent:t,featureEditResults:r})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(r))))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){const r=!0===e.success?null:e.error||{code:void 0,description:
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import has from"../../../core/has.js";import r from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import{debounce as s}from"../../../core/promiseUtils.js";import{open as i}from"../../../core/workers/workers.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/RandomLCG.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import u from"../../../geometry/Extent.js";import l from"../../../geometry/Polygon.js";import{featureGeometryTypeKebabDictionary as c}from"../../../geometry/support/typeUtils.js";import{createCapabilities as d}from"./support/clientSideDefaults.js";import h from"../../../rest/support/FeatureSet.js";let p=class extends r{constructor(){super(...arguments),this.type="geojson",this.refresh=s((async e=>{await this.load();const{extent:t,timeExtent:r}=await this._connection.invoke("refresh",e);return this.sourceJSON.extent=t,r&&(this.sourceJSON.timeInfo.timeExtent=[r.start,r.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}}))}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}applyEdits(e){return this.load().then((()=>this._applyEdits(e)))}openPorts(){return this.load().then((()=>this._connection.openPorts()))}queryFeatures(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatures",e?e.toJSON():null,t))).then((e=>h.fromJSON(e)))}queryFeaturesJSON(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatures",e?e.toJSON():null,t)))}queryFeatureCount(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatureCount",e?e.toJSON():null,t)))}queryObjectIds(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryObjectIds",e?e.toJSON():null,t)))}queryExtent(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryExtent",e?e.toJSON():null,t))).then((e=>({count:e.count,extent:u.fromJSON(e.extent)})))}querySnapping(e,t={}){return this.load(t).then((()=>this._connection.invoke("querySnapping",e,t)))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke("queryAttributeBins",e?.toJSON(),t)}_applyEdits(e){if(!this._connection)throw new t("geojson-layer-source:edit-failure","Memory source not loaded");const r=this.layer.objectIdField,o=[],s=[],i=[];if(e.addFeatures)for(const t of e.addFeatures)o.push(this._serializeFeature(t));if(e.deleteFeatures)for(const t of e.deleteFeatures)"objectId"in t&&null!=t.objectId?s.push(t.objectId):"attributes"in t&&null!=t.attributes[r]&&s.push(t.attributes[r]);if(e.updateFeatures)for(const t of e.updateFeatures)i.push(this._serializeFeature(t));return this._connection.invoke("applyEdits",{adds:o,updates:i,deletes:s}).then((({extent:e,timeExtent:t,featureEditResults:r})=>(this.sourceJSON.extent=e,t&&(this.sourceJSON.timeInfo.timeExtent=[t.start,t.end]),this._createEditsResult(r))))}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){const r=!0===e.success?null:e.error||{code:void 0,description:""};return{objectId:e.objectId,globalId:e.globalId,error:r?new t("geojson-layer-source:edit-failure",r.description,{code:r.code}):null}}_serializeFeature(e){const{attributes:t}=e,r=this._geometryForSerialization(e);return r?{geometry:r.toJSON(),attributes:t}:{attributes:t}}_geometryForSerialization(e){const{geometry:t}=e;return null==t?null:"mesh"===t.type||"extent"===t.type?l.fromExtent(t.extent):t}async _startWorker(e){this._connection=await i("GeoJSONSourceWorker",{strategy:has("feature-layers-workers")?"dedicated":"local",signal:e,registryTarget:this});const{fields:t,spatialReference:r,hasZ:s,geometryType:n,objectIdField:a,url:u,timeInfo:l,customParameters:h}=this.layer,p="defaults"===this.layer.originOf("spatialReference"),m={url:u,customParameters:h,fields:t&&t.map((e=>e.toJSON())),geometryType:c.toJSON(n),hasZ:s,objectIdField:a,timeInfo:l?l.toJSON():null,spatialReference:p?null:r&&r.toJSON()},y=await this._connection.invoke("load",m,{signal:e});for(const i of y.warnings)o.getLogger(this.layer).warn("#load()",`${i.message} (title: '${this.layer.title||"no title"}', id: '${this.layer.id??"no id"}')`,{warning:i});y.featureErrors.length&&o.getLogger(this.layer).warn("#load()",`Encountered ${y.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||"no title"}', id: '${this.layer.id??"no id"}')`,{errors:y.featureErrors}),this.sourceJSON=y.layerDefinition,this.capabilities=d(this.sourceJSON.hasZ,!0)}};e([n()],p.prototype,"capabilities",void 0),e([n()],p.prototype,"type",void 0),e([n({constructOnly:!0})],p.prototype,"layer",void 0),e([n()],p.prototype,"sourceJSON",void 0),p=e([a("esri.layers.graphics.sources.GeoJSONSource")],p);export{p as GeoJSONSource};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import r from"../../../core/Collection.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import s from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import n from"../../../core/Promise.js";import{open as a}from"../../../core/workers/workers.js";import{property as l}from"../../../core/accessorSupport/decorators/property.js";import{ensureType as u}from"../../../core/accessorSupport/ensureType.js";import"../../../core/RandomLCG.js";import{shared as p}from"../../../core/accessorSupport/decorators/shared.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import d from"../../../geometry/Extent.js";import h from"../../../geometry/Polygon.js";import{typeKebabDictionary as y}from"../../../geometry/support/typeUtils.js";import{unapplyEditsZUnitScaling as m}from"../../../rest/query/operations/editsZScale.js";import{applyFeatureSetZUnitScaling as f}from"../../../rest/query/operations/queryZScale.js";import g from"../../../rest/support/FeatureSet.js";let _=0,T=class extends(s.LoadableMixin(n.EsriPromiseMixin(r))){constructor(e){super(e),this._idToClientGraphic=null,this.type="memory"}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}get _workerGeometryType(){const e=this.layer?.geometryType;return e?this._geometryTypeRequiresClientGraphicMapping(e)?"polygon":e:null}applyEdits(e){return this.load().then((()=>this._applyEdits(e)))}openPorts(){return this.load().then((()=>this._connection.openPorts()))}async queryFeatures(e,t={}){await this.load(t);const r=await this._connection.invoke("queryFeatures",e?e.toJSON():null,t);f(e,this.layer.spatialReference,r);const i=g.fromJSON(r);if(!this._requiresClientGraphicMapping())return i;const s=this.layer.objectIdField;for(const o of i.features){const e=o.attributes[s],t=this._idToClientGraphic.get(e);t&&(o.geometry=t.geometry)}return i.geometryType=this.layer.geometryType,i}async queryFeaturesJSON(e,t={}){if(this._requiresClientGraphicMapping())throw new i("query-features-json:unsupported","Cannot query in JSON format for client only geometry types (mesh and extent)");await this.load(t);const r=await this._connection.invoke("queryFeatures",e?e.toJSON():null,t);return f(e,this.layer.spatialReference,r),r}queryFeatureCount(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatureCount",e?e.toJSON():null,t)))}queryObjectIds(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryObjectIds",e?e.toJSON():null,t)))}queryExtent(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryExtent",e?e.toJSON():null,t))).then((e=>({count:e.count,extent:d.fromJSON(e.extent)})))}querySnapping(e,t={}){return this.load(t).then((()=>this._connection.invoke("querySnapping",e,t)))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke("queryAttributeBins",e?.toJSON(),t)}async _applyEdits(e){if(!this._connection)throw new i("feature-layer-source:edit-failure","Memory source not loaded");const t=this.layer.objectIdField;let r=null;const s=[],o=[];await Promise.all([this._prepareClientMapping(e.addFeatures,null),this._prepareClientMapping(e.updateFeatures,null)]);const n=e=>"objectId"in e&&null!=e.objectId?e.objectId:"attributes"in e&&null!=e.attributes[t]?e.attributes[t]:null;if(e.addFeatures&&(r=this._prepareAddFeatures(e.addFeatures)),e.deleteFeatures)for(const i of e.deleteFeatures){const e=n(i);null!=e&&s.push(e)}const a=e.updateFeatures&&this._idToClientGraphic?new Map:null;if(e.updateFeatures)for(const i of e.updateFeatures)if(o.push(this._serializeFeature(i)),a){const e=n(i);null!=e&&a.set(e,i)}m(r?r.features:null,o,this.layer.spatialReference);const{fullExtent:l,featureEditResults:u}=await this._connection.invoke("applyEdits",{adds:r?r.features:[],updates:o,deletes:s});return this.fullExtent=l,r&&r.finish(u.uidToObjectId),this._updateClientGraphicIds(a,u),this._createEditsResult(u)}async _prepareClientMapping(e,t){if("mesh"!==this._layerOrSourceGeometryType||null==e)return;const r=[];for(const{geometry:i}of e)null==i||"mesh"!==i.type||i.hasExtent||i.loaded||r.push(i.load({signal:t}));r.length&&await Promise.all(r)}_updateClientGraphicIds(e,t){if(this._idToClientGraphic){if(e)for(const r of t.updateResults){if(!r.success)continue;const t=e.get(r.objectId);null!=t&&this._addIdToClientGraphic(t)}for(const e of t.deleteResults)e.success&&this._idToClientGraphic.delete(e.objectId)}}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){const t=!0===e.success?null:e.error||{code:void 0,description:
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import r from"../../../core/Collection.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import s from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import n from"../../../core/Promise.js";import{open as a}from"../../../core/workers/workers.js";import{property as l}from"../../../core/accessorSupport/decorators/property.js";import{ensureType as u}from"../../../core/accessorSupport/ensureType.js";import"../../../core/RandomLCG.js";import{shared as p}from"../../../core/accessorSupport/decorators/shared.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import d from"../../../geometry/Extent.js";import h from"../../../geometry/Polygon.js";import{typeKebabDictionary as y}from"../../../geometry/support/typeUtils.js";import{unapplyEditsZUnitScaling as m}from"../../../rest/query/operations/editsZScale.js";import{applyFeatureSetZUnitScaling as f}from"../../../rest/query/operations/queryZScale.js";import g from"../../../rest/support/FeatureSet.js";let _=0,T=class extends(s.LoadableMixin(n.EsriPromiseMixin(r))){constructor(e){super(e),this._idToClientGraphic=null,this.type="memory"}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._startWorker(t)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}get _workerGeometryType(){const e=this.layer?.geometryType;return e?this._geometryTypeRequiresClientGraphicMapping(e)?"polygon":e:null}applyEdits(e){return this.load().then((()=>this._applyEdits(e)))}openPorts(){return this.load().then((()=>this._connection.openPorts()))}async queryFeatures(e,t={}){await this.load(t);const r=await this._connection.invoke("queryFeatures",e?e.toJSON():null,t);f(e,this.layer.spatialReference,r);const i=g.fromJSON(r);if(!this._requiresClientGraphicMapping())return i;const s=this.layer.objectIdField;for(const o of i.features){const e=o.attributes[s],t=this._idToClientGraphic.get(e);t&&(o.geometry=t.geometry)}return i.geometryType=this.layer.geometryType,i}async queryFeaturesJSON(e,t={}){if(this._requiresClientGraphicMapping())throw new i("query-features-json:unsupported","Cannot query in JSON format for client only geometry types (mesh and extent)");await this.load(t);const r=await this._connection.invoke("queryFeatures",e?e.toJSON():null,t);return f(e,this.layer.spatialReference,r),r}queryFeatureCount(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryFeatureCount",e?e.toJSON():null,t)))}queryObjectIds(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryObjectIds",e?e.toJSON():null,t)))}queryExtent(e,t={}){return this.load(t).then((()=>this._connection.invoke("queryExtent",e?e.toJSON():null,t))).then((e=>({count:e.count,extent:d.fromJSON(e.extent)})))}querySnapping(e,t={}){return this.load(t).then((()=>this._connection.invoke("querySnapping",e,t)))}async queryAttributeBins(e,t={}){return await this.load(),this._connection.invoke("queryAttributeBins",e?.toJSON(),t)}async _applyEdits(e){if(!this._connection)throw new i("feature-layer-source:edit-failure","Memory source not loaded");const t=this.layer.objectIdField;let r=null;const s=[],o=[];await Promise.all([this._prepareClientMapping(e.addFeatures,null),this._prepareClientMapping(e.updateFeatures,null)]);const n=e=>"objectId"in e&&null!=e.objectId?e.objectId:"attributes"in e&&null!=e.attributes[t]?e.attributes[t]:null;if(e.addFeatures&&(r=this._prepareAddFeatures(e.addFeatures)),e.deleteFeatures)for(const i of e.deleteFeatures){const e=n(i);null!=e&&s.push(e)}const a=e.updateFeatures&&this._idToClientGraphic?new Map:null;if(e.updateFeatures)for(const i of e.updateFeatures)if(o.push(this._serializeFeature(i)),a){const e=n(i);null!=e&&a.set(e,i)}m(r?r.features:null,o,this.layer.spatialReference);const{fullExtent:l,featureEditResults:u}=await this._connection.invoke("applyEdits",{adds:r?r.features:[],updates:o,deletes:s});return this.fullExtent=l,r&&r.finish(u.uidToObjectId),this._updateClientGraphicIds(a,u),this._createEditsResult(u)}async _prepareClientMapping(e,t){if("mesh"!==this._layerOrSourceGeometryType||null==e)return;const r=[];for(const{geometry:i}of e)null==i||"mesh"!==i.type||i.hasExtent||i.loaded||r.push(i.load({signal:t}));r.length&&await Promise.all(r)}_updateClientGraphicIds(e,t){if(this._idToClientGraphic){if(e)for(const r of t.updateResults){if(!r.success)continue;const t=e.get(r.objectId);null!=t&&this._addIdToClientGraphic(t)}for(const e of t.deleteResults)e.success&&this._idToClientGraphic.delete(e.objectId)}}_createEditsResult(e){return{addFeatureResults:e.addResults?e.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:e.updateResults?e.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:e.deleteResults?e.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:[],updateAttachmentResults:[],deleteAttachmentResults:[]}}_createFeatureEditResult(e){const t=!0===e.success?null:e.error||{code:void 0,description:""};return{objectId:e.objectId,globalId:e.globalId,error:t?new i("feature-layer-source:edit-failure",t.description,{code:t.code}):null}}_prepareAddFeatures(e){const t=new Map,r=new Array(e.length);let i=null;for(let o=0;o<e.length;o++){const s=e[o],n=this._serializeFeature(s);i||null==s.geometry||(i=s.geometry.type),r[o]=n,t.set(`${n.uid}`,s)}const s=this;return{features:r,inferredGeometryType:i,finish(e){const r=s.sourceJSON.objectIdField;for(const i in e){const o=e[i],n=t.get(i);n&&(n.attributes||(n.attributes={}),-1===o?delete n.attributes[r]:n.attributes[r]=o,s._addIdToClientGraphic(n))}}}}_addIdToClientGraphic(e){if(!this._idToClientGraphic)return;const t=this.sourceJSON.objectIdField,r=e.attributes?.[t];null!=r&&this._idToClientGraphic.set(r,e)}get _layerOrSourceGeometryType(){return this.layer?.geometryType??this.sourceJSON?.geometryType}_requiresClientGraphicMapping(){return this._geometryTypeRequiresClientGraphicMapping(this._layerOrSourceGeometryType)}_geometryRequiresClientGraphicMapping(e){return this._geometryTypeRequiresClientGraphicMapping(e.type)}_geometryTypeRequiresClientGraphicMapping(e){return"mesh"===e||"multipatch"===e||"extent"===e}_serializeFeature(e){const{attributes:t}=e,r=this._geometryForSerialization(e),i=(_++).toString();return r?{uid:i,geometry:r.toJSON(),attributes:t}:{uid:i,attributes:t}}_geometryForSerialization(e){const{geometry:t}=e;if(null==t)return null;if(this._geometryRequiresClientGraphicMapping(t)){return t.extent?h.fromExtent(t.extent):null}return t}async _startWorker(e){this._connection=await a("MemorySourceWorker",{strategy:has("feature-layers-workers")?"dedicated":"local",signal:e,registryTarget:this});const{fields:t,spatialReference:r,objectIdField:i,hasM:s,hasZ:n,timeInfo:l,dateFieldsTimeZone:u}=this.layer,p="defaults"===this.layer.originOf("spatialReference");await this._prepareClientMapping(this.items,e);const c=this._prepareAddFeatures(this.items);this.addHandles(this.on("before-changes",(e=>{o.getLogger(this).error("Source modifications will not propagate after layer has been loaded. Please use .applyEdits() instead"),e.preventDefault()})));const d={features:c.features,fields:t?.map((e=>e.toJSON())),geometryType:y.toJSON(this._workerGeometryType),hasM:"mesh"!==this._layerOrSourceGeometryType&&s,hasZ:"mesh"===this._layerOrSourceGeometryType||n,objectIdField:i,spatialReference:p?null:r&&r.toJSON(),timeInfo:l?.toJSON()??null,dateFieldsTimeZone:u},h=await this._connection.invoke("load",d,{signal:e});for(const a of h.warnings)o.getLogger(this.layer).warn("#load()",`${a.message} (title: '${this.layer.title||"no title"}', id: '${this.layer.id??"no id"}')`,{warning:a});h.featureErrors.length&&o.getLogger(this.layer).warn("#load()",`Encountered ${h.featureErrors.length} validation errors while loading features. (title: '${this.layer.title||"no title"}', id: '${this.layer.id??"no id"}')`,{errors:h.featureErrors});const m=h.layerDefinition;this._geometryTypeRequiresClientGraphicMapping(c.inferredGeometryType)&&(m.geometryType=y.toJSON(c.inferredGeometryType)),this.sourceJSON=m,this._requiresClientGraphicMapping()&&(this._idToClientGraphic=new Map),c.finish(h.assignedObjectIds)}};e([p({Type:t,ensureType:u(t)})],T.prototype,"itemType",void 0),e([l()],T.prototype,"type",void 0),e([l({constructOnly:!0})],T.prototype,"layer",void 0),e([l({readOnly:!0})],T.prototype,"_workerGeometryType",null),e([l()],T.prototype,"sourceJSON",void 0),T=e([c("esri.layers.graphics.sources.MemorySource")],T);export{T as MemorySource};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../request.js";import r from"../../../../core/Error.js";import
|
|
5
|
+
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../request.js";import r from"../../../../core/Error.js";import o from"../../../../core/Logger.js";import{createResolver as i}from"../../../../core/promiseUtils.js";import{addQueryParameters as s}from"../../../../core/urlUtils.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import a from"../../../../geometry/SpatialReference.js";import{fromJSON as c}from"../../../../geometry/support/jsonUtils.js";import{WebSocketConnection as u}from"./WebSocketConnection.js";import{executeQuery as l}from"../../../../rest/query/operations/query.js";import f from"../../../../rest/support/Query.js";const h=1e4,d={maxQueryDepth:5,maxRecordCountFactor:3};let g=class extends u{constructor(e){super({...d,...e}),this._buddyServicesQuery=null,this._relatedFeatures=null}async _open(){const e=await this._fetchServiceDefinition(this._config.source);e.timeInfo.trackIdField||o.getLogger(this).warn("GeoEvent service was configured without a TrackIdField. This may result in certain functionality being disabled. The purgeOptions.maxObservations property will have no effect.");const t=this._fetchWebSocketUrl(e.streamUrls,this._config.spatialReference);this._buddyServicesQuery||(this._buddyServicesQuery=this._queryBuddyServices()),await this._buddyServicesQuery,await this._tryCreateWebSocket(t);const{filter:r,outFields:i}=this._config;this.destroyed||this._setFilter(r,i)}_onMessage(e){if("attributes"in e){let i;try{i=this._enrich(e),null!=this._featureZScaler&&this._featureZScaler(i.geometry)}catch(t){return void o.getLogger(this).error(new r("geoevent-connection","Failed to parse message",t))}this.onFeature(i)}else this.onMessage(e)}async _fetchServiceDefinition(e){const r={f:"json",...this._config.customParameters},o=t(e.path,{query:r,responseType:"json"}),i=(await o).data;return this._serviceDefinition=i,i}_fetchWebSocketUrl(e,t){const r=e[0],{urls:o,token:i}=r,n=this._inferWebSocketBaseUrl(o);return s(`${n}/subscribe`,{outSR:""+t.wkid,token:i})}_inferWebSocketBaseUrl(e){if(1===e.length)return e[0];for(const t of e)if(t.includes("wss"))return t;return o.getLogger(this).error(new r("geoevent-connection","Unable to infer WebSocket url",e)),null}async _setFilter(e,t){const s=this._websocket;if(null==s||null==e&&null==t)return;const n=JSON.stringify({filter:this._serializeFilter(e,t)});let a=!1;const c=i(),u=()=>{a||(this.destroyed||this._websocket!==s||o.getLogger(this).error(new r("geoevent-connection","Server timed out when setting filter")),c.reject())},l=e=>{const t=JSON.parse(e.data);t.filter&&(t.error&&(o.getLogger(this).error(new r("geoevent-connection","Failed to set service filter",t.error)),this._set("errorString",`Could not set service filter - ${t.error}`),c.reject(t.error)),this._setWebSocketJSONParseHandler(s),a=!0,c.resolve())};return s.onmessage=l,s.send(n),setTimeout(u,h),c.promise}_serializeFilter(e,t){const i={};if(null==e&&null==t)return i;if(e?.geometry)try{const t=c(e.geometry);if("extent"!==t.type)throw new r("geoevent-connection",`Expected extent but found type ${t.type}`);i.geometry=JSON.stringify(t.shiftCentralMeridian())}catch(s){o.getLogger(this).error(new r("geoevent-connection","Encountered an error when setting connection geometryDefinition",s))}return e?.where&&"1 = 1"!==e.where&&"1=1"!==e.where&&(i.where=e.where),null!=t&&(i.outFields=t.join(",")),i}_enrich(e){if(!this._relatedFeatures)return e;const t=this._serviceDefinition.relatedFeatures.joinField,i=e.attributes[t],s=this._relatedFeatures.get(i);if(!s)return o.getLogger(this).warn("geoevent-connection","Feature join failed. Is the join field configured correctly?",e),e;const{attributes:n,geometry:a}=s;for(const r in n)e.attributes[r]=n[r];return a&&(e.geometry=a),e.geometry||e.centroid||o.getLogger(this).error(new r("geoevent-connection","Found malformed feature - no geometry found",e)),e}async _queryBuddyServices(){try{const{relatedFeatures:e,keepLatestArchive:t}=this._serviceDefinition,r=this._queryRelatedFeatures(e),o=this._queryArchive(t);await r;const i=await o;if(!i)return;for(const s of i.features)this.onFeature(this._enrich(s))}catch(e){o.getLogger(this).error(new r("geoevent-connection","Encountered an error when querying buddy services",{error:e}))}}async _queryRelatedFeatures(e){if(!e)return;const t=await this._queryBuddy(e.featuresUrl);this._addRelatedFeatures(t)}async _queryArchive(e){if(e)return this._queryBuddy(e.featuresUrl)}async _queryBuddy(e){const t=new((await import("../../../FeatureLayer.js")).default)({url:e}),{capabilities:r}=await t.load(),o=r.query.supportsMaxRecordCountFactor,i=r.query.supportsPagination,s=r.query.supportsCentroid,n=this._config.maxRecordCountFactor,c=t.capabilities.query.maxRecordCount,u=o?c*n:c,h=new f;if(h.outFields=this._config.outFields??["*"],h.where=this._config.filter?.where??"1=1",h.returnGeometry=!0,h.returnExceededLimitFeatures=!0,h.outSpatialReference=a.fromJSON(this._config.spatialReference),s&&(h.returnCentroid=!0),o&&(h.maxRecordCountFactor=n),i)return h.num=u,t.destroy(),this._queryPages(e,h);const d=await l(e,h,this._config.sourceSpatialReference);return t.destroy(),d.data}async _queryPages(e,t,r=[],o=0){t.start=null!=t.num?o*t.num:null;const{data:i}=await l(e,t,this._config.sourceSpatialReference);return i.exceededTransferLimit&&o<(this._config.maxQueryDepth??0)?(i.features.forEach((e=>r.push(e))),this._queryPages(e,t,r,o+1)):(r.forEach((e=>i.features.push(e))),i)}_addRelatedFeatures(e){const t=new Map,r=e.features,o=this._serviceDefinition.relatedFeatures.joinField;for(const i of r){const e=i.attributes[o];t.set(e,i)}this._relatedFeatures=t}};g=e([n("esri.layers.graphics.sources.connections.GeoEventConnection")],g);const y=g;export{y as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{parseDate as t}from"../../../../core/date.js";import{isValid as e}from"../../../../geometry/support/spatialReferenceUtils.js";import{validateFieldValue as n,validationErrorToString as r,isNumericField as o,isStringField as
|
|
5
|
+
import{parseDate as t}from"../../../../core/date.js";import{isValid as e}from"../../../../geometry/support/spatialReferenceUtils.js";import{validateFieldValue as n,validationErrorToString as r,isNumericField as o,isStringField as s,isDateField as i,sanitizeNullFieldValue as u}from"../../../support/fieldUtils.js";class l{constructor(t){this.description=t,this.code=null}}class a{constructor(t){this.globalId=null,this.objectId=null,this.success=!1,this.uniqueId=null,this.error=new l(t)}}function p(t){return new a(t)}class c{constructor(t){this.globalId=null,this.success=!0,this.objectId=this.uniqueId=t}}function f(t){return new c(t)}const g=new Set;function d(t,e,o,s=!1){g.clear();for(const i in o){const u=t.get(i);if(!u)continue;const l=m(u,o[i]);if(g.add(u.name),u&&(s||u.editable)){const t=n(u,l);if(t)return p(r(t,u,l));e[u.name]=l}}for(const n of t.requiredFields??[])if(!g.has(n.name))return p(`missing required field "${n.name}"`);return null}function m(e,n){let r=n;return o(e)&&"string"==typeof n?r=parseFloat(n):s(e)&&null!=n&&"string"!=typeof n?r=String(n):i(e)&&"string"==typeof n&&(r=t(n)),u(r)}let y;function h(t,n){if(!t||!e(n))return t;if("rings"in t||"paths"in t){if(null==y)throw new TypeError("geometry engine not loaded");return y.simplify(n,t)}return t}async function I(){return null==y&&(y=await import("../../../../geometry/geometryEngineJSON.js")),y}async function E(t,n){!e(t)||"esriGeometryPolygon"!==n&&"esriGeometryPolyline"!==n||await I()}const S={supportsAutoIntervalBin:!0,supportsFixedIntervalBin:!0,supportsFixedBoundariesBin:!0,supportsDateBin:!0,supportsStackBy:!0,supportsSplitBy:!0,supportsNormalization:!0,supportedStatisticTypes:["COUNT","SUM","AVG","VAR","STDDEV","MIN","MAX","PERCENTILE_CONT","PERCENTILE_DISC","CentroidAggregate","EnvelopeAggregate","ConvexHullAggregate"],supportedNormalizationTypes:["field","log","naturalLog","percentOfTotal","squareRoot"]};export{p as createFeatureEditErrorResult,f as createFeatureEditSuccessResult,E as loadGeometryEngineForSimplify,d as mixAttributes,S as queryBinsCapabilities,h as simplify};
|