UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.64 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import"../../../../core/has.js";import{generateUID as t}from"../../../../core/uid.js";import{d as i}from"../../../../chunks/vec32.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as o}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{projectBuffer as s}from"../../../../geometry/projection/projectBuffer.js";import{Attribute as e}from"./Attribute.js";import{ContentObjectType as n}from"./ContentObjectType.js";import{Geometry as a}from"./Geometry.js";import{fromValues as h}from"./LocalOriginFactory.js";import{Object3D as m}from"./Object3D.js";import{gridLocalOriginFactory as c}from"./testUtils.js";import{VertexAttribute as g}from"./VertexAttribute.js";import{WebGLLayer as d}from"./WebGLLayer.js";import{RibbonLineMaterial as f}from"../materials/RibbonLineMaterial.js";class _{constructor(i){this._originSR=i,this._rootOriginId="root/"+t(),this._origins=new Map,this._objects=new Map,this._gridSize=5e5}getOrigin(t){const r=this._origins.get(this._rootOriginId);if(null==r){const i=c.rootOrigin;if(null!=i)return this._origins.set(this._rootOriginId,h(i[0],i[1],i[2],this._rootOriginId)),this.getOrigin(t);const r=h(t[0]+Math.random()-.5,t[1]+Math.random()-.5,t[2]+Math.random()-.5,this._rootOriginId);return this._origins.set(this._rootOriginId,r),r}const o=this._gridSize,s=Math.round(t[0]/o),e=Math.round(t[1]/o),n=Math.round(t[2]/o),a=`${s}/${e}/${n}`;let m=this._origins.get(a);const g=.5*o;if(i(l,t,r.vec3),l[0]=Math.abs(l[0]),l[1]=Math.abs(l[1]),l[2]=Math.abs(l[2]),l[0]<g&&l[1]<g&&l[2]<g){if(m){const r=Math.max(...l);i(l,t,m.vec3),l[0]=Math.abs(l[0]),l[1]=Math.abs(l[1]),l[2]=Math.abs(l[2]);if(Math.max(...l)<r)return m}return r}return m||(m=h(s*o,e*o,n*o,a),this._origins.set(a,m)),m}_drawOriginBox(t,i=o(1,1,0,1)){const r=window.view,h=r._stage,c=i.toString();if(!this._objects.has(c)){this._material=new f({width:2,color:i}),h.add(this._material);const t=new d(h,{pickable:!1}),r=new m({castShadow:!1});h.add(r),t.add(r),this._objects.set(c,r)}const _=this._objects.get(c),l=[0,1,5,4,0,2,1,7,6,2,0,1,3,7,5,4,6,2,0],p=l.length,j=new Array(3*p),b=new Array,u=.5*this._gridSize;for(let o=0;o<p;o++)j[3*o]=t[0]+(1&l[o]?u:-u),j[3*o+1]=t[1]+(2&l[o]?u:-u),j[3*o+2]=t[2]+(4&l[o]?u:-u),o>0&&b.push(o-1,o);s(j,this._originSR,0,j,r.renderSpatialReference,0,p);const M=new a(this._material,[[g.POSITION,new e(j,b,3,!0)]],null,n.Line);h.add(M),_.addGeometry(M)}get test(){}}const l=r();export{_ as GridLocalOriginFactory};