@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.02 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{fromValues as e,create as t}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import r from"../../../geometry/SpatialReference.js";import{projectVectorToVector as o}from"../../../geometry/projection/projectVectorToVector.js";import{wrap as i}from"../../../geometry/support/aaBoundingBox.js";import{create as s}from"../../../geometry/support/aaBoundingRect.js";import{isPlateCarree as n}from"../../../geometry/support/spatialReferenceUtils.js";import{createPlanarGlobePatch as a,updateCornersPlanar as l,updateEdgesAndCornersPlanar as u,updateEdgeElevationsAndResolutionsPlanar as h}from"./PatchGeometryFactory.js";import{Tile as d,CenterPosition as c}from"./Tile.js";import{TileFrustumVisibility as m}from"./TileFrustumVisibility.js";import{intersectAabbInvDirBefore as p}from"../webgl-engine/lib/RayIntersections.js";class _ extends d{constructor(e,t,r,o,i){super(),this._horizontalScaleFactor=1,this._extentInRenderSR=s(),this._baseUsedMemory=900,this._subtreeGeometryElevationBoundMin=0,this._subtreeGeometryElevationBoundMax=0,this.init(e,t,r,o,i)}init(t,i,s,a,l){super.init(t,i,s,a,l);const u=l.view.renderSpatialReference,h=l.spatialReference,d=null!=u&&n(u)&&null!=h&&h.isGeographic?this.ellipsoid.radius*Math.PI/180:1;this._horizontalScaleFactor=d;const{isWebMercatorOnPlateCarree:c}=l,m=this._extentInRenderSR,p=this.extent;if(c){const t=e(p[0],p[1],0);o(t,r.WebMercator,t,r.PlateCarree);const i=e(p[2],p[3],0);o(i,r.WebMercator,i,r.PlateCarree),m[0]=t[0],m[1]=t[1],m[2]=i[0],m[3]=i[1]}else for(let e=0;e<4;++e)m[e]=p[e]*d;this.centerAtSeaLevel[0]=.5*(m[0]+m[2]),this.centerAtSeaLevel[1]=.5*(m[1]+m[3]),this.centerAtSeaLevel[2]=0,this._edgeLen=Math.max(m[2]-m[0],m[3]-m[1]),this._edgeLen2=this._edgeLen*this._edgeLen,this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateCenter();const e=this._extentInRenderSR,t=.5*(e[2]-e[0]),r=.5*(e[3]-e[1]),o=Math.sqrt(t*t+r*r),i=.5*(this.elevationBoundsMax-this.elevationBoundsMin),s=Math.max(o,i);this._center[c.MIDDLE][3]=s}_calculateFrustumVisibility(e){const t=this._aabb(),r=t[0],o=t[1],i=t[2],s=t[3],n=t[4],a=t[5];let l=!0;for(let u=0;u<6;u++){const t=e[u],h=t[0],d=t[1],c=t[2],p=t[3];if(h*(h>0?r:s)+d*(d>0?o:n)+c*(c>0?i:a)+p>=0)return m.OUTSIDE;l=l&&h*(h<0?r:s)+d*(d<0?o:n)+c*(c<0?i:a)+p<=0}return l?m.INSIDE:m.INTERSECTS}_aabb(){const e=this._extentInRenderSR;return i(e[0],e[1],Math.min(this.elevationBoundsMin,this._subtreeGeometryElevationBoundMin),e[2],e[3],Math.max(this.elevationBoundsMax,this._subtreeGeometryElevationBoundMax))}intersectsRay(e,t,r,o){return b[0]=1/t[0],b[1]=1/t[1],b[2]=1/t[2],p(this._aabb(),e,b,r,o)}createGeometry(){a(this.renderData,this._horizontalScaleFactor),this._updateSubtreeGeometryElevationsBounds(),this.setMemoryDirty()}_updateSubtreeGeometryElevationsBounds(){const e=this._subtreeGeometryElevationBoundMin,t=this._subtreeGeometryElevationBoundMax,r=this.renderData;let o=e,i=t;if(r){const e=r.geometry.boundingBox;o=e[2],i=e[5]}else if(!this.leaf){o=1/0,i=-1/0;for(const e of this.children){const t=e;o=Math.min(o,t._subtreeGeometryElevationBoundMin),i=Math.max(i,t._subtreeGeometryElevationBoundMax)}}if(o!==this._subtreeGeometryElevationBoundMin||i!==this._subtreeGeometryElevationBoundMax){this._subtreeGeometryElevationBoundMin=o,this._subtreeGeometryElevationBoundMax=i;const e=this.parent;e?._updateSubtreeGeometryElevationsBounds()}}get minimumVerticesPerSide(){return this.level<9?3:2}updateCornerElevations(){l(this.renderData,this._horizontalScaleFactor),this._updateSubtreeGeometryElevationsBounds()}updateEdgeElevations(){u(this.renderData,this._horizontalScaleFactor),this._updateSubtreeGeometryElevationsBounds()}updateEdgeElevationsAndResolutions(){h(this.renderData,this._horizontalScaleFactor),this._updateSubtreeGeometryElevationsBounds()}get horizontalScale(){return this._horizontalScaleFactor}}const b=t();export{_ as PlanarPatch};