Slide.js 7.8 KB

12345678910111213141516171819
  1. // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  2. // See https://js.arcgis.com/4.7/esri/copyright.txt for details.
  3. //>>built
  4. define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper dojo/_base/lang dojo/promise/all ../Basemap ../Viewpoint ../core/Collection ../core/collectionUtils ../core/JSONSupport ../core/lang ../core/Logger ../core/promiseUtils ../core/accessorSupport/decorators ../core/accessorSupport/ensureType ../support/basemapUtils ../views/3d/lib/glMatrix ./Environment ./Lighting ./support/Description ./support/Thumbnail ./support/Title".split(" "),function(K,L,t,d,m,A,B,
  5. C,u,D,v,E,F,g,c,n,w,G,k,H,p,l,h){var I=0,x=function(f){function b(){var a=null!==f&&f.apply(this,arguments)||this;a.id="";return a}t(b,f);a=b;b.prototype.clone=function(){return new a({id:this.id})};d([c.property({type:String,json:{write:!0}})],b.prototype,"id",void 0);return b=a=d([c.subclass()],b);var a}(c.declared(v)),q=u.ofType(x),J=F.getLogger("esri.webscene.Slide");return function(f){function b(a){a=f.call(this,a)||this;a._currentAnimation=null;a.id=Date.now().toString(16)+"-slide-"+I++;a.title=
  6. new h.default;a.description=new p.default;a.thumbnail=new l.default;a.viewpoint=null;a.basemap=null;a.environment=new k;a.visibleLayers=new q;return a}t(b,f);b.prototype.castTitle=function(a){return"string"===typeof a?new h.default({text:a}):n.ensureType(h.default,a)};b.prototype.castDescription=function(a){return"string"===typeof a?new p.default({text:a}):n.ensureType(p.default,a)};b.prototype.castThumbnail=function(a){return"string"===typeof a?new l.default({url:a}):n.ensureType(l.default,a)};b.prototype.castBasemap=
  7. function(a){return w.ensureType(a)};Object.defineProperty(b.prototype,"visibleLayers",{set:function(a){this._set("visibleLayers",D.referenceSetter(a,this._get("visibleLayers"),q))},enumerable:!0,configurable:!0});b.prototype.castVisibleLayers=function(a){return a&&"function"===typeof a.map?a.map(function(a){if("string"===typeof a)return{id:a};if(a.id)return{id:a.id};J.warn('Invalid visible layer, expected { id }, Layer or "id"');return a}):a};b.prototype.clone=function(){return new this.constructor({id:this.id,
  8. 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,visibleLayers:this.visibleLayers.clone(),environment:this.environment&&this.environment.clone()||null})};b.prototype._updateVisibleLayersFrom=function(a){var b=this,y=[];return g.eachAlways(this._allLayers(a.map).map(function(b){return a.whenLayerView(b).then(function(a){a.visible&&
  9. y.push(new x({id:a.layer.id}))})}).toArray()).then(function(){b.visibleLayers.removeAll();b.visibleLayers.addMany(y)})};b.prototype.updateFrom=function(a,b){var e=this;b=m.mixin({screenshot:m.mixin({format:"jpeg",quality:80,width:120,height:75},b&&b.screenshot)},b);return a.when(function(){e.viewpoint=a.viewpoint.clone();e.environment.lighting=H.prototype.clone.apply(a.environment.lighting);e.basemap=a.map.basemap&&a.map.basemap.clone()||null;return e._updateVisibleLayersFrom(a)}).then(function(){return a.takeScreenshot(b.screenshot)}).then(function(a){e.thumbnail=
  10. new l.default({url:a.dataURL});return e})};b.prototype.applyTo=function(a,b){var e=this,z=m.mixin({animate:!0},b);return this._applyBasemap(a).then(function(){return A([e._applyViewpoint(a,z),e._applyLayerVisibility(a,z)])}).then(function(){return e})};b.prototype._applyBasemap=function(a){var b=this;return this.basemap?this.basemap.load().always(function(){a.map.basemap=w.clonePreservingTiledLayers(b.basemap,a.map.basemap)}):g.resolve()};b.prototype._allLayers=function(a){var b=new u;this._collectLayers(a,
  11. b);this._collectLayers(a.ground,b);return b};b.prototype._collectLayers=function(a,b){var e=this;a.layers.forEach(function(a){b.add(a);a.layers&&e._collectLayers(a,b)})};b.prototype._applyLayerVisibility=function(a,b){var e=this;if(this.visibleLayers){var c=this._allLayers(a.map);if(b.applyToLayerViews)return g.eachAlways(c.map(function(b){return a.whenLayerView(b).then(function(a){a.visible=e.visibleLayers.some(function(b){return b.id===a.layer.id})})}).toArray());c.forEach(function(a){return a.visible=
  12. e.visibleLayers.some(function(b){return b.id===a.id})});return g.resolve()}};b.prototype._applyViewpoint=function(a,b){if(this.viewpoint){this.viewpoint.camera.fov=a.camera.fov;if(b.animate){if(this.get("environment.lighting.date"))return this._animateToLighting(a,b);a.environment.lighting=this.environment.lighting.clone();return a.goTo(this.viewpoint,b)}a.viewpoint=this.viewpoint;a.environment.lighting=this.environment.lighting.clone()}return g.resolve()};b.prototype._animateToLighting=function(a,
  13. b){var e=this,c;"global"===a.viewingMode&&(c=this._animateLightingWithCamera(a));this._currentAnimation&&(this._currentAnimation.cancel(),this._currentAnimation=null);a.environment.lighting.cameraTrackingEnabled=!1;a.environment.lighting.directShadowsEnabled=this.environment.lighting.directShadowsEnabled;null!=this.environment.lighting.displayUTCOffset&&(a.environment.lighting.displayUTCOffset=this.environment.lighting.displayUTCOffset);var d=a.goTo(this.viewpoint,b);this._currentAnimation=d;this._currentAnimation.always(function(){c&&
  14. c.remove();e._currentAnimation===d&&(a.environment.lighting.cameraTrackingEnabled=!0)});this._currentAnimation.then(function(){a.environment.lighting=e.environment.lighting.clone()});return this._currentAnimation};b.prototype._getTime=function(a){var b=a.getTime();a=3600*a.getUTCHours()+60*a.getUTCMinutes()+a.getUTCSeconds();return[b,a]};b.prototype._setTime=function(a,b,c){a.setTime(b);a.setUTCHours(c/3600);a.setUTCMinutes(c%3600/60);a.setUTCSeconds(c%3600%60);return a};b.prototype._animateLightingWithCamera=
  15. function(a){var b=this,c=G.vec3d,d=this._getTime(new Date(a.environment.lighting.date.toString())),f=d[0],g=d[1],d=this._getTime(this.environment.lighting.date),l=d[0],p=d[1],h=a.renderCoordsHelper,m=[0,0,0];h.toRenderCoords(a.camera.position,m);var n=[0,0,0];h.toRenderCoords(this.viewpoint.camera.position,n);var k=[0,0,0],q=new Date;return a.watch("camera",function(e){h.toRenderCoords(e.position,k);e=c.dist2(m,k);var d=c.dist2(n,k),r=0;0!==e+d&&(r=e/(e+d));a.environment.lighting.date=b._setTime(q,
  16. f+(l-f)*r,g+(p-g)*r)})};b.createFrom=function(a,b){return(new this).updateFrom(a,b)};b.sanitizeJSON=function(a){var b;b=void 0!==a.visibleLayers&&Array.isArray(a.visibleLayers)?E.clone(a.visibleLayers):[];b={id:a.id||"",title:a.title||{text:""},thumbnail:a.thumbnail||{url:""},viewpoint:a.viewpoint,baseMap:a.baseMap,visibleLayers:b};void 0!==a.description&&(b.description=a.description);void 0!==a.environment&&(b.environment=k.sanitizeJSON(a.environment));return b};d([c.property({type:String,json:{write:{isRequired:!0}}})],
  17. b.prototype,"id",void 0);d([c.property({type:h.default,json:{write:{isRequired:!0}}})],b.prototype,"title",void 0);d([c.cast("title")],b.prototype,"castTitle",null);d([c.property({type:p.default,json:{write:{overridePolicy:function(a){return{enabled:!(!a||!a.text)}}}}})],b.prototype,"description",void 0);d([c.cast("description")],b.prototype,"castDescription",null);d([c.property({type:l.default,json:{write:{isRequired:!0}}})],b.prototype,"thumbnail",void 0);d([c.cast("thumbnail")],b.prototype,"castThumbnail",
  18. null);d([c.property({type:C,json:{write:{isRequired:!0}}})],b.prototype,"viewpoint",void 0);d([c.property({type:B,json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],b.prototype,"basemap",void 0);d([c.cast("basemap")],b.prototype,"castBasemap",null);d([c.property({type:q,json:{write:{isRequired:!0}}})],b.prototype,"visibleLayers",null);d([c.cast("visibleLayers")],b.prototype,"castVisibleLayers",null);d([c.property({type:k,json:{write:!0}})],b.prototype,"environment",void 0);return b=d([c.subclass("esri.webscene.Slide")],
  19. b)}(c.declared(v))});