@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.06 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{ArcadeDate as e}from"./ArcadeDate.js";import{ArcadeExecutionError as t}from"./executionError.js";import r from"./ImmutableArray.js";import{c as i}from"../chunks/languageUtils.js";import{isDate as n}from"../support/guards.js";const s="Voxel.Position",a="Voxel.LocalTime";function l(e){const i=e.getAttribute(s);if("string"!=typeof i)throw new t(null,"InvalidParameter",null);const n=JSON.parse(i);if(!Array.isArray(n)||"number"!=typeof n[0]||"number"!=typeof n[1]||"number"!=typeof n[2])throw new t(null,"InvalidParameter",null);return new r(n)}function o(r,i){const s=r.getAttribute(a);if(null==s)return null;if(!n(s))throw new t(null,"InvalidParameter",null);return e.dateJSAndZoneToArcadeDate(s,i)}class u{constructor(e,t){this._graphic=e,this._timeZone=t,this.arcadeDeclaredClass="esri.arcade.Voxel",this._layer=e.sourceLayer}static getDeclaredMembers(e){return e.fields.map(e=>{switch(e.name){case s:return{name:e.name,type:"array",elementType:{type:"number"}};case a:return{name:e.name,type:"date"};default:switch(e.type){case"string":return{name:e.name,type:"text"};case"double":return{name:e.name,type:"number"}}return null}}).filter(e=>null!=e)}getPosition(){return void 0!==this._position?this._position:this._position=l(this._graphic)}getLocalTime(){return void 0!==this._localTime?this._localTime:this._localTime=o(this._graphic,this._timeZone??"system")}keys(){return this._layer.fields.map(e=>e.name).sort()}hasField(e){return this._layer.fieldsIndex.has(e)}field(e){const r=this._layer.fieldsIndex?.get(e)?.name;if(null==r)throw new t(null,"FieldNotFound",null,{key:e});switch(r){case s:return this.getPosition();case a:return this.getLocalTime()}return this._graphic.attributes[r]??null}isEmpty(){return this._layer.fields.length<=0}castToText(e=!1){const t={...this._graphic.attributes};t[s]=this.getPosition(),a in t&&(t[a]=this.getLocalTime());for(const r of Object.keys(t))this._layer.fieldsIndex?.has(r)||delete t[r];return i(t,{useNumbersForDates:e})}}export{u as Voxel};