UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 11.3 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import t from"../Basemap.js";import i from"../Viewpoint.js";import{result as n}from"../core/asyncUtils.js";import r from"../core/Clonable.js";import s from"../core/Collection.js";import{referenceSetter as o}from"../core/collectionUtils.js";import a from"../core/JSONSupport.js";import l from"../core/Logger.js";import{moduloPositive as p}from"../core/mathUtils.js";import{destroyMaybe as m,removeMaybe as c}from"../core/maybe.js";import{onAbortOrThrow as h,createAbortError as d,isAbortError as u}from"../core/promiseUtils.js";import{whenOnce as y,when as g}from"../core/reactiveUtils.js";import{Milliseconds as b,Seconds as v}from"../core/time.js";import{property as w}from"../core/accessorSupport/decorators/property.js";import{cast as f}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{subclass as T}from"../core/accessorSupport/decorators/subclass.js";import{ensureType as j}from"../core/accessorSupport/ensureType.js";import{s as L}from"../chunks/vec32.js";import{create as C}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import _ from"../layers/Layer.js";import{basemapEnsureType as E,clonePreservingTiledLayers as S}from"../support/basemapEnsureType.js";import{TaskPriority as k}from"../views/support/Scheduler.js";import{SlideThumbnail as A}from"../webdoc/support/SlideThumbnail.js";import{timeExtent as V}from"../webdoc/support/timeProperties.js";import U from"./SunLighting.js";import x from"./VirtualLighting.js";import F from"./support/Description.js";import I from"./support/SlideElements.js";import{SlideEnvironment as D}from"./support/SlideEnvironment.js";import R from"./support/SlideGround.js";import{SlideVisibleLayer as M}from"./support/SlideVisibleLayer.js";import O from"./support/Title.js";let P=0;const q=s.ofType(M),B=["caption","cover","none"];let G=class extends(r.ClonableMixin(a)){constructor(e){super(e),this.id=Date.now().toString(16)+"-slide-"+P++,this.title=new O,this.description=new F,this.hidden=!1,this.thumbnail=new A,this.viewpoint=null,this.basemap=null,this.ground=null,this.layout="caption",this.enabledFocusAreas=null,this.environment=new D,this.timeExtent=null,this.elements=new I,this.visibleLayers=new q}destroy(){this.visibleLayers.removeAll(),this.enabledFocusAreas=null,this.basemap=null,this.thumbnail=m(this.thumbnail),this.description=null,this.title=null,this.thumbnail=null,this.elements=null}castTitle(e){return"string"==typeof e?new O({text:e}):j(O,e)}castDescription(e){return"string"==typeof e?new F({text:e}):j(F,e)}castThumbnail(e){return"string"==typeof e?new A({url:e}):j(A,e)}castBasemap(e){return E(e)}set visibleLayers(e){this._set("visibleLayers",o(e,this._get("visibleLayers"),q))}castVisibleLayers(e){return e&&"function"==typeof e.map?e.map((e=>{if("string"==typeof e)return{id:e};if(e instanceof _){const t=H(e);return{id:e.id,sublayerIds:t}}return e.id?{id:e.id,sublayerIds:"sublayerIds"in e?e.sublayerIds:void 0}:(l.getLogger(this).warn('Invalid visible layer, expected { id }, Layer or "id"'),e)})):null}async _updateVisibleLayers(e){const t=[];await Promise.allSettled(this._getLayers(e.map).map((i=>e.whenLayerView(i).then((e=>{if(e.visible){const n=H(i);t.push(new M({id:e.layer.id,sublayerIds:n}))}})))).toArray()),this.visibleLayers.removeAll(),this.visibleLayers.addMany(t)}async updateFrom(e,t){const i={format:"png",quality:80,width:120,height:75,disableDecorations:!0,...t?.screenshot};await e.when(),this.viewpoint=e.viewpoint.clone(),this.environment.lighting="virtual"===e.environment.lighting.type?x.prototype.clone.apply(e.environment.lighting):U.prototype.clone.apply(e.environment.lighting),this.environment.weather=e.environment.weather.clone(),this.enabledFocusAreas=new s(e.focusAreasView?.enabledAreas.map((({id:e})=>e))??[]),this.basemap=e.map.basemap?.clone()||null,this.ground=e.map.ground?R.fromGround(e.map.ground):null,this.timeExtent=e.timeExtent?.clone()??null,this.elements.analyses.updateFrom(e),await this._updateVisibleLayers(e);const n=await e.takeScreenshot(i);return this.thumbnail=new A({url:n.dataUrl}),this}async applyTo(e,t){null!=this._applyToController&&this._applyToController.abort();let i=new AbortController;this._applyToController=i;const r=h(t,(()=>i?.abort())),s=()=>{this._applyToController===i&&(this._applyToController=null),i=null,r?.remove()};try{await y((()=>e.ready),i.signal)}catch(c){throw s(),c}if(i.signal.aborted)throw s(),d();const o=e.resourceController.scheduler.registerTask(k.SLIDE);let a=!1;const l={animate:!0,...t,signal:this._applyToController.signal},p=async()=>{await Promise.all([o.schedule((async()=>a=await this._setViewpointOfInterest(e,l))),o.schedule((()=>this._applyBasemap(e,l)),l.signal),o.schedule((()=>this._loadLayersWithSublayerVisibility(e)))]),await Promise.all([o.schedule((()=>this._applyLayerVisibility(e)),l.signal),o.schedule((()=>this._applyFocusAreaEnabled(e.map?.focusAreas.areas))),o.schedule((()=>this._applyGround(e)),l.signal),o.schedule((()=>this.elements.analyses.applyTo(e)),l.signal),o.schedule((()=>this._applyViewpoint(e,l)),l.signal),o.schedule((()=>e.timeExtent=this.timeExtent?.clone()??null),l.signal),o.schedule((()=>e.environment.weather=this.environment.weather.clone()))])},m=await n(e.addUpdatingPromise(p()));if(a&&(e.contentCamera=null),o.remove(),s(),!1===m.ok)throw m.error;return this}async _applyBasemap(e,t){if(this.basemap){try{await this.basemap.load(t)}catch(i){if(u(i))throw i}e.map.basemap=S(this.basemap,e.map.basemap)}}_applyGround(e){this.ground&&(e.map.ground=this.ground.cloneAndApplyTo(e.map.ground))}_applyFocusAreaEnabled(e){if(e&&this.enabledFocusAreas)for(const t of e)t.enabled=this.enabledFocusAreas.includes(t.id)}_getLayers(e){const t=new s;return this._collectLayers(e,t),this._collectLayers(e.ground,t),t}_collectLayers(e,t){e.layers.forEach((e=>{e.persistenceEnabled&&(t.add(e),"layers"in e&&this._collectLayers(e,t))}))}async _loadLayersWithSublayerVisibility(e){this.visibleLayers&&await Promise.allSettled(this._getLayers(e.map).items.map((e=>{const t=this.visibleLayers.find((t=>t.id===e.id))?.sublayerIds;return t?e.load():null})))}_applyLayerVisibility(e){if(!this.visibleLayers)return;this._getLayers(e.map).forEach((e=>{const t=this.visibleLayers.find((t=>t.id===e.id));e.visible=null!=t;const i=t?.sublayerIds,n=W(e);i&&n&&n.forEach((e=>e.visible=i.includes(e.id)))}))}async _setViewpointOfInterest(e,t){if(e.state.fixedContentCamera||!this.viewpoint||t?.ignoreViewpoint||!t?.useDestinationCamera)return!1;const{toCameraAsync:i}=await import("../views/3d/support/viewpointUtils.js"),n=await i(e,this.viewpoint);return e.contentCamera=n,null!=n}async _applyViewpoint(e,t){if(this._applyCachedCameraTrackingEnabled(e),this.viewpoint&&!t.ignoreViewpoint){const i=this.environment.lighting;if(t.animate&&"sun"===i.type&&i.date)return this._animateToLighting(e,t);t.animate&&(e.environment.applyLighting(i.clone()),await e.goTo(this.viewpoint,t)),e.viewpoint=this.viewpoint}e.environment.applyLighting(this.environment.lighting.clone())}async _animateToLighting(e,t){let i=null;"virtual"!==e.environment.lighting.type&&"virtual"!==this.environment.lighting.type&&("global"===e.viewingMode&&(i=this._animateLightingWithCamera(e,e.environment.lighting,this.environment.lighting)),e.environment.cachedCameraTrackingEnabled=e.environment.lighting.cameraTrackingEnabled,e.environment.lighting.cameraTrackingEnabled=!1),e.environment.lighting.directShadowsEnabled=this.environment.lighting.directShadowsEnabled,"virtual"===this.environment.lighting.type||"virtual"===e.environment.lighting.type?(e.environment.applyLighting(this.environment.lighting.clone()),"virtual"!==e.environment.lighting.type&&(e.environment.cachedCameraTrackingEnabled=e.environment.lighting.cameraTrackingEnabled,e.environment.lighting.cameraTrackingEnabled=!1)):null!=this.environment.lighting.displayUTCOffset&&(e.environment.lighting.displayUTCOffset=this.environment.lighting.displayUTCOffset);return e.goTo(this.viewpoint,t).then((()=>{this._applyCachedCameraTrackingEnabled(e),e.environment.applyLighting(this.environment.lighting.clone())})).catch((t=>{throw null==e.animation&&this._applyCachedCameraTrackingEnabled(e),t})).finally((()=>{c(i)}))}_applyCachedCameraTrackingEnabled(e){null!=e.environment.cachedCameraTrackingEnabled&&(e.environment.lighting.cameraTrackingEnabled=e.environment.cachedCameraTrackingEnabled,e.environment.cachedCameraTrackingEnabled=null)}_getTime(e){return[b(e.getTime()),v(3600*e.getUTCHours()+60*e.getUTCMinutes()+e.getUTCSeconds())]}_setTime(e,t,i){return e.setTime(t),e.setUTCHours(i/3600),e.setUTCMinutes(i%3600/60),e.setUTCSeconds(i%3600%60),e}_animateLightingWithCamera(e,t,i){const n=new Date(t.date.toString()),[r,s]=this._getTime(n),[o,a]=this._getTime(i.date),l=K(s,a),p=e.renderCoordsHelper,m=C();p.toRenderCoords(e.camera.position,m);const c=C(),h=C();null!=this.viewpoint.camera&&p.toRenderCoords(this.viewpoint.camera.position,c);const d=new Date;return g((()=>e.camera),(e=>{p.toRenderCoords(e.position,h);const i=L(m,h),n=L(c,h);let a=0;i+n!==0&&(a=i/(i+n));const u=r+(o-r)*a,y=Q(s,v(l*a));t.date=this._setTime(d,u,y)}))}write(e,t){const i=super.write(e,t);return i?.elements&&0===Object.keys(i.elements).length&&delete i.elements,i}static createFrom(e,t){return(new this).updateFrom(e,t)}};e([w({type:String,json:{write:{isRequired:!0}}})],G.prototype,"id",void 0),e([w({type:O,json:{default:()=>new O({text:""}),write:{isRequired:!0}}})],G.prototype,"title",void 0),e([f("title")],G.prototype,"castTitle",null),e([w({type:F,json:{write:{overridePolicy:e=>({enabled:!(!e||!e.text)})}}})],G.prototype,"description",void 0),e([f("description")],G.prototype,"castDescription",null),e([w({type:Boolean,nonNullable:!0,json:{write:!0,default:!1}})],G.prototype,"hidden",void 0),e([w({type:A,json:{default:()=>new A({url:""}),write:{isRequired:!0}}})],G.prototype,"thumbnail",void 0),e([f("thumbnail")],G.prototype,"castThumbnail",null),e([w({type:i,nonNullable:!0,json:{write:{isRequired:!0}}})],G.prototype,"viewpoint",void 0),e([w({type:t,json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],G.prototype,"basemap",void 0),e([f("basemap")],G.prototype,"castBasemap",null),e([w({type:R,json:{write:!0}})],G.prototype,"ground",void 0),e([w({type:B,json:{write:!0,default:"caption"},nonNullable:!0})],G.prototype,"layout",void 0),e([w({type:q,json:{write:{isRequired:!0}}})],G.prototype,"visibleLayers",null),e([f("visibleLayers")],G.prototype,"castVisibleLayers",null),e([w({type:s.ofType(String),json:{write:!0},clonable:e=>e?new s(e.items):null})],G.prototype,"enabledFocusAreas",void 0),e([w({type:D,json:{write:!0}})],G.prototype,"environment",void 0),e([w(V)],G.prototype,"timeExtent",void 0),e([w({type:I,nonNullable:!0,json:{write:!0}})],G.prototype,"elements",void 0),G=e([T("esri.webscene.Slide")],G);const N=G;function W(e){if("building-scene"===e.type||"map-image"===e.type)return e.allSublayers.toArray()}function H(e){const t=W(e);if(t)return t.filter((e=>e.visible)).map((e=>e.id))}const J=v(86400),z=v(43200);function K(e,t){let i=t-e;return i>z&&(i-=J),i<-z&&(i+=J),v(i)}function Q(e,t){return v(p(e+t,J))}export{N as default};