@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.17 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as r}from"tslib";import e from"./Color.js";import o from"./core/Collection.js";import t from"./core/CollectionFlattener.js";import{referenceSetter as s}from"./core/collectionUtils.js";import{typeCast as a}from"./core/compilerUtils.js";import{JSONSupportMixin as i}from"./core/JSONSupport.js";import{clone as n}from"./core/lang.js";import{Loadable as l}from"./core/Loadable.js";import{loadAll as p}from"./core/loadAll.js";import c from"./core/Logger.js";import{destroyMaybe as u}from"./core/maybe.js";import{isAbortError as y,throwIfAborted as d}from"./core/promiseUtils.js";import{property as m,subclass as h}from"./core/accessorSupport/decorators.js";import{Integer as f}from"./core/accessorSupport/ensureType.js";import g from"./ground/NavigationConstraint.js";import{GroundSymbol as v}from"./support/groundInstanceUtils.js";import{transparencyToOpacity as j,opacityToTransparency as w}from"./webdoc/support/opacityUtils.js";import{addLayerUnsupportedError as C}from"./webdoc/support/unsupportedErrors.js";import{writer as L}from"./core/accessorSupport/decorators/writer.js";var S,I;let b=I=class extends(i(l)){static{S=v}constructor(r){super(r),this[S]=!0,this.parent=null,this.opacity=1,this.surfaceColor=null,this.undergroundColor=new e("white"),this.navigationConstraint=null,this.layers=new o;const s=r=>{const{parent:e}=r;e&&e!==this&&"remove"in e&&e.remove?.(r),r.parent=this,"elevation"!==r.type&&"base-elevation"!==r.type&&c.getLogger(this).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.`)},a=r=>{r.parent=null};this.addHandles([this.layers.on("after-add",r=>s(r.item)),this.layers.on("after-remove",r=>a(r.item))]),this.allLayers=new t({getCollections:()=>[this.layers,this.parent?.basemap?.groundLayers]})}removeChildLayer(r){this.layers.remove(r)}initialize(){this.when().catch(r=>{y(r)||c.getLogger(this).error("#load()","Failed to load ground",r)}),this.resourceInfo&&this.read(this.resourceInfo.data,this.resourceInfo.context)}get integratedMeshGround(){const r=this.parent?.basemap?.groundLayers.at(0);return r?.replacesTerrain?r:null}destroy(){const r=this.layers.removeAll();for(const e of r)u(e);this.layers.destroy()}normalizeCtorArgs(r){return r&&"resourceInfo"in r&&(this._set("resourceInfo",r.resourceInfo),delete(r={...r}).resourceInfo),r}get loaded(){return super.loaded}get layers(){return this._get("layers")}set layers(r){this._set("layers",s(r,this._get("layers")))}writeLayers(r,e,o,t){const s=[];r?(t={...t,layerContainerType:"ground"},r.forEach(r=>{if("write"in r){const e={};a(r)().write(e,t)&&s.push(e)}else C(t,r)}),e.layers=s):e.layers=s}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{queryAll:o}=await import("./layers/support/ElevationQuery.js");d(e);const t=this.layers.filter(A).toArray();return this.parent?.basemap?.groundLayers&&this.parent?.basemap?.groundLayers.forEach(r=>{t.push(r)}),o(t,r,e)}async createElevationSampler(r,e){await this.load({signal:e?.signal});const{createSampler:o}=await import("./layers/support/ElevationQuery.js");d(e);return o(this.layers.filter(A).toArray(),r,e)}clone(){const r={opacity:this.opacity,surfaceColor:n(this.surfaceColor),undergroundColor:n(this.undergroundColor),navigationConstraint:n(this.navigationConstraint),layers:this.layers.slice()};return this.loaded&&(r.loadStatus="loaded"),new I({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()}async _loadLayersFromJSON(r,e,o){const t=e?.origin||"web-scene",s=e?.portal||null,a=e?.url||null,{populateOperationalLayers:i}=await import("./layers/support/layersCreator.js");d(o);const n=[];if(r.layers&&Array.isArray(r.layers)){const e={context:{origin:t,url:a,portal:s,layerContainerType:"ground"},defaultLayerType:"ArcGISTiledElevationServiceLayer"};n.push(i(this.layers,r.layers,e))}await Promise.allSettled(n)}};function A(r){return r&&"createElevationSampler"in r}r([m()],b.prototype,"parent",void 0),r([m()],b.prototype,"integratedMeshGround",null),r([m({json:{read:!1,write:{isRequired:!0}}})],b.prototype,"layers",null),r([m()],b.prototype,"allLayers",void 0),r([L("layers")],b.prototype,"writeLayers",null),r([m({readOnly:!0})],b.prototype,"resourceInfo",void 0),r([m({type:Number,nonNullable:!0,range:{min:0,max:1},json:{type:f,read:{reader:j,source:"transparency"},write:{writer:(r,e)=>{e.transparency=w(r)},target:"transparency"}}})],b.prototype,"opacity",void 0),r([m({type:e,json:{type:[f],write:(r,e)=>{e.surfaceColor=r.toJSON().slice(0,3)}}})],b.prototype,"surfaceColor",void 0),r([m({type:e})],b.prototype,"undergroundColor",void 0),r([m({type:g,json:{write:!0}})],b.prototype,"navigationConstraint",void 0),b=I=r([h("esri.Ground")],b);const E=b;export{E as default};