Slide.js 9.8 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. 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/Collection.js";import{referenceSetter as o}from"../core/collectionUtils.js";import{JSONSupport as s}from"../core/JSONSupport.js";import a from"../core/Logger.js";import{isSome as l,isNone as p,removeMaybe as m}from"../core/maybe.js";import{eachAlways as h,onAbortOrThrow as c,isAbortError as d}from"../core/promiseUtils.js";import{when as u}from"../core/reactiveUtils.js";import{property as g}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{cast as y}from"../core/accessorSupport/decorators/cast.js";import{subclass as v}from"../core/accessorSupport/decorators/subclass.js";import{ensureType as b}from"../core/accessorSupport/ensureType.js";import{d as w}from"../chunks/vec3.js";import{c as f}from"../chunks/vec3f64.js";import T from"../layers/Layer.js";import{isOperationalLayer as L}from"../layers/mixins/OperationalLayer.js";import{ensureType as C,clonePreservingTiledLayers as j}from"../support/basemapUtils.js";import{moduloPositive as _}from"../views/3d/support/mathUtils.js";import{toCamera as S}from"../views/3d/support/viewpointUtils.js";import{TaskPriority as E}from"../views/support/Scheduler.js";import{SlideThumbnail as k}from"../webdoc/support/SlideThumbnail.js";import U from"./SunLighting.js";import V from"./VirtualLighting.js";import x from"./support/Description.js";import{SlideEnvironment as D}from"./support/SlideEnvironment.js";import I from"./support/SlideGround.js";import{SlideVisibleLayer as R}from"./support/SlideVisibleLayer.js";import A from"./support/Title.js";let O=0;const q=r.ofType(R);let M=class extends s{constructor(e){super(e),this.id=Date.now().toString(16)+"-slide-"+O++,this.title=new A,this.description=new x,this.thumbnail=new k,this.viewpoint=null,this.basemap=null,this.ground=null,this.environment=new D,this.visibleLayers=new q}destroy(){this.visibleLayers.removeAll(),this.basemap=null,this.thumbnail&&this.thumbnail.destroy(),this.description=null,this.title=null,this.thumbnail=null}castTitle(e){return"string"==typeof e?new A({text:e}):b(A,e)}castDescription(e){return"string"==typeof e?new x({text:e}):b(x,e)}castThumbnail(e){return"string"==typeof e?new k({url:e}):b(k,e)}castBasemap(e){return C(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 T){const t=F(e);return{id:e.id,sublayerIds:t}}return e.id?{id:e.id,sublayerIds:e.sublayerIds}:(a.getLogger(this.declaredClass).warn('Invalid visible layer, expected { id }, Layer or "id"'),e)})):null}clone(){return new(0,this.constructor)({id:this.id,title:this.title.clone(),thumbnail:this.thumbnail.clone(),description:this.description&&this.description.clone()||null,viewpoint:this.viewpoint&&this.viewpoint.clone()||null,basemap:this.basemap&&this.basemap.clone()||null,ground:this.ground&&this.ground.clone()||null,visibleLayers:this.visibleLayers.clone(),environment:this.environment&&this.environment.clone()||null})}_updateVisibleLayersFrom(e){const t=[];return h(this._getLayers(e.map).map((i=>e.whenLayerView(i).then((e=>{if(e.visible){const n=F(i);t.push(new R({id:e.layer.id,sublayerIds:n}))}})))).toArray()).then((()=>{this.visibleLayers.removeAll(),this.visibleLayers.addMany(t)}))}updateFrom(e,t){return t={screenshot:{format:"png",quality:80,width:120,height:75,disableDecorations:!0,...t&&t.screenshot}},e.when((()=>(this.viewpoint=e.viewpoint.clone(),this.environment.lighting="virtual"===e.environment.lighting.type?V.prototype.clone.apply(e.environment.lighting):U.prototype.clone.apply(e.environment.lighting),this.environment.weather=e.environment.weather.clone(),this.basemap=e.map.basemap&&e.map.basemap.clone()||null,this.ground=e.map.ground?I.fromGround(e.map.ground):null,this._updateVisibleLayersFrom(e)))).then((()=>e.takeScreenshot(t.screenshot))).then((e=>(this.thumbnail=new k({url:e.dataUrl}),this)))}async applyTo(e,t){l(this._applyToController)&&this._applyToController.abort();let i=new AbortController;this._applyToController=i;const r=c(t,(()=>i.abort())),o=e.resourceController.scheduler.registerTask(E.SLIDE);let s=!1;t={animate:!0,...t,signal:this._applyToController.signal};const a=async()=>{await Promise.all([o.schedule((()=>s=this._setViewpointOfInterest(e,t))),o.schedule((()=>this._applyBasemap(e,t)),t.signal)]),await Promise.all([o.schedule((()=>this._applyLayerVisibility(e)),t.signal),o.schedule((()=>this._applyGround(e)),t.signal),o.schedule((()=>this._applyViewpoint(e,t)),t.signal)]),await o.schedule((()=>e.environment.weather=this.environment.weather.clone()))},p=await n(e.addUpdatingPromise(a()));if(s&&(e.contentCamera=null),o.remove(),this._applyToController===i&&(this._applyToController=null),i=null,r?.remove(),!1===p.ok)throw p.error;return this}async _applyBasemap(e,t){if(this.basemap){try{await this.basemap.load(t)}catch(i){if(d(i))throw i}e.map.basemap=j(this.basemap,e.map.basemap)}}_applyGround(e){this.ground&&(e.map.ground=this.ground.cloneAndApplyTo(e.map.ground))}_getLayers(e){const t=new r;return this._collectLayers(e,t),this._collectLayers(e.ground,t),t}_collectLayers(e,t){e.layers.forEach((e=>{L(e)&&(t.add(e),"layers"in e&&this._collectLayers(e,t))}))}_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&&t.sublayerIds,n=B(e);i&&n&&n.forEach((e=>e.visible=i.includes(e.id)))}))}_setViewpointOfInterest(e,t){if(e.state.fixedContentCamera||!this.viewpoint||t.ignoreViewpoint||!t.useDestinationCamera)return!1;const i=S(e,this.viewpoint);return e.contentCamera=i,l(i)}async _applyViewpoint(e,t){if(this._applyCachedCameraTrackingEnabled(e),this.viewpoint&&!t.ignoreViewpoint){if(l(this.viewpoint.camera)&&(this.viewpoint.camera.fov=e.camera.fov),t.animate&&this.get("environment.lighting.date"))return this._animateToLighting(e,t);t.animate&&(e.environment.applyLighting(this.environment.lighting.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 p(e.animation)&&this._applyCachedCameraTrackingEnabled(e),t})).finally((()=>{m(i)}))}_applyCachedCameraTrackingEnabled(e){l(e.environment.cachedCameraTrackingEnabled)&&(e.environment.lighting.cameraTrackingEnabled=e.environment.cachedCameraTrackingEnabled,e.environment.cachedCameraTrackingEnabled=null)}_getTime(e){return[e.getTime(),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,o]=this._getTime(n),[s,a]=this._getTime(i.date),p=H(o,a),m=e.renderCoordsHelper,h=f();m.toRenderCoords(e.camera.position,h);const c=f(),d=f();l(this.viewpoint.camera)&&m.toRenderCoords(this.viewpoint.camera.position,c);const g=new Date;return u((()=>e.camera),(e=>{m.toRenderCoords(e.position,d);const i=w(h,d),n=w(c,d);let a=0;i+n!==0&&(a=i/(i+n));const l=r+(s-r)*a,u=N(o,p*a);t.date=this._setTime(g,l,u)}))}static createFrom(e,t){return(new this).updateFrom(e,t)}};function B(e){if("building-scene"===e.type||"map-image"===e.type)return e.allSublayers.toArray()}function F(e){const t=B(e);if(t)return t.filter((e=>e.visible)).map((e=>e.id))}e([g({type:String,json:{write:{isRequired:!0}}})],M.prototype,"id",void 0),e([g({type:A,json:{default:()=>new A({text:""}),write:{isRequired:!0}}})],M.prototype,"title",void 0),e([y("title")],M.prototype,"castTitle",null),e([g({type:x,json:{write:{overridePolicy:e=>({enabled:!(!e||!e.text)})}}})],M.prototype,"description",void 0),e([y("description")],M.prototype,"castDescription",null),e([g({type:k,json:{default:()=>new k({url:""}),write:{isRequired:!0}}})],M.prototype,"thumbnail",void 0),e([y("thumbnail")],M.prototype,"castThumbnail",null),e([g({type:i,nonNullable:!0,json:{write:{isRequired:!0}}})],M.prototype,"viewpoint",void 0),e([g({type:t,json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],M.prototype,"basemap",void 0),e([y("basemap")],M.prototype,"castBasemap",null),e([g({type:I,json:{write:!0}})],M.prototype,"ground",void 0),e([g({type:q,json:{write:{isRequired:!0}}})],M.prototype,"visibleLayers",null),e([y("visibleLayers")],M.prototype,"castVisibleLayers",null),e([g({type:D,json:{write:!0}})],M.prototype,"environment",void 0),M=e([v("esri.webscene.Slide")],M);const G=86400,P=43200;function H(e,t){let i=t-e;return i>P&&(i-=G),i<-P&&(i+=G),i}function N(e,t){return _(e+t,G)}const W=M;export{W as default};