@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.67 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../request.js";import o from"../core/Error.js";import has from"../core/has.js";import r from"../core/Logger.js";import{MultiOriginJSONSupportMixin as i}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as s}from"../core/promiseUtils.js";import{on as a,sync as n}from"../core/reactiveUtils.js";import{property as l,subclass as p}from"../core/accessorSupport/decorators.js";import{persistable as m}from"../core/accessorSupport/decorators/persistable.js";import c from"../geometry/Extent.js";import d from"../geometry/SpatialReference.js";import u from"./Layer.js";import{APIKeyMixin as h}from"./mixins/APIKeyMixin.js";import{ArcGISService as f}from"./mixins/ArcGISService.js";import{CustomParametersMixin as y}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as g}from"./mixins/OperationalLayer.js";import{PortalLayer as S}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as _}from"./mixins/ScaleRangeLayer.js";import{elevationInfo as v,url as j}from"./support/commonProperties.js";import T from"./support/SceneModifications.js";import{default3DTilesSpatialReference as w,default3DTilesFullExtent as L,initFullExtent as b}from"./support/tiles3DUtils.js";import x from"../portal/Portal.js";import{logInvalidElevationInfoWarning as P,elevationModeRequiredMessage as I,featureExpressionUnsupportedMessage as k}from"../support/elevationInfoUtils.js";import{f as R}from"../chunks/persistableUrlUtils.js";import{isBasemap as D}from"../support/userTypeGuards/isBasemap.js";import{initialize as U,switchMeshModificationPolygonVCSSync as E}from"../views/3d/layers/Lyr3DWorker.js";import{toWasmModification as O,fromWasmModificationInLoad as M}from"../views/3d/layers/SceneLayerWorkerHandle.js";import{reader as q}from"../core/accessorSupport/decorators/reader.js";let A=class extends(f(g(S(_(i(y(h(u)))))))){readModifications(e,t,o){this._modificationsSource={url:R(e,o),context:o}}initialize(){this.addHandles(a(()=>this.modifications,"after-changes",()=>this.modifications=this.modifications,n))}constructor(e){super(e),this.operationalLayerType="IntegratedMesh3DTilesLayer",this.modifications=null,this._modificationsSource=null,this.spatialReference=w,this.fullExtent=L,this.url=null,this.type="integrated-mesh-3dtiles",this.path=null,this.minScale=0,this.maxScale=0,this._rootTilesetJSON=null,this._rootTileset=null,this._key=null,this._session=null,this._rootRequestPromise=null,this.queryElevationCallback=null}set elevationInfo(e){null!=e&&"absolute-height"!==e.mode||this._set("elevationInfo",e),this._validateElevationInfo(e)}async load(e){return this.addResolvingPromise(this._doLoad(e)),this}get rootTilesetJSON(){return this._rootTilesetJSON}get rootTileset(){return this._rootTileset}get key(){return this._key}get session(){return this._session}_findSessionParameter(e){const t=[e];for(;t?.length>0;){const e=t.pop();if(!e)return;for(const[r,i]of Object.entries(e)){if("uri"===r)try{const e=new URL("https://tmp"+i).searchParams.get("session");if(e)return e}catch(o){}"object"==typeof i&&null!==i&&t.push(i)}}return null}async requestRootAndSession(e){const i=(e,t)=>new o("3dtiles-init:"+e,t);return this._rootRequestPromise||(this._rootRequestPromise=new Promise((o,a)=>{this.url||a(i("url-missing","Layer url missing")),this._key=this.customParameters?this.customParameters.key:null;new Promise((e,o)=>{if(this.replacesTerrain&&!this._key){const r=this.portalItem?.portal||this.parent?.portalItem?.portal||x.getDefault();r.signIn().then(()=>{r.g3dTilesEnabled?t(r.restUrl+"/portals/self/modules/g3dtiles",{responseType:"json",query:{f:"json"}}).then(t=>{this._key=t.data.keyString,e()},()=>o(i("g3dtiles-key-error","Error fetching Google 3D Tiles key from portal"))):o(i("g3dTilesEnabled-false","Google 3D Tiles are not enabled on Portal "+r.url))},()=>o(i("sign-in-failed","Error signing in to Portal")))}else e()}).then(()=>{t(this.url,{query:this._key?{key:this._key,token:this.apiKey}:{token:this.apiKey},responseType:"array-buffer",signal:e}).then(e=>{try{this._rootTilesetJSON=JSON.parse((new TextDecoder).decode(e.data))}catch(t){return void a(i("root-parse-failed","Error parsing root tile, details: "+t))}this._rootTilesetJSON?(this._session=this._findSessionParameter(this._rootTilesetJSON),this._rootTileset=e.data,this.fullExtent=b(this._rootTilesetJSON),o(),this._rootRequestPromise=null):a(i("root-is-null","Root tile is null."))},e=>{s(e),a(i("root-load-failed","Error loading root tile")),this._rootRequestPromise=null,r.getLogger("IntegratedMesh3DTilesLayer").error("Layer loading failed",e)})},e=>a(e))})),this._rootRequestPromise}async _doLoad(e){const t=null!=e?e.signal:null;if(this.isUsedAsGroundLayer&&!has("enable-feature:basemap-groundlayers"))throw new o("3dtiles-init:not-supported-in-groundlayers","Layer is not supported in basemap.");try{await this.loadFromPortal({supportedTypes:["3DTiles Service"],validateItem:e=>{if(e.typeKeywords?.includes("IntegratedMesh"))return!0;throw new o("portal:invalid-layer-item-type","Invalid layer item, expected '${expectedType}' ",{expectedType:"3DTiles Service containing IntegratedMesh"})}},e)}catch(i){s(i)}if(null!=this._modificationsSource){const t=await T.fromUrl(this._modificationsSource.url,this.spatialReference,e);if(t&&t.length>0){await U();try{const e=O(null,t.toArray(),this.spatialReference),o=E({modifications:e,inVCS:115700});o.success&&o.modifications&&M(o.modifications,t)}catch(a){r.getLogger(this).error("convert-mesh-modification-z-error","Error when converting:",a)}null!=this._modificationsSource&&this.setAtOrigin("modifications",t,this._modificationsSource.context.origin),this._modificationsSource=null}}await this.requestRootAndSession(t)}async beforeSave(){if(null==this._modificationsSource){const{modifications:e}=this;return void(e&&e.length>0&&await U())}await this.load().then(()=>{},()=>{})}get hasAttributionData(){return!1}_validateElevationInfo(e){const t="Integrated mesh 3d tiles layers";P(r.getLogger(this),I(t,"absolute-height",e)),P(r.getLogger(this),k(t,e))}get replacesTerrain(){return!!has("enable-feature:basemap-groundlayers")&&this.hasGoogleUrl&&this.isUsedAsGroundLayer}get isUsedAsGroundLayer(){return D(this.parent)}get hasGoogleUrl(){return!!this.url?.match(/.+\.googleapis.com/)}};e([l({type:["IntegratedMesh3DTilesLayer"]})],A.prototype,"operationalLayerType",void 0),e([l({type:T,clonable:e=>e.clone()}),m({origins:["web-scene","portal-item"],type:"resource",prefix:"modifications"})],A.prototype,"modifications",void 0),e([q(["web-scene","portal-item"],"modifications")],A.prototype,"readModifications",null),e([l({type:d})],A.prototype,"spatialReference",void 0),e([l({type:c})],A.prototype,"fullExtent",void 0),e([l(v)],A.prototype,"elevationInfo",null),e([l({type:["show","hide"]})],A.prototype,"listMode",void 0),e([l(j)],A.prototype,"url",void 0),e([l({readOnly:!0})],A.prototype,"type",void 0),e([l({type:String,json:{origins:{"web-scene":{read:!0,write:!0},"portal-item":{read:!0,write:!0}},read:!1}})],A.prototype,"path",void 0),e([l({type:Number,json:{name:"layerDefinition.minScale",write:!0,origins:{service:{read:!1,write:!1}}}})],A.prototype,"minScale",void 0),e([l({type:Number,json:{name:"layerDefinition.maxScale",write:!0,origins:{service:{read:!1,write:!1}}}})],A.prototype,"maxScale",void 0),e([l({readOnly:!0})],A.prototype,"hasAttributionData",null),e([l()],A.prototype,"replacesTerrain",null),e([l()],A.prototype,"isUsedAsGroundLayer",null),e([l()],A.prototype,"hasGoogleUrl",null),A=e([p("esri.layers.IntegratedMesh3DTilesLayer")],A);const G=A;export{G as default};