UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.29 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import o from"../../core/Accessor.js";import{equals as r}from"../../core/arrayUtils.js";import t from"../../core/Collection.js";import s from"../../core/Error.js";import i from"../../core/Logger.js";import{mapCollection as n}from"../../core/mapCollectionUtils.js";import{watch as a,initial as m}from"../../core/reactiveUtils.js";import{convertToSpatialReferenceUnit as l,convertFromSpatialReferenceUnit as c}from"../../core/units.js";import{property as p,subclass as u}from"../../core/accessorSupport/decorators.js";import{e as d}from"../../chunks/earcut.js";import{create as h}from"../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as f}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as g}from"../../geometry/ellipsoidUtils.js";import y from"../../geometry/Point.js";import{project as w}from"../../geometry/projectionUtils.js";import{execute as v}from"../../geometry/operators/gx/operatorDensify.js";import{execute as j}from"../../geometry/operators/gx/operatorSimplify.js";import{fromSpatialReference as _,fromPolygon as A,toPolygon as x}from"../../geometry/operators/support/apiConverter.js";import{computeTranslationToOriginAndRotation as R}from"../../geometry/projection/computeTranslationToOriginAndRotation.js";import{newDoubleArray as b}from"../../geometry/support/DoubleArray.js";import{earth as N}from"../../geometry/support/Ellipsoid.js";import{newIndexArray as M}from"../../geometry/support/Indices.js";import{t as C}from"../../chunks/vec3.js";import{ElevationContext as U}from"./layers/graphics/ElevationContext.js";import{extrudePolygon as k}from"./layers/graphics/extrudeUtils.js";import{computeCentroid as V}from"./layers/graphics/graphicUtils.js";import{polygonToRenderInfo as H}from"./support/renderInfoUtils/polygon.js";import{FocusAreaColorNode as F}from"./webgl-engine/effects/focusArea/FocusAreaColorNode.js";import{FocusAreaMaskNode as I}from"./webgl-engine/effects/focusArea/FocusAreaMaskNode.js";import{FocusAreaOutlineItem as P}from"./webgl-engine/effects/focusArea/FocusAreaOutlineItem.js";const E=2e4;let G=class extends o{constructor(e){super(e),this._volumes=new Map,this._elevationContext=new U,this._outlineMap=new t}initialize(){this.addHandles([a(()=>({polygons:this.polygons,ready:this.view.groundView?.ready}),({polygons:e,ready:o})=>{o&&this._updateVolumes(e)},m)]),this._outlineMap=n(()=>this.areas?.areas,e=>new P({area:e,view:this.view}),{recycleItems:!0})}destroy(){this.removeAllHandles(),this._outlineMap.destroy()}get areas(){return this.view.map?.focusAreas}get enabledAreas(){return this.areas?.areas.toArray().filter(({enabled:e})=>e)??[]}get style(){return this.areas?.style??"bright"}get polygons(){return this.enabledAreas.reduce((e,o)=>e.concat(o.geometries.toArray()),new Array)}containsGeometry(e){if(0===this.polygons.length)return!0;const o=new y(e);return this.polygons.some(e=>e.contains(o))}_updateVolumes(e){this._extrude(e),this._ensureRenderNodes()}_extrude(e){if(!this.view.renderCoordsHelper||r(Array.from(this._volumes.keys()),e))return;const o=this.view.renderCoordsHelper,t=f(),n=1===o.viewingMode,a=h(),m=h(),p=this.view.spatialReference,u=_(p),y=g(p).radius/N.radius,U=l(5e5*y,"meters",p,!0);n||o.worldUpAtPosition([0,0,0],t);const F=new Map;for(const r of e){const e=this._volumes.get(r);if(e)F.set(r,e);else try{const e=p.equals(r.spatialReference)?r:w(r,p),s=Math.max(e.extent.width,e.extent.height),i=c(s,p,"meters",!0),l=Math.max(5*i,E*y),h=n?y/10:y,f=this._reduceGeometryHeight(e,l,h),g=V(f);if(null==g)continue;const _=A(f),N=j(_,u,!1)??_,I=v(N,U,0,0),P=x(I,p);if(null==P)continue;R(p,[g.x,g.y,0],a,o.spatialReference),m[12]=-a[12],m[13]=-a[13],m[14]=-a[14];const G=H(P,this.view.elevationProvider,o,this._elevationContext),{polygons:q,mapPositions:D,position:L}=G,S=new Array,T=new O(S,[a[12],a[13],a[14]]);for(const o of q){const e=o.count,r=d(o.mapPositions,o.holeIndices,3);if(0===r.length)continue;const s=r.length,i=6*e,a=i+s,c=b(3*i),p=M(a),u=M(s);k(L,D,r,o,c,null,null,null,p,u,l,t,n),C(c,c,m);const h=new z(c,u,p,l);S.push(h)}F.set(r,T)}catch(I){i.getLogger(this).error(new s("focusareasview:projection-failed","Failed to project focus area geometry to view spatial reference",{geometry:r,error:I}))}}this._volumes=F,0!==this.volumes.size&&this._maskRenderNode?.updateGeometries()}_ensureRenderNodes(){if(this.view.stage)if(0===this.volumes.size){const{_maskRenderNode:e,_colorRenderNode:o}=this;this._maskRenderNode=this._colorRenderNode=null,o?.fadeOut(()=>{e?.destroy(),o?.destroy()})}else this._maskRenderNode??=new I({focusAreasView:this}),this._colorRenderNode??=new F({focusAreasView:this}),this.view.stage.renderView.requestRender()}_reduceGeometryHeight(e,o,r){const t=-12e5*r,s=Math.max(-o/2,t),i=e.rings.map(e=>e.map(e=>[e[0],e[1],s])),n=e.clone();return n.rings=i,n.hasZ=!0,n}get volumes(){return this._volumes}};e([p()],G.prototype,"_volumes",void 0),e([p({constructOnly:!0})],G.prototype,"view",void 0),G=e([u("esri.views.3d.FocusAreasView")],G);class O{constructor(e,o){this.geometryVolumes=e,this.origin=o}}class z{constructor(e,o,r,t){this.positions=e,this.indicesBottom=o,this.indicesExtruded=r,this.height=t}}export{G as FocusAreasView};