WebScene.js 35.1 KB
// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.6/esri/copyright.txt for details.
//>>built
require({cache:{"esri/core/accessorSupport/originUtils":function(){define(["require","exports","../MultiOriginJSONSupport"],function(r,m,p){Object.defineProperty(m,"__esModule",{value:!0});m.updateOrigins=function(a){a&&a.writtenProperties&&a.writtenProperties.forEach(function(a){var g=a.target;a.newOrigin&&a.oldOrigin!==a.newOrigin&&g.isInstanceOf(p)&&g.updateOrigin(a.propName,a.newOrigin)})}})},"esri/support/webSceneUtils":function(){define(["require","exports","../core/Error"],function(r,m,p){Object.defineProperty(m,
"__esModule",{value:!0});m.createCopyError=function(){return new p("webscene:failed-to-copy-embedded-resources","Copying of embedded resources is currently not supported")};m.isCopyError=function(a){return a&&"webscene:failed-to-copy-embedded-resources"===a.name};m.createSchemaValidationError=function(a){return new p("webscene:schema-validation","Failed to save webscene due to schema validation errors. See 'details.errors' for more detailed information",{errors:a})};m.isSchemaValidationError=function(a){return a&&
"webscene:schema-validation"===a.name}})},"esri/webscene/Presentation":function(){define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/JSONSupport ../core/Collection ../core/collectionUtils ../core/accessorSupport/decorators ./Slide".split(" "),function(r,m,p,a,e,g,h,b,d){var t=g.ofType(d);return function(g){function e(a){a=g.call(this,a)||this;a.slides=new t;return a}p(e,g);Object.defineProperty(e.prototype,"slides",{set:function(a){this._set("slides",
h.referenceSetter(a,this._get("slides"),t))},enumerable:!0,configurable:!0});e.prototype.clone=function(){return new this.constructor({slides:this.slides.clone()})};e.sanitizeJSON=function(a){return{slides:void 0!==a.slides&&Array.isArray(a.slides)?a.slides.filter(function(a){return a&&!!a.viewpoint}).map(function(a){return d.sanitizeJSON(a)}):[]}};a([b.property({type:t,json:{write:!0}}),b.cast(h.castForReferenceSetter)],e.prototype,"slides",null);return e=a([b.subclass("esri.webscene.Presentation")],
e)}(b.declared(e))})},"esri/webscene/Slide":function(){define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/accessorSupport/decorators ../Viewpoint ../Basemap ../support/basemapUtils ../core/JSONSupport ../core/lang ../core/Logger ../core/Collection ../core/collectionUtils ../core/promiseUtils ./Environment ./Lighting ./support/Description ./support/Title ./support/Thumbnail dojo/_base/lang dojo/promise/all ../views/3d/lib/glMatrix".split(" "),function(r,
m,p,a,e,g,h,b,d,t,f,F,x,w,z,G,A,B,C,D,M,N){var v=0,J=function(b){function d(){var a=null!==b&&b.apply(this,arguments)||this;a.id="";return a}p(d,b);n=d;d.prototype.clone=function(){return new n({id:this.id})};a([e.property({type:String,json:{write:!0}})],d.prototype,"id",void 0);return d=n=a([e.subclass()],d);var n}(e.declared(d)),y=F.ofType(J),K=f.getLogger("esri.webscene.Slide");return function(d){function f(a){a=d.call(this,a)||this;a._currentAnimation=null;a.id=Date.now().toString(16)+"-slide-"+
v++;a.title=new B.default;a.description=new A.default;a.thumbnail=new C.default;a.viewpoint=null;a.basemap=null;a.environment=new z;a.visibleLayers=new y;return a}p(f,d);f.prototype.castBasemap=function(a){return b.ensureType(a)};Object.defineProperty(f.prototype,"visibleLayers",{set:function(a){this._set("visibleLayers",x.referenceSetter(a,this._get("visibleLayers"),y))},enumerable:!0,configurable:!0});f.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};K.warn('Invalid visible layer, expected { id }, Layer or "id"');return a}):a};f.prototype.clone=function(){return new 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,visibleLayers:this.visibleLayers.clone(),environment:this.environment&&this.environment.clone()||
null})};f.prototype._updateVisibleLayersFrom=function(a){var n=this,b=[];return w.eachAlways(this._allLayers(a.map).map(function(n){return a.whenLayerView(n).then(function(a){a.visible&&b.push(new J({id:a.layer.id}))})}).toArray()).then(function(){n.visibleLayers.removeAll();n.visibleLayers.addMany(b)})};f.prototype.updateFrom=function(a,b){var n=this;b=D.mixin({screenshot:D.mixin({format:"jpeg",quality:80,width:120,height:75},b&&b.screenshot)},b);return a.when(function(){n.viewpoint=a.viewpoint.clone();
n.environment.lighting=G.prototype.clone.apply(a.environment.lighting);n.basemap=a.map.basemap&&a.map.basemap.clone()||null;return n._updateVisibleLayersFrom(a)}).then(function(){return a.takeScreenshot(b.screenshot)}).then(function(a){n.thumbnail=new C.default({url:a.dataURL});return n})};f.prototype.applyTo=function(a,b){var n=this,d=D.mixin({animate:!0},b);return this._applyBasemap(a).then(function(){return M([n._applyViewpoint(a,d),n._applyLayerVisibility(a,d)])}).then(function(){return n})};
f.prototype._applyBasemap=function(a){var n=this;return this.basemap?this.basemap.load().always(function(){a.map.basemap=b.clonePreservingTiledLayers(n.basemap,a.map.basemap)}):w.resolve()};f.prototype._allLayers=function(a){var b=new F;this._collectLayers(a,b);this._collectLayers(a.ground,b);return b};f.prototype._collectLayers=function(a,b){var n=this;a.layers.forEach(function(a){b.add(a);a.layers&&n._collectLayers(a,b)})};f.prototype._applyLayerVisibility=function(a,b){var n=this;if(this.visibleLayers){var d=
this._allLayers(a.map);if(b.applyToLayerViews)return w.eachAlways(d.map(function(b){return a.whenLayerView(b).then(function(a){a.visible=n.visibleLayers.some(function(b){return b.id===a.layer.id})})}).toArray());d.forEach(function(a){return a.visible=n.visibleLayers.some(function(b){return b.id===a.id})});return w.resolve()}};f.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 w.resolve()};f.prototype._animateToLighting=function(a,b){var d=this,f;"global"===a.viewingMode&&(f=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 n=a.goTo(this.viewpoint,b);this._currentAnimation=n;this._currentAnimation.always(function(){f&&f.remove();d._currentAnimation===n&&(a.environment.lighting.cameraTrackingEnabled=!0)});this._currentAnimation.then(function(){a.environment.lighting=d.environment.lighting.clone()});return this._currentAnimation};f.prototype._getTime=function(a){var b=a.getTime();a=
3600*a.getUTCHours()+60*a.getUTCMinutes()+a.getUTCSeconds();return[b,a]};f.prototype._setTime=function(a,b,d){a.setTime(b);a.setUTCHours(d/3600);a.setUTCMinutes(d%3600/60);a.setUTCSeconds(d%3600%60);return a};f.prototype._animateLightingWithCamera=function(a){var b=this,d=N.vec3d,f=this._getTime(new Date(a.environment.lighting.date.toString())),g=f[0],h=f[1],f=this._getTime(this.environment.lighting.date),e=f[0],t=f[1],c=a.renderCoordsHelper,k=[0,0,0];c.toRenderCoords(a.camera.position,k);var l=[0,
0,0];c.toRenderCoords(this.viewpoint.camera.position,l);var P=[0,0,0],n=new Date;return a.watch("camera",function(f){c.toRenderCoords(f.position,P);f=d.dist2(k,P);var R=d.dist2(l,P),Q=0;0!==f+R&&(Q=f/(f+R));a.environment.lighting.date=b._setTime(n,g+(e-g)*Q,h+(t-h)*Q)})};f.createFrom=function(a,b){return(new this).updateFrom(a,b)};f.sanitizeJSON=function(a){var b;b=void 0!==a.visibleLayers&&Array.isArray(a.visibleLayers)?t.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=z.sanitizeJSON(a.environment));return b};a([e.property({type:String,json:{write:{isRequired:!0}}})],f.prototype,"id",void 0);a([e.property({type:B.default,json:{write:{isRequired:!0}}})],f.prototype,"title",void 0);a([e.property({type:A.default,json:{write:!0}})],f.prototype,"description",void 0);a([e.property({type:C.default,json:{write:{isRequired:!0}}})],
f.prototype,"thumbnail",void 0);a([e.property({type:g,json:{write:{isRequired:!0}}})],f.prototype,"viewpoint",void 0);a([e.property({type:h,json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],f.prototype,"basemap",void 0);a([e.cast("basemap")],f.prototype,"castBasemap",null);a([e.property({type:y,json:{write:{isRequired:!0}}})],f.prototype,"visibleLayers",null);a([e.cast("visibleLayers")],f.prototype,"castVisibleLayers",null);a([e.property({type:z,json:{write:!0}})],f.prototype,"environment",
void 0);return f=a([e.subclass("esri.webscene.Slide")],f)}(e.declared(d))})},"esri/webscene/Environment":function(){define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/JSONSupport ../core/accessorSupport/decorators ./Lighting".split(" "),function(r,m,p,a,e,g,h){return function(b){function d(a){a=b.call(this,a)||this;a.lighting=new h;return a}p(d,b);e=d;d.prototype.clone=function(){return new e({lighting:h.prototype.clone.call(this.lighting)})};d.sanitizeJSON=
function(a){return{lighting:a.lighting?h.sanitizeJSON(a.lighting):(new h).toJSON()}};a([g.property({type:h,json:{write:!0}})],d.prototype,"lighting",void 0);return d=e=a([g.subclass("esri.webscene.Environment")],d);var e}(g.declared(e))})},"esri/webscene/Lighting":function(){define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/JSONSupport ../core/accessorSupport/decorators".split(" "),function(r,m,p,a,e,g){return function(e){function b(a){a=e.call(this,
a)||this;a.date=null;a.directShadowsEnabled=!1;a.displayUTCOffset=null;return a}p(b,e);d=b;b.prototype.readDate=function(a,b){return null!=b.datetime&&new Date(b.datetime)||null};b.prototype.writeDate=function(a,b,d){b[d]=a.getTime()};b.prototype.readDirectShadowsEnabled=function(a,b){return!!b.directShadows};b.prototype.writedirectShadowsEnabled=function(a,b,d){a&&(b[d]=a)};b.prototype.writeDisplayUTCOffset=function(a,b){null!=a&&(b.displayUTCOffset=a)};b.prototype.clone=function(){return new d({date:null!=
this.date?new Date(this.date.getTime()):null,directShadowsEnabled:this.directShadowsEnabled,displayUTCOffset:null!=this.displayUTCOffset?this.displayUTCOffset:null})};b.sanitizeJSON=function(a){var b={datetime:a.datetime};void 0!==a.directShadows&&(b.directShadows=!!a.directShadows);void 0!==a.displayUTCOffset&&(b.displayUTCOffset=a.displayUTCOffset);return b};a([g.property({type:Date,json:{type:Number,write:{target:"datetime"}}})],b.prototype,"date",void 0);a([g.reader("date",["datetime"])],b.prototype,
"readDate",null);a([g.writer("date")],b.prototype,"writeDate",null);a([g.property({type:Boolean,json:{write:{target:"directShadows"}}})],b.prototype,"directShadowsEnabled",void 0);a([g.reader("directShadowsEnabled",["directShadows"])],b.prototype,"readDirectShadowsEnabled",null);a([g.writer("directShadowsEnabled")],b.prototype,"writedirectShadowsEnabled",null);a([g.property({type:Number,json:{write:!0}})],b.prototype,"displayUTCOffset",void 0);a([g.writer("displayUTCOffset")],b.prototype,"writeDisplayUTCOffset",
null);return b=d=a([g.subclass("esri.webscene.Lighting")],b);var d}(g.declared(e))})},"esri/webscene/support/Description":function(){define("require exports ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../core/JSONSupport ../../core/accessorSupport/decorators".split(" "),function(r,m,p,a,e,g){Object.defineProperty(m,"__esModule",{value:!0});r=function(e){function b(){var a=null!==e&&e.apply(this,arguments)||this;a.text="";return a}p(b,e);d=b;b.prototype.clone=function(){return new d({text:this.text})};
a([g.property({type:String,json:{write:!0}})],b.prototype,"text",void 0);return b=d=a([g.subclass("esri.webscene.support.Description")],b);var d}(g.declared(e));m.default=r})},"esri/webscene/support/Title":function(){define("require exports ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../core/JSONSupport ../../core/accessorSupport/decorators".split(" "),function(r,m,p,a,e,g){Object.defineProperty(m,"__esModule",{value:!0});r=function(e){function b(){var a=null!==
e&&e.apply(this,arguments)||this;a.text="";return a}p(b,e);d=b;b.prototype.clone=function(){return new d({text:this.text})};a([g.property({type:String,json:{write:{isRequired:!0}}})],b.prototype,"text",void 0);return b=d=a([g.subclass("esri.webscene.support.Title")],b);var d}(g.declared(e));m.default=r})},"esri/webscene/support/Thumbnail":function(){define("require exports ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../core/JSONSupport ../../core/accessorSupport/decorators".split(" "),
function(r,m,p,a,e,g){Object.defineProperty(m,"__esModule",{value:!0});r=function(e){function b(){var a=null!==e&&e.apply(this,arguments)||this;a.url="";return a}p(b,e);d=b;b.prototype.clone=function(){return new d({url:this.url})};a([g.property({type:String,json:{write:{isRequired:!0}}})],b.prototype,"url",void 0);return b=d=a([g.subclass("esri.webscene.support.Thumbnail")],b);var d}(g.declared(e));m.default=r})},"esri/webscene/InitialViewProperties":function(){define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../Viewpoint ../core/Accessor ../geometry/SpatialReference ./Environment ../core/accessorSupport/decorators".split(" "),
function(r,m,p,a,e,g,h,b,d){return function(g){function f(a){a=g.call(this,a)||this;a.environment=new b;a.spatialReference=null;a.viewpoint=null;return a}p(f,g);m=f;Object.defineProperty(f.prototype,"viewingMode",{set:function(a){"local"!==a&&"global"!==a||this._set("viewingMode",a)},enumerable:!0,configurable:!0});f.prototype.clone=function(){return new m({environment:this.environment.clone(),spatialReference:this.spatialReference?this.spatialReference.clone():null,viewingMode:this.viewingMode,viewpoint:this.viewpoint?
this.viewpoint.clone():null})};a([d.property({type:b,json:{write:{isRequired:!0}}})],f.prototype,"environment",void 0);a([d.property({type:h})],f.prototype,"spatialReference",void 0);a([d.property()],f.prototype,"viewingMode",null);a([d.property({type:e,json:{write:{isRequired:!0}}})],f.prototype,"viewpoint",void 0);return f=m=a([d.subclass("esri.webscene.InitialViewProperties")],f);var m}(d.declared(g))})},"esri/webscene/Version":function(){define(["require","exports","../core/tsSupport/extendsHelper",
"../core/Version"],function(r,m,p,a){Object.defineProperty(m,"__esModule",{value:!0});r=function(a){function e(e,b){return a.call(this,e,b,"webscene")||this}p(e,a);Object.defineProperty(e.prototype,"supportsGround",{get:function(){return this.since(1,8)},enumerable:!0,configurable:!0});Object.defineProperty(e.prototype,"supportsVisibleElevationLayersInSlides",{get:function(){return this.lessThan(1,8)},enumerable:!0,configurable:!0});return e}(a.Version);m.Version=r;m.default=r})},"esri/core/Version":function(){define(["require",
"exports","./Error"],function(r,m,p){Object.defineProperty(m,"__esModule",{value:!0});r=function(){function a(a,g,h){void 0===h&&(h="");this.major=a;this.minor=g;this._context=h}a.prototype.lessThan=function(a,g){return this.major<a||a===this.major&&this.minor<g};a.prototype.since=function(a,g){return!this.lessThan(a,g)};a.prototype.validate=function(a){if(this.major!==a.major)throw new p((this._context&&this._context+":")+"unsupported-version","Required major "+(this._context&&this._context+" ")+
"version is '"+this.major+"', but got '${version.major}.${version.minor}'",{version:a});};a.prototype.clone=function(){return new a(this.major,this.minor,this._context)};a.parse=function(e,g){void 0===g&&(g="");var h=e.split("."),b=h[0],h=h[1],d=/^\s*\d+\s*$/;if(!b||!b.match||!b.match(d))throw new p((g&&g+":")+"invalid-version","Expected major version to be a number, but got '${version}'",{version:e});if(!h||!h.match||!h.match(d))throw new p((g&&g+":")+"invalid-version","Expected minor version to be a number, but got '${version}'",
{version:e});e=parseInt(b,10);b=parseInt(h,10);return new a(e,b,g)};return a}();m.Version=r})},"*noref":1}});
define("require exports ./core/tsSupport/declareExtendsHelper ./core/tsSupport/decorateHelper ./core/tsSupport/paramHelper ./Map ./core/Error ./core/requireUtils ./core/promiseUtils ./core/JSONSupport ./core/Loadable ./core/Collection ./core/urlUtils ./core/Logger ./core/accessorSupport/read ./core/accessorSupport/originUtils ./support/webSceneUtils ./Viewpoint ./kernel ./geometry/support/jsonUtils ./geometry/Extent ./geometry/HeightModelInfo ./geometry/SpatialReference ./geometry/support/heightModelInfoUtils ./webscene/Presentation ./webscene/InitialViewProperties ./webscene/Environment ./webscene/Version ./portal/PortalItem ./portal/Portal dojo/has dojo/_base/lang ./core/accessorSupport/decorators".split(" "),function(r,
m,p,a,e,g,h,b,d,t,f,F,x,w,z,G,A,B,C,D,M,N,v,J,y,K,O,H,n,I,S,u,q){var E=w.getLogger("esri.WebScene"),L=new H.default(1,9);return function(f){function c(a){a=f.call(this)||this;a.clippingArea=null;a.clippingEnabled=!1;a.heightModelInfo=null;a.sourceVersion=null;a.supportsHeightModelInfo=!0;a.presentation=null;a.initialViewProperties=null;a.portalItem=null;a.resourceInfo=null;a.authoringApp=null;a.authoringAppVersion=null;a._isAuthoringAppSetByUser=!1;a._isAuthoringAppVersionSetByUser=!1;return a}p(c,
f);c.prototype.initialize=function(){this.when().catch(function(a){E.error("#load()","Failed to load web scene",a)});if(this.resourceInfo){var a=void 0;try{a=this._validateJSON(this.resourceInfo)}catch(l){this.addResolvingPromise(d.reject(l));return}this.read(a);this.addResolvingPromise(this._validateSpatialReference());this.addResolvingPromise(this._validateHeightModelInfo())}};c.prototype.getDefaults=function(a){return u.mixin(this.inherited(arguments),{presentation:{},initialViewProperties:{}})};
c.prototype.writeClippingArea=function(a,l){l.clippingArea||(l.clippingArea={});l.clippingArea.geometry=a.toJSON()};c.prototype.readClippingEnabled=function(a,l){return l.clippingArea?!!l.clippingArea.clip:!1};c.prototype.writeClippingEnabled=function(a,l){this.clippingArea&&(l.clippingArea||(l.clippingArea={}),l.clippingArea.clip=a)};c.prototype.writeLayers=function(a,l,b,d){var k=this,c=u.mixin({},d,{layerContainerType:"operational-layers"});a=a.filter(function(a){return k.verifyWriteLayer(a,c)}).map(function(a){return a.write(null,
c)}).filter(function(a){return!!a});l[b]=a.toArray()};c.prototype.verifyWriteLayer=function(a,l){return a.write?!0:(l&&l.messages&&l.messages.push(new h("layer:unsupported","Layers ("+a.title+", "+a.id+") of type '"+a.declaredClass+"' cannot be persisted in web scenes",{layer:a})),!1)};c.prototype.readSourceVersion=function(a,l){a=l.version.split(".");l=a[1];return new H.default(parseInt(a[0],10),parseInt(l,10))};c.prototype.writeSourceVersion=function(a,l,b){l[b]=L.major+"."+L.minor};Object.defineProperty(c.prototype,
"authoringApp",{set:function(a){this._isAuthoringAppSetByUser=!0;this._set("authoringApp",a)},enumerable:!0,configurable:!0});c.prototype.writeAuthoringApp=function(a,b){b.authoringApp=a&&this._isAuthoringAppSetByUser?a:"ArcGIS API for JavaScript"};Object.defineProperty(c.prototype,"authoringAppVersion",{set:function(a){this._isAuthoringAppVersionSetByUser=!0;this._set("authoringAppVersion",a)},enumerable:!0,configurable:!0});c.prototype.writeAuthoringAppVersion=function(a,b){b.authoringAppVersion=
a&&this._isAuthoringAppVersionSetByUser?a:C.version};c.prototype.writeGround=function(a,b,d,c){b[d]=a?a.write(null,c):{layers:[]}};c.prototype.readInitialViewProperties=function(a,b){a={};b.initialState&&b.initialState.environment&&(a.environment=O.fromJSON(b.initialState.environment));b.spatialReference&&(a.spatialReference=v.fromJSON(b.spatialReference));a.viewingMode=b.viewingMode||"global";b.initialState&&b.initialState.viewpoint&&(a.viewpoint=B.fromJSON(b.initialState.viewpoint));return new K(a)};
c.prototype.writeInitialViewProperties=function(a,b,d,c){a&&(d={},a.environment&&(d.environment=a.environment.write({},c)),a.viewpoint&&(d.viewpoint=a.viewpoint.write({},c)),0!==Object.keys(d).length&&(b.initialState=d),b.spatialReference=a.spatialReference?a.spatialReference.write({},c):v.WebMercator.toJSON(),b.viewingMode=null!=a.viewingMode?a.viewingMode:"global")};c.prototype.load=function(){this.addResolvingPromise(this._loadFromSource());return this.when()};c.prototype.read=function(a,b){var k=
this;b=u.mixin({},b,{origin:"web-scene"});var l=this._isAuthoringAppVersionSetByUser,d=this._isAuthoringAppSetByUser,c=arguments;z.readLoadable(this,a,function(b){return k.inherited(c,[a,b])},b);d||(this._isAuthoringAppSetByUser=!1);l||(this._isAuthoringAppVersionSetByUser=!1);if(a.baseMap&&Array.isArray(a.baseMap.elevationLayers)&&this.sourceVersion.supportsVisibleElevationLayersInSlides){var l=a.baseMap.elevationLayers.map(function(a){return{id:a.id}}),e=this.presentation.slides,f=function(a,b){return a.visibleLayers.some(function(a){return a.id===
b})},g=l.filter(function(a){return!e.some(function(b){return f(b,a.id)})});e.forEach(function(a){a.visibleLayers.addMany(g)})}return this};c.prototype._writeBasemapElevationLayers=function(a){var b=a.ground&&a.ground.layers;!a.baseMap&&b&&b.length&&(a.baseMap={title:"Basemap",baseMapLayers:[]});a.baseMap&&(a.baseMap.elevationLayers=u.clone(b))};c.prototype.write=function(a,b){if("loaded"!==this.loadStatus){var k=new h("webscene:not-loaded","Web scene must be loaded before it can be serialized");E.error("#toJSON()",
"Web scene must be loaded before it can be serialized",this.loadError||this.loadStatus);throw k;}b=u.mixin({},b,{origin:"web-scene"});k=this.inherited(arguments,[a,b]);this._writeBasemapElevationLayers(k);return k};c.prototype.save=function(a){var b=this;if(!this.portalItem)return E.error("save(): requires the .portalItem property to be set"),d.reject(new h("webscene:portal-item-not-set","Portal item to save to has not been set on the WebScene"));if("Web Scene"!==this.portalItem.type)return d.reject(new h("webscene:portal-item-wrong-type",
'Portal item needs to have type "Web Scene"'));var k,c;return this.load().then(function(){return b._loadObjectsWithLayers()}).then(function(){k=b._enableVerifyItemRelativeUrls({origin:"web-scene",url:b.portalItem.itemUrl&&x.urlToObject(b.portalItem.itemUrl),messages:[],portal:b.portalItem.portal||I.getDefault(),writtenProperties:[],blockedRelativeUrls:[]});c=b.write(null,k);return b._verifySave(c,k,a).then(function(){b._updateTypeKeywords(b.portalItem);return b.portalItem.update({data:c})})}).then(function(){G.updateOrigins(k);
return d.resolve(b.portalItem)})};c.prototype.saveAs=function(a,b){var k=this;if(!a)return E.error("saveAs(portalItem): requires a portal item parameter"),d.reject(new h("webscene:portal-item-required","saveAs requires a portal item to save to"));if(a.type&&"Web Scene"!==a.type||a.id)return d.reject(new h("webscene:portal-item-already-exists","WebScene can only saveAs to a new and empty portal item"));var c=a.portal||I.getDefault(),l,e;return this.load().then(function(){return k._loadObjectsWithLayers()}).then(function(){l=
k._enableVerifyItemRelativeUrls({origin:"web-scene",url:null,messages:[],portal:c,writtenProperties:[],blockedRelativeUrls:[]});e=k.write(null,l);return k._verifySaveAs(e,l,b).then(function(){return c._signIn()})}).then(function(){a.type="Web Scene";a.portal=c;k._updateTypeKeywords(a);return c.user.addItem({item:a,folder:b&&b.folder,data:e})}).then(function(){k.portalItem=a;t.prototype.read.call(k,{version:e.version,authoringApp:e.authoringApp,authoringAppVersion:e.authoringAppVersion},{name:"web-scene",
url:a.itemUrl&&x.urlToObject(a.itemUrl)});G.updateOrigins(l);return d.resolve(a)})};c.prototype._verifySave=function(a,c,e,f){void 0===f&&(f=!1);var k=c.messages.filter(function(a){return"error"===a.type}).map(function(a){return new h(a.name,a.message,a.details)});c.blockedRelativeUrls&&(k=k.concat(c.blockedRelativeUrls.map(function(a){return new h("url:unsupported","Relative url '"+a+"' is not supported in Web Scene")})));e&&e.ignoreUnsupported&&(k=k.filter(function(a){return"layer:unsupported"!==
a.name&&"symbol:unsupported"!==a.name&&"property:unsupported"!==a.name}));e&&e.strictSchemaValidationEnabled||(k=k.filter(function(a){return"web-document-write:property-required"!==a.name}));var l=e&&e.strictSchemaValidationEnabled;return(l?b.when(r,"./webscene/validator").then(function(b){b=b.validate(a);if(0<b.length){var k="webscene did not validate:\n"+b.join("\n");E.error((f?"saveAs":"save")+"(): "+k)}return b.map(function(a){return new h("webscene:schema-validation",a)})}).then(function(a){return l&&
0<a.length?(a=A.createSchemaValidationError(a.concat(k)),d.reject(a)):k}):d.resolve(k)).then(function(a){if(0<a.length)return d.reject(new h("webscene:save","Failed to save webscene due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:a}))})};c.prototype._verifySaveAs=function(a,b,c){return this.canSaveAs(b)?d.reject(A.createCopyError()):this._verifySave(a,b,c,!0)};c.prototype.verifySaveAs=function(a){var b=this._enableVerifyItemRelativeUrls({origin:"web-scene",
messages:[]}),k=this.write(null,b);return this._verifySaveAs(k,b,a)};c.prototype.canSaveAs=function(a){a||(a=this._enableVerifyItemRelativeUrls({origin:"web-scene",messages:[]}),this.write(null,a));return a.verifyItemRelativeUrls&&0<a.verifyItemRelativeUrls.writtenUrls.length};c.prototype.updateFrom=function(a,b){void 0===b&&(b={});b.environmentExcluded||(this.initialViewProperties.environment=O.prototype.clone.apply(a.environment));b.viewpointExcluded||(this.initialViewProperties.viewpoint=a.viewpoint.clone());
this.initialViewProperties.spatialReference=a.spatialReference.clone();this.initialViewProperties.viewingMode=a.viewingMode;a.clippingArea?a.clippingArea!==this.clippingArea&&(this.clippingArea=a.clippingArea.clone(),this.clippingEnabled=!0):this.clippingEnabled=!1;a.heightModelInfo&&(this.heightModelInfo=a.heightModelInfo.clone());a.map===this&&a.allLayerViews.forEach(function(a){a.layer.visible=a.visible})};c.prototype._loadFromSource=function(){return this.resourceInfo?this._loadFromJSON(this.resourceInfo,
{origin:"web-scene"}):this.portalItem&&this.portalItem.id?this._loadFromItem(this.portalItem):this._loadObjectsWithLayers()};c.prototype._readAndLoadFromJSON=function(a,b){a=this._validateJSON(a,b&&b.url&&b.url.path);this.read(a,b);return this._loadFromJSON(a,b)};c.prototype._extractOperationalLayers=function(a){var b=this,c=[];if(!this.sourceVersion.supportsGround&&a.baseMap&&Array.isArray(a.baseMap.elevationLayers))for(var d=0,k=a.baseMap.elevationLayers;d<k.length;d++)c.push(k[d]);var e=[],f=function(a){a.layers&&
(a.layers=a.layers.filter(f));return"ArcGISTiledElevationServiceLayer"===a.layerType?(b.sourceVersion.supportsGround||e.push(a),!1):!0};return{operationalLayers:a.operationalLayers?a.operationalLayers.filter(f):[],operationalElevationLayers:e,basemapElevationLayers:c}};c.prototype._loadFromJSON=function(a,c){var k=this,e=new F;return this._validateSpatialReference().then(function(){return k._validateHeightModelInfo()}).then(function(){return b.when(r,"./portal/support/layersCreator")}).then(function(b){var f=
k._extractOperationalLayers(a),l=f.operationalLayers,g=f.operationalElevationLayers,f=f.basemapElevationLayers,h=[],m={context:u.mixin({},c,{layerContainerType:"operational-layers"})};k.portalItem&&(m.context.portal=k.portalItem.portal||I.getDefault());if(0<f.length){var n=u.mixin({},m,{context:u.mixin({},m.context,{layerContainerType:"ground"})});n.defaultLayerType="ArcGISTiledElevationServiceLayer";h.push.apply(h,b.populateOperationalLayers(k.ground.layers,f,n))}0<g.length&&(n=u.mixin({},m,{context:u.mixin({},
m.context,{layerContainerType:"ground"})}),n.defaultLayerType="ArcGISTiledElevationServiceLayer",h.push.apply(h,b.populateOperationalLayers(e,g,n)));l&&0<l.length&&h.push.apply(h,b.populateOperationalLayers(k.layers,l,m));return d.eachAlways(h).then(function(){})}).then(function(){return k._loadObjectsWithLayers()}).then(function(){k.ground.layers.addMany(e)})};c.prototype._loadObjectsWithLayers=function(){var a=[];this.ground&&a.push(this.ground.load());this.basemap&&a.push(this.basemap.load());
this.presentation.slides.forEach(function(b){b.basemap&&a.push(b.basemap.load())});return d.eachAlways(a).then(function(){})};c.prototype._loadFromItem=function(a){var b=this;return a.load().otherwise(function(a){throw new h("webscene:load-portal-item","Failed to load portal item",{error:a});}).then(function(){if("Web Scene"!==a.type)throw new h("webscene:invalid-portal-item","Invalid portal item type '${type}', expected 'Web Scene'",{type:a.type});}).then(function(){return a.fetchData()}).then(function(c){b.resourceInfo=
c;return b._readAndLoadFromJSON(c,{origin:"web-scene",url:x.urlToObject(a.itemUrl),portal:a.portal||I.getDefault()})})};c.prototype._validateSpatialReference=function(){var a=this.initialViewProperties,b=this._sceneSpatialReference,c;if("local"!==a.viewingMode){if(!b.isWGS84&&!b.isWebMercator)return d.reject(new h("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in global mode, only Web Mercator or WGS84 GCS are supported",{spatialReference:b,viewingMode:a.viewingMode}));
c=function(a){return!a||a.isWGS84||a.isWebMercator}}else{if(b.isGeographic)return d.reject(new h("webscene:unsupported-spatial-reference","Unsupported spatial reference (${spatialReference.wkid}) in local mode, only projected coordinate systems are supported",{spatialReference:b,viewingMode:a.viewingMode}));c=function(a){return!a||a.equals(b)}}var e=function(a){return a&&(a.camera&&a.camera.position&&a.camera.position.spatialReference||a.targetGeometry&&a.targetGeometry.spatialReference)},f=e(a.viewpoint);
return f&&!c(f)?d.reject(new h("webscene:incompatible-camera-spatial-reference","Camera spatial reference (${cameraSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",{cameraSpatialReference:f,sceneSpatialReference:b,viewingMode:a.viewingMode})):(f=this.presentation.slides.find(function(a){return!c(e(a.viewpoint))}))?(f=e(f.viewpoint),d.reject(new h("webscene:incompatible-slide-spatial-reference","Slide spatial reference (${slideSpatialReference.wkid}) is incompatible with the scene spatial reference (${sceneSpatialReference.wkid})",
{slideSpatialReference:f,sceneSpatialReference:b,viewingMode:a.viewingMode}))):d.resolve()};c.prototype._validateHeightModelInfo=function(){var a=J.validateWebSceneError(this.heightModelInfo,this._sceneSpatialReference);return a?d.reject(a):d.resolve()};c.prototype._validateJSON=function(a,b){void 0===b&&(b=null);a=this._sanitizeJSON(a,b);b=H.default.parse(a.version,"webscene");L.validate(b);a.version=b.major+"."+b.minor;1===b.major&&2>=b.minor&&(a.spatialReference=v.WebMercator.toJSON());return a};
c.prototype._sanitizeJSON=function(a,b){void 0===b&&(b=null);return{version:a.version||"",baseMap:a.baseMap,ground:a.ground,operationalLayers:a.operationalLayers,authoringApp:a.authoringApp||"",authoringAppVersion:a.authoringAppVersion||"",viewingMode:a.viewingMode||"global",presentation:a.presentation&&y.sanitizeJSON(a.presentation)||{},initialState:a.initialState,spatialReference:a.spatialReference||v.WebMercator.toJSON(),heightModelInfo:a.heightModelInfo||null,clippingArea:a.clippingArea}};c.prototype._updateTypeKeywords=
function(a){"local"===this.initialViewProperties.viewingMode?a.typeKeywords?-1===a.typeKeywords.indexOf("ViewingMode-Local")&&a.typeKeywords.push("ViewingMode-Local"):a.typeKeywords=["ViewingMode-Local"]:"global"===this.initialViewProperties.viewingMode&&a.typeKeywords&&(a.typeKeywords=a.typeKeywords.filter(function(a){return"ViewingMode-Local"!==a}));a.typeKeywords&&(a.typeKeywords=a.typeKeywords.filter(function(a,b,c){return c.indexOf(a)===b}))};Object.defineProperty(c.prototype,"_sceneSpatialReference",
{get:function(){return this.initialViewProperties.spatialReference||v.WebMercator},enumerable:!0,configurable:!0});Object.defineProperty(c.prototype,"_verifyItemRelativeRootPath",{get:function(){return this.portalItem&&this.portalItem.itemUrl?x.urlToObject(this.portalItem.itemUrl).path:null},enumerable:!0,configurable:!0});c.prototype._enableVerifyItemRelativeUrls=function(a){var b=this._verifyItemRelativeRootPath;b&&(a.verifyItemRelativeUrls={rootPath:b,writtenUrls:[]});return a};c.fromJSON=function(a){if(!a)throw new h("webscene:empty-resource",
"Expected a JSON resource but got nothing");return new this({resourceInfo:a})};c.VERSION=L;a([q.property({json:{read:{source:"baseMap"},write:{target:"baseMap"}}})],c.prototype,"basemap",void 0);a([q.property({type:M,json:{read:{source:"clippingArea.geometry",reader:D.fromJSON},write:{target:"clippingArea.geometry"}}})],c.prototype,"clippingArea",void 0);a([q.writer("clippingArea")],c.prototype,"writeClippingArea",null);a([q.property({type:Boolean,json:{write:{target:"clippingArea.clip"}}})],c.prototype,
"clippingEnabled",void 0);a([q.reader("clippingEnabled",["clippingArea"])],c.prototype,"readClippingEnabled",null);a([q.writer("clippingEnabled")],c.prototype,"writeClippingEnabled",null);a([q.property({type:N,json:{write:!0}})],c.prototype,"heightModelInfo",void 0);a([q.property({json:{write:{target:"operationalLayers"}}})],c.prototype,"layers",void 0);a([q.writer("layers")],c.prototype,"writeLayers",null);a([q.property({readOnly:!0,type:H.default,json:{type:String,write:{allowNull:!0,target:"version",
isRequired:!0}}})],c.prototype,"sourceVersion",void 0);a([q.reader("sourceVersion",["version"])],c.prototype,"readSourceVersion",null);a([q.writer("sourceVersion")],c.prototype,"writeSourceVersion",null);a([q.property({type:String,json:{write:{allowNull:!0}}})],c.prototype,"authoringApp",null);a([q.writer("authoringApp")],c.prototype,"writeAuthoringApp",null);a([q.property({type:String,json:{write:{allowNull:!0}}})],c.prototype,"authoringAppVersion",null);a([q.writer("authoringAppVersion")],c.prototype,
"writeAuthoringAppVersion",null);a([q.property({json:{write:{isRequired:!0,allowNull:!0,enabled:!0}}})],c.prototype,"ground",void 0);a([q.writer("ground")],c.prototype,"writeGround",null);a([q.property({type:y,json:{write:!0}})],c.prototype,"presentation",void 0);a([q.property({type:K})],c.prototype,"initialViewProperties",void 0);a([q.reader("initialViewProperties",["initialState.environment","spatialReference","viewingMode","initialState.viewpoint"])],c.prototype,"readInitialViewProperties",null);
a([q.writer("initialViewProperties",{"initialState.environment":{type:O},spatialReference:{type:v},viewingMode:{type:String},"initialState.viewpoint":{type:B}})],c.prototype,"writeInitialViewProperties",null);a([q.property({type:n})],c.prototype,"portalItem",void 0);a([q.property()],c.prototype,"resourceInfo",void 0);a([e(0,q.cast(n))],c.prototype,"saveAs",null);a([q.property()],c.prototype,"_sceneSpatialReference",null);a([q.property()],c.prototype,"_verifyItemRelativeRootPath",null);return c=a([q.subclass("esri.WebScene")],
c)}(q.declared(g,f,t))});