12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/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/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,removeMaybe as p}from"../core/maybe.js";import{eachAlways as m,onAbortOrThrow as h,isAbortError as c}from"../core/promiseUtils.js";import{watch as u}from"../core/reactiveUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as y}from"../core/accessorSupport/decorators/cast.js";import{subclass as g}from"../core/accessorSupport/decorators/subclass.js";import{ensureType as v}from"../core/accessorSupport/ensureType.js";import{d as w}from"../chunks/vec3.js";import{c as b}from"../chunks/vec3f64.js";import f from"../layers/Layer.js";import{isOperationalLayer as L}from"../layers/mixins/OperationalLayer.js";import{ensureType as j,clonePreservingTiledLayers as T}from"../support/basemapUtils.js";import{moduloPositive as _}from"../views/3d/support/mathUtils.js";import{toCamera as C}from"../views/3d/support/viewpointUtils.js";import{TaskPriority as S}from"../views/support/Scheduler.js";import{SlideThumbnail as U}from"../webdoc/support/SlideThumbnail.js";import V from"./SunLighting.js";import E from"./VirtualLighting.js";import k from"./support/Description.js";import{SlideEnvironment as x}from"./support/SlideEnvironment.js";import D from"./support/SlideGround.js";import{SlideVisibleLayer as I}from"./support/SlideVisibleLayer.js";import R from"./support/Title.js";let A=0;const O=r.ofType(I),q=a.getLogger("esri.webscene.Slide");let M=class extends s{constructor(e){super(e),this.id=Date.now().toString(16)+"-slide-"+A++,this.title=new R,this.description=new k,this.thumbnail=new U,this.viewpoint=null,this.basemap=null,this.ground=null,this.environment=new x,this.visibleLayers=new O}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 R({text:e}):v(R,e)}castDescription(e){return"string"==typeof e?new k({text:e}):v(k,e)}castThumbnail(e){return"string"==typeof e?new U({url:e}):v(U,e)}castBasemap(e){return j(e)}set visibleLayers(e){this._set("visibleLayers",o(e,this._get("visibleLayers"),O))}castVisibleLayers(e){return e&&"function"==typeof e.map?e.map((e=>{if("string"==typeof e)return{id:e};if(e instanceof f){const t=F(e);return{id:e.id,sublayerIds:t}}return e.id?{id:e.id,sublayerIds:e.sublayerIds}:(q.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 m(this._getLayers(e.map).map((i=>e.whenLayerView(i).then((e=>{if(e.visible){const n=F(i);t.push(new I({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?E.prototype.clone.apply(e.environment.lighting):V.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?D.fromGround(e.map.ground):null,this._updateVisibleLayersFrom(e)))).then((()=>e.takeScreenshot(t.screenshot))).then((e=>(this.thumbnail=new U({url:e.dataUrl}),this)))}async applyTo(e,t){l(this._applyToController)&&this._applyToController.abort();let i=new AbortController;this._applyToController=i;const r=h(t,(()=>i.abort())),o=e.resourceController.scheduler.registerTask(S.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(c(i))throw i}e.map.basemap=T(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=C(e,this.viewpoint);return e.contentCamera=i,l(i)}async _applyViewpoint(e,t){if(this.viewpoint&&!t.ignoreViewpoint){if(l(this.viewpoint.camera)&&(this.viewpoint.camera.fov=e.camera.fov),t.animate&&this.get("environment.lighting.date"))return void await 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;"sun"===e.environment.lighting.type&&"sun"===this.environment.lighting.type&&("global"===e.viewingMode&&(i=this._animateLightingWithCamera(e,e.environment.lighting,this.environment.lighting)),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()),"sun"===e.environment.lighting.type&&(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((()=>e.environment.applyLighting(this.environment.lighting.clone()))).finally((()=>{p(i),"sun"===e.environment.lighting.type&&(e.environment.lighting.cameraTrackingEnabled=!0)}))}_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=b();m.toRenderCoords(e.camera.position,h);const c=b(),d=b();l(this.viewpoint.camera)&&m.toRenderCoords(this.viewpoint.camera.position,c);const y=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(y,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([d({type:String,json:{write:{isRequired:!0}}})],M.prototype,"id",void 0),e([d({type:R,json:{default:()=>new R({text:""}),write:{isRequired:!0}}})],M.prototype,"title",void 0),e([y("title")],M.prototype,"castTitle",null),e([d({type:k,json:{write:{overridePolicy:e=>({enabled:!(!e||!e.text)})}}})],M.prototype,"description",void 0),e([y("description")],M.prototype,"castDescription",null),e([d({type:U,json:{default:()=>new U({url:""}),write:{isRequired:!0}}})],M.prototype,"thumbnail",void 0),e([y("thumbnail")],M.prototype,"castThumbnail",null),e([d({type:i,nonNullable:!0,json:{write:{isRequired:!0}}})],M.prototype,"viewpoint",void 0),e([d({type:t,json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],M.prototype,"basemap",void 0),e([y("basemap")],M.prototype,"castBasemap",null),e([d({type:D,json:{write:!0}})],M.prototype,"ground",void 0),e([d({type:O,json:{write:{isRequired:!0}}})],M.prototype,"visibleLayers",null),e([y("visibleLayers")],M.prototype,"castVisibleLayers",null),e([d({type:x,json:{write:!0}})],M.prototype,"environment",void 0),M=e([g("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};
|