Ground.js 4.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 r}from"./chunks/tslib.es6.js";import e from"./Color.js";import o from"./core/Collection.js";import{referenceSetter as t}from"./core/collectionUtils.js";import{typeCast as s}from"./core/compilerUtils.js";import a from"./core/Error.js";import{JSONSupportMixin as i}from"./core/JSONSupport.js";import{clone as n}from"./core/lang.js";import l from"./core/Loadable.js";import{loadAll as p}from"./core/loadAll.js";import c from"./core/Logger.js";import{throwIfAborted as y,eachAlways as u}from"./core/promiseUtils.js";import{property as d}from"./core/accessorSupport/decorators/property.js";import{Integer as m}from"./core/accessorSupport/ensureType.js";import{subclass as f}from"./core/accessorSupport/decorators/subclass.js";import{writer as h}from"./core/accessorSupport/decorators/writer.js";import{NavigationConstraint as g}from"./ground/NavigationConstraint.js";import v from"./views/3d/support/debugFlags.js";import{transparencyToOpacity as j,opacityToTransparency as w}from"./webdoc/support/opacityUtils.js";var C;let S=C=class extends(i(l)){constructor(r){super(r),this.opacity=1,this.shading=!v.TERRAIN_USE_LEGACY_SHADING,this.surfaceColor=null,this.navigationConstraint=null,this.layers=new o;const e=r=>{r.parent&&r.parent!==this&&"remove"in r.parent&&r.parent.remove(r),r.parent=this,"elevation"!==r.type&&"base-elevation"!==r.type&&c.getLogger(this.declaredClass).error(`Layer '${r.title}, id:${r.id}' of type '${r.type}' is not supported as a ground layer and will therefore be ignored. Only layers of type 'elevation' are supported.`)},t=r=>{r.parent=null};this.layers.on("after-add",(r=>e(r.item))),this.layers.on("after-remove",(r=>t(r.item)))}initialize(){this.when().catch((r=>{c.getLogger(this.declaredClass).error("#load()","Failed to load ground",r)})),this.resourceInfo&&this.read(this.resourceInfo.data,this.resourceInfo.context)}destroy(){const r=this.layers.removeAll();for(const e of r)e.destroy();this.layers.destroy()}normalizeCtorArgs(r){return r&&"resourceInfo"in r&&(this._set("resourceInfo",r.resourceInfo),delete(r={...r}).resourceInfo),r}set layers(r){this._set("layers",t(r,this._get("layers")))}writeLayers(r,e,o,t){const i=[];r?(t={...t,layerContainerType:"ground"},r.forEach((r=>{if("write"in r){const e={};s(r)().write(e,t)&&i.push(e)}else t&&t.messages&&t.messages.push(new a("layer:unsupported",`Layers (${r.title}, ${r.id}) of type '${r.declaredClass}' cannot be persisted in the ground`,{layer:r}))})),e.layers=i):e.layers=i}load(r){return this.addResolvingPromise(this._loadFromSource(r)),Promise.resolve(this)}loadAll(){return p(this,(r=>{r(this.layers)}))}async queryElevation(r,e){await this.load({signal:e?.signal});const{ElevationQuery:o}=await import("./layers/support/ElevationQuery.js");y(e);const t=new o,s=this.layers.filter(A).toArray();return t.queryAll(s,r,e)}async createElevationSampler(r,e){await this.load({signal:e?.signal});const{ElevationQuery:o}=await import("./layers/support/ElevationQuery.js");y(e);const t=new o,s=this.layers.filter(A).toArray();return t.createSamplerAll(s,r,e)}clone(){const r={opacity:this.opacity,surfaceColor:n(this.surfaceColor),navigationConstraint:n(this.navigationConstraint),layers:this.layers.slice()};return this.loaded&&(r.loadStatus="loaded"),new C({resourceInfo:this.resourceInfo}).set(r)}read(r,e){this.resourceInfo||this._set("resourceInfo",{data:r,context:e}),super.read(r,e)}_loadFromSource(r){const e=this.resourceInfo;return e?this._loadLayersFromJSON(e.data,e.context,r):Promise.resolve()}_loadLayersFromJSON(r,e,o){const t=e&&e.origin||"web-scene",s=e&&e.portal||null,a=e&&e.url||null;return import("./layers/support/layersCreator.js").then((({populateOperationalLayers:e})=>{y(o);const i=[];if(r.layers&&Array.isArray(r.layers)){const o={context:{origin:t,url:a,portal:s,layerContainerType:"ground"},defaultLayerType:"ArcGISTiledElevationServiceLayer"};i.push(e(this.layers,r.layers,o))}return u(i)})).then((()=>{}))}};function I(r){return r&&"createElevationSampler"in r}function A(r){return"elevation"===r.type||I(r)}r([d({json:{read:!1}})],S.prototype,"layers",null),r([h("layers")],S.prototype,"writeLayers",null),r([d({readOnly:!0})],S.prototype,"resourceInfo",void 0),r([d({type:Number,nonNullable:!0,range:{min:0,max:1},json:{type:m,read:{reader:j,source:"transparency"},write:{writer:(r,e)=>{e.transparency=w(r)},target:"transparency"}}})],S.prototype,"opacity",void 0),r([d({type:Boolean,nonNullable:!0,json:{read:!1}})],S.prototype,"shading",void 0),r([d({type:e,json:{type:[m],write:(r,e)=>{e.surfaceColor=r.toJSON().slice(0,3)}}})],S.prototype,"surfaceColor",void 0),r([d({type:g,json:{write:!0}})],S.prototype,"navigationConstraint",void 0),S=C=r([f("esri.Ground")],S);const L=S;export{L as default};