@arcgis/core 4.24.0-next.20220604 → 4.24.0-next.20220607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/analysis/Analysis.js +1 -1
  2. package/analysis/LineOfSightAnalysis.js +1 -1
  3. package/arcade/featureset/support/sqlUtils.js +1 -1
  4. package/assets/esri/core/workers/RemoteClient.js +1 -1
  5. package/assets/esri/core/workers/chunks/471beeb6924599209567.js +1 -0
  6. package/assets/esri/core/workers/chunks/{8102bb78fe96e6197e4e.js → 5da1b3dacc6c8c080a1c.js} +1 -1
  7. package/assets/esri/core/workers/chunks/b780228a520e1a0b100b.js +1 -0
  8. package/assets/esri/themes/base/widgets/_Daylight.scss +31 -32
  9. package/assets/esri/themes/base/widgets/_FloorFilter.scss +1 -0
  10. package/assets/esri/themes/base/widgets/_SnappingControls.scss +14 -0
  11. package/assets/esri/themes/dark/main.css +1 -1
  12. package/assets/esri/themes/light/main.css +1 -1
  13. package/assets/esri/themes/light/view.css +1 -1
  14. package/core/unitUtils.js +1 -1
  15. package/interfaces.d.ts +19 -41
  16. package/layers/LineOfSightLayer.js +1 -1
  17. package/networks/support/typeUtils.js +1 -1
  18. package/package.json +1 -1
  19. package/properties/defaultUnit.js +1 -1
  20. package/rest/networks/queryAssociations.js +5 -0
  21. package/rest/networks/support/Association.js +1 -1
  22. package/rest/networks/support/QueryAssociationsParameters.js +5 -0
  23. package/rest/networks/support/QueryAssociationsResult.js +5 -0
  24. package/smartMapping/support/adapters/FeatureLayerAdapter.js +1 -1
  25. package/support/revision.js +1 -1
  26. package/symbols/cim/CIMSymbolDrawHelper.js +1 -1
  27. package/views/2d/engine/webgl/mesh/templates/WGLLabelTemplate.js +1 -1
  28. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  29. package/views/3d/analysis/LineOfSight/LineOfSightVisualization.js +1 -1
  30. package/views/3d/interactive/editingTools/moveGraphic/GraphicMoveTool.js +1 -1
  31. package/views/3d/interactive/editingTools/reshapeGraphic/ReshapeOperation.js +1 -1
  32. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  33. package/views/3d/layers/i3s/I3SIntersectionHandler.js +1 -1
  34. package/views/3d/layers/i3s/I3SUtil.js +1 -1
  35. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  36. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  37. package/views/draw/DrawOperation.js +1 -1
  38. package/views/interactive/SegmentLabels.js +1 -1
  39. package/views/interactive/tooltip/Tooltip.js +1 -1
  40. package/views/interactive/tooltip/content/TooltipContent.js +1 -1
  41. package/views/support/lengthMeasurementUtils.js +1 -1
  42. package/widgets/Daylight/support/SliderWithDropdown.js +1 -1
  43. package/widgets/Slider.js +1 -1
  44. package/widgets/support/AnalysisViewModel.js +1 -1
  45. package/widgets/support/InteractiveAnalysisViewModel.js +1 -1
  46. package/widgets/support/SnappingControls/SnappingControlsViewModel.js +1 -1
  47. package/widgets/support/SnappingControls/SnappingListItem.js +1 -1
  48. package/widgets/support/SnappingControls.js +1 -1
  49. package/assets/esri/core/workers/chunks/0832c0f5e61b7b354a17.js +0 -1
  50. package/assets/esri/core/workers/chunks/6f41f039226a043a2d18.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import{getFeatureId as t}from"../../../../analysis/analysisUtils.js";import o from"../../../../core/Accessor.js";import i from"../../../../core/Evented.js";import n from"../../../../core/Handles.js";import{handlesGroup as r,makeHandle as s}from"../../../../core/handleUtils.js";import{equals as a}from"../../../../core/lang.js";import c from"../../../../core/Logger.js";import{isNone as l,isSome as p,abortMaybe as u,unwrapOr as d,none as g}from"../../../../core/maybe.js";import{createTask as h,ignoreAbortErrors as m}from"../../../../core/promiseUtils.js";import{watch as v,on as f,syncAndInitial as _,sync as b}from"../../../../core/reactiveUtils.js";import{property as y}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as C}from"../../../../core/accessorSupport/decorators/subclass.js";import{c as I,i as T,b as P,n as O,g as S,a as j,j as w,v as R}from"../../../../chunks/vec3.js";import{c as A}from"../../../../chunks/vec3f64.js";import{WatchUpdatingTracking as E}from"../../../../core/support/WatchUpdatingTracking.js";import{projectOrLoad as L,projectBoundingRect as F}from"../../../../geometry/projection.js";import{empty as H,containsPointObject as V,intersectsSegment as x}from"../../../../geometry/support/aaBoundingRect.js";import{fromPoints as D,create as N}from"../../../../geometry/support/ray.js";import{zValueInAbsoluteHeightMode as k}from"../../../../support/elevationInfoUtils.js";import{LineOfSightAnalysisResult as z}from"../LineOfSightAnalysisResult.js";import{LineOfSightComputation as M}from"./LineOfSightComputation.js";import{LineOfSightRayIntersector as U}from"./LineOfSightRayIntersector.js";import{logFailedGeometryProjectionError as G}from"../support/projectionUtils.js";import{StoreResults as q}from"../../webgl-engine/lib/IntersectorInterfaces.js";import{toGraphic as B,getIntersectedFeatureBSRadius as W}from"../../webgl-engine/lib/intersectorUtilsConversions.js";import{ImmediateTask as Z,TaskPriority as J}from"../../../support/Scheduler.js";import K from"../../../../geometry/Point.js";const Q=c.getLogger("esri.views.3d.analysis.LineOfSight.LineOfSightController");let X=class extends(i.EventedMixin(o)){constructor(e){super(e),this.updateOnCameraChange=!0,this._effectiveObserverElevationMode="absolute-height",this._observerFeatureId=null,this._updatingHandles=new E,this._frameTask=Z,this._handles=new n,this._computationHandles=new n,this._externalObserverUpdate=!0}initialize(){const e=this.view.resourceController?.scheduler;this._frameTask=e?e.registerTask(J.LINE_OF_SIGHT_TOOL):Z,this._intersector=new U({view:this.view}),this._handles.add([this._connectObserver(),this._connectComputations(),this._connectTargets()])}destroy(){this._handles.destroy(),this._computationHandles.destroy(),this._computations.removeAll(),this._updatingHandles.destroy()}get updating(){return this._frameTask.updating||this._updatingHandles.updating}get priority(){return this._frameTask.priority}set priority(e){this._frameTask.priority=e}get _computations(){return this.analysisViewData.computations}get _elevationAlignedObserverPositionRenderSpace(){return this.analysisViewData.observerEngineLocation}set _elevationAlignedObserverPositionRenderSpace(e){this.analysisViewData.observerEngineLocation=e}get _screenPixelSize(){return this.view.state.camera.computeScreenPixelSizeAt(this._elevationAlignedObserverPositionRenderSpace)}getLineOfSightComputationDependencies(e){const{inputPoints:t}=e;return{inputPoints:t}}_computeResult(e){const t=e.computation,{inputPoints:o,computationResult:i}=t,{observerAdjusted:n,targetAdjusted:r}=o,{start:s,end:a}=i;I(s,n),I(a,r);this._canCompute(t)?this._computeIntersection(e):this._interpolateIntersection(e),t.notifyResultChanged(),this.emit("result-changed",{target:e.computation.target,result:t.result})}_adjustStartEndPositionsFromFeatures(e){const o=this.view,{sceneIntersectionHelper:i}=o,{inputPoints:n}=e,{observer:r,target:s,observerFeatureId:a,targetFeatureId:c}=n;if(l(a)&&l(c))return;const u=T(r,s),d=this._intersector.intersector,g=D(n.observer,n.target,ee);d.options.store=q.ALL,i.intersectToolIntersectorRay(g,d);let h=null,m=null,v=null,f=null;for(const _ of d.results.all){const e=B(_,this.view);if(l(e)||l(_.distanceInRenderSpace))continue;const i=t(e);if(!l(i)){if(p(a)&&i===a){if(l(h)){const e=W(_,o);h=p(e)?e*oe:0}_.distanceInRenderSpace<h&&(v=_)}if(p(c)&&i===c){if(l(m)){const e=W(_,o);m=p(e)?e*oe:0}_.distanceInRenderSpace<u&&u-_.distanceInRenderSpace<m&&(f=_)}}}p(v)&&v.getIntersectionPoint(r)&&(n.observerSurfaceNormal=v.getTransformedNormal(A())),p(f)&&f.getIntersectionPoint(s)&&(n.targetSurfaceNormal=f.getTransformedNormal(A()))}_adjustStartEndPositions(e){const t=this._screenPixelSize,o=this.view,{inputPoints:i}=e,{observer:n,observerSurfaceNormal:r,target:s,targetSurfaceNormal:a,observerAdjusted:c,targetAdjusted:l}=i,u=$;p(r)?I(u,r):P(u,s,n);const d=t;O(u,u),S(u,u,Math.min(d,1)),j(c,n,u),p(a)?I(u,a):P(u,n,s);const g=o.state.camera.computeScreenPixelSizeAt(s);O(u,u),S(u,u,Math.min(g,1)),j(l,s,u)}_computeIntersection({computation:e,interpolationInfo:t}){const{view:o}=this,{sceneIntersectionHelper:i,renderCoordsHelper:n}=o;if(l(i))return;const r=this._intersector.intersector,{computationResult:s,inputPoints:a}=e,{observer:c,target:u}=a,{start:d,end:g}=s,h=D(d,g,ee);r.options.store=q.MIN,i.intersectToolIntersectorRay(h,r);const m=r.results.min,v=s.intersection,f=$;let _=!0;if(p(m)&&m.getIntersectionPoint(v)){I(t.originalIntersection,v),I(t.originalObserver,d),I(t.originalTarget,g),n.fromRenderCoords(v,f,o.spatialReference);const e=1-w(g,u)/w(d,u);_=w(c,v)>=e*w(c,u)}const b=new K(f,o.spatialReference);{const{result:t,target:i}=e;p(t)?(t.target=i,t.intersectedGraphic=_?null:B(m,o),t.intersectedLocation=_?null:b,t.visible=_):e.result=new z({target:i,elevationAlignedTargetLocation:e.elevationAlignedTargetLocation,intersectedGraphic:_?null:B(m,o),intersectedLocation:_?null:b,visible:_})}s.isValid=a.isValid=!0,s.isTargetVisible=_}_interpolateIntersection({computation:e,interpolationInfo:t}){const{computationResult:o,inputPoints:i}=e,{start:n,end:r,intersection:s}=o,{originalIntersection:a,originalObserver:c,originalTarget:l}=t;if(I(s,a),i.isValid){const e=$,t=w(c,a)/w(c,l);R(e,n,c),S(e,e,1-t),j(s,s,e),R(e,r,l),S(e,e,t),j(s,s,e),o.isValid=!0}else e.result=null,o.isValid=!1,o.isTargetVisible=!1}_canCompute(e){const t=this.analysisViewData.elevationAlignedObserver,o=this.view.frustum;if(l(t)||l(e.elevationAlignedTargetLocation)||l(o))return!1;const{observerAdjusted:i,targetAdjusted:n}=e.inputPoints,r=o.intersectsPoint(i),s=o.intersectsPoint(n);return r&&s}_onObserverPositionChange(e,o,i,n,r){if(this._externalObserverUpdate=r,l(e))return this.analysisViewData.elevationAlignedObserver=null,void(this._observerFeatureId=null);if(l(o))return G(this.analysis,e.spatialReference,Q),void(this.analysisViewData.elevationAlignedObserver=null);const s=this._getEffectiveElevationInfo(o,i);o.z=k(o.x,o.y,o.z,this.view.spatialReference,this.view,s),this._effectiveObserverElevationMode=s.mode,this.analysisViewData.elevationAlignedObserver=o;const a=A();this.view.renderCoordsHelper.toRenderCoords(o,a),this._elevationAlignedObserverPositionRenderSpace=a,this._observerFeatureId=t(n),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_onObserverRenderSpacePositionChangeForComputation(e,t,o,i){const{inputPoints:n}=e;switch(I(n.observer,t),o){case"on-the-ground":case"relative-to-ground":n.observerSurfaceNormal=this._intersector.adjustFromGroundIntersection(t,n.observer);break;case"relative-to-scene":case"absolute-height":n.observerSurfaceNormal=null}n.observerFeatureId=i,this._adjustStartEndPositions(e),e.notifyInputPointsChanged(),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_onTargetPositionChange(e,o,i,n,r,s=!0){const a=e.inputPoints;if(s&&(a.isValid=!1),l(i))return G(this.analysis,o.spatialReference,Q),e.elevationAlignedTargetLocation=null,void e.notifyInputPointsChanged();const c=this._getEffectiveElevationInfo(i,n);switch(i.z=k(i.x,i.y,i.z,this.view.spatialReference,this.view,c),e.elevationAlignedTargetLocation=i,this.view.renderCoordsHelper.toRenderCoords(e.elevationAlignedTargetLocation,a.target),c.mode){case"on-the-ground":case"relative-to-ground":a.targetSurfaceNormal=this._intersector.adjustFromGroundIntersection(a.target,a.targetAdjusted);break;case"relative-to-scene":case"absolute-height":a.targetSurfaceNormal=null}a.targetFeatureId=t(r),this._adjustStartEndPositionsFromFeatures(e),this._adjustStartEndPositions(e),e.notifyInputPointsChanged(),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_connectComputationToTarget(e){return r([v((()=>({computation:e,targetPosition:e.target.position,targetElevationInfo:e.target.elevationInfo,targetFeatureInfo:e.target.feature,projectedTargetPosition:L(e.target.position,this.view.spatialReference)})),(({computation:e,targetPosition:t,targetElevationInfo:o,targetFeatureInfo:i,projectedTargetPosition:n})=>{l(t)||(p(n.pending)?this._updatingHandles.addPromise(n.pending):this._onTargetPositionChange(e,t,n.geometry,o,i))}),_)])}_connectComputationToObserver(e){return v((()=>({computation:e,observer:this.analysisViewData.elevationAlignedObserver})),(({computation:e})=>{this._externalObserverUpdate&&(e.inputPoints.isValid=!1,e.notifyInputPointsChanged())}),_)}_connectComputationToRenderSpaceObserver(e){return v((()=>({computation:e,observer:this._elevationAlignedObserverPositionRenderSpace,observerElevationMode:this._effectiveObserverElevationMode,observerFeatureId:this._observerFeatureId})),(({computation:e,observer:t,observerElevationMode:o,observerFeatureId:i})=>{this._onObserverRenderSpacePositionChangeForComputation(e,t,o,i)}),_)}_connectComputationToCamera(e){return v((()=>({camera:this.view.state.camera,isDirty:this._isCameraDirty})),(({isDirty:t})=>{!this.updateOnCameraChange||e.inputPoints.isValid&&!t||e.notifyInputPointsChanged()}),b)}_connectComputationToSlicePlane(e){return v((()=>this.view.slicePlane),(()=>e.notifyInputPointsChanged()))}_connectComputationToElevation(e){const t=(o,i)=>{const n=this.analysis.observer,r=e.target;let s=null,a=null,c=null,u=null,d=null,g=null;if(p(n)&&p(n.position)){const e=L(n.position,this.view.spatialReference);if(p(e.pending))return this._updatingHandles.addPromise(e.pending),void e.pending.finally((()=>t(o,i)));s=e.geometry,a=n.elevationInfo,c=n.feature}if(p(r.position)){const e=L(r.position,this.view.spatialReference);if(p(e.pending))return this._updatingHandles.addPromise(e.pending),void e.pending.finally((()=>t(o,i)));u=e.geometry,d=r.elevationInfo,g=r.feature}l(s)&&l(u)||(F(o,i,te,this.view.spatialReference),p(n)&&p(s)&&V(te,s)&&this._onObserverPositionChange(n.position,s,a,c,!1),p(r)&&p(r.position)&&p(u)&&V(te,u)&&this._onTargetPositionChange(e,r.position,u,d,g,!1),p(s)&&p(u)&&x(te,s,u)&&e.notifyInputPointsChanged())};return this.view.elevationProvider.on("elevation-change",(e=>t(e.extent,e.spatialReference)))}_connectComputationToTask(e){let t=g;const o={computation:e,interpolationInfo:{originalIntersection:A(),originalObserver:A(),originalTarget:A()}};return r([v((()=>this.getLineOfSightComputationDependencies(e)),(()=>{t=u(t),t=h((async e=>{await m(this._frameTask.schedule((()=>this._computeResult(o)),e))}))}),{sync:!0,initial:!0,equals:a}),s((()=>t=u(t)))])}_connectComputation(e){const t=this._computationHandles;t.has(e)||t.add([this._connectComputationToTarget(e),this._connectComputationToObserver(e),this._connectComputationToRenderSpaceObserver(e),this._connectComputationToCamera(e),this._connectComputationToSlicePlane(e),this._connectComputationToElevation(e),this._connectComputationToTask(e)],e)}_disconnectComputation(e){this._computationHandles.remove(e)}_onComputationCollectionChange({added:e,removed:t}){for(const o of t)this._disconnectComputation(o);for(const o of e)this._connectComputation(o)}_onTargetCollectionChange({added:e,removed:t}){for(const o of t)this._removeTarget(o);for(const o of e)this._addTarget(o)}_onCursorTargetChange(e,t){p(t)&&this._removeTarget(t),p(e)&&this._addTarget(e)}_addTarget(e){this._computations.some((t=>t.target===e))||this._computations.add(new M({target:e}))}_removeTarget(e){const t=this._computations.findIndex((t=>t.target===e));this._computations.removeAt(t)}_connectObserver(){return r([v((()=>({observerPosition:p(this.analysis.observer)?this.analysis.observer.position:null,projectedObserverPosition:L(p(this.analysis.observer)?this.analysis.observer.position:null,this.view.spatialReference),observerElevationInfo:p(this.analysis.observer)?this.analysis.observer.elevationInfo:null,observerFeatureInfo:p(this.analysis.observer)?this.analysis.observer.feature:null})),(({observerPosition:e,projectedObserverPosition:t,observerElevationInfo:o,observerFeatureInfo:i})=>{p(t.pending)?this._updatingHandles.addPromise(t.pending):this._onObserverPositionChange(e,t.geometry,o,i,!0)}),_)])}_connectComputations(){return f((()=>this._computations),"change",(e=>this._onComputationCollectionChange(e)),{onListenerAdd:e=>{for(const t of e)this._connectComputation(t)},onListenerRemove:e=>{for(const t of e)this._disconnectComputation(t)},sync:!0})}_connectTargets(){return r([this._updatingHandles.addOnCollectionChange((()=>this.analysis.targets),(e=>this._onTargetCollectionChange(e)),{initial:!0,final:!0}),v((()=>this.analysisViewData.cursorTarget),((e,t)=>{this._onCursorTargetChange(e,t)}))])}get _isCameraDirty(){const e=this.analysisViewData.elevationAlignedObserver,{view:t}=this,{renderCoordsHelper:o}=t;if(l(e)||l(o))return!1;const i=$;o.toRenderCoords(e,i);const n=t.state.camera.computeScreenPixelSizeAt(i);return Math.abs((n-this._screenPixelSize)/this._screenPixelSize)>Y}_getEffectiveElevationInfo(e,t){return e.hasZ?d(t,{mode:"absolute-height",offset:0}):{mode:"on-the-ground",offset:0}}};e([y({constructOnly:!0})],X.prototype,"analysis",void 0),e([y({constructOnly:!0})],X.prototype,"analysisViewData",void 0),e([y({constructOnly:!0})],X.prototype,"view",void 0),e([y()],X.prototype,"updating",null),e([y()],X.prototype,"priority",null),e([y()],X.prototype,"updateOnCameraChange",void 0),e([y()],X.prototype,"_computations",null),e([y()],X.prototype,"_elevationAlignedObserverPositionRenderSpace",null),e([y()],X.prototype,"_effectiveObserverElevationMode",void 0),e([y()],X.prototype,"_observerFeatureId",void 0),e([y()],X.prototype,"_screenPixelSize",null),e([y({readOnly:!0})],X.prototype,"_updatingHandles",void 0),e([y()],X.prototype,"_frameTask",void 0),e([y()],X.prototype,"_isCameraDirty",null),X=e([C("esri.views.3d.analysis.LineOfSight.LineOfSightController")],X);const Y=.1,$=A(),ee=N(),te=H(),oe=.05;export{X as LineOfSightController};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import{getFeatureId as t}from"../../../../analysis/analysisUtils.js";import o from"../../../../core/Accessor.js";import i from"../../../../core/Evented.js";import n from"../../../../core/Handles.js";import{handlesGroup as r,makeHandle as s}from"../../../../core/handleUtils.js";import{equals as a}from"../../../../core/lang.js";import c from"../../../../core/Logger.js";import{isNone as l,isSome as p,abortMaybe as u,unwrapOr as d,none as g}from"../../../../core/maybe.js";import{createTask as h,ignoreAbortErrors as m}from"../../../../core/promiseUtils.js";import{watch as v,on as f,syncAndInitial as _,sync as b}from"../../../../core/reactiveUtils.js";import{property as y}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as C}from"../../../../core/accessorSupport/decorators/subclass.js";import{c as I,i as T,b as P,n as O,g as S,a as j,j as w,v as R}from"../../../../chunks/vec3.js";import{c as A}from"../../../../chunks/vec3f64.js";import{WatchUpdatingTracking as E}from"../../../../core/support/WatchUpdatingTracking.js";import{projectOrLoad as L,projectBoundingRect as F}from"../../../../geometry/projection.js";import{empty as V,containsPointObject as H,intersectsSegment as x}from"../../../../geometry/support/aaBoundingRect.js";import{fromPoints as D,create as N}from"../../../../geometry/support/ray.js";import{zValueInAbsoluteHeightMode as k}from"../../../../support/elevationInfoUtils.js";import{LineOfSightAnalysisResult as z}from"../LineOfSightAnalysisResult.js";import{LineOfSightComputation as M}from"./LineOfSightComputation.js";import{LineOfSightRayIntersector as U}from"./LineOfSightRayIntersector.js";import{logFailedGeometryProjectionError as G}from"../support/projectionUtils.js";import{StoreResults as q}from"../../webgl-engine/lib/IntersectorInterfaces.js";import{toGraphic as B,getIntersectedFeatureBSRadius as W}from"../../webgl-engine/lib/intersectorUtilsConversions.js";import{ImmediateTask as Z,TaskPriority as J}from"../../../support/Scheduler.js";import K from"../../../../geometry/Point.js";const Q=c.getLogger("esri.views.3d.analysis.LineOfSight.LineOfSightController");let X=class extends(i.EventedMixin(o)){constructor(e){super(e),this.updateOnCameraChange=!0,this._effectiveObserverElevationMode="absolute-height",this._observerFeatureId=null,this._updatingHandles=new E,this._frameTask=Z,this._handles=new n,this._computationHandles=new n,this._externalObserverUpdate=!0}initialize(){const e=this.view.resourceController?.scheduler;this._frameTask=e?e.registerTask(J.LINE_OF_SIGHT_TOOL):Z,this._intersector=new U({view:this.view}),this._handles.add([this._connectObserver(),this._connectComputations(),this._connectTargets()])}destroy(){this._handles.destroy(),this._computationHandles.destroy(),this._computations.removeAll(),this._updatingHandles.destroy()}get updating(){return this._frameTask.updating||this._updatingHandles.updating}get priority(){return this._frameTask.priority}set priority(e){this._frameTask.priority=e}get _computations(){return this.analysisViewData.computations}get _elevationAlignedObserverPositionRenderSpace(){return this.analysisViewData.observerEngineLocation}set _elevationAlignedObserverPositionRenderSpace(e){this.analysisViewData.observerEngineLocation=e}get _screenPixelSize(){return this.view.state.camera.computeScreenPixelSizeAt(this._elevationAlignedObserverPositionRenderSpace)}getLineOfSightComputationDependencies(e){const{inputPoints:t}=e;return{inputPoints:t}}_computeResult(e){const t=e.computation,{inputPoints:o,computationResult:i}=t,{observerAdjusted:n,targetAdjusted:r}=o,{start:s,end:a}=i;I(s,n),I(a,r);this._canCompute(t)?this._computeIntersection(e):this._interpolateIntersection(e),t.notifyResultChanged(),this.emit("result-changed",{target:e.computation.target,result:t.result})}_adjustStartEndPositionsFromFeatures(e){const o=this.view,{sceneIntersectionHelper:i}=o,{inputPoints:n}=e,{observer:r,target:s,observerFeatureId:a,targetFeatureId:c}=n;if(l(a)&&l(c))return;const u=T(r,s),d=this._intersector.intersector,g=D(n.observer,n.target,ee);d.options.store=q.ALL,i.intersectToolIntersectorRay(g,d);let h=null,m=null,v=null,f=null;for(const _ of d.results.all){const e=B(_,this.view);if(l(e)||l(_.distanceInRenderSpace))continue;const i=t(e);if(!l(i)){if(p(a)&&i===a){if(l(h)){const e=W(_,o);h=p(e)?e*oe:0}_.distanceInRenderSpace<h&&(v=_)}if(p(c)&&i===c){if(l(m)){const e=W(_,o);m=p(e)?e*oe:0}_.distanceInRenderSpace<u&&u-_.distanceInRenderSpace<m&&(f=_)}}}p(v)&&v.getIntersectionPoint(r)&&(n.observerSurfaceNormal=v.getTransformedNormal(A())),p(f)&&f.getIntersectionPoint(s)&&(n.targetSurfaceNormal=f.getTransformedNormal(A()))}_adjustStartEndPositions(e){const t=this._screenPixelSize,o=this.view,{inputPoints:i}=e,{observer:n,observerSurfaceNormal:r,target:s,targetSurfaceNormal:a,observerAdjusted:c,targetAdjusted:l}=i,u=$;p(r)?I(u,r):P(u,s,n);const d=t;O(u,u),S(u,u,Math.min(d,1)),j(c,n,u),p(a)?I(u,a):P(u,n,s);const g=o.state.camera.computeScreenPixelSizeAt(s);O(u,u),S(u,u,Math.min(g,1)),j(l,s,u)}_computeIntersection({computation:e,interpolationInfo:t}){const{view:o}=this,{sceneIntersectionHelper:i,renderCoordsHelper:n}=o;if(l(i))return;const r=this._intersector.intersector,{computationResult:s,inputPoints:a}=e,{observer:c,target:u}=a,{start:d,end:g}=s,h=D(d,g,ee);r.options.store=q.MIN,i.intersectToolIntersectorRay(h,r);const m=r.results.min,v=s.intersection,f=$;let _=!0;if(p(m)&&m.getIntersectionPoint(v)){I(t.originalIntersection,v),I(t.originalObserver,d),I(t.originalTarget,g),n.fromRenderCoords(v,f,o.spatialReference);const e=1-w(g,u)/w(d,u);_=w(c,v)>=e*w(c,u)}const b=new K(f,o.spatialReference);{const{result:t,target:i}=e;p(t)?(t.target=i,t.intersectedGraphic=_?null:B(m,o),t.intersectedLocation=_?null:b,t.visible=_):e.result=new z({target:i,elevationAlignedTargetLocation:e.elevationAlignedTargetLocation,intersectedGraphic:_?null:B(m,o),intersectedLocation:_?null:b,visible:_})}s.isValid=a.isValid=!0,s.isTargetVisible=_}_interpolateIntersection({computation:e,interpolationInfo:t}){const{computationResult:o,inputPoints:i}=e,{start:n,end:r,intersection:s}=o,{originalIntersection:a,originalObserver:c,originalTarget:l}=t;if(I(s,a),i.isValid){const e=$,t=w(c,a)/w(c,l);R(e,n,c),S(e,e,1-t),j(s,s,e),R(e,r,l),S(e,e,t),j(s,s,e),o.isValid=!0}else e.result=null,o.isValid=!1,o.isTargetVisible=!1}_canCompute(e){const t=this.analysisViewData.elevationAlignedObserver,o=this.view.frustum;if(l(t)||l(e.elevationAlignedTargetLocation)||l(o))return!1;const{observerAdjusted:i,targetAdjusted:n}=e.inputPoints,r=o.intersectsPoint(i),s=o.intersectsPoint(n);return r&&s}_onObserverPositionChange(e,o,i,n,r){if(this._externalObserverUpdate=r,l(e))return this.analysisViewData.elevationAlignedObserver=null,void(this._observerFeatureId=null);if(l(o))return G(this.analysis,e.spatialReference,Q),void(this.analysisViewData.elevationAlignedObserver=null);const s=this._getEffectiveElevationInfo(o,i);o.z=k(o.x,o.y,o.z,this.view.spatialReference,this.view,s),this._effectiveObserverElevationMode=s.mode,this.analysisViewData.elevationAlignedObserver=o;const a=A();this.view.renderCoordsHelper.toRenderCoords(o,a),this._elevationAlignedObserverPositionRenderSpace=a,this._observerFeatureId=t(n),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_onObserverRenderSpacePositionChangeForComputation(e,t,o,i){const{inputPoints:n}=e;switch(I(n.observer,t),o){case"on-the-ground":case"relative-to-ground":n.observerSurfaceNormal=this._intersector.adjustFromGroundIntersection(t,n.observer);break;case"relative-to-scene":case"absolute-height":n.observerSurfaceNormal=null}n.observerFeatureId=i,this._adjustStartEndPositions(e),e.notifyInputPointsChanged(),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_onTargetPositionChange(e,o,i,n,r,s=!0){const a=e.inputPoints;if(s&&(a.isValid=!1),l(i))return G(this.analysis,o.spatialReference,Q),e.elevationAlignedTargetLocation=null,void e.notifyInputPointsChanged();const c=this._getEffectiveElevationInfo(i,n);switch(i.z=k(i.x,i.y,i.z,this.view.spatialReference,this.view,c),e.elevationAlignedTargetLocation=i,this.view.renderCoordsHelper.toRenderCoords(e.elevationAlignedTargetLocation,a.target),c.mode){case"on-the-ground":case"relative-to-ground":a.targetSurfaceNormal=this._intersector.adjustFromGroundIntersection(a.target,a.targetAdjusted);break;case"relative-to-scene":case"absolute-height":a.targetSurfaceNormal=null}a.targetFeatureId=t(r),this._adjustStartEndPositionsFromFeatures(e),this._adjustStartEndPositions(e),e.notifyInputPointsChanged(),this.priority=J.LINE_OF_SIGHT_TOOL_INTERACTIVE}_connectComputationToTarget(e){return r([v((()=>({computation:e,targetPosition:e.target.position,targetElevationInfo:e.target.elevationInfo,targetFeatureInfo:e.target.feature,projectedTargetPosition:L(e.target.position,this.view.spatialReference)})),(({computation:e,targetPosition:t,targetElevationInfo:o,targetFeatureInfo:i,projectedTargetPosition:n})=>{l(t)||(p(n.pending)?this._updatingHandles.addPromise(n.pending):this._onTargetPositionChange(e,t,n.geometry,o,i))}),_)])}_connectComputationToObserver(e){return v((()=>({computation:e,observer:this.analysisViewData.elevationAlignedObserver})),(({computation:e})=>{this._externalObserverUpdate&&(e.inputPoints.isValid=!1,e.notifyInputPointsChanged())}),_)}_connectComputationToRenderSpaceObserver(e){return v((()=>({computation:e,observer:this._elevationAlignedObserverPositionRenderSpace,observerElevationMode:this._effectiveObserverElevationMode,observerFeatureId:this._observerFeatureId})),(({computation:e,observer:t,observerElevationMode:o,observerFeatureId:i})=>{this._onObserverRenderSpacePositionChangeForComputation(e,t,o,i)}),_)}_connectComputationToCamera(e){return v((()=>({camera:this.view.state.camera,isDirty:this._isCameraDirty})),(({isDirty:t})=>{!this.updateOnCameraChange||e.inputPoints.isValid&&!t||e.notifyInputPointsChanged()}),b)}_connectComputationToSlicePlane(e){return v((()=>this.view.slicePlane),(()=>{e.inputPoints.isValid=!1,e.notifyInputPointsChanged()}))}_connectComputationToElevation(e){const t=(o,i)=>{const n=this.analysis.observer,r=e.target;let s=null,a=null,c=null,u=null,d=null,g=null;if(p(n)&&p(n.position)){const e=L(n.position,this.view.spatialReference);if(p(e.pending))return this._updatingHandles.addPromise(e.pending),void e.pending.finally((()=>t(o,i)));s=e.geometry,a=n.elevationInfo,c=n.feature}if(p(r.position)){const e=L(r.position,this.view.spatialReference);if(p(e.pending))return this._updatingHandles.addPromise(e.pending),void e.pending.finally((()=>t(o,i)));u=e.geometry,d=r.elevationInfo,g=r.feature}l(s)&&l(u)||(F(o,i,te,this.view.spatialReference),p(n)&&p(s)&&H(te,s)&&this._onObserverPositionChange(n.position,s,a,c,!1),p(r)&&p(r.position)&&p(u)&&H(te,u)&&this._onTargetPositionChange(e,r.position,u,d,g,!1),p(s)&&p(u)&&x(te,s,u)&&e.notifyInputPointsChanged())};return this.view.elevationProvider.on("elevation-change",(e=>t(e.extent,e.spatialReference)))}_connectComputationToTask(e){let t=g;const o={computation:e,interpolationInfo:{originalIntersection:A(),originalObserver:A(),originalTarget:A()}};return r([v((()=>this.getLineOfSightComputationDependencies(e)),(()=>{t=u(t),t=h((async e=>{await m(this._frameTask.schedule((()=>this._computeResult(o)),e))}))}),{sync:!0,initial:!0,equals:a}),s((()=>t=u(t)))])}_connectComputation(e){const t=this._computationHandles;t.has(e)||t.add([this._connectComputationToTarget(e),this._connectComputationToObserver(e),this._connectComputationToRenderSpaceObserver(e),this._connectComputationToCamera(e),this._connectComputationToSlicePlane(e),this._connectComputationToElevation(e),this._connectComputationToTask(e)],e)}_disconnectComputation(e){this._computationHandles.remove(e)}_onComputationCollectionChange({added:e,removed:t}){for(const o of t)this._disconnectComputation(o);for(const o of e)this._connectComputation(o)}_onTargetCollectionChange({added:e,removed:t}){for(const o of t)this._removeTarget(o);for(const o of e)this._addTarget(o)}_onCursorTargetChange(e,t){p(t)&&this._removeTarget(t),p(e)&&this._addTarget(e)}_addTarget(e){this._computations.some((t=>t.target===e))||this._computations.add(new M({target:e}))}_removeTarget(e){const t=this._computations.findIndex((t=>t.target===e));this._computations.removeAt(t)}_connectObserver(){return r([v((()=>({observerPosition:p(this.analysis.observer)?this.analysis.observer.position:null,projectedObserverPosition:L(p(this.analysis.observer)?this.analysis.observer.position:null,this.view.spatialReference),observerElevationInfo:p(this.analysis.observer)?this.analysis.observer.elevationInfo:null,observerFeatureInfo:p(this.analysis.observer)?this.analysis.observer.feature:null})),(({observerPosition:e,projectedObserverPosition:t,observerElevationInfo:o,observerFeatureInfo:i})=>{p(t.pending)?this._updatingHandles.addPromise(t.pending):this._onObserverPositionChange(e,t.geometry,o,i,!0)}),_)])}_connectComputations(){return f((()=>this._computations),"change",(e=>this._onComputationCollectionChange(e)),{onListenerAdd:e=>{for(const t of e)this._connectComputation(t)},onListenerRemove:e=>{for(const t of e)this._disconnectComputation(t)},sync:!0})}_connectTargets(){return r([this._updatingHandles.addOnCollectionChange((()=>this.analysis.targets),(e=>this._onTargetCollectionChange(e)),{initial:!0,final:!0}),v((()=>this.analysisViewData.cursorTarget),((e,t)=>{this._onCursorTargetChange(e,t)}))])}get _isCameraDirty(){const e=this.analysisViewData.elevationAlignedObserver,{view:t}=this,{renderCoordsHelper:o}=t;if(l(e)||l(o))return!1;const i=$;o.toRenderCoords(e,i);const n=t.state.camera.computeScreenPixelSizeAt(i);return Math.abs((n-this._screenPixelSize)/this._screenPixelSize)>Y}_getEffectiveElevationInfo(e,t){return e.hasZ?d(t,{mode:"absolute-height",offset:0}):{mode:"on-the-ground",offset:0}}};e([y({constructOnly:!0})],X.prototype,"analysis",void 0),e([y({constructOnly:!0})],X.prototype,"analysisViewData",void 0),e([y({constructOnly:!0})],X.prototype,"view",void 0),e([y()],X.prototype,"updating",null),e([y()],X.prototype,"priority",null),e([y()],X.prototype,"updateOnCameraChange",void 0),e([y()],X.prototype,"_computations",null),e([y()],X.prototype,"_elevationAlignedObserverPositionRenderSpace",null),e([y()],X.prototype,"_effectiveObserverElevationMode",void 0),e([y()],X.prototype,"_observerFeatureId",void 0),e([y()],X.prototype,"_screenPixelSize",null),e([y({readOnly:!0})],X.prototype,"_updatingHandles",void 0),e([y()],X.prototype,"_frameTask",void 0),e([y()],X.prototype,"_isCameraDirty",null),X=e([C("esri.views.3d.analysis.LineOfSight.LineOfSightController")],X);const Y=.1,$=A(),ee=N(),te=V(),oe=.05;export{X as LineOfSightController};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as i}from"../../../../chunks/tslib.es6.js";import t from"../../../../Color.js";import e from"../../../../core/Accessor.js";import o from"../../../../core/Handles.js";import{makeHandle as n}from"../../../../core/handleUtils.js";import{equals as s}from"../../../../core/lang.js";import{removeMaybe as r,destroyMaybe as l,isNone as a}from"../../../../core/maybe.js";import{watch as c,on as u}from"../../../../core/reactiveUtils.js";import{property as d}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as m}from"../../../../core/accessorSupport/decorators/subclass.js";import{c as h}from"../../../../chunks/mat4f64.js";import{b as p}from"../../../../chunks/vec3.js";import{d as f,c as g}from"../../../../chunks/vec3f64.js";import{LineVisualElement as v}from"../../interactive/visualElements/LineVisualElement.js";let V=class extends e{constructor(i){super(i),this._lineOfSightVisualizations=[],this._handle=null,this._computationHandles=new o}initialize(){this._handle=this._connectComputations()}destroy(){this._handle=r(this._handle),this._computationHandles=l(this._computationHandles)}get visible(){return this.analysisViewData.visible}get testInfo(){return{visualizations:this._lineOfSightVisualizations}}get _configuration(){return this.analysisViewData.configuration}createLineOfSightVisualization(){const i=this._configuration,e={view:this.view,attached:!0,width:i.outerWidth,innerWidth:i.innerWidth},o=t.toUnitRGBA(i.visibleOuterColor),n=t.toUnitRGBA(i.visibleInnerColor),s=t.toUnitRGBA(i.occludedOuterColor),r=t.toUnitRGBA(i.occludedInnerColor),l=t.toUnitRGBA(i.undefinedOuterColor),a=t.toUnitRGBA(i.undefinedInnerColor),c={visibleLineVisualElement:new v({...e,color:o,innerColor:n}),occludedLineVisualElement:new v({...e,color:s,innerColor:r}),undefinedLineVisualElement:new v({...e,color:l,innerColor:a})};return this._lineOfSightVisualizations.push(c),c}destroyLineOfSightVisualization(i){i.visibleLineVisualElement=l(i.visibleLineVisualElement),i.occludedLineVisualElement=l(i.occludedLineVisualElement),i.undefinedLineVisualElement=l(i.undefinedLineVisualElement),this._lineOfSightVisualizations.splice(this._lineOfSightVisualizations.indexOf(i),1)}updateLineOfSightVisualization(i,e){const o=this._configuration,{computationResult:n,inputPoints:s}=i,{start:r,end:l,intersection:c,isValid:u,isTargetVisible:d}=n,{observer:m}=s,h=_;h[12]=m[0],h[13]=m[1],h[14]=m[2];const g=p(y,r,m),v=p(C,l,m),V=p(O,c,m),{visibleLineVisualElement:L,occludedLineVisualElement:b,undefinedLineVisualElement:S}=e,z=a(this.analysisViewData.elevationAlignedObserver)||a(i.elevationAlignedTargetLocation),j=this.visible&&!z;L.visible=j,b.visible=j,S.visible=j,j&&(L.geometry=null,b.geometry=null,S.geometry=null,u?d?(L.geometry=[[f(g),f(v)]],L.transform=h,L.color=t.toUnitRGBA(o.visibleOuterColor)):(L.geometry=[[f(g),f(V)]],L.transform=h,L.color=t.toUnitRGBA(o.occludedOuterColor),b.geometry=[[f(V),f(v)]],b.transform=h):(S.geometry=[[f(g),f(v)]],S.transform=h))}getLineOfSightVisualizationDependencies(i){const{computationResult:t}=i,{occludedOuterColor:e,visibleOuterColor:o}=this._configuration;return{computationResult:t,occludedOuterColor:e,visibleOuterColor:o,visible:this.visible}}_connectComputation(i){const t=this._computationHandles;if(t.has(i))return;const e=this.createLineOfSightVisualization();t.add([c((()=>this.getLineOfSightVisualizationDependencies(i)),(()=>this.updateLineOfSightVisualization(i,e)),{sync:!0,initial:!0,equals:s}),n((()=>this.destroyLineOfSightVisualization(e)))],i)}_disconnectComputation(i){this._computationHandles.remove(i)}_connectComputations(){return u((()=>this.analysisViewData.computations),"change",(i=>this._onComputationsCollectionChange(i)),{sync:!0,onListenerAdd:i=>{for(const t of i)this._connectComputation(t)},onListenerRemove:i=>{for(const t of i)this._disconnectComputation(t)}})}_onComputationsCollectionChange({added:i,removed:t}){for(const e of t)this._disconnectComputation(e);for(const e of i)this._connectComputation(e)}};i([d({constructOnly:!0})],V.prototype,"analysis",void 0),i([d({constructOnly:!0})],V.prototype,"analysisViewData",void 0),i([d({constructOnly:!0})],V.prototype,"view",void 0),i([d({readOnly:!0})],V.prototype,"visible",null),i([d()],V.prototype,"testInfo",null),i([d()],V.prototype,"_configuration",null),V=i([m("esri.views.3d.analysis.LineOfSight.LineOfSightVisualization")],V);const y=g(),C=g(),O=g(),_=h();export{V as LineOfSightVisualization};
5
+ import{_ as i}from"../../../../chunks/tslib.es6.js";import e from"../../../../Color.js";import t from"../../../../core/Accessor.js";import o from"../../../../core/Handles.js";import{makeHandle as n}from"../../../../core/handleUtils.js";import{equals as s}from"../../../../core/lang.js";import{destroyMaybe as r,isNone as a}from"../../../../core/maybe.js";import{watch as l,on as c,initial as u}from"../../../../core/reactiveUtils.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as d}from"../../../../core/accessorSupport/decorators/subclass.js";import{c as h}from"../../../../chunks/mat4f64.js";import{b as p}from"../../../../chunks/vec3.js";import{d as f,c as v}from"../../../../chunks/vec3f64.js";import{LineVisualElement as g}from"../../interactive/visualElements/LineVisualElement.js";import{PointVisualElement as V}from"../../interactive/visualElements/PointVisualElement.js";let _=class extends t{constructor(i){super(i),this._lineOfSightVisualizations=[],this._computationHandles=new o}initialize(){this.own(this._connectComputations()),this._createObserverVisualization()}destroy(){this._computationHandles=r(this._computationHandles),this._observerVisualElement=r(this._observerVisualElement)}get visible(){return this.analysisViewData.visible}get testInfo(){return{visualizations:this._lineOfSightVisualizations}}get _configuration(){return this.analysisViewData.configuration}_createLineOfSightVisualization(){const i=this._configuration,t=this.view,o={view:t,attached:!0,width:i.outerWidth,innerWidth:i.innerWidth},n=e.toUnitRGBA(i.visibleOuterColor),s=e.toUnitRGBA(i.visibleInnerColor),r=e.toUnitRGBA(i.occludedOuterColor),a=e.toUnitRGBA(i.occludedInnerColor),l=e.toUnitRGBA(i.undefinedOuterColor),c=e.toUnitRGBA(i.undefinedInnerColor),u={visibleLineVisualElement:new g({...o,color:n,innerColor:s}),occludedLineVisualElement:new g({...o,color:r,innerColor:a}),undefinedLineVisualElement:new g({...o,color:l,innerColor:c}),targetVisualElement:new V({view:t,attached:!0,...b,size:8})};return this._lineOfSightVisualizations.push(u),u}_destroyLineOfSightVisualization(i){i.visibleLineVisualElement=r(i.visibleLineVisualElement),i.occludedLineVisualElement=r(i.occludedLineVisualElement),i.undefinedLineVisualElement=r(i.undefinedLineVisualElement),i.targetVisualElement=r(i.targetVisualElement),this._lineOfSightVisualizations.splice(this._lineOfSightVisualizations.indexOf(i),1)}_updateLineOfSightVisualization(i,t,o){const n=this._configuration,{computationResult:s,inputPoints:r}=i,{start:l,end:c,intersection:u,isValid:m,isTargetVisible:d}=s,{observer:h}=r,v=L;v[12]=h[0],v[13]=h[1],v[14]=h[2];const g=p(y,l,h),V=p(C,c,h),_=p(O,u,h),{visibleLineVisualElement:b,occludedLineVisualElement:E,undefinedLineVisualElement:w,targetVisualElement:z}=t,S=a(this.analysisViewData.elevationAlignedObserver)||a(i.elevationAlignedTargetLocation),A=this.visible&&!S;b.visible=A,E.visible=A,w.visible=A,z.visible=A,z.attached=!o.interactive,A&&(b.geometry=null,E.geometry=null,w.geometry=null,z.geometry=i.elevationAlignedTargetLocation,m?d?(b.geometry=[[f(g),f(V)]],b.transform=v,b.color=e.toUnitRGBA(n.visibleOuterColor),z.color=e.toUnitRGBA(n.visibleInnerColor)):(b.geometry=[[f(g),f(_)]],b.transform=v,b.color=e.toUnitRGBA(n.occludedOuterColor),E.geometry=[[f(_),f(V)]],E.transform=v,z.color=e.toUnitRGBA(n.occludedInnerColor)):(w.geometry=[[f(g),f(V)]],w.transform=v,z.color=e.toUnitRGBA(n.undefinedInnerColor)))}_getLineOfSightVisualizationDependencies(i){const{computationResult:e}=i,{occludedOuterColor:t,visibleOuterColor:o}=this._configuration;return{computationResult:e,occludedOuterColor:t,visibleOuterColor:o,visible:this.visible,interactive:this.analysisViewData.interactive}}_connectComputation(i){const e=this._computationHandles;if(e.has(i))return;const t=this._createLineOfSightVisualization();e.add([l((()=>this._getLineOfSightVisualizationDependencies(i)),(e=>this._updateLineOfSightVisualization(i,t,e)),{sync:!0,initial:!0,equals:s}),n((()=>this._destroyLineOfSightVisualization(t)))],i)}_disconnectComputation(i){this._computationHandles.remove(i)}_connectComputations(){return c((()=>this.analysisViewData.computations),"change",(i=>this._onComputationsCollectionChange(i)),{sync:!0,onListenerAdd:i=>{for(const e of i)this._connectComputation(e)},onListenerRemove:i=>{for(const e of i)this._disconnectComputation(e)}})}_onComputationsCollectionChange({added:i,removed:e}){for(const t of e)this._disconnectComputation(t);for(const t of i)this._connectComputation(t)}_createObserverVisualization(){const i=e.toUnitRGBA(this._configuration.visibleInnerColor),t=new V({view:this.view,attached:!1,color:i,...b});this._observerVisualElement=t,this.own(l((()=>({observer:this.analysisViewData.elevationAlignedObserver,interactive:this.analysisViewData.interactive})),(({observer:i,interactive:e})=>{a(i)||e?t.attached=!1:(t.geometry=i,this._observerVisualElement.attached=!0)}),u))}};i([m({constructOnly:!0})],_.prototype,"analysis",void 0),i([m({constructOnly:!0})],_.prototype,"analysisViewData",void 0),i([m({constructOnly:!0})],_.prototype,"view",void 0),i([m({readOnly:!0})],_.prototype,"visible",null),i([m()],_.prototype,"testInfo",null),i([m()],_.prototype,"_configuration",null),_=i([d("esri.views.3d.analysis.LineOfSight.LineOfSightVisualization")],_);const b={size:6,pixelSnappingEnabled:!1,primitive:"circle",elevationInfo:{mode:"absolute-height",offset:0},outlineSize:0},y=v(),C=v(),O=v(),L=h();export{_ as LineOfSightVisualization};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../../../chunks/tslib.es6.js";import i from"../../../../../core/Collection.js";import e from"../../../../../core/Evented.js";import{HandleOwnerMixin as o}from"../../../../../core/HandleOwner.js";import{makeHandle as n}from"../../../../../core/handleUtils.js";import{destroyMaybe as a,isNone as s,unwrap as r,isSome as p}from"../../../../../core/maybe.js";import{watch as l,initial as h}from"../../../../../core/reactiveUtils.js";import{property as c}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import"../../../../../core/accessorSupport/ensureType.js";import{subclass as m}from"../../../../../core/accessorSupport/decorators/subclass.js";import{makeDehydratedPoint as u}from"../../../../../layers/graphics/dehydratedFeatures.js";import{getGraphicEffectiveElevationInfo as d,getConvertedElevation as g}from"../../../../../support/elevationInfoUtils.js";import{getGraphicAttachmentOrigin as v}from"../../manipulatorUtils.js";import{SnappingVisualizer3D as f}from"../../SnappingVisualizer3D.js";import{SupportedGraphicResult as y}from"../isSupportedGraphicUtils.js";import{ManipulatorType as M}from"../ManipulatorType.js";import{canMoveZ as _}from"../manipulatorUtils.js";import{createVisualElements as w}from"../visualElementUtils.js";import{DISC_RADIUS as j}from"../manipulations/config.js";import{ManipulationType as b,MoveManipulation as S}from"../manipulations/MoveManipulation.js";import{shapeOrientation as x}from"../manipulations/moveUtils.js";import{MoveXYGraphicManipulation as E}from"../manipulations/MoveXYGraphicManipulation.js";import{isSupportedGraphic as O}from"./isSupportedGraphic.js";import{OutlineVisualElement as T}from"../../visualElements/OutlineVisualElement.js";import{GraphicState as A}from"../../../layers/graphics/GraphicState.js";import{dragGraphicMany as P,resetGraphicMany as X}from"../../../../interactive/dragEventPipeline.js";import{InteractiveToolBase as D}from"../../../../interactive/InteractiveToolBase.js";import{EditGeometryOperations as Y}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import G from"../../../../interactive/sketch/SketchTooltipOptions.js";import{SnappingContext as R}from"../../../../interactive/snapping/SnappingContext.js";import{SnappingPipeline as U}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{Tooltip as z}from"../../../../interactive/tooltip/Tooltip.js";import{TranslateGraphicTooltipInfo as k,TranslateZTooltipInfo as I}from"../../../../interactive/tooltip/TranslateTooltipInfos.js";import{euclideanHorizontalDistanceBetweenPoints as Z,verticalDistanceBetweenPoints as C}from"../../../../support/lengthMeasurementUtils.js";class H{constructor(t){this.allGraphics=t,this.type="graphic-move-start"}}class V{constructor(t,i,e){this.dx=t,this.dy=i,this.allGraphics=e,this.type="graphic-move"}}class N{constructor(t){this.allGraphics=t,this.type="graphic-move-stop"}}let F=class extends(o(e.EventedMixin(D))){constructor(t){super(t),this.graphics=new i,this.enableZ=!0,this.tooltipOptions=new G,this.type="move-3d",this._snappingPipeline=new U,this._tooltip=null}initialize(){const{graphics:t,view:i}=this;this._tooltip=new z({view:i}),this.own([t.on("change",(()=>this._refreshManipulators())),l((()=>this.tooltipOptions.enabled),(t=>{this._tooltip=t?new z({view:i}):a(this._tooltip)}),h)]),this._refreshManipulators(),this.finishToolCreation()}destroy(){this._tooltip=a(this._tooltip),this.graphics.removeAll(),this._set("view",null)}get updating(){return this.updatingHandles.updating}reset(){}_refreshManipulators(){this.handles.removeAll(),this._moveManipulation&&this._moveManipulation.destroy(),this.manipulators.removeAll();const t=this.graphics.toArray().filter((t=>O(t)===y.SUPPORTED)).map((t=>new L(t)));t.length&&(this._createManipulators(t),this._createVisualElements(t),this.handles.add(t.map((t=>this.view.trackGraphicState(t.state)))),this._updateMoveManipulation(t))}_createManipulators(t){for(const i of t){const e=i.state;i.manipulationXY=new E({tool:this,view:this.view,graphicState:e}),i.manipulationXY.forEachManipulator((t=>this.handles.add([t.events.on("immediate-click",(t=>{this.emit("immediate-click",{...t,graphic:e.graphic}),t.stopPropagation()})),t.events.on("grab-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new k({tooltipOptions:i}):this._tooltip.clear()}))]))),this.handles.add(i.manipulationXY.createDragPipeline(((i,e,o,n)=>this._buildDragEventPipeline(t,b.XY,i,e,o,n))))}this._createMoveManipulation(t)}_createMoveManipulation(t){const i=new S({tool:this,view:this.view,snapToScene:!1,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:!0,radius:1===t.length?S.radiusForSymbol(t[0].graphic.symbol):j});this._moveManipulation=i,i.elevationInfo={mode:"absolute-height",offset:0},i.forEachManipulator(((t,e)=>{this.handles.add(t.events.on("immediate-click",(e=>{i.zManipulation.hasManipulator(t)||1!==this.graphics.length||this.emit("immediate-click",{...e,graphic:this.graphics.getItemAt(0)}),e.stopPropagation()}))),e===M.TRANSLATE_XY&&this.handles.add(t.events.on("focus-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new k({tooltipOptions:i}):this._tooltip.clear()}))),e===M.TRANSLATE_Z&&this.handles.add(t.events.on("focus-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new I({tooltipOptions:i}):this._tooltip.clear()})))}));const e=()=>this._updateMoveManipulation(t);for(const n of t)this.handles.add([n.state.on("changed",e),l((()=>n.state.displaying),e)]);const o=t[t.length-1];this.handles.add(o.state.on("changed",(()=>this._updateMoveManipulationAngle(o)))),this.handles.add(i.createDragPipeline(((i,e,o,n,a)=>this._buildDragEventPipeline(t,i,e,o,n,a)),d(o.graphic),r(o.graphic.geometry).spatialReference,o.graphic)),this._updateMoveManipulationAngle(o)}_createVisualElements(t){for(const i of t){const e=i.graphic,o=w({view:this.view,graphic:e,forEachManipulator:t=>{i.manipulationXY.forEachManipulator(t),this._moveManipulation.forEachManipulator(t)},onManipulatorsChanged:()=>n()});s(o)||(i.geometryRepresentation=o.visualElement,i.geometryRepresentation instanceof T&&this.handles.add([i.geometryRepresentation.events.on("attachment-origin-changed",(()=>{i.state.isDraped||this._updateMoveManipulation(t)})),l((()=>i.state.isDraped),(()=>this._updateMoveManipulation(t)))]),this.handles.add(o))}}_updateMoveManipulationAngle(t){this._moveManipulation.angleDeferred=()=>x(t.graphic.geometry)}_updateMoveManipulation(t){const i=u(0,0,0,this.view.spatialReference);let e=0,o=!1;const n=this._moveManipulation;for(const a of t){if(!a.state.displaying)continue;const t=a.state.graphic;this.enableZ&&_(t)&&(o=!0);const n=a.geometryRepresentation instanceof T&&!a.state.isDraped?a.geometryRepresentation.attachmentOrigin:v(this.view,t);p(n)&&(i.x+=n.x,i.y+=n.y,i.z+=n.z,e++)}e>0?(i.x/=e,i.y/=e,i.z/=e,n.location=i,n.xyManipulation.available=!0,n.xyAxisManipulation.available=!0,n.zManipulation.available=o):n.available=!1}_buildDragEventPipeline(t,i,e,o,n,a){const s=[],r=[];let p=null,l=null;const h=()=>{for(const t of s)t.dragging=!1;s.length=0,r.length=0,p=null,l=null,this._moveManipulation.interactive=!0};if(1===t.length&&i===b.XY){const i=t[0].graphic;o=this._buildSnappingPipelineSteps(i,d(i),o,n,a)}const c=o.next((i=>{if("start"===i.action){s.length=0,r.length=0;for(const i of t)i.dragging||!i.manipulationXY.hasManipulator(e)&&i.manipulationXY.grabbing||(s.push(i),r.push(i.graphic),i.dragging=!0);if(0!==r.length&&(this._moveManipulation.interactive=!1,p=P(r,this.view.state.viewingMode),l=X(r),this.emit("graphic-move-start",new H(r)),this.destroyed))return null}return 0!==r.length?i:null})).next((t=>p(t))).next((t=>this._updateMoveTooltip(t,i))).next((t=>{switch(t.action){case"start":case"update":if(t.translationX||t.translationY||t.translationZ){const i=this.view.toScreen(t.mapStart),e=this.view.toScreen(t.mapEnd),o=e.x-i.x,n=e.y-i.y;if(this.emit("graphic-move",new V(o,n,r)),this.destroyed)return null}break;case"end":if(this.emit("graphic-move-stop",new N(r)),this.destroyed)return null;h()}}));return n.next((t=>l(t))).next((()=>{if(this.emit("graphic-move-stop",new N(r)),this.destroyed)return null;h()})),c}_updateMoveTooltip(t,i){if(s(this._tooltip))return t;const{tooltipOptions:e}=this;if(!e.enabled)return this._tooltip.clear(),t;if(i===b.XY||i===b.XY_AXIS){const i=Z(t.mapStart,t.mapEnd);p(i)&&(this._tooltip.info=new k({tooltipOptions:e,distance:i}))}if(i===b.Z){const i=C(t.mapStart,t.mapEnd);p(i)&&(this._tooltip.info=new I({tooltipOptions:e,distance:i}))}return t}_buildSnappingPipelineSteps(t,i,e,o,n){const a=t.geometry;if(s(a)||"point"!==a.type&&"mesh"!==a.type)return e;const r=("point"===a.type?a:a.anchor).clone(),p=new R({elevationInfo:i,pointer:n,editGeometryOperations:Y.fromGeometry(r,this.view.state.viewingMode),visualizer:new f,excludeFeature:t}),l=this.snappingManager;return e.next((i=>{r.z=g(this.view,r,d(t),{mode:"absolute-height",offset:0});return{...i,snapOrigin:p.coordinateHelper.pointToVector(r)}})).next(this._snappingPipeline.createSnapDragEventPipelineStep({snappingContext:p,snappingManager:l,cancel:o,updatingHandles:this.updatingHandles}),this._snappingPipeline.next)}};t([c({constructOnly:!0,nonNullable:!0})],F.prototype,"view",void 0),t([c()],F.prototype,"graphics",void 0),t([c({constructOnly:!0,nonNullable:!0})],F.prototype,"enableZ",void 0),t([c({constructOnly:!0,type:G})],F.prototype,"tooltipOptions",void 0),t([c({constructOnly:!0})],F.prototype,"snappingManager",void 0),t([c()],F.prototype,"type",void 0),t([c()],F.prototype,"updating",null),F=t([m("esri.views.3d.interactive.editingTools.graphicMove3D.GraphicMoveTool")],F);class L{constructor(t){this.state=null,this.geometryRepresentation=null,this.manipulationXY=null,this.dragging=!1,this.state=new A({graphic:t})}get graphic(){return this.state.graphic}}export{V as GraphicMoveEvent,H as GraphicMoveStartEvent,N as GraphicMoveStopEvent,F as GraphicMoveTool};
5
+ import{_ as t}from"../../../../../chunks/tslib.es6.js";import i from"../../../../../core/Collection.js";import e from"../../../../../core/Evented.js";import{HandleOwnerMixin as o}from"../../../../../core/HandleOwner.js";import{makeHandle as n}from"../../../../../core/handleUtils.js";import{destroyMaybe as a,isNone as s,unwrap as r,isSome as p}from"../../../../../core/maybe.js";import{watch as l,initial as h}from"../../../../../core/reactiveUtils.js";import{property as c}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import"../../../../../core/accessorSupport/ensureType.js";import{subclass as m}from"../../../../../core/accessorSupport/decorators/subclass.js";import{makeDehydratedPoint as u}from"../../../../../layers/graphics/dehydratedFeatures.js";import{getGraphicEffectiveElevationInfo as d,getConvertedElevation as g}from"../../../../../support/elevationInfoUtils.js";import{getGraphicAttachmentOrigin as v}from"../../manipulatorUtils.js";import{SnappingVisualizer3D as f}from"../../SnappingVisualizer3D.js";import{SupportedGraphicResult as y}from"../isSupportedGraphicUtils.js";import{ManipulatorType as M}from"../ManipulatorType.js";import{canMoveZ as _}from"../manipulatorUtils.js";import{createVisualElements as w}from"../visualElementUtils.js";import{DISC_RADIUS as j}from"../manipulations/config.js";import{ManipulationType as b,MoveManipulation as S}from"../manipulations/MoveManipulation.js";import{shapeOrientation as x}from"../manipulations/moveUtils.js";import{MoveXYGraphicManipulation as E}from"../manipulations/MoveXYGraphicManipulation.js";import{isSupportedGraphic as O}from"./isSupportedGraphic.js";import{OutlineVisualElement as T}from"../../visualElements/OutlineVisualElement.js";import{GraphicState as A}from"../../../layers/graphics/GraphicState.js";import{dragGraphicMany as P,resetGraphicMany as X}from"../../../../interactive/dragEventPipeline.js";import{InteractiveToolBase as D}from"../../../../interactive/InteractiveToolBase.js";import{EditGeometryOperations as Y}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import G from"../../../../interactive/sketch/SketchTooltipOptions.js";import{SnappingContext as R}from"../../../../interactive/snapping/SnappingContext.js";import{SnappingPipeline as U}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{Tooltip as z}from"../../../../interactive/tooltip/Tooltip.js";import{TranslateGraphicTooltipInfo as k,TranslateZTooltipInfo as I}from"../../../../interactive/tooltip/TranslateTooltipInfos.js";import{euclideanHorizontalDistanceBetweenPoints as Z,verticalSignedDistanceBetweenPoints as C}from"../../../../support/lengthMeasurementUtils.js";class H{constructor(t){this.allGraphics=t,this.type="graphic-move-start"}}class V{constructor(t,i,e){this.dx=t,this.dy=i,this.allGraphics=e,this.type="graphic-move"}}class N{constructor(t){this.allGraphics=t,this.type="graphic-move-stop"}}let F=class extends(o(e.EventedMixin(D))){constructor(t){super(t),this.graphics=new i,this.enableZ=!0,this.tooltipOptions=new G,this.type="move-3d",this._snappingPipeline=new U,this._tooltip=null}initialize(){const{graphics:t,view:i}=this;this._tooltip=new z({view:i}),this.own([t.on("change",(()=>this._refreshManipulators())),l((()=>this.tooltipOptions.enabled),(t=>{this._tooltip=t?new z({view:i}):a(this._tooltip)}),h)]),this._refreshManipulators(),this.finishToolCreation()}destroy(){this._tooltip=a(this._tooltip),this.graphics.removeAll(),this._set("view",null)}get updating(){return this.updatingHandles.updating}reset(){}_refreshManipulators(){this.handles.removeAll(),this._moveManipulation&&this._moveManipulation.destroy(),this.manipulators.removeAll();const t=this.graphics.toArray().filter((t=>O(t)===y.SUPPORTED)).map((t=>new L(t)));t.length&&(this._createManipulators(t),this._createVisualElements(t),this.handles.add(t.map((t=>this.view.trackGraphicState(t.state)))),this._updateMoveManipulation(t))}_createManipulators(t){for(const i of t){const e=i.state;i.manipulationXY=new E({tool:this,view:this.view,graphicState:e}),i.manipulationXY.forEachManipulator((t=>this.handles.add([t.events.on("immediate-click",(t=>{this.emit("immediate-click",{...t,graphic:e.graphic}),t.stopPropagation()})),t.events.on("grab-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new k({tooltipOptions:i}):this._tooltip.clear()}))]))),this.handles.add(i.manipulationXY.createDragPipeline(((i,e,o,n)=>this._buildDragEventPipeline(t,b.XY,i,e,o,n))))}this._createMoveManipulation(t)}_createMoveManipulation(t){const i=new S({tool:this,view:this.view,snapToScene:!1,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:!0,radius:1===t.length?S.radiusForSymbol(t[0].graphic.symbol):j});this._moveManipulation=i,i.elevationInfo={mode:"absolute-height",offset:0},i.forEachManipulator(((t,e)=>{this.handles.add(t.events.on("immediate-click",(e=>{i.zManipulation.hasManipulator(t)||1!==this.graphics.length||this.emit("immediate-click",{...e,graphic:this.graphics.getItemAt(0)}),e.stopPropagation()}))),e===M.TRANSLATE_XY&&this.handles.add(t.events.on("focus-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new k({tooltipOptions:i}):this._tooltip.clear()}))),e===M.TRANSLATE_Z&&this.handles.add(t.events.on("focus-changed",(({action:t})=>{if(s(this._tooltip))return;const{tooltipOptions:i}=this;"focus"===t&&i.enabled?this._tooltip.info=new I({tooltipOptions:i}):this._tooltip.clear()})))}));const e=()=>this._updateMoveManipulation(t);for(const n of t)this.handles.add([n.state.on("changed",e),l((()=>n.state.displaying),e)]);const o=t[t.length-1];this.handles.add(o.state.on("changed",(()=>this._updateMoveManipulationAngle(o)))),this.handles.add(i.createDragPipeline(((i,e,o,n,a)=>this._buildDragEventPipeline(t,i,e,o,n,a)),d(o.graphic),r(o.graphic.geometry).spatialReference,o.graphic)),this._updateMoveManipulationAngle(o)}_createVisualElements(t){for(const i of t){const e=i.graphic,o=w({view:this.view,graphic:e,forEachManipulator:t=>{i.manipulationXY.forEachManipulator(t),this._moveManipulation.forEachManipulator(t)},onManipulatorsChanged:()=>n()});s(o)||(i.geometryRepresentation=o.visualElement,i.geometryRepresentation instanceof T&&this.handles.add([i.geometryRepresentation.events.on("attachment-origin-changed",(()=>{i.state.isDraped||this._updateMoveManipulation(t)})),l((()=>i.state.isDraped),(()=>this._updateMoveManipulation(t)))]),this.handles.add(o))}}_updateMoveManipulationAngle(t){this._moveManipulation.angleDeferred=()=>x(t.graphic.geometry)}_updateMoveManipulation(t){const i=u(0,0,0,this.view.spatialReference);let e=0,o=!1;const n=this._moveManipulation;for(const a of t){if(!a.state.displaying)continue;const t=a.state.graphic;this.enableZ&&_(t)&&(o=!0);const n=a.geometryRepresentation instanceof T&&!a.state.isDraped?a.geometryRepresentation.attachmentOrigin:v(this.view,t);p(n)&&(i.x+=n.x,i.y+=n.y,i.z+=n.z,e++)}e>0?(i.x/=e,i.y/=e,i.z/=e,n.location=i,n.xyManipulation.available=!0,n.xyAxisManipulation.available=!0,n.zManipulation.available=o):n.available=!1}_buildDragEventPipeline(t,i,e,o,n,a){const s=[],r=[];let p=null,l=null;const h=()=>{for(const t of s)t.dragging=!1;s.length=0,r.length=0,p=null,l=null,this._moveManipulation.interactive=!0};if(1===t.length&&i===b.XY){const i=t[0].graphic;o=this._buildSnappingPipelineSteps(i,d(i),o,n,a)}const c=o.next((i=>{if("start"===i.action){s.length=0,r.length=0;for(const i of t)i.dragging||!i.manipulationXY.hasManipulator(e)&&i.manipulationXY.grabbing||(s.push(i),r.push(i.graphic),i.dragging=!0);if(0!==r.length&&(this._moveManipulation.interactive=!1,p=P(r,this.view.state.viewingMode),l=X(r),this.emit("graphic-move-start",new H(r)),this.destroyed))return null}return 0!==r.length?i:null})).next((t=>p(t))).next((t=>this._updateMoveTooltip(t,i))).next((t=>{switch(t.action){case"start":case"update":if(t.translationX||t.translationY||t.translationZ){const i=this.view.toScreen(t.mapStart),e=this.view.toScreen(t.mapEnd),o=e.x-i.x,n=e.y-i.y;if(this.emit("graphic-move",new V(o,n,r)),this.destroyed)return null}break;case"end":if(this.emit("graphic-move-stop",new N(r)),this.destroyed)return null;h()}}));return n.next((t=>l(t))).next((()=>{if(this.emit("graphic-move-stop",new N(r)),this.destroyed)return null;h()})),c}_updateMoveTooltip(t,i){if(s(this._tooltip))return t;const{tooltipOptions:e}=this;if(!e.enabled)return this._tooltip.clear(),t;if(i===b.XY||i===b.XY_AXIS){const i=Z(t.mapStart,t.mapEnd);p(i)&&(this._tooltip.info=new k({tooltipOptions:e,distance:i}))}if(i===b.Z){const i=C(t.mapStart,t.mapEnd);p(i)&&(this._tooltip.info=new I({tooltipOptions:e,distance:i}))}return t}_buildSnappingPipelineSteps(t,i,e,o,n){const a=t.geometry;if(s(a)||"point"!==a.type&&"mesh"!==a.type)return e;const r=("point"===a.type?a:a.anchor).clone(),p=new R({elevationInfo:i,pointer:n,editGeometryOperations:Y.fromGeometry(r,this.view.state.viewingMode),visualizer:new f,excludeFeature:t}),l=this.snappingManager;return e.next((i=>{r.z=g(this.view,r,d(t),{mode:"absolute-height",offset:0});return{...i,snapOrigin:p.coordinateHelper.pointToVector(r)}})).next(this._snappingPipeline.createSnapDragEventPipelineStep({snappingContext:p,snappingManager:l,cancel:o,updatingHandles:this.updatingHandles}),this._snappingPipeline.next)}};t([c({constructOnly:!0,nonNullable:!0})],F.prototype,"view",void 0),t([c()],F.prototype,"graphics",void 0),t([c({constructOnly:!0,nonNullable:!0})],F.prototype,"enableZ",void 0),t([c({constructOnly:!0,type:G})],F.prototype,"tooltipOptions",void 0),t([c({constructOnly:!0})],F.prototype,"snappingManager",void 0),t([c()],F.prototype,"type",void 0),t([c()],F.prototype,"updating",null),F=t([m("esri.views.3d.interactive.editingTools.graphicMove3D.GraphicMoveTool")],F);class L{constructor(t){this.state=null,this.geometryRepresentation=null,this.manipulationXY=null,this.dragging=!1,this.state=new A({graphic:t})}get graphic(){return this.state.graphic}}export{V as GraphicMoveEvent,H as GraphicMoveStartEvent,N as GraphicMoveStopEvent,F as GraphicMoveTool};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../../chunks/tslib.es6.js";import"../../../../../core/has.js";import t from"../../../../../core/Evented.js";import{HandleOwner as i}from"../../../../../core/HandleOwner.js";import a from"../../../../../core/Handles.js";import{handlesGroup as o,destroyHandle as n}from"../../../../../core/handleUtils.js";import{destroyMaybe as r,isSome as s,isNone as l,unwrap as p,removeMaybe as h}from"../../../../../core/maybe.js";import{createLength as d}from"../../../../../core/quantityUtils.js";import{watch as u,when as c,initial as m}from"../../../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as g}from"../../../../../core/unitUtils.js";import{property as _}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/arrayUtils.js";import"../../../../../core/accessorSupport/ensureType.js";import{subclass as f}from"../../../../../core/accessorSupport/decorators/subclass.js";import{I as v}from"../../../../../chunks/mat4f64.js";import{l as M,b as y,h as O,s as x,a as b,g as E}from"../../../../../chunks/vec3.js";import{f as G,c as S}from"../../../../../chunks/vec3f64.js";import I from"../../../../../geometry/Polyline.js";import{makeDehydratedPoint as V}from"../../../../../layers/graphics/dehydratedFeatures.js";import{getGraphicEffectiveElevationInfo as H}from"../../../../../support/elevationInfoUtils.js";import{isVolumetricSymbol as w}from"../../../../../symbols/support/utils.js";import{Manipulator3D as A}from"../../Manipulator3D.js";import{createManipulatorMaterial as L,createManipulatorOutlineMaterial as D,placeAtGraphic as P}from"../../manipulatorUtils.js";import{SegmentLabels3D as T}from"../../SegmentLabels3D.js";import{SnappingVisualizer3D as j}from"../../SnappingVisualizer3D.js";import{screenToRenderPlaneFromEvent as N,convertToMapCoordinates as U,screenToMapXYAtLocation as k,screenToMapXYForGraphicAtLocation as R}from"../dragEventPipeline3D.js";import{ManipulatorType as C}from"../ManipulatorType.js";import{canMoveZ as F}from"../manipulatorUtils.js";import{settings as z,colors as Z}from"../settings.js";import{createVisualElements as X}from"../visualElementUtils.js";import{DISC_RADIUS_SMALL as Y}from"../manipulations/config.js";import{ManipulationType as q,MoveManipulation as W}from"../manipulations/MoveManipulation.js";import{shapeOrientation as K}from"../manipulations/moveUtils.js";import{MoveXYGraphicManipulation as B}from"../manipulations/MoveXYGraphicManipulation.js";import{createEdgeOffsetIntersectionPlane as J,createEdgeOffsetOperation as Q,edgeOffsetRotationMatrix as $,screenEdgeLengthSquared as ee}from"./edgeOffsetUtils.js";import{OutlineVisualElement as te}from"../../visualElements/OutlineVisualElement.js";import{GraphicState as ie}from"../../../layers/graphics/GraphicState.js";import ae from"../../../webgl-engine/lib/GeometryUtil.js";import{MouseButton as oe}from"../../../../input/IViewEvents.js";import{addMapDelta as ne,createManipulatorDragEventPipeline as re,dragAtLocation as se,addScreenDelta as le}from"../../../../interactive/dragEventPipeline.js";import{ManipulatorStateFlags as pe,ManipulatorStateCustomFlags as he}from"../../../../interactive/interfaces.js";import{EditGeometryOperations as de}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import{AccumulationBehaviour as ue}from"../../../../interactive/editGeometry/interfaces.js";import{SnappingContext as ce}from"../../../../interactive/snapping/SnappingContext.js";import{SnappingPipeline as me}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{ReshapeEdgeOffsetTooltipInfo as ge}from"../../../../interactive/tooltip/ReshapeTooltipInfos.js";import{Tooltip as _e}from"../../../../interactive/tooltip/Tooltip.js";import{TranslateGraphicTooltipInfo as fe,TranslateZTooltipInfo as ve}from"../../../../interactive/tooltip/TranslateTooltipInfos.js";import{euclideanHorizontalDistanceBetweenPoints as Me,verticalDistanceBetweenPoints as ye}from"../../../../support/lengthMeasurementUtils.js";let Oe=class extends(t.EventedMixin(i)){constructor(e){super(e),this._vertexManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.vertex.color),z.reshapeManipulators.vertex.renderOccluded),this._vertexManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.vertex.outlineColor),z.reshapeManipulators.vertex.renderOccluded),this._vertexManipulatorHoverOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.vertex.hoverOutlineColor),z.reshapeManipulators.vertex.renderOccluded),this._edgeManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.edge.color),z.reshapeManipulators.edge.renderOccluded),this._edgeManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.edge.outlineColor),z.reshapeManipulators.edge.renderOccluded),this._edgeOffsetManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.edgeOffset.color),z.reshapeManipulators.edgeOffset.renderOccluded,!1),this._edgeOffsetManipulatorHoverMaterial=L(z.colorToVec4(z.reshapeManipulators.edgeOffset.hoverColor),z.reshapeManipulators.edgeOffset.renderOccluded,!1),this._selectedManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.selected.color),z.reshapeManipulators.selected.renderOccluded),this._selectedManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.selected.outlineColor),z.reshapeManipulators.selected.renderOccluded),this._selectedManipulatorHoverOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.selected.hoverOutlineColor),z.reshapeManipulators.selected.renderOccluded),this._selectedIndex=0,this._vertexManipulatorGeometry=null,this._vertexManipulatorOutlineGeometry=null,this._edgeManipulatorGeometry=null,this._edgeManipulatorOutlineGeometry=null,this._edgeOffsetManipulatorGeometryInside=null,this._edgeOffsetManipulatorGeometryOutside=null,this._manipulatorHandles=new a,this._manipulatorInfos=[],this._editGeometryOperations=null,this._graphicMoveManipulation=null,this._moveManipulation=null,this._numGrabbing=0,this._numDragging=0,this._reshapeEventState=Se.NONE,this._outlineVisualElement=null,this._segmentLabels=null,this.outputGeometry=null,this._snappingPipeline=new me,this._snappingPipelineHandle=new me,this._vertexLaserLineVisualElement=null}initialize(){const{graphic:e,view:t}=this,i=this._graphicState=new ie({graphic:e});this._tooltip=new _e({view:t}),this.own([u((()=>i.displaying),(e=>{for(const t of this._manipulatorInfos)t.manipulator.available=e})),u((()=>this._labelOptions.enabled),(()=>this._updateSegmentLabelsVisibility()),m),c((()=>!this._tooltipOptions.enabled),(()=>this._tooltip.clear()),m),this.view.trackGraphicState(i)])}destroy(){this._segmentLabels=r(this._segmentLabels),this._tooltip=r(this._tooltip),this._editGeometryOperations=r(this._editGeometryOperations),this._moveManipulation=r(this._moveManipulation),this._graphicMoveManipulation=r(this._graphicMoveManipulation),this._manipulatorHandles=r(this._manipulatorHandles),this.manipulators.removeAll(),this._manipulatorInfos=[],this._resetGrabbingDragging()}get inputGeometry(){return s(this._editGeometryOperations)?this._editGeometryOperations.data.geometry:null}set inputGeometry(e){this._recreateEditGeometryAndManipulators(e)}get updating(){return this.updatingHandles.updating}get manipulators(){return this.tool.manipulators}get view(){return this.tool.view}get graphic(){return this.tool.graphic}get enableZShape(){return this.tool.enableZShape}get enableZVertex(){return this.tool.enableZVertex}get enableMoveGraphic(){return this.tool.enableMoveGraphic}get enableMidpoints(){return this.tool.enableMidpoints}get enableEdgeOffset(){return this.tool.enableEdgeOffset}get _labelOptions(){return this.tool.labelOptions}get _tooltipOptions(){return this.tool.tooltipOptions}removeSelectedVertices(){const e=this._manipulatorInfos.filter((e=>e.manipulator.selected&&"vertex"===e.type));this._removeVertices(e)}manipulatorSelectionChanged(){this.emit("manipulators-changed")}_removeManipulators(){this._moveManipulation=r(this._moveManipulation),this._graphicMoveManipulation=r(this._graphicMoveManipulation),this._manipulatorHandles.removeAll(),this.manipulators.removeAll(),this._manipulatorInfos=[]}_resetGrabbingDragging(){this._numGrabbing=0,this._numDragging=0}_createManipulators(){if(l(this._editGeometryOperations))return;const e=H(this.graphic);for(const t of this._editGeometryOperations.data.components){for(const i of t.vertices)this._createVertexOrEdgeManipulator(i,e);for(const i of t.edges)this._createVertexOrEdgeManipulator(i,e)}this._createGraphicMoveManipulators(e)}get canRedo(){return s(this._editGeometryOperations)&&this._editGeometryOperations.canRedo}get canUndo(){return s(this._editGeometryOperations)&&this._editGeometryOperations.canUndo}redo(){if(l(this._editGeometryOperations))return null;const e=this._editGeometryOperations.redo();return s(e)&&(this.outputGeometry=this._editGeometryOperations.data.geometry,this._recreateManipulators()),e}undo(){if(l(this._editGeometryOperations))return null;this.emit("undo");const e=this._editGeometryOperations.undo();return s(e)&&(this.outputGeometry=this._editGeometryOperations.data.geometry,this._recreateManipulators()),e}_recreateManipulators(){this._removeManipulators(),this._resetGrabbingDragging(),this._tooltip.clear(),this._createManipulators()}_recreateEditGeometryAndManipulators(e=this.inputGeometry){this._removeManipulators(),this._resetGrabbingDragging(),this._tooltip.clear(),l(e)||(r(this._editGeometryOperations),this._editGeometryOperations=de.fromGeometry(e,this.view.state.viewingMode),this._createManipulators(),r(this._segmentLabels),this._segmentLabels=new T({context:{view:this.view,editGeometryOperations:this._editGeometryOperations,elevationInfo:H(this.graphic)}}),this._updateSegmentLabelsVisibility())}_perGraphicManipulatorDragAction(e,t){if("end"===t.action)return t;let i=0;const a=[],o=this._manipulatorInfos.some((e=>"vertex"===e.type&&e.manipulator.selected)),n=e===Ie.SELECTED_OR_ALL&&o;for(const r of this._manipulatorInfos)"vertex"===r.type&&(r.manipulator.grabbing||n&&!r.manipulator.selected||a.push(r),i++);if(0===a.length)return t;this._moveVertices(a,t);if(a.length===i){if(this._updateEventState(Se.MOVING),this.destroyed)return t;this.emit("move",{type:"move",dx:t.screenDeltaX,dy:t.screenDeltaY,mover:this.graphic})}else{if(this._updateEventState(Se.RESHAPING),this.destroyed)return t;this.emit("reshape",{type:"reshape",mover:this.graphic})}return t}_isMultiVertexSelection(){let e=0;for(const t of this._manipulatorInfos)"vertex"===t.type&&t.manipulator.selected&&e++;return e>1}_perVertexManipulatorDragAction(e){if(this._updateEventState(Se.RESHAPING),this.destroyed)return;const{mapDeltaX:t,mapDeltaY:i,mapDeltaZ:a}=e;if(!t&&!i&&!a)return;const o=[];for(const n of this._manipulatorInfos)"vertex"===n.type&&(n.manipulator.selected&&!n.manipulator.grabbing||n===e.info)&&o.push(n);this._moveVertices(o,e,ue.ACCUMULATE_STEPS),this.emit("reshape",{type:"reshape",mover:this.graphic})}_updateEventState(e){if(e===this._reshapeEventState)return!1;switch(e){case Se.NONE:if(0!==this._numGrabbing||0!==this._numDragging)return!1;switch(this._reshapeEventState){case Se.MOVING:this.emit("move",{type:"move-stop",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape-stop",mover:this.graphic})}break;case Se.MOVING:switch(this._reshapeEventState){case Se.NONE:this.emit("move",{type:"move-start",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape-stop",mover:this.graphic}),this.destroyed||this.emit("move",{type:"move-start",dx:0,dy:0,mover:this.graphic})}break;case Se.RESHAPING:switch(this._reshapeEventState){case Se.NONE:this.emit("reshape",{type:"reshape-start",mover:this.graphic});break;case Se.MOVING:this.emit("move",{type:"move-stop",dx:0,dy:0,mover:this.graphic}),this.destroyed||this.emit("reshape",{type:"reshape-start",mover:this.graphic})}}if(this.destroyed)return!1;const t=this._reshapeEventState!==e;return this._reshapeEventState=e,t}_createGraphicMoveManipulators(e){const{graphic:t,handles:i,tool:a,view:o}=this,n=this._graphicState;if(this._graphicMoveManipulation=new B({tool:a,view:o,graphicState:n}),this.enableMoveGraphic){let e=null;this._graphicMoveManipulation.forEachManipulator((e=>{this._manipulatorHandles.add(e.events.on("grab-changed",(({action:e})=>{const t=this._tooltipOptions;"start"===e&&t.enabled?this._tooltip.info=new fe({tooltipOptions:t}):this._tooltip.clear()})))})),this._manipulatorHandles.add(this._graphicMoveManipulation.createDragPipeline(((t,i,a)=>{i.next((e=>this._trackNumDragging(e))).next((t=>("start"===t.action&&(e=p(this._editGeometryOperations).createUndoGroup()),t))).next((e=>this._perGraphicManipulatorDragAction(Ie.ALL,e))).next((e=>this._updateMoveTooltip(e,q.XY))).next((t=>{"end"===t.action&&(e=h(e))})),a.next(this._cancelDragOperation((()=>e=h(e))))})))}else this._graphicMoveManipulation.forEachManipulator((e=>{e.grabbable=!1,e.cursor=null}));this._graphicMoveManipulation.forEachManipulator((e=>this._manipulatorHandles.add([this._watchAndUpdateGrabState(e,!1),e.events.on("immediate-click",(e=>{this._manipulatorInfos.some((e=>e.manipulator.selected))?this._clearSelection():this.emit("immediate-click",{...e,graphic:this.graphic}),e.stopPropagation()}))]))),this._moveManipulation=new W({tool:a,view:o,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZShape&&F(t),snapToScene:!1,radius:W.radiusForSymbol(t.symbol)}),this._moveManipulation.forEachManipulator(((e,a)=>{i.add([this._watchAndUpdateGrabState(e,!1),e.events.on("immediate-click",(i=>{this._moveManipulation.zManipulation.hasManipulator(e)||this._manipulatorInfos.some((e=>e.manipulator.selected))||this.emit("immediate-click",{...i,graphic:t}),i.stopPropagation()}))]),a===C.TRANSLATE_XY&&i.add(e.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new fe({tooltipOptions:t}):this._tooltip.clear()}))),a===C.TRANSLATE_Z&&i.add(e.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new ve({tooltipOptions:t}):this._tooltip.clear()})))})),this._moveManipulation.elevationInfo={mode:"absolute-height",offset:0};const r=p(t.geometry).spatialReference;i.add([this._moveManipulation.createDragPipeline(((i,o,n,r,s)=>{const l=n.next((e=>this._trackNumDragging(e))).next((e=>{const t=this._manipulatorInfos.filter((e=>"vertex"===e.type&&e.manipulator.selected));return e.manipulatorType===C.TRANSLATE_XY&&1===t.length?{...e,info:t[0],snapOrigin:t[0].handle.pos}:{...e,info:null}})).next(this._snappingPipelineHandle.createSnapDragEventPipelineStep({predicate:e=>!!e.info,cancel:r,snappingManager:a.snappingManager,snappingContext:new ce({editGeometryOperations:p(this._editGeometryOperations),elevationInfo:e,pointer:s,excludeFeature:t,visualizer:new j}),updatingHandles:this.updatingHandles}),this._snappingPipelineHandle.next).next(ne()).next((e=>this._perGraphicManipulatorDragAction(Ie.SELECTED_OR_ALL,e))).next((e=>this._updateMoveTooltip(e,i)));return r.next(this._cancelDragOperation()),l}),e,r,t),u((()=>n?.displaying),(()=>{this._updateMoveManipulationPosition()}),m),n.on("changed",(()=>this._updateMoveManipulationPosition())),u((()=>n?.isDraped),(e=>{const t="align-move-manipulation";e?i.add(this.view.elevationProvider.on("elevation-change",(()=>this._updateMoveManipulationPosition())),t):i.remove(t)}),m)]),this._updateMoveManipulationPosition();const l=X({view:o,graphic:t,forEachManipulator:e=>{if(!this.destroyed){s(this._graphicMoveManipulation)&&this._graphicMoveManipulation.forEachManipulator(e);for(const t of this._manipulatorInfos)e(t.manipulator,C.TRANSLATE_XY);this._moveManipulation.forEachManipulator(e)}},onManipulatorsChanged:e=>this.on("manipulators-changed",e)});s(l)&&(this._outlineVisualElement=l.visualElement instanceof te?l.visualElement:null),s(this._outlineVisualElement)&&this._manipulatorHandles.add([this._outlineVisualElement.events.on("attachment-origin-changed",(()=>{n.isDraped||this._updateMoveManipulationPosition()})),u((()=>n.isDraped),(()=>this._updateMoveManipulationPosition()))]),this._manipulatorHandles.add(l)}_createEdgeOffsetManipulator(e,t=H(this.graphic)){const i=z.reshapeManipulators.edgeOffset,a=i.size/2,n=a+i.collisionPadding;if(l(this._edgeOffsetManipulatorGeometryInside)||l(this._edgeOffsetManipulatorGeometryOutside)){const e=a/n,t=e*Math.sqrt(3)/2;this._edgeOffsetManipulatorGeometryInside=ae.createExtrudedTriangle(t,e/2,e/2,i.height,i.offset),this._edgeOffsetManipulatorGeometryOutside=ae.createExtrudedTriangle(-t,e/2,e/2,i.height,-i.offset)}const r=[{geometry:this._edgeOffsetManipulatorGeometryInside,material:this._edgeOffsetManipulatorMaterial,stateMask:pe.Unfocused},{geometry:this._edgeOffsetManipulatorGeometryInside,material:this._edgeOffsetManipulatorHoverMaterial,stateMask:pe.Focused},{geometry:this._edgeOffsetManipulatorGeometryOutside,material:this._edgeOffsetManipulatorMaterial,stateMask:pe.Unfocused},{geometry:this._edgeOffsetManipulatorGeometryOutside,material:this._edgeOffsetManipulatorHoverMaterial,stateMask:pe.Focused}],p=new A({view:this.view,renderObjects:r,elevationInfo:"on-the-ground"!==t.mode||w(this.graphic.symbol)?{mode:"absolute-height",offset:0}:t,worldOriented:!1,focusMultiplier:1,radius:n,available:!(!this.graphic.visible||!this.graphic.layer.visible),collisionType:{type:"disc",direction:G(0,0,1)},collisionPriority:1}),h=new A({view:this.view,renderObjects:[],worldSized:!0,worldOriented:!1,available:!(!this.graphic.visible||!this.graphic.layer.visible),collisionPriority:-10,cursor:this.enableMoveGraphic?"move":"default"}),d={manipulator:p,handle:e,locationUpdateHandle:null,type:"edge",selectedIndex:0,edgeManipulator:h,elevationInfo:t,visibilityHandle:null};this._autoHideEdgeOffsetManipulator(d,i.minSquaredEdgeLength),this._updateEdgeOffsetManipulator(d);const u=this._getManipulatorInfoFromHandle(d.handle.leftVertex).manipulator.events.on("location-update",(()=>this._updateEdgeOffsetManipulator(d))),c=this._getManipulatorInfoFromHandle(d.handle.rightVertex).manipulator.events.on("location-update",(()=>this._updateEdgeOffsetManipulator(d)));d.locationUpdateHandle=o([u,c]),this._manipulatorHandles.add(d.locationUpdateHandle,p),this._manipulatorHandles.add([this._watchAndUpdateGrabState(p,!0),this._watchAndUpdateGrabState(h,!0)],p),this._manipulatorHandles.add(re(p,this._createEdgeOffsetPipeline(d,t)),p),this._manipulatorHandles.add(re(h,((e,i,a,o)=>{if("touch"===o){this._createEdgeOffsetPipeline(d,t)(e,i,a)}else if(this.enableMoveGraphic){const o=this.graphic,n=s(o.geometry)?o.geometry.spatialReference:null;i.next((e=>this._trackNumDragging(e))).next(se(this.view,e.elevationAlignedLocation)).next(k(this.view,e.elevationAlignedLocation,t,n,o)).next(le()).next(ne()).next((e=>this._perGraphicManipulatorDragAction(Ie.ALL,e))),a.next(this._cancelDragOperation())}})),p);const m=e=>{this._manipulatorInfos.some((e=>e.manipulator.selected))?this._clearSelection():this.emit("immediate-click",{...e,graphic:this.graphic}),e.stopPropagation()};return this._manipulatorHandles.add([p.events.on("immediate-click",m),h.events.on("immediate-click",m),p.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new ge({tooltipOptions:t}):this._tooltip.clear()}))],p),this._manipulatorInfos.push(d),this.manipulators.add(p),this.manipulators.add(h),this.emit("manipulators-changed"),d}_autoHideEdgeOffsetManipulator(e,t){const i=e.manipulator,a=e.edgeManipulator,n=()=>{h(e.visibilityHandle);const n=ee(this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator.renderLocation,this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator.renderLocation,this.view.state.camera)<t;(!i.focused&&!a.focused||n)&&(i.grabbable=!n,a.grabbable=!n,e.visibilityHandle=o([i.disableDisplay(),{remove:()=>{i.grabbable=!0,a.grabbable=this.enableMoveGraphic}}]))};this._manipulatorHandles.add([i.events.on("focus-changed",n),a.events.on("focus-changed",n),{remove:()=>{h(e.visibilityHandle),this.manipulators.remove(a)}}],i),n()}_updateEdgeOffsetManipulator(e){this._updateManipulatorPosition(e);const t=p(this._editGeometryOperations).data.coordinateHelper,i=J(this.view,e.manipulator.elevationAlignedLocation,Q(t,e.handle,p(e.manipulator.elevationInfo))),a=this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator.renderLocation,o=this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator.renderLocation,n=s(i)?$(i,a,o):v;e.manipulator.modelTransform=n,e.edgeManipulator.elevationAlignedLocation=e.manipulator.elevationAlignedLocation,e.edgeManipulator.modelTransform=n;const r=M(y(Ee,a,o))/2;e.edgeManipulator.collisionType={type:"line",paths:[[[-r,0,0],[r,0,0]]]}}_createEdgeOffsetPipeline(e,t){return(i,a,o)=>{this._clearSelection();const{step:n,cleanup:r}=this._initializeEdgeOffset(e,t);a.next((e=>this._trackNumDragging(e))).next(se(this.view,i.elevationAlignedLocation)).next(n).next(N(this.view)).next(U(this.view,p(this._editGeometryOperations).data.spatialReference)).next(ne()).next(this._applyComputeEdgeOffsetDistanceStep()).next(this._applyEdgeOffsetStep(e)).next(this._showEdgeOffsetTooltip()).next((e=>{"end"===e.action&&r()})),o.next((e=>(r(),e))).next((e=>(this._tooltip.clear(),e))).next(this._cancelDragOperation())}}_initializeEdgeOffset(e,t){const i=p(this._editGeometryOperations),a=Q(i.data.coordinateHelper,e.handle,t),r=i.createUndoGroup(),s=J(this.view,e.manipulator.elevationAlignedLocation,a);a.requiresSplitEdgeLeft&&this._splitEdgeManipulator(this._getManipulatorInfoFromHandle(e.handle.leftVertex.leftEdge),1),a.requiresSplitEdgeRight&&this._splitEdgeManipulator(this._getManipulatorInfoFromHandle(e.handle.rightVertex.rightEdge),0);const d=()=>new I({paths:[[e.handle.leftVertex.pos,e.handle.rightVertex.pos]],spatialReference:p(this._editGeometryOperations).data.spatialReference}),c=new te({view:this.view,isDraped:this._graphicState.isDraped,geometry:d(),elevationInfo:e.elevationInfo,width:z.visualElements.lineGraphics.outline.width,color:z.colorToVec4(Z.main),attached:!0});let m;const g=()=>{this._cleanEdgeOffsetCollapsedEdges(e),m=h(m)},_=this.on("undo",g);return m=o([n(c),u((()=>this._graphicState.isDraped),(e=>c.isDraped=e)),this._graphicState.on("changed",(()=>c.geometry=d())),r,_]),{step:e=>l(a)||l(s)?(g(),null):{...e,operation:a,plane:s},cleanup:g}}_applyEdgeOffsetStep(e){return t=>{if(this.destroyed||l(t.operation))return t;this._updateEventState(Se.RESHAPING);const{mapDeltaX:i,mapDeltaY:a,mapDeltaZ:o}=t;return(i||a||o)&&(this._offsetEdge(e,t),this.emit("reshape",{type:"reshape",mover:this.graphic})),t}}_applyComputeEdgeOffsetDistanceStep(){return e=>{const{operation:t,mapEnd:i}=e;if(l(t)||l(i))return e;const a=t.signedDistanceToPoint(i);return{...e,signedDistance:a}}}_showEdgeOffsetTooltip(){return e=>{const{mapEnd:t,signedDistance:i}=e,a=this._tooltip,o=this._tooltipOptions;if(!o.enabled||l(i))return a.clear(),e;const n=g(t.spatialReference),r=d(-i*n,"meters");return l(a.info)||"reshape-edge-offset"!==a.info.type?a.info=new ge({tooltipOptions:o,distance:r}):a.info.distance=r,e}}_cleanEdgeOffsetCollapsedEdges(e){const t=e.handle.leftVertex.leftEdge?.leftVertex,i=e.handle.leftVertex,a=e.handle.rightVertex.rightEdge?.rightVertex,o=e.handle.rightVertex,n=p(this._editGeometryOperations).data.coordinateHelper,r=1e-6,s=[];t&&n.distance(t.pos,i.pos)<r&&s.push(this._getManipulatorInfoFromHandle(i)),(n.distance(i.pos,o.pos)<r||a&&n.distance(a.pos,o.pos)<r)&&s.push(this._getManipulatorInfoFromHandle(o)),s.length&&this._removeVertices(s)}_computeVertexManipulatorSizeAndOutline(e){const t=e.size/2,i=t+e.collisionPadding;return{size:t/i,outlineSize:(t+e.outlineSize)/i}}_createVertexOrEdgeManipulator(e,t=H(this.graphic)){if("edge"===e.type){if(this.enableEdgeOffset)return this._createEdgeOffsetManipulator(e,t);if(!this.enableMidpoints)return null}if(l(this._vertexManipulatorGeometry)||l(this._vertexManipulatorOutlineGeometry)){const{size:e,outlineSize:t}=this._computeVertexManipulatorSizeAndOutline(z.reshapeManipulators.vertex);this._vertexManipulatorGeometry=ae.createSphereGeometry(e,16,16),this._vertexManipulatorOutlineGeometry=ae.createSphereGeometry(t,16,16)}if(l(this._edgeManipulatorGeometry)||l(this._edgeManipulatorOutlineGeometry)){const{size:e,outlineSize:t}=this._computeVertexManipulatorSizeAndOutline(z.reshapeManipulators.edge);this._edgeManipulatorGeometry=ae.createSphereGeometry(e,16,16),this._edgeManipulatorOutlineGeometry=ae.createSphereGeometry(t,16,16)}const i=s(this.graphic.geometry)&&"point"===this.graphic.geometry.type?[]:[{geometry:this._vertexManipulatorGeometry,material:this._vertexManipulatorMaterial,stateMask:Ge.Vertex|pe.Unselected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._vertexManipulatorOutlineMaterial,stateMask:Ge.Vertex|pe.Unfocused|pe.Unselected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._vertexManipulatorHoverOutlineMaterial,stateMask:Ge.Vertex|pe.Focused|pe.Unselected},{geometry:this._vertexManipulatorGeometry,material:this._selectedManipulatorMaterial,stateMask:pe.Selected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._selectedManipulatorOutlineMaterial,stateMask:pe.Selected|pe.Unfocused},{geometry:this._vertexManipulatorOutlineGeometry,material:this._selectedManipulatorHoverOutlineMaterial,stateMask:pe.Selected|pe.Focused}];this.enableMidpoints&&i.push({geometry:this._edgeManipulatorGeometry,material:this._vertexManipulatorMaterial,stateMask:Ge.Edge|pe.Focused|pe.Unselected},{geometry:this._edgeManipulatorOutlineGeometry,material:this._vertexManipulatorHoverOutlineMaterial,stateMask:Ge.Edge|pe.Focused|pe.Unselected},{geometry:this._edgeManipulatorGeometry,material:this._edgeManipulatorMaterial,stateMask:Ge.Edge|pe.Unfocused|pe.Unselected},{geometry:this._edgeManipulatorOutlineGeometry,material:this._edgeManipulatorOutlineMaterial,stateMask:Ge.Edge|pe.Unfocused|pe.Unselected});const a=new A({view:this.view,renderObjects:i,elevationInfo:t,focusMultiplier:1,touchMultiplier:1,available:!(!this.graphic.visible||!this.graphic.layer.visible)});this._setTypeSpecificManipulatorSettings(a,e,t);const n="edge"===e.type?{manipulator:a,handle:e,locationUpdateHandle:null,type:"edge",selectedIndex:0}:{manipulator:a,handle:e,type:"vertex",selectedIndex:0};if(this._manipulatorInfos.push(n),this.manipulators.add(a),this._updateManipulatorPosition(n),"edge"===n.type){const e=this._getManipulatorInfoFromHandle(n.handle.leftVertex).manipulator.events.on("location-update",(()=>this._updateManipulatorPosition(n))),t=this._getManipulatorInfoFromHandle(n.handle.rightVertex).manipulator.events.on("location-update",(()=>this._updateManipulatorPosition(n)));n.locationUpdateHandle=o([e,t]),this._manipulatorHandles.add(n.locationUpdateHandle,a)}this._manipulatorHandles.add(this._watchAndUpdateGrabState(a,!0),a);const r=re(a,((e,i,a,o)=>{let r=null;i.next((e=>this._trackNumDragging(e))).next((e=>{if("start"===e.action&&(r=p(this._editGeometryOperations).createUndoGroup()),"edge"===n.type){const t=this._splitEdgeManipulator(n);return{...e,info:t,snapOrigin:t.handle.pos}}return{...e,info:n,snapOrigin:n.handle.pos}})).next(se(this.view,e.elevationAlignedLocation)).next(R(this.view,this.graphic,e.elevationAlignedLocation,e.location.spatialReference,this.graphic)).next(this._snappingPipeline.createSnapDragEventPipelineStep({predicate:()=>!this._isMultiVertexSelection(),cancel:a,snappingManager:this.tool.snappingManager,snappingContext:new ce({editGeometryOperations:p(this._editGeometryOperations),elevationInfo:t,pointer:o,excludeFeature:this.graphic,visualizer:new j}),updatingHandles:this.updatingHandles}),this._snappingPipeline.next).next(ne()).next((e=>{this._perVertexManipulatorDragAction(e),"end"===e.action&&(r=h(r))})),a.next(this._cancelDragOperation((()=>r=h(r))))}));return this._manipulatorHandles.add([r,a.events.on("immediate-click",(e=>this._manipulatorClickCallback(e,n))),a.events.on("select-changed",(()=>{n.selectedIndex=++this._selectedIndex,this._updateMoveManipulationPosition()})),a.events.on("focus-changed",(()=>this._updateSegmentLabelsVisibility()))],a),this.emit("manipulators-changed"),n}_trackNumDragging(e){switch(e.action){case"start":this._numDragging++;break;case"end":this._numDragging--}return e}_updateSegmentLabelsVisibility(){l(this._segmentLabels)||(this._segmentLabels.visible=this._labelOptions.enabled&&!this._manipulatorInfos.some((e=>"edge"===e.type&&e.manipulator.focused)))}_cancelDragOperation(e){return()=>{switch(this._numDragging--,this.undo(),this.outputGeometry=s(this._editGeometryOperations)?this._editGeometryOperations.data.geometry:null,s(this.tool.snappingManager)&&this.tool.snappingManager.doneSnapping(),this._reshapeEventState){case Se.NONE:break;case Se.MOVING:this.emit("move",{type:"move",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape",mover:this.graphic})}e&&e(),this.destroyed||this._updateEventState(Se.NONE)}}_setTypeSpecificManipulatorSettings(e,t,i){switch(t.type){case"vertex":e.state=Ge.Vertex,e.selectable=!0,e.cursor="move",e.collisionPriority=2,e.radius=z.reshapeManipulators.vertex.size/2+z.reshapeManipulators.vertex.collisionPadding,e.elevationInfo=i,e.interactive=s(this.graphic.geometry)&&"point"!==this.graphic.geometry.type;break;case"edge":e.state=Ge.Edge,e.selectable=!1,e.cursor="copy",e.collisionPriority=-1,e.radius=z.reshapeManipulators.edge.size/2+z.reshapeManipulators.edge.collisionPadding,e.elevationInfo="on-the-ground"!==i.mode||w(this.graphic.symbol)?{mode:"absolute-height",offset:0}:i}}_watchAndUpdateGrabState(e,t){return e.events.on("grab-changed",(i=>{if("start"===i.action)t&&this._updateSelection(e),this._numGrabbing++;else if(this._numGrabbing--,this._updateEventState(Se.NONE),this.destroyed)return;this._moveManipulation.interactive=!this._numGrabbing,("touch"!==i.pointerType||this.enableEdgeOffset)&&(this._manipulatorInfos.forEach((e=>{e.manipulator.interactive=!this._numGrabbing&&s(this.graphic.geometry)&&"point"!==this.graphic.geometry.type,"edgeManipulator"in e&&(e.edgeManipulator.interactive=!this._numGrabbing)})),p(this._graphicMoveManipulation).forEachManipulator((e=>e.interactive=!this._numGrabbing)))}))}_clearSelection(){for(const e of this._manipulatorInfos)e.manipulator.grabbing||(e.manipulator.selected=!1)}_updateSelection(e){e.grabbing&&!e.selected&&e.selectable&&(this._clearSelection(),e.selected=!0,this.emit("manipulators-changed"))}_removeManipulator(e){e&&(this._manipulatorHandles.remove(e.manipulator),this._manipulatorInfos.splice(this._manipulatorInfos.indexOf(e),1),this.manipulators.remove(e.manipulator),this.emit("manipulators-changed"))}_getManipulatorInfoFromHandle(e){if(e)for(const t of this._manipulatorInfos)if(e===t.handle)return t;return null}_updateManipulatorPosition(e){if(!e)return;const t=p(this._editGeometryOperations);if("vertex"===e.type)e.manipulator.location=t.data.coordinateHelper.vectorToDehydratedPoint(e.handle.pos,be),e.manipulator.grabbing&&s(this._vertexLaserLineVisualElement)&&(this._vertexLaserLineVisualElement.visualElement.intersectsWorldUpAtLocation=e.manipulator.renderLocation);else if("edge"===e.type){const i=this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator,a=this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator;if(s(e.manipulator.elevationInfo)&&"on-the-ground"===e.manipulator.elevationInfo.mode){const o=i.location,n=a.location,r=.5,s=o.x+r*(n.x-o.x),l=o.y+r*(n.y-o.y),p=o.hasZ&&n.hasZ?0:void 0;e.manipulator.location=V(s,l,p,t.data.spatialReference)}else O(Ee,i.renderLocation,a.renderLocation,.5),e.manipulator.renderLocation=Ee}}_splitEdgeManipulator(e,t=.5){const i=p(this._editGeometryOperations),a=p(i.splitEdge(e.handle,t).createdVertex);e.locationUpdateHandle.remove(),e.locationUpdateHandle=void 0;const o=H(this.graphic);let n;this.enableEdgeOffset?(this._removeManipulator(e),n=this._createVertexOrEdgeManipulator(a)):(n=e,n.handle=a,n.type="vertex",this._setTypeSpecificManipulatorSettings(e.manipulator,e.handle,o)),this._updateSegmentLabelsVisibility(),a.leftEdge&&this._createVertexOrEdgeManipulator(a.leftEdge),a.rightEdge&&this._createVertexOrEdgeManipulator(a.rightEdge),this.outputGeometry=i.data.geometry,this._updateManipulatorPosition(n),this._updateSelection(e.manipulator);const r=this._updateEventState(Se.RESHAPING),s=i.data.coordinateHelper.vectorToArray(n.handle.pos),l=i.data.components.indexOf(a.component);return this.emit("vertex-add",{type:"vertex-add",vertices:[{coordinates:s,componentIndex:l,vertexIndex:p(a.index)}],added:s}),r&&this._updateEventState(Se.NONE),n}_updateMoveManipulationPosition(){const e=x(Ee,0,0,0);let t=0,i=!1,a=null,o=null;for(const n of this._manipulatorInfos)"vertex"===n.type&&(n.manipulator.selected?(t++,b(e,e,n.manipulator.renderLocation),l(a)||n.selectedIndex>a.selectedIndex?(o=a,a=n):(l(o)||n.selectedIndex>o.selectedIndex)&&(o=n)):i=!0);if(0!==t){const e=this._graphicState.displaying;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.zManipulation.available=e&&this.enableZVertex&&F(this.graphic),this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e&&1!==t}else{const e=this._graphicState.displaying&&this.enableMoveGraphic;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e,this._moveManipulation.zManipulation.available=e&&this.enableZShape&&F(this.graphic)}if(0!==t){let e=0;if(s(a)){const t=a.handle.pos,i=s(o)?o.handle.pos:a.handle.leftEdge&&a.handle.leftEdge.leftVertex?a.handle.leftEdge.leftVertex.pos:null,n=l(o)&&a.handle.rightEdge&&a.handle.rightEdge.rightVertex?a.handle.rightEdge.rightVertex.pos:null;i&&n?this._moveManipulation.xyAxisManipulation.available=!1:i?e=xe(i,t):n&&(e=xe(t,n))}this._moveManipulation.angle=e,this._moveManipulation.radius=Y}else this._moveManipulation.angleDeferred=()=>K(p(this.graphic.geometry)),this._moveManipulation.radius=W.radiusForSymbol(this.graphic.symbol);0!==t&&i?(E(e,e,1/t),be.spatialReference=p(this._editGeometryOperations).data.spatialReference,be.hasZ=!0,this.view.renderCoordsHelper.fromRenderCoords(e,be),this._moveManipulation.elevationAlignedLocation=be):s(this._outlineVisualElement)&&!this._graphicState.isDraped&&s(this._outlineVisualElement.attachmentOrigin)?this._moveManipulation.elevationAlignedLocation=this._outlineVisualElement.attachmentOrigin:P(this.view,this._moveManipulation,this.graphic)}_removeVertices(e){const t=[],i=p(this._editGeometryOperations);for(const a of e)if("vertex"===a.type&&i.canRemoveVertex()){t.push(a.handle),this._removeManipulator(a),this._removeManipulator(this._getManipulatorInfoFromHandle(a.handle.leftEdge)),this._removeManipulator(this._getManipulatorInfoFromHandle(a.handle.rightEdge));const e=p(i.removeVertices([a.handle]).removedVertices[0].createdEdge);e&&this._createVertexOrEdgeManipulator(e)}if(t.length>0){const e=t.map((e=>{const t=i.data.components.indexOf(e.component);return{coordinates:i.data.coordinateHelper.vectorToArray(e.pos),componentIndex:t,vertexIndex:p(e.index)}}));this.outputGeometry=i.data.geometry;const a=this._updateEventState(Se.RESHAPING);if(this.destroyed)return;if(this.emit("vertex-remove",{type:"vertex-remove",removed:e.map((e=>e.coordinates)),vertices:e}),this.destroyed)return;if(a&&(this._updateEventState(Se.NONE),this.destroyed))return;this._updateMoveManipulationPosition()}}_moveVertices(e,t,i=("start"===t.action?ue.NEW_STEP:ue.ACCUMULATE_STEPS)){const a=p(this._editGeometryOperations);a.moveVertices(e.map((e=>e.handle)),t.mapDeltaX,t.mapDeltaY,t.mapDeltaZ,i),this.outputGeometry=a.data.geometry;for(const o of e)this._updateManipulatorPosition(o)}_offsetEdge(e,t){if(l(t.operation)||l(t.signedDistance))return;const i=p(this._editGeometryOperations),a=t.operation.clone();a.distance=t.signedDistance,i.updateVertices([e.handle.leftVertex,e.handle.rightVertex],a),this.outputGeometry=i.data.geometry,this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.leftVertex)),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.rightVertex))}_manipulatorClickCallback(e,t){e.shiftKey||this._clearSelection(),"vertex"===t.type&&(t.manipulator.selected=!t.manipulator.selected,e.button===oe.Right&&this._removeVertices([t])),"edge"===t.type&&e.button===oe.Left&&this._splitEdgeManipulator(t),e.stopPropagation()}_updateMoveTooltip(e,t){const i=this._tooltipOptions;if(!i.enabled)return e;if(t===q.XY||t===q.XY_AXIS){const t=Me(e.mapStart,e.mapEnd);s(t)&&(this._tooltip.info=new fe({tooltipOptions:i,distance:t}))}if(t===q.Z){const t=ye(e.mapStart,e.mapEnd);s(t)&&(this._tooltip.info=new ve({tooltipOptions:i,distance:t}))}return e}get test(){return{segmentLabels:this._segmentLabels,tooltip:this._tooltip}}};function xe(e,t){return Math.atan2(t[1]-e[1],t[0]-e[0])+Math.PI/2}e([_({constructOnly:!0})],Oe.prototype,"tool",void 0),e([_()],Oe.prototype,"_tooltip",void 0),e([_()],Oe.prototype,"inputGeometry",null),e([_()],Oe.prototype,"outputGeometry",void 0),e([_({readOnly:!0})],Oe.prototype,"updating",null),e([_()],Oe.prototype,"_labelOptions",null),e([_()],Oe.prototype,"_tooltipOptions",null),Oe=e([f("esri.views.3d.interactive.editingTools.reshapeGraphic.ReshapeOperation")],Oe);const be=V(0,0,null,null),Ee=S();var Ge,Se,Ie;!function(e){e.Vertex=he.Custom1,e.Edge=he.Custom2}(Ge||(Ge={})),function(e){e[e.NONE=0]="NONE",e[e.MOVING=1]="MOVING",e[e.RESHAPING=2]="RESHAPING"}(Se||(Se={})),function(e){e[e.ALL=0]="ALL",e[e.SELECTED_OR_ALL=1]="SELECTED_OR_ALL"}(Ie||(Ie={}));export{Oe as ReshapeOperation};
5
+ import{_ as e}from"../../../../../chunks/tslib.es6.js";import"../../../../../core/has.js";import t from"../../../../../core/Evented.js";import{HandleOwner as i}from"../../../../../core/HandleOwner.js";import a from"../../../../../core/Handles.js";import{handlesGroup as o,destroyHandle as n}from"../../../../../core/handleUtils.js";import{destroyMaybe as r,isSome as s,isNone as l,unwrap as p,removeMaybe as h}from"../../../../../core/maybe.js";import{createLength as d}from"../../../../../core/quantityUtils.js";import{watch as u,when as c,initial as m}from"../../../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as g}from"../../../../../core/unitUtils.js";import{property as _}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/arrayUtils.js";import"../../../../../core/accessorSupport/ensureType.js";import{subclass as f}from"../../../../../core/accessorSupport/decorators/subclass.js";import{I as v}from"../../../../../chunks/mat4f64.js";import{l as M,b as y,h as O,s as x,a as b,g as E}from"../../../../../chunks/vec3.js";import{f as G,c as S}from"../../../../../chunks/vec3f64.js";import I from"../../../../../geometry/Polyline.js";import{makeDehydratedPoint as V}from"../../../../../layers/graphics/dehydratedFeatures.js";import{getGraphicEffectiveElevationInfo as H}from"../../../../../support/elevationInfoUtils.js";import{isVolumetricSymbol as w}from"../../../../../symbols/support/utils.js";import{Manipulator3D as A}from"../../Manipulator3D.js";import{createManipulatorMaterial as L,createManipulatorOutlineMaterial as D,placeAtGraphic as P}from"../../manipulatorUtils.js";import{SegmentLabels3D as T}from"../../SegmentLabels3D.js";import{SnappingVisualizer3D as j}from"../../SnappingVisualizer3D.js";import{screenToRenderPlaneFromEvent as N,convertToMapCoordinates as U,screenToMapXYAtLocation as k,screenToMapXYForGraphicAtLocation as R}from"../dragEventPipeline3D.js";import{ManipulatorType as C}from"../ManipulatorType.js";import{canMoveZ as F}from"../manipulatorUtils.js";import{settings as z,colors as Z}from"../settings.js";import{createVisualElements as X}from"../visualElementUtils.js";import{DISC_RADIUS_SMALL as Y}from"../manipulations/config.js";import{ManipulationType as q,MoveManipulation as W}from"../manipulations/MoveManipulation.js";import{shapeOrientation as K}from"../manipulations/moveUtils.js";import{MoveXYGraphicManipulation as B}from"../manipulations/MoveXYGraphicManipulation.js";import{createEdgeOffsetIntersectionPlane as J,createEdgeOffsetOperation as Q,edgeOffsetRotationMatrix as $,screenEdgeLengthSquared as ee}from"./edgeOffsetUtils.js";import{OutlineVisualElement as te}from"../../visualElements/OutlineVisualElement.js";import{GraphicState as ie}from"../../../layers/graphics/GraphicState.js";import ae from"../../../webgl-engine/lib/GeometryUtil.js";import{MouseButton as oe}from"../../../../input/IViewEvents.js";import{addMapDelta as ne,createManipulatorDragEventPipeline as re,dragAtLocation as se,addScreenDelta as le}from"../../../../interactive/dragEventPipeline.js";import{ManipulatorStateFlags as pe,ManipulatorStateCustomFlags as he}from"../../../../interactive/interfaces.js";import{EditGeometryOperations as de}from"../../../../interactive/editGeometry/EditGeometryOperations.js";import{AccumulationBehaviour as ue}from"../../../../interactive/editGeometry/interfaces.js";import{SnappingContext as ce}from"../../../../interactive/snapping/SnappingContext.js";import{SnappingPipeline as me}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{ReshapeEdgeOffsetTooltipInfo as ge}from"../../../../interactive/tooltip/ReshapeTooltipInfos.js";import{Tooltip as _e}from"../../../../interactive/tooltip/Tooltip.js";import{TranslateGraphicTooltipInfo as fe,TranslateZTooltipInfo as ve}from"../../../../interactive/tooltip/TranslateTooltipInfos.js";import{euclideanHorizontalDistanceBetweenPoints as Me,verticalSignedDistanceBetweenPoints as ye}from"../../../../support/lengthMeasurementUtils.js";let Oe=class extends(t.EventedMixin(i)){constructor(e){super(e),this._vertexManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.vertex.color),z.reshapeManipulators.vertex.renderOccluded),this._vertexManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.vertex.outlineColor),z.reshapeManipulators.vertex.renderOccluded),this._vertexManipulatorHoverOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.vertex.hoverOutlineColor),z.reshapeManipulators.vertex.renderOccluded),this._edgeManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.edge.color),z.reshapeManipulators.edge.renderOccluded),this._edgeManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.edge.outlineColor),z.reshapeManipulators.edge.renderOccluded),this._edgeOffsetManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.edgeOffset.color),z.reshapeManipulators.edgeOffset.renderOccluded,!1),this._edgeOffsetManipulatorHoverMaterial=L(z.colorToVec4(z.reshapeManipulators.edgeOffset.hoverColor),z.reshapeManipulators.edgeOffset.renderOccluded,!1),this._selectedManipulatorMaterial=L(z.colorToVec4(z.reshapeManipulators.selected.color),z.reshapeManipulators.selected.renderOccluded),this._selectedManipulatorOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.selected.outlineColor),z.reshapeManipulators.selected.renderOccluded),this._selectedManipulatorHoverOutlineMaterial=D(z.colorToVec4(z.reshapeManipulators.selected.hoverOutlineColor),z.reshapeManipulators.selected.renderOccluded),this._selectedIndex=0,this._vertexManipulatorGeometry=null,this._vertexManipulatorOutlineGeometry=null,this._edgeManipulatorGeometry=null,this._edgeManipulatorOutlineGeometry=null,this._edgeOffsetManipulatorGeometryInside=null,this._edgeOffsetManipulatorGeometryOutside=null,this._manipulatorHandles=new a,this._manipulatorInfos=[],this._editGeometryOperations=null,this._graphicMoveManipulation=null,this._moveManipulation=null,this._numGrabbing=0,this._numDragging=0,this._reshapeEventState=Se.NONE,this._outlineVisualElement=null,this._segmentLabels=null,this.outputGeometry=null,this._snappingPipeline=new me,this._snappingPipelineHandle=new me,this._vertexLaserLineVisualElement=null}initialize(){const{graphic:e,view:t}=this,i=this._graphicState=new ie({graphic:e});this._tooltip=new _e({view:t}),this.own([u((()=>i.displaying),(e=>{for(const t of this._manipulatorInfos)t.manipulator.available=e})),u((()=>this._labelOptions.enabled),(()=>this._updateSegmentLabelsVisibility()),m),c((()=>!this._tooltipOptions.enabled),(()=>this._tooltip.clear()),m),this.view.trackGraphicState(i)])}destroy(){this._segmentLabels=r(this._segmentLabels),this._tooltip=r(this._tooltip),this._editGeometryOperations=r(this._editGeometryOperations),this._moveManipulation=r(this._moveManipulation),this._graphicMoveManipulation=r(this._graphicMoveManipulation),this._manipulatorHandles=r(this._manipulatorHandles),this.manipulators.removeAll(),this._manipulatorInfos=[],this._resetGrabbingDragging()}get inputGeometry(){return s(this._editGeometryOperations)?this._editGeometryOperations.data.geometry:null}set inputGeometry(e){this._recreateEditGeometryAndManipulators(e)}get updating(){return this.updatingHandles.updating}get manipulators(){return this.tool.manipulators}get view(){return this.tool.view}get graphic(){return this.tool.graphic}get enableZShape(){return this.tool.enableZShape}get enableZVertex(){return this.tool.enableZVertex}get enableMoveGraphic(){return this.tool.enableMoveGraphic}get enableMidpoints(){return this.tool.enableMidpoints}get enableEdgeOffset(){return this.tool.enableEdgeOffset}get _labelOptions(){return this.tool.labelOptions}get _tooltipOptions(){return this.tool.tooltipOptions}removeSelectedVertices(){const e=this._manipulatorInfos.filter((e=>e.manipulator.selected&&"vertex"===e.type));this._removeVertices(e)}manipulatorSelectionChanged(){this.emit("manipulators-changed")}_removeManipulators(){this._moveManipulation=r(this._moveManipulation),this._graphicMoveManipulation=r(this._graphicMoveManipulation),this._manipulatorHandles.removeAll(),this.manipulators.removeAll(),this._manipulatorInfos=[]}_resetGrabbingDragging(){this._numGrabbing=0,this._numDragging=0}_createManipulators(){if(l(this._editGeometryOperations))return;const e=H(this.graphic);for(const t of this._editGeometryOperations.data.components){for(const i of t.vertices)this._createVertexOrEdgeManipulator(i,e);for(const i of t.edges)this._createVertexOrEdgeManipulator(i,e)}this._createGraphicMoveManipulators(e)}get canRedo(){return s(this._editGeometryOperations)&&this._editGeometryOperations.canRedo}get canUndo(){return s(this._editGeometryOperations)&&this._editGeometryOperations.canUndo}redo(){if(l(this._editGeometryOperations))return null;const e=this._editGeometryOperations.redo();return s(e)&&(this.outputGeometry=this._editGeometryOperations.data.geometry,this._recreateManipulators()),e}undo(){if(l(this._editGeometryOperations))return null;this.emit("undo");const e=this._editGeometryOperations.undo();return s(e)&&(this.outputGeometry=this._editGeometryOperations.data.geometry,this._recreateManipulators()),e}_recreateManipulators(){this._removeManipulators(),this._resetGrabbingDragging(),this._tooltip.clear(),this._createManipulators()}_recreateEditGeometryAndManipulators(e=this.inputGeometry){this._removeManipulators(),this._resetGrabbingDragging(),this._tooltip.clear(),l(e)||(r(this._editGeometryOperations),this._editGeometryOperations=de.fromGeometry(e,this.view.state.viewingMode),this._createManipulators(),r(this._segmentLabels),this._segmentLabels=new T({context:{view:this.view,editGeometryOperations:this._editGeometryOperations,elevationInfo:H(this.graphic),labelOptions:this._labelOptions}}),this._updateSegmentLabelsVisibility())}_perGraphicManipulatorDragAction(e,t){if("end"===t.action)return t;let i=0;const a=[],o=this._manipulatorInfos.some((e=>"vertex"===e.type&&e.manipulator.selected)),n=e===Ie.SELECTED_OR_ALL&&o;for(const r of this._manipulatorInfos)"vertex"===r.type&&(r.manipulator.grabbing||n&&!r.manipulator.selected||a.push(r),i++);if(0===a.length)return t;this._moveVertices(a,t);if(a.length===i){if(this._updateEventState(Se.MOVING),this.destroyed)return t;this.emit("move",{type:"move",dx:t.screenDeltaX,dy:t.screenDeltaY,mover:this.graphic})}else{if(this._updateEventState(Se.RESHAPING),this.destroyed)return t;this.emit("reshape",{type:"reshape",mover:this.graphic})}return t}_isMultiVertexSelection(){let e=0;for(const t of this._manipulatorInfos)"vertex"===t.type&&t.manipulator.selected&&e++;return e>1}_perVertexManipulatorDragAction(e){if(this._updateEventState(Se.RESHAPING),this.destroyed)return;const{mapDeltaX:t,mapDeltaY:i,mapDeltaZ:a}=e;if(!t&&!i&&!a)return;const o=[];for(const n of this._manipulatorInfos)"vertex"===n.type&&(n.manipulator.selected&&!n.manipulator.grabbing||n===e.info)&&o.push(n);this._moveVertices(o,e,ue.ACCUMULATE_STEPS),this.emit("reshape",{type:"reshape",mover:this.graphic})}_updateEventState(e){if(e===this._reshapeEventState)return!1;switch(e){case Se.NONE:if(0!==this._numGrabbing||0!==this._numDragging)return!1;switch(this._reshapeEventState){case Se.MOVING:this.emit("move",{type:"move-stop",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape-stop",mover:this.graphic})}break;case Se.MOVING:switch(this._reshapeEventState){case Se.NONE:this.emit("move",{type:"move-start",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape-stop",mover:this.graphic}),this.destroyed||this.emit("move",{type:"move-start",dx:0,dy:0,mover:this.graphic})}break;case Se.RESHAPING:switch(this._reshapeEventState){case Se.NONE:this.emit("reshape",{type:"reshape-start",mover:this.graphic});break;case Se.MOVING:this.emit("move",{type:"move-stop",dx:0,dy:0,mover:this.graphic}),this.destroyed||this.emit("reshape",{type:"reshape-start",mover:this.graphic})}}if(this.destroyed)return!1;const t=this._reshapeEventState!==e;return this._reshapeEventState=e,t}_createGraphicMoveManipulators(e){const{graphic:t,handles:i,tool:a,view:o}=this,n=this._graphicState;if(this._graphicMoveManipulation=new B({tool:a,view:o,graphicState:n}),this.enableMoveGraphic){let e=null;this._graphicMoveManipulation.forEachManipulator((e=>{this._manipulatorHandles.add(e.events.on("grab-changed",(({action:e})=>{const t=this._tooltipOptions;"start"===e&&t.enabled?this._tooltip.info=new fe({tooltipOptions:t}):this._tooltip.clear()})))})),this._manipulatorHandles.add(this._graphicMoveManipulation.createDragPipeline(((t,i,a)=>{i.next((e=>this._trackNumDragging(e))).next((t=>("start"===t.action&&(e=p(this._editGeometryOperations).createUndoGroup()),t))).next((e=>this._perGraphicManipulatorDragAction(Ie.ALL,e))).next((e=>this._updateMoveTooltip(e,q.XY))).next((t=>{"end"===t.action&&(e=h(e))})),a.next(this._cancelDragOperation((()=>e=h(e))))})))}else this._graphicMoveManipulation.forEachManipulator((e=>{e.grabbable=!1,e.cursor=null}));this._graphicMoveManipulation.forEachManipulator((e=>this._manipulatorHandles.add([this._watchAndUpdateGrabState(e,!1),e.events.on("immediate-click",(e=>{this._manipulatorInfos.some((e=>e.manipulator.selected))?this._clearSelection():this.emit("immediate-click",{...e,graphic:this.graphic}),e.stopPropagation()}))]))),this._moveManipulation=new W({tool:a,view:o,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZShape&&F(t),snapToScene:!1,radius:W.radiusForSymbol(t.symbol)}),this._moveManipulation.forEachManipulator(((e,a)=>{i.add([this._watchAndUpdateGrabState(e,!1),e.events.on("immediate-click",(i=>{this._moveManipulation.zManipulation.hasManipulator(e)||this._manipulatorInfos.some((e=>e.manipulator.selected))||this.emit("immediate-click",{...i,graphic:t}),i.stopPropagation()}))]),a===C.TRANSLATE_XY&&i.add(e.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new fe({tooltipOptions:t}):this._tooltip.clear()}))),a===C.TRANSLATE_Z&&i.add(e.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new ve({tooltipOptions:t}):this._tooltip.clear()})))})),this._moveManipulation.elevationInfo={mode:"absolute-height",offset:0};const r=p(t.geometry).spatialReference;i.add([this._moveManipulation.createDragPipeline(((i,o,n,r,s)=>{const l=n.next((e=>this._trackNumDragging(e))).next((e=>{const t=this._manipulatorInfos.filter((e=>"vertex"===e.type&&e.manipulator.selected));return e.manipulatorType===C.TRANSLATE_XY&&1===t.length?{...e,info:t[0],snapOrigin:t[0].handle.pos}:{...e,info:null}})).next(this._snappingPipelineHandle.createSnapDragEventPipelineStep({predicate:e=>!!e.info,cancel:r,snappingManager:a.snappingManager,snappingContext:new ce({editGeometryOperations:p(this._editGeometryOperations),elevationInfo:e,pointer:s,excludeFeature:t,visualizer:new j}),updatingHandles:this.updatingHandles}),this._snappingPipelineHandle.next).next(ne()).next((e=>this._perGraphicManipulatorDragAction(Ie.SELECTED_OR_ALL,e))).next((e=>this._updateMoveTooltip(e,i)));return r.next(this._cancelDragOperation()),l}),e,r,t),u((()=>n?.displaying),(()=>{this._updateMoveManipulationPosition()}),m),n.on("changed",(()=>this._updateMoveManipulationPosition())),u((()=>n?.isDraped),(e=>{const t="align-move-manipulation";e?i.add(this.view.elevationProvider.on("elevation-change",(()=>this._updateMoveManipulationPosition())),t):i.remove(t)}),m)]),this._updateMoveManipulationPosition();const l=X({view:o,graphic:t,forEachManipulator:e=>{if(!this.destroyed){s(this._graphicMoveManipulation)&&this._graphicMoveManipulation.forEachManipulator(e);for(const t of this._manipulatorInfos)e(t.manipulator,C.TRANSLATE_XY);this._moveManipulation.forEachManipulator(e)}},onManipulatorsChanged:e=>this.on("manipulators-changed",e)});s(l)&&(this._outlineVisualElement=l.visualElement instanceof te?l.visualElement:null),s(this._outlineVisualElement)&&this._manipulatorHandles.add([this._outlineVisualElement.events.on("attachment-origin-changed",(()=>{n.isDraped||this._updateMoveManipulationPosition()})),u((()=>n.isDraped),(()=>this._updateMoveManipulationPosition()))]),this._manipulatorHandles.add(l)}_createEdgeOffsetManipulator(e,t=H(this.graphic)){const i=z.reshapeManipulators.edgeOffset,a=i.size/2,n=a+i.collisionPadding;if(l(this._edgeOffsetManipulatorGeometryInside)||l(this._edgeOffsetManipulatorGeometryOutside)){const e=a/n,t=e*Math.sqrt(3)/2;this._edgeOffsetManipulatorGeometryInside=ae.createExtrudedTriangle(t,e/2,e/2,i.height,i.offset),this._edgeOffsetManipulatorGeometryOutside=ae.createExtrudedTriangle(-t,e/2,e/2,i.height,-i.offset)}const r=[{geometry:this._edgeOffsetManipulatorGeometryInside,material:this._edgeOffsetManipulatorMaterial,stateMask:pe.Unfocused},{geometry:this._edgeOffsetManipulatorGeometryInside,material:this._edgeOffsetManipulatorHoverMaterial,stateMask:pe.Focused},{geometry:this._edgeOffsetManipulatorGeometryOutside,material:this._edgeOffsetManipulatorMaterial,stateMask:pe.Unfocused},{geometry:this._edgeOffsetManipulatorGeometryOutside,material:this._edgeOffsetManipulatorHoverMaterial,stateMask:pe.Focused}],p=new A({view:this.view,renderObjects:r,elevationInfo:"on-the-ground"!==t.mode||w(this.graphic.symbol)?{mode:"absolute-height",offset:0}:t,worldOriented:!1,focusMultiplier:1,radius:n,available:!(!this.graphic.visible||!this.graphic.layer.visible),collisionType:{type:"disc",direction:G(0,0,1)},collisionPriority:1}),h=new A({view:this.view,renderObjects:[],worldSized:!0,worldOriented:!1,available:!(!this.graphic.visible||!this.graphic.layer.visible),collisionPriority:-10,cursor:this.enableMoveGraphic?"move":"default"}),d={manipulator:p,handle:e,locationUpdateHandle:null,type:"edge",selectedIndex:0,edgeManipulator:h,elevationInfo:t,visibilityHandle:null};this._autoHideEdgeOffsetManipulator(d,i.minSquaredEdgeLength),this._updateEdgeOffsetManipulator(d);const u=this._getManipulatorInfoFromHandle(d.handle.leftVertex).manipulator.events.on("location-update",(()=>this._updateEdgeOffsetManipulator(d))),c=this._getManipulatorInfoFromHandle(d.handle.rightVertex).manipulator.events.on("location-update",(()=>this._updateEdgeOffsetManipulator(d)));d.locationUpdateHandle=o([u,c]),this._manipulatorHandles.add(d.locationUpdateHandle,p),this._manipulatorHandles.add([this._watchAndUpdateGrabState(p,!0),this._watchAndUpdateGrabState(h,!0)],p),this._manipulatorHandles.add(re(p,this._createEdgeOffsetPipeline(d,t)),p),this._manipulatorHandles.add(re(h,((e,i,a,o)=>{if("touch"===o){this._createEdgeOffsetPipeline(d,t)(e,i,a)}else if(this.enableMoveGraphic){const o=this.graphic,n=s(o.geometry)?o.geometry.spatialReference:null;i.next((e=>this._trackNumDragging(e))).next(se(this.view,e.elevationAlignedLocation)).next(k(this.view,e.elevationAlignedLocation,t,n,o)).next(le()).next(ne()).next((e=>this._perGraphicManipulatorDragAction(Ie.ALL,e))),a.next(this._cancelDragOperation())}})),p);const m=e=>{this._manipulatorInfos.some((e=>e.manipulator.selected))?this._clearSelection():this.emit("immediate-click",{...e,graphic:this.graphic}),e.stopPropagation()};return this._manipulatorHandles.add([p.events.on("immediate-click",m),h.events.on("immediate-click",m),p.events.on("focus-changed",(({action:e})=>{const t=this._tooltipOptions;"focus"===e&&t.enabled?this._tooltip.info=new ge({tooltipOptions:t}):this._tooltip.clear()}))],p),this._manipulatorInfos.push(d),this.manipulators.add(p),this.manipulators.add(h),this.emit("manipulators-changed"),d}_autoHideEdgeOffsetManipulator(e,t){const i=e.manipulator,a=e.edgeManipulator,n=()=>{h(e.visibilityHandle);const n=ee(this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator.renderLocation,this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator.renderLocation,this.view.state.camera)<t;(!i.focused&&!a.focused||n)&&(i.grabbable=!n,a.grabbable=!n,e.visibilityHandle=o([i.disableDisplay(),{remove:()=>{i.grabbable=!0,a.grabbable=this.enableMoveGraphic}}]))};this._manipulatorHandles.add([i.events.on("focus-changed",n),a.events.on("focus-changed",n),{remove:()=>{h(e.visibilityHandle),this.manipulators.remove(a)}}],i),n()}_updateEdgeOffsetManipulator(e){this._updateManipulatorPosition(e);const t=p(this._editGeometryOperations).data.coordinateHelper,i=J(this.view,e.manipulator.elevationAlignedLocation,Q(t,e.handle,p(e.manipulator.elevationInfo))),a=this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator.renderLocation,o=this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator.renderLocation,n=s(i)?$(i,a,o):v;e.manipulator.modelTransform=n,e.edgeManipulator.elevationAlignedLocation=e.manipulator.elevationAlignedLocation,e.edgeManipulator.modelTransform=n;const r=M(y(Ee,a,o))/2;e.edgeManipulator.collisionType={type:"line",paths:[[[-r,0,0],[r,0,0]]]}}_createEdgeOffsetPipeline(e,t){return(i,a,o)=>{this._clearSelection();const{step:n,cleanup:r}=this._initializeEdgeOffset(e,t);a.next((e=>this._trackNumDragging(e))).next(se(this.view,i.elevationAlignedLocation)).next(n).next(N(this.view)).next(U(this.view,p(this._editGeometryOperations).data.spatialReference)).next(ne()).next(this._applyComputeEdgeOffsetDistanceStep()).next(this._applyEdgeOffsetStep(e)).next(this._showEdgeOffsetTooltip()).next((e=>{"end"===e.action&&r()})),o.next((e=>(r(),e))).next((e=>(this._tooltip.clear(),e))).next(this._cancelDragOperation())}}_initializeEdgeOffset(e,t){const i=p(this._editGeometryOperations),a=Q(i.data.coordinateHelper,e.handle,t),r=i.createUndoGroup(),s=J(this.view,e.manipulator.elevationAlignedLocation,a);a.requiresSplitEdgeLeft&&this._splitEdgeManipulator(this._getManipulatorInfoFromHandle(e.handle.leftVertex.leftEdge),1),a.requiresSplitEdgeRight&&this._splitEdgeManipulator(this._getManipulatorInfoFromHandle(e.handle.rightVertex.rightEdge),0);const d=()=>new I({paths:[[e.handle.leftVertex.pos,e.handle.rightVertex.pos]],spatialReference:p(this._editGeometryOperations).data.spatialReference}),c=new te({view:this.view,isDraped:this._graphicState.isDraped,geometry:d(),elevationInfo:e.elevationInfo,width:z.visualElements.lineGraphics.outline.width,color:z.colorToVec4(Z.main),attached:!0});let m;const g=()=>{this._cleanEdgeOffsetCollapsedEdges(e),m=h(m)},_=this.on("undo",g);return m=o([n(c),u((()=>this._graphicState.isDraped),(e=>c.isDraped=e)),this._graphicState.on("changed",(()=>c.geometry=d())),r,_]),{step:e=>l(a)||l(s)?(g(),null):{...e,operation:a,plane:s},cleanup:g}}_applyEdgeOffsetStep(e){return t=>{if(this.destroyed||l(t.operation))return t;this._updateEventState(Se.RESHAPING);const{mapDeltaX:i,mapDeltaY:a,mapDeltaZ:o}=t;return(i||a||o)&&(this._offsetEdge(e,t),this.emit("reshape",{type:"reshape",mover:this.graphic})),t}}_applyComputeEdgeOffsetDistanceStep(){return e=>{const{operation:t,mapEnd:i}=e;if(l(t)||l(i))return e;const a=t.signedDistanceToPoint(i);return{...e,signedDistance:a}}}_showEdgeOffsetTooltip(){return e=>{const{mapEnd:t,signedDistance:i}=e,a=this._tooltip,o=this._tooltipOptions;if(!o.enabled||l(i))return a.clear(),e;const n=g(t.spatialReference),r=d(-i*n,"meters");return l(a.info)||"reshape-edge-offset"!==a.info.type?a.info=new ge({tooltipOptions:o,distance:r}):a.info.distance=r,e}}_cleanEdgeOffsetCollapsedEdges(e){const t=e.handle.leftVertex.leftEdge?.leftVertex,i=e.handle.leftVertex,a=e.handle.rightVertex.rightEdge?.rightVertex,o=e.handle.rightVertex,n=p(this._editGeometryOperations).data.coordinateHelper,r=1e-6,s=[];t&&n.distance(t.pos,i.pos)<r&&s.push(this._getManipulatorInfoFromHandle(i)),(n.distance(i.pos,o.pos)<r||a&&n.distance(a.pos,o.pos)<r)&&s.push(this._getManipulatorInfoFromHandle(o)),s.length&&this._removeVertices(s)}_computeVertexManipulatorSizeAndOutline(e){const t=e.size/2,i=t+e.collisionPadding;return{size:t/i,outlineSize:(t+e.outlineSize)/i}}_createVertexOrEdgeManipulator(e,t=H(this.graphic)){if("edge"===e.type){if(this.enableEdgeOffset)return this._createEdgeOffsetManipulator(e,t);if(!this.enableMidpoints)return null}if(l(this._vertexManipulatorGeometry)||l(this._vertexManipulatorOutlineGeometry)){const{size:e,outlineSize:t}=this._computeVertexManipulatorSizeAndOutline(z.reshapeManipulators.vertex);this._vertexManipulatorGeometry=ae.createSphereGeometry(e,16,16),this._vertexManipulatorOutlineGeometry=ae.createSphereGeometry(t,16,16)}if(l(this._edgeManipulatorGeometry)||l(this._edgeManipulatorOutlineGeometry)){const{size:e,outlineSize:t}=this._computeVertexManipulatorSizeAndOutline(z.reshapeManipulators.edge);this._edgeManipulatorGeometry=ae.createSphereGeometry(e,16,16),this._edgeManipulatorOutlineGeometry=ae.createSphereGeometry(t,16,16)}const i=s(this.graphic.geometry)&&"point"===this.graphic.geometry.type?[]:[{geometry:this._vertexManipulatorGeometry,material:this._vertexManipulatorMaterial,stateMask:Ge.Vertex|pe.Unselected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._vertexManipulatorOutlineMaterial,stateMask:Ge.Vertex|pe.Unfocused|pe.Unselected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._vertexManipulatorHoverOutlineMaterial,stateMask:Ge.Vertex|pe.Focused|pe.Unselected},{geometry:this._vertexManipulatorGeometry,material:this._selectedManipulatorMaterial,stateMask:pe.Selected},{geometry:this._vertexManipulatorOutlineGeometry,material:this._selectedManipulatorOutlineMaterial,stateMask:pe.Selected|pe.Unfocused},{geometry:this._vertexManipulatorOutlineGeometry,material:this._selectedManipulatorHoverOutlineMaterial,stateMask:pe.Selected|pe.Focused}];this.enableMidpoints&&i.push({geometry:this._edgeManipulatorGeometry,material:this._vertexManipulatorMaterial,stateMask:Ge.Edge|pe.Focused|pe.Unselected},{geometry:this._edgeManipulatorOutlineGeometry,material:this._vertexManipulatorHoverOutlineMaterial,stateMask:Ge.Edge|pe.Focused|pe.Unselected},{geometry:this._edgeManipulatorGeometry,material:this._edgeManipulatorMaterial,stateMask:Ge.Edge|pe.Unfocused|pe.Unselected},{geometry:this._edgeManipulatorOutlineGeometry,material:this._edgeManipulatorOutlineMaterial,stateMask:Ge.Edge|pe.Unfocused|pe.Unselected});const a=new A({view:this.view,renderObjects:i,elevationInfo:t,focusMultiplier:1,touchMultiplier:1,available:!(!this.graphic.visible||!this.graphic.layer.visible)});this._setTypeSpecificManipulatorSettings(a,e,t);const n="edge"===e.type?{manipulator:a,handle:e,locationUpdateHandle:null,type:"edge",selectedIndex:0}:{manipulator:a,handle:e,type:"vertex",selectedIndex:0};if(this._manipulatorInfos.push(n),this.manipulators.add(a),this._updateManipulatorPosition(n),"edge"===n.type){const e=this._getManipulatorInfoFromHandle(n.handle.leftVertex).manipulator.events.on("location-update",(()=>this._updateManipulatorPosition(n))),t=this._getManipulatorInfoFromHandle(n.handle.rightVertex).manipulator.events.on("location-update",(()=>this._updateManipulatorPosition(n)));n.locationUpdateHandle=o([e,t]),this._manipulatorHandles.add(n.locationUpdateHandle,a)}this._manipulatorHandles.add(this._watchAndUpdateGrabState(a,!0),a);const r=re(a,((e,i,a,o)=>{let r=null;i.next((e=>this._trackNumDragging(e))).next((e=>{if("start"===e.action&&(r=p(this._editGeometryOperations).createUndoGroup()),"edge"===n.type){const t=this._splitEdgeManipulator(n);return{...e,info:t,snapOrigin:t.handle.pos}}return{...e,info:n,snapOrigin:n.handle.pos}})).next(se(this.view,e.elevationAlignedLocation)).next(R(this.view,this.graphic,e.elevationAlignedLocation,e.location.spatialReference,this.graphic)).next(this._snappingPipeline.createSnapDragEventPipelineStep({predicate:()=>!this._isMultiVertexSelection(),cancel:a,snappingManager:this.tool.snappingManager,snappingContext:new ce({editGeometryOperations:p(this._editGeometryOperations),elevationInfo:t,pointer:o,excludeFeature:this.graphic,visualizer:new j}),updatingHandles:this.updatingHandles}),this._snappingPipeline.next).next(ne()).next((e=>{this._perVertexManipulatorDragAction(e),"end"===e.action&&(r=h(r))})),a.next(this._cancelDragOperation((()=>r=h(r))))}));return this._manipulatorHandles.add([r,a.events.on("immediate-click",(e=>this._manipulatorClickCallback(e,n))),a.events.on("select-changed",(()=>{n.selectedIndex=++this._selectedIndex,this._updateMoveManipulationPosition()})),a.events.on("focus-changed",(()=>this._updateSegmentLabelsVisibility()))],a),this.emit("manipulators-changed"),n}_trackNumDragging(e){switch(e.action){case"start":this._numDragging++;break;case"end":this._numDragging--}return e}_updateSegmentLabelsVisibility(){l(this._segmentLabels)||(this._segmentLabels.visible=this._labelOptions.enabled&&!this._manipulatorInfos.some((e=>"edge"===e.type&&e.manipulator.focused)))}_cancelDragOperation(e){return()=>{switch(this._numDragging--,this.undo(),this.outputGeometry=s(this._editGeometryOperations)?this._editGeometryOperations.data.geometry:null,s(this.tool.snappingManager)&&this.tool.snappingManager.doneSnapping(),this._reshapeEventState){case Se.NONE:break;case Se.MOVING:this.emit("move",{type:"move",dx:0,dy:0,mover:this.graphic});break;case Se.RESHAPING:this.emit("reshape",{type:"reshape",mover:this.graphic})}e&&e(),this.destroyed||this._updateEventState(Se.NONE)}}_setTypeSpecificManipulatorSettings(e,t,i){switch(t.type){case"vertex":e.state=Ge.Vertex,e.selectable=!0,e.cursor="move",e.collisionPriority=2,e.radius=z.reshapeManipulators.vertex.size/2+z.reshapeManipulators.vertex.collisionPadding,e.elevationInfo=i,e.interactive=s(this.graphic.geometry)&&"point"!==this.graphic.geometry.type;break;case"edge":e.state=Ge.Edge,e.selectable=!1,e.cursor="copy",e.collisionPriority=-1,e.radius=z.reshapeManipulators.edge.size/2+z.reshapeManipulators.edge.collisionPadding,e.elevationInfo="on-the-ground"!==i.mode||w(this.graphic.symbol)?{mode:"absolute-height",offset:0}:i}}_watchAndUpdateGrabState(e,t){return e.events.on("grab-changed",(i=>{if("start"===i.action)t&&this._updateSelection(e),this._numGrabbing++;else if(this._numGrabbing--,this._updateEventState(Se.NONE),this.destroyed)return;this._moveManipulation.interactive=!this._numGrabbing,("touch"!==i.pointerType||this.enableEdgeOffset)&&(this._manipulatorInfos.forEach((e=>{e.manipulator.interactive=!this._numGrabbing&&s(this.graphic.geometry)&&"point"!==this.graphic.geometry.type,"edgeManipulator"in e&&(e.edgeManipulator.interactive=!this._numGrabbing)})),p(this._graphicMoveManipulation).forEachManipulator((e=>e.interactive=!this._numGrabbing)))}))}_clearSelection(){for(const e of this._manipulatorInfos)e.manipulator.grabbing||(e.manipulator.selected=!1)}_updateSelection(e){e.grabbing&&!e.selected&&e.selectable&&(this._clearSelection(),e.selected=!0,this.emit("manipulators-changed"))}_removeManipulator(e){e&&(this._manipulatorHandles.remove(e.manipulator),this._manipulatorInfos.splice(this._manipulatorInfos.indexOf(e),1),this.manipulators.remove(e.manipulator),this.emit("manipulators-changed"))}_getManipulatorInfoFromHandle(e){if(e)for(const t of this._manipulatorInfos)if(e===t.handle)return t;return null}_updateManipulatorPosition(e){if(!e)return;const t=p(this._editGeometryOperations);if("vertex"===e.type)e.manipulator.location=t.data.coordinateHelper.vectorToDehydratedPoint(e.handle.pos,be),e.manipulator.grabbing&&s(this._vertexLaserLineVisualElement)&&(this._vertexLaserLineVisualElement.visualElement.intersectsWorldUpAtLocation=e.manipulator.renderLocation);else if("edge"===e.type){const i=this._getManipulatorInfoFromHandle(e.handle.leftVertex).manipulator,a=this._getManipulatorInfoFromHandle(e.handle.rightVertex).manipulator;if(s(e.manipulator.elevationInfo)&&"on-the-ground"===e.manipulator.elevationInfo.mode){const o=i.location,n=a.location,r=.5,s=o.x+r*(n.x-o.x),l=o.y+r*(n.y-o.y),p=o.hasZ&&n.hasZ?0:void 0;e.manipulator.location=V(s,l,p,t.data.spatialReference)}else O(Ee,i.renderLocation,a.renderLocation,.5),e.manipulator.renderLocation=Ee}}_splitEdgeManipulator(e,t=.5){const i=p(this._editGeometryOperations),a=p(i.splitEdge(e.handle,t).createdVertex);e.locationUpdateHandle.remove(),e.locationUpdateHandle=void 0;const o=H(this.graphic);let n;this.enableEdgeOffset?(this._removeManipulator(e),n=this._createVertexOrEdgeManipulator(a)):(n=e,n.handle=a,n.type="vertex",this._setTypeSpecificManipulatorSettings(e.manipulator,e.handle,o)),this._updateSegmentLabelsVisibility(),a.leftEdge&&this._createVertexOrEdgeManipulator(a.leftEdge),a.rightEdge&&this._createVertexOrEdgeManipulator(a.rightEdge),this.outputGeometry=i.data.geometry,this._updateManipulatorPosition(n),this._updateSelection(e.manipulator);const r=this._updateEventState(Se.RESHAPING),s=i.data.coordinateHelper.vectorToArray(n.handle.pos),l=i.data.components.indexOf(a.component);return this.emit("vertex-add",{type:"vertex-add",vertices:[{coordinates:s,componentIndex:l,vertexIndex:p(a.index)}],added:s}),r&&this._updateEventState(Se.NONE),n}_updateMoveManipulationPosition(){const e=x(Ee,0,0,0);let t=0,i=!1,a=null,o=null;for(const n of this._manipulatorInfos)"vertex"===n.type&&(n.manipulator.selected?(t++,b(e,e,n.manipulator.renderLocation),l(a)||n.selectedIndex>a.selectedIndex?(o=a,a=n):(l(o)||n.selectedIndex>o.selectedIndex)&&(o=n)):i=!0);if(0!==t){const e=this._graphicState.displaying;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.zManipulation.available=e&&this.enableZVertex&&F(this.graphic),this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e&&1!==t}else{const e=this._graphicState.displaying&&this.enableMoveGraphic;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e,this._moveManipulation.zManipulation.available=e&&this.enableZShape&&F(this.graphic)}if(0!==t){let e=0;if(s(a)){const t=a.handle.pos,i=s(o)?o.handle.pos:a.handle.leftEdge&&a.handle.leftEdge.leftVertex?a.handle.leftEdge.leftVertex.pos:null,n=l(o)&&a.handle.rightEdge&&a.handle.rightEdge.rightVertex?a.handle.rightEdge.rightVertex.pos:null;i&&n?this._moveManipulation.xyAxisManipulation.available=!1:i?e=xe(i,t):n&&(e=xe(t,n))}this._moveManipulation.angle=e,this._moveManipulation.radius=Y}else this._moveManipulation.angleDeferred=()=>K(p(this.graphic.geometry)),this._moveManipulation.radius=W.radiusForSymbol(this.graphic.symbol);0!==t&&i?(E(e,e,1/t),be.spatialReference=p(this._editGeometryOperations).data.spatialReference,be.hasZ=!0,this.view.renderCoordsHelper.fromRenderCoords(e,be),this._moveManipulation.elevationAlignedLocation=be):s(this._outlineVisualElement)&&!this._graphicState.isDraped&&s(this._outlineVisualElement.attachmentOrigin)?this._moveManipulation.elevationAlignedLocation=this._outlineVisualElement.attachmentOrigin:P(this.view,this._moveManipulation,this.graphic)}_removeVertices(e){const t=[],i=p(this._editGeometryOperations);for(const a of e)if("vertex"===a.type&&i.canRemoveVertex()){t.push(a.handle),this._removeManipulator(a),this._removeManipulator(this._getManipulatorInfoFromHandle(a.handle.leftEdge)),this._removeManipulator(this._getManipulatorInfoFromHandle(a.handle.rightEdge));const e=p(i.removeVertices([a.handle]).removedVertices[0].createdEdge);e&&this._createVertexOrEdgeManipulator(e)}if(t.length>0){const e=t.map((e=>{const t=i.data.components.indexOf(e.component);return{coordinates:i.data.coordinateHelper.vectorToArray(e.pos),componentIndex:t,vertexIndex:p(e.index)}}));this.outputGeometry=i.data.geometry;const a=this._updateEventState(Se.RESHAPING);if(this.destroyed)return;if(this.emit("vertex-remove",{type:"vertex-remove",removed:e.map((e=>e.coordinates)),vertices:e}),this.destroyed)return;if(a&&(this._updateEventState(Se.NONE),this.destroyed))return;this._updateMoveManipulationPosition()}}_moveVertices(e,t,i=("start"===t.action?ue.NEW_STEP:ue.ACCUMULATE_STEPS)){const a=p(this._editGeometryOperations);a.moveVertices(e.map((e=>e.handle)),t.mapDeltaX,t.mapDeltaY,t.mapDeltaZ,i),this.outputGeometry=a.data.geometry;for(const o of e)this._updateManipulatorPosition(o)}_offsetEdge(e,t){if(l(t.operation)||l(t.signedDistance))return;const i=p(this._editGeometryOperations),a=t.operation.clone();a.distance=t.signedDistance,i.updateVertices([e.handle.leftVertex,e.handle.rightVertex],a),this.outputGeometry=i.data.geometry,this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.leftVertex)),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.rightVertex))}_manipulatorClickCallback(e,t){e.shiftKey||this._clearSelection(),"vertex"===t.type&&(t.manipulator.selected=!t.manipulator.selected,e.button===oe.Right&&this._removeVertices([t])),"edge"===t.type&&e.button===oe.Left&&this._splitEdgeManipulator(t),e.stopPropagation()}_updateMoveTooltip(e,t){const i=this._tooltipOptions;if(!i.enabled)return e;if(t===q.XY||t===q.XY_AXIS){const t=Me(e.mapStart,e.mapEnd);s(t)&&(this._tooltip.info=new fe({tooltipOptions:i,distance:t}))}if(t===q.Z){const t=ye(e.mapStart,e.mapEnd);s(t)&&(this._tooltip.info=new ve({tooltipOptions:i,distance:t}))}return e}get test(){return{segmentLabels:this._segmentLabels,tooltip:this._tooltip}}};function xe(e,t){return Math.atan2(t[1]-e[1],t[0]-e[0])+Math.PI/2}e([_({constructOnly:!0})],Oe.prototype,"tool",void 0),e([_()],Oe.prototype,"_tooltip",void 0),e([_()],Oe.prototype,"inputGeometry",null),e([_()],Oe.prototype,"outputGeometry",void 0),e([_({readOnly:!0})],Oe.prototype,"updating",null),e([_()],Oe.prototype,"_labelOptions",null),e([_()],Oe.prototype,"_tooltipOptions",null),Oe=e([f("esri.views.3d.interactive.editingTools.reshapeGraphic.ReshapeOperation")],Oe);const be=V(0,0,null,null),Ee=S();var Ge,Se,Ie;!function(e){e.Vertex=he.Custom1,e.Edge=he.Custom2}(Ge||(Ge={})),function(e){e[e.NONE=0]="NONE",e[e.MOVING=1]="MOVING",e[e.RESHAPING=2]="RESHAPING"}(Se||(Se={})),function(e){e[e.ALL=0]="ALL",e[e.SELECTED_OR_ALL=1]="SELECTED_OR_ALL"}(Ie||(Ie={}));export{Oe as ReshapeOperation};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as e,isNone as t,unwrap as i}from"../../../../core/maybe.js";import s from"../../../../core/PooledArray.js";import{isAbortError as r}from"../../../../core/promiseUtils.js";import{l as n}from"../../../../chunks/vec3.js";import{b as o}from"../../../../chunks/vec4f64.js";import{LodMetric as a,NodeBase as d,Node as l,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{addWraparound as g}from"./I3SUtil.js";import{clone as _}from"../../support/orientedBoundingBox.js";class m{constructor(e,t,i,s,r){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=s,this.node=r,this.useAsHole=0,this.filterImpact=h.NotChecked}}class f{constructor(e,t,i,r,n,o,d,l,h,u,c,g,_,m){this.streamDataController=i,this.viewportQueries=r,this.logger=n,this.holeFilling=o,this._isLoaded=d,this._isReloading=l,this._isSelected=h,this._enable=u,this._needsUpdate=c,this._canRequest=g,this._computeVisibilityObb=_,this._computeNodeFiltering=m,this._dirty=!0,this._nodePages=[],this.nodeCount=0,this.nodesPerPage=0,this.rootIndex=0,this.lodMetric=a.None,this._lodConversion=e=>e,this.urlPrefix="",this._loading=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._nodeTraversalState=new Map,this._version=P(0),this._visibilityCacheVersion=P(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missing=new s({deallocator:null}),this._prefetch=new s({deallocator:null}),this._updates=new b(this._missing),this._imModificationUncategorized=new s({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=[],this.layerHasModifications=!1,this._layerHasFilter=!1,this.logLayer=e,e.serviceUpdateTimeStamp&&e.serviceUpdateTimeStamp.lastUpdate&&(this.lastUpdate=`${e.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this.viewportQueries?this.viewportQueries.maxLodLevel:1,this._init(t)}_init(e){if("page"===e.type){switch(this.urlPrefix=e.urlPrefix,this.nodesPerPage=e.pageSize,this.rootIndex=e.rootIndex,e.lodMetric){case"maxScreenThreshold":this.lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this.lodMetric=a.MaxScreenThreshold,this._lodConversion=L}this._addPage(C(this.rootIndex,this.nodesPerPage),e.rootPage),this._updateParentsAndLevel()}else if("node"===e.type){this.urlPrefix=e.urlPrefix,this._nodePages.push({nodes:[],children:[],parents:[]}),this._makeRefNode(new d(e.rootNode.id,null),-1);const t=this._validateNode(e.rootNode.id,e.rootNode);t&&this._addNode(t,0)}}_loadPage(e){this._loading.add(e);const t=this.urlPrefix+e;this.streamDataController.request(t,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((t=>{this._loading.delete(e),r(t)||(this._failedPages.add(e),this.logger.error("#loadPage()",this.logLayer,`Error when loading page ${e}`,t))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loading.delete(t),e.madeProgress()}this._updateParentsAndLevel()}_addPage(e,t){for(let n=this._nodePages.length;n<e;n++)this._nodePages[n]=null;const i=[],s=[],r=t.nodes.map(((t,r)=>{const a=i.length,d=t.children?t.children.length:0;s.push(-1);for(let e=0;e<d;e++)i.push(t.children[e]);const h=`${t.index}`,u=_(t.obb),c=o([u.center[0],u.center[1],u.center[2],n(u.halfSize)]),g=t.mesh&&t.mesh.attribute,f=t.mesh&&t.mesh.geometry,v=t.mesh&&t.mesh.material,b={hasSharedResource:!1,hasFeatureData:!!f,attributes:g&&null!=g.resource?`${g.resource}`:null,geometry:f&&null!=f.resource?`${f.resource}`:null,texture:v&&null!=v.resource?`${v.resource}`:null,geometryDefinition:f?f.definition:-1,materialDefinition:v?v.definition:-1},p=new l(h,e*this.nodesPerPage+r,c,d,0,b,this.lastUpdate,this.lodMetric,this._lodConversion(t.lodThreshold),f?f.featureCount:null);return p.serviceObb=u,p.visibilityObb=this._computeVisibilityObb(p),p.vertexCount=f?f.vertexCount:0,new m(a,d,y(this._visibilityCacheVersion),null,p)}));this._nodePages[e]={nodes:r,children:i,parents:s},this.nodeCount+=r.length}_updateParentsAndLevel(){const t=new Array,i=(i,s,r)=>{const n=this._getPage(i);if(e(n)){const o=w(i,this.nodesPerPage);n.parents[o]=s;const a=n.nodes[o].node;e(a)&&(a.level=r,t.push(i))}};for(i(this.rootIndex,-1,0);t.length;){const s=t.pop(),r=this.getNode(s);if(e(r))for(let e=0;e<r.childCount;e++){i(this.getChildIndex(r,e),s,r.level+1),this._maxLevel=Math.max(this._maxLevel,r.level+1)}}}_getPage(e){return this._nodePages[C(e,this.nodesPerPage)]}_getNodeInternal(e){const i=this._getPage(e);return t(i)?null:i.nodes[w(e,this.nodesPerPage)]}_addNode(t,s){null!=t.children&&this.populateChildren(s,t.children);const r=this.getParent(s),n=e(r)?r.level+1:0;this._maxLevel=Math.max(this._maxLevel,t.children?n+1:n);const{lodMetric:a,maxError:d}=M(t.lodSelection),h=i(this._getNodeInternal(s));return h.node=new l(t.id,s,o(t.mbs),h.childCount,n,t.resources,t.version,a,d,t.numFeatures),t.obb&&(h.node.serviceObb=_(t.obb)),h.node.visibilityObb=this._computeVisibilityObb(h.node),e(h.ref)&&(null==h.ref.mbs&&(h.ref.mbs=t.mbs),h.node.renderMbs=h.ref.renderMbs,h.node.serviceObbInRenderSR=h.ref.serviceObbInRenderSR,h.ref.visibilityObb=h.node.visibilityObb),h.node}_makeRefNode(t,i){const s=this._nodePages[0],r=s.nodes.length;return s.nodes.push(new m(0,0,y(this._visibilityCacheVersion),t,null)),this.nodeCount++,s.parents.push(i),t.renderMbs[3]=-1,e(t.serviceObbInRenderSR)&&(t.serviceObbInRenderSR.halfSize[0]=-1),r}populateChildren(e,t){const s=i(this._getNodeInternal(e)),r=i(this._getPage(e));s.childOffset=r.children.length,s.childCount=t.length;for(let i=0;i<t.length;i++){const s=this._makeRefNode(t[i],e);r.children.push(s)}}getNode(t){const i=this._getNodeInternal(t);return e(i)?i.node:null}getIndexById(t){let i;return this._forAllNodes(((s,r)=>{(e(s.node)&&s.node.id===t||e(s.ref)&&s.ref.id===t)&&(i=r)})),i}getNodeById(e){const t=this.getIndexById(e);return t>=0?this.getNode(t):null}getChildIndex(e,i){const s=this._getPage(e.index);if(t(s))return-1;const r=s.nodes[w(e.index,this.nodesPerPage)];return s.children[r.childOffset+i]}getParentIndex(t){const i=this._getPage(t);return e(i)?i.parents[w(t,this.nodesPerPage)]:-1}getParent(e){return(e=this.getParentIndex(e))>=0?this.getNode(e):null}isLeaf(t){const i=this._getNodeInternal(t);return e(i)&&0===i.childCount}get rootNode(){return this.getNode(this.rootIndex)}get size(){return this.nodeCount}removeAllGeometryObbs(){this._forAllNodes((t=>{e(t.node)&&(t.node.geometryObb=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=P(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(t){const i=this._getNodeInternal(t);e(i)&&this.invalidateNodeVisibilityCacheInternal(i)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=y(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(t){const i=this._getNodeInternal(t);e(i)&&(p(i),this.invalidateNodeVisibilityCacheInternal(i))}invalidateGeometryVisibility(t){const i=this._getNodeInternal(t);e(i)&&e(i.node)&&(i.node.geometryObb=null,i.node.renderMbs[3]=-1,e(i.node.serviceObbInRenderSR)&&(i.node.serviceObbInRenderSR.halfSize[0]=-1))}invalidateVisibilityObbs(){t(this.rootNode)||this.traverse(this.rootNode,(e=>(e.visibilityObb=this._computeVisibilityObb(e),e.geometryObb=null,!0)))}isNodeVisible(i){const s=this._getNodeInternal(i);if(t(s)||e(s.ref)&&!s.ref.mbs)return!0;if(!x(s.visibilityCache,this._visibilityCacheVersion)){const i=s.node,r=e(i)&&(t(s.ref)||e(i.visibilityObb))?i:e(s.ref)?s.ref:null;if(this._layerHasFilter&&this._computeNodeFiltering&&(e(i)||e(s.ref))&&s.filterImpact===h.NotChecked){const t=e(i)?i.mbs:e(s.ref)?s.ref.mbs:null;s.filterImpact=null!=t?this._computeNodeFiltering(t):h.Unmodified}const n=e(i)&&s.filterImpact===h.Culled,o=!(e(i)&&i.imModificationImpact===u.Culled)&&(!r||this.viewportQueries.isNodeVisible(r))&&!n;return s.visibilityCache=N(o,this._visibilityCacheVersion),o}return I(s.visibilityCache)}isGeometryVisible(t){if(!this.isNodeVisible(t))return!1;const i=this._getNodeInternal(t);return!(e(i)&&e(i.node)&&e(i.node.geometryObb)&&(!this.layerHasModifications||i.node.imModificationImpact!==u.NotChecked))||this.viewportQueries.isGeometryVisible(i.node)}_traverseCoverage(s,r,n,o,a){const d=this._getPage(s);if(t(d)||0===r.childCount)return;const l=r.childOffset+r.childCount,h=new Array;for(let t=r.childOffset;t<l;++t){const i=d.children[t],s=this._getNodeInternal(i);e(s)&&e(s.node)&&this.isGeometryVisible(i)&&h.push(s)}o/=h.length;for(const e of h){const t=i(e.node).index;this._isLoaded(t)||this._isReloading(t)?(a.delta=Math.max(a.delta,n),a.coverage+=o):this._traverseCoverage(t,e,n+1,o,a)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const i=this._getNodeInternal(e);if(t(i))return!1;if("always"===this.holeFilling)return!0;if(x(i.useAsHole,this._version))return I(i.useAsHole);const s={delta:0,coverage:0};this._traverseCoverage(e,i,0,1,s);const r=s.delta*s.coverage<=.5;return i.useAsHole=N(r,this._version),r}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=P(this._version)}imModificationsChanged(t){this.layerHasModifications=t,this._forAllNodes((({node:t})=>{e(t)&&(t.imModificationImpact=u.NotChecked,t.visibilityObb=this._computeVisibilityObb(t),t.hasModifications&&this.invalidateGeometryVisibility(t.index))})),this.invalidateVisibilityCache()}layerFilterChanged(t){this._layerHasFilter=t,this._forAllNodes((t=>{if(e(t)){t.filterImpact=h.NotChecked;const i=t.node;e(i)&&this.invalidateNodeVisibilityCache(i.index)}})),this.invalidateVisibilityCache()}update(s,r,n){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(r),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missing.clear(),this._prefetch.clear(),this._updates.reset(s),v.clear();let o=!0;const a=new O,d=new O,l=this._imModificationUncategorized;l.clear();const h=new Set,c=(c,g,_)=>{if(t(g)){let e=this._entryPriority(c);e===1/0&&(e=this._entryPriority(_));const t=C(c,this.nodesPerPage);return v.set(t,Math.max(e,v.get(t)||0)),this._loading.has(t)||this._failedPages.has(t)||this._missing.push(t),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const m=g.node;if(this._updateNodeFeatureEstimate(m,d),t(m)){const e=this._entryPriority(c);return this._loading.has(c)||this._failedNodes.has(c)||(this._missing.push(c),v.set(c,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const f=i(this._getPage(c));if(0===this._missing.length&&0===this.nodesPerPage)for(let t=0;t<g.childCount;t++){const i=f.children[g.childOffset+t],s=this._getNodeInternal(i);!e(s)||s.node||this._loading.has(i)||this._failedNodes.has(i)||(v.set(i,this._entryPriority(i)),this._prefetch.push(i))}if(m.failed||!m.resources.hasFeatureData)return void(o&&g.childCount>0&&this._isSelected(m)&&(o=!1));if(h.add(m.id),this._isLoaded(c)){if(a.known+=m.memory,++a.knownNodes,this._isSelected(m)?g.childCount>0&&(o=!1):(a.unremoved+=m.memory,o=!1),this._needsUpdate(m)){const e=this._entryPriority(c);v.set(c,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(c)}return}if(m.memory&&(a.known+=m.memory,++a.knownNodes),!this._isSelected(m))return void(this._isReloading(c)&&this._updates.remove.push(c));if(g.childCount>0&&(o=!1),m.memory?(a.missing+=m.memory,a.known+=m.memory,++a.knownNodes):++a.missingNodes,s.includes(m.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(c)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==m.index)));if(!r.done&&this._enable(m))return void r.madeProgress();const b=this._entryPriority(c);v.set(c,b),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,b),this._updates.add.push(c),this.layerHasModifications&&n&&e(m)&&m.imModificationImpact===u.NotChecked&&l.push(c)};this.traverseVisible(c);const g=this._updates.add;g.length>0&&this.layerHasModifications&&(l.length>0&&n(l),g.filterInPlace((e=>{const i=this._getNodeInternal(e),s=t(i)||t(i.node)||i.node.imModificationImpact!==u.Culled;return s||this.invalidateNodeVisibilityCache(e),s}))),this._unloadedMemoryEstimate=a.missing-a.unremoved,a.knownNodes>3&&a.missingNodes>0&&(this._unloadedMemoryEstimate+=a.known/a.knownNodes*a.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(d),this._featureEstimate.leavesReached=o,this._missing.sort(((e,t)=>e-t)),this._missing.filterInPlace(((e,t)=>t<1||this._missing.data[t-1]!==e)),this._missing.sort(((e,t)=>v.get(e)-v.get(t))),this._missing.length>0&&(this._maxUnloadedPrio=v.get(this._missing.back()),this._prefetch.clear()),this._updates.add.filterInPlace((e=>v.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>v.get(e)-v.get(t))),this._updates.update.sort(((e,t)=>v.get(e)-v.get(t))),this._indexMissing=this._loading.size+this._missing.length,this._dirty=this._indexMissing>0,v.clear()}checkFeatureTarget(e,t){const i=this.viewportQueries.updateScreenSpaceErrorBias(t);let s=t,r=t,n=i,o=10;for(;o--;){const i=new O;this._updateFeatureEstimate(s,i);if(this._computeFeatureEstimate(i)<=e){if(s>=t||i.missingNodes>0||0===o)break;n=s,s=.5*(s+r)}else r=s,s=.5*(s+n)}return this._version=P(this._version),this.viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,s)}_updateFeatureEstimate(t,i){this._version=P(this._version),this.viewportQueries.updateScreenSpaceErrorBias(t),this.traverseVisible(((t,s)=>this._updateNodeFeatureEstimate(e(s)&&s.node,i)))}_updateNodeFeatureEstimate(i,s){if(!(t(i)||i.failed||t(i.numFeatures)))return this._isLoaded(i.index)?(s.known+=i.numFeatures,++s.knownNodes,void(this._isSelected(i)||(s.unremoved+=i.numFeatures))):void(this._isSelected(i)&&(e(i.numFeatures)?(s.missing+=i.numFeatures,s.known+=i.numFeatures,++s.knownNodes):++s.missingNodes))}_computeFeatureEstimate(e){let t=e.known-e.unremoved;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.known/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missing)}prefetch(){return this._prefetch.sort(((e,t)=>v.get(e)-v.get(t))),this._load(this._prefetch)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();)0===this.nodesPerPage?this._loadNode(e.pop()):this._loadPage(e.pop());return!0}isLoading(){return this._indexMissing>0}getIndexLoading(){return this._loading.size}getIndexMissing(){return this._indexMissing}getUnloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}nodeTraversalState(e){if(t(e))return null;let i=this._nodeTraversalState.get(e.index);if(i&&x(i.version,this._version))return i;const s=this.viewportQueries.getLodLevel(e),r=this.viewportQueries.hasLOD(e);let n=!0;if(r){const t=this.getParentIndex(e.index);if(t>=0){const e=this._nodeTraversalState.get(t);n=e&&s>e.lodLevel}else n=s>0}else n=0===e.childCount;return i?(i.lodLevel=s,i.isChosen=n,i.version=N(!0,this._version),i):(i=new c(r,n,s,N(!0,this._version)),this._nodeTraversalState.set(e.index,i),i)}_loadNode(e){this._loading.add(e);const s=i(this._getNodeInternal(e)).ref;if(t(s))return void this._failedNodes.add(e);const n=s.id,o=this.urlPrefix+n,a=()=>{this._loading.delete(e),0===this._missing.length&&0===this._loading.size&&this.requestUpdate()};this.streamDataController.request(o,"json").then((t=>{a();const i=this._validateNode(n,t);if(null==i)return;i.obb&&this.invalidateNodeVisibilityCache(e);const s=this._addNode(i,e);this.nodeTraversalState(s)}),(t=>{a(),r(t)||(this.logger.error("#loadNode()",this.logLayer,"Error loading node: "+o),this._failedNodes.add(e))}))}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this.logger.error("#validateNode()",this.logLayer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this.logger.error("#validateNode()",this.logLayer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this.logger.warn("#validateNode()",this.logLayer,`Invalid shared resource href on node "${e}"`),null==t.geometryData||Array.isArray(t.geometryData)&&1===t.geometryData.length&&"./geometries/0"===t.geometryData[0].href||this.logger.warn("#validateNode()",this.logLayer,`Invalid geometry data on node "${e}"`),null==t.attributeData||Array.isArray(t.attributeData)&&!t.attributeData.some(((e,t)=>e.href!==`./attributes/f_${t}/0`))||this.logger.warn("#validateNode()",this.logLayer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this.logger.warn("#validateNode()",this.logLayer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const i=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:null,s=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:null,r=t=>{if(null==t)return null;const i=t=>this.logger.error("#validateNode()",this.logLayer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this.logger.error("#validateNode()",this.logLayer,`Invalid node href on node "${e}"`);const s=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:null,r=new d(`${t.id}`,t.mbs);return r.serviceObb=s,r.visibilityObb=this._computeVisibilityObb(r),r},n=Array.isArray(t.children)?t.children.map(r).filter((e=>null!=e)):null;return{id:e,mbs:t.mbs,obb:i,children:n,resources:{hasFeatureData:t.featureData&&t.featureData.length>0,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:null,texture:t.textureData&&t.textureData.length>0?e:null,geometry:null!=t.geometryData?e:null},version:"string"==typeof t.version?t.version:null,lodSelection:Array.isArray(t.lodSelection)?t.lodSelection:null,numFeatures:s}}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((t=>{e(t.node)&&(t.node.failed=!1)}))}_entryPriority(i){const s=this._getNodeInternal(i),r=this.getParentIndex(i);if(t(s)||r<0&&null==s.node)return r<0?1/0:this._entryPriority(r);let n=0;if(s.node&&r>=0){const e=this._nodeTraversalState.get(r);null!=e&&(n=e.lodLevel)}let o=this.progressiveLoadPenalty;for(let e=i;e>=0;e=this.getParentIndex(e))if(this._isLoaded(e)){o=0;break}const a=e(s.ref)?this.viewportQueries.distToPOI(s.ref):e(s.node)?this.viewportQueries.distToPOI(s.node):0;return-a-n*(a+this.progressiveLoadPenalty)+o}traverseVisible(e){const i=this._getNodeInternal(this.rootIndex);t(i)?e(this.rootIndex,null,null):this._traverseVisible(this.rootIndex,-1,i,e)}_traverseVisible(t,s,r,n){if(r.node&&0===r.childCount)return void(this.isGeometryVisible(t)&&n(t,r,s));if(!this.isNodeVisible(t))return;if(n(t,r,s),null==r.node)return;const o=this.nodeTraversalState(r.node);if(o.nodeHasLOD&&o.lodLevel===this._maxLodLevel)return;const a=i(this._getPage(t));for(let i=0;i<r.childCount;i++){const s=a.children[r.childOffset+i],o=this._getNodeInternal(s);e(o)?this._traverseVisible(s,t,o,n):n(s,null,t)}}traverse(e,t){t(e)&&this.traverseChildren(e,t)}traverseChildren(t,i){const s=t.index,r=this._getNodeInternal(s);e(r)&&this._traverseChildren(s,r,i)}_traverseChildren(i,s,r){const n=this._getPage(i);if(t(n))return;const o=s.childOffset+s.childCount;for(let t=s.childOffset;t<o;++t){const i=n.children[t],s=this._getNodeInternal(i);e(s)&&e(s.node)&&r(s.node)&&this._traverseChildren(i,s,r)}}updateChildrenLoaded(t,i){let s=this.getNode(t);for(;e(s);)s.childrenLoaded+=i,s=this.getParent(s.index)}checkChildrenLoadedInvariant(){if(t(this.rootNode))return!0;const e=[],i=t=>{let s=this._isLoaded(t.index)||this._isReloading(t.index)?1:0;return this.traverseChildren(t,(e=>(s+=i(e),!1))),t.childrenLoaded!==s&&e.push(t.index),s};return i(this.rootNode),e.length&&this.logger.error("childrenLoaded invariant broken at following nodes: "+e.join(",")),e.length>0}updateStats(e){if(this._updates.add.length>0&&(e.nodes+=" + "+this._updates.add.length),(this._indexMissing||this._prefetch.length>0)&&(e.index+=" + "+this._indexMissing||this._prefetch.length),e.prio=this._maxProcessingPrio,this._featureEstimate.estimate){const t=this._featureEstimate.estimate-e.features;t>0?e.features+=" + "+t:t<0&&(e.features+=" - "+-t)}}getPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}updateElevationInfo(e){this._forAllNodes(p),this.viewportQueries.updateElevationInfo(e)}_forAllNodes(e){for(let t=0;t<this._nodePages.length;t++){const i=this._nodePages[t];if(i){const s=t*this.nodesPerPage;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],s+t)}}}get test(){return{addNode:(e,t)=>this._addNode(e,t)}}}const v=new Map;class b{constructor(e){this.missing=e,this.update=new s({deallocator:null}),this.add=new s({deallocator:null}),this.remove=new s({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function p(t){e(t.node)&&(t.node.renderMbs[3]=-1,e(t.node.serviceObbInRenderSR)&&(t.node.serviceObbInRenderSR.halfSize[0]=-1)),e(t.ref)&&(t.ref.renderMbs[3]=-1,e(t.ref.serviceObbInRenderSR)&&(t.ref.serviceObbInRenderSR.halfSize[0]=-1))}function y(e){return g(e,-2)}function P(e){return g(e,2)}function N(e,t){return t+(e?1:0)}function x(e,t){return(-2&e)===t}function I(e){return 1==(1&e)}function C(e,t){return 0===t?0:e/t|0}function w(e,t){return 0===t?e:e%t}const S=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function M(e){if(e)for(let t=0;t<e.length;t++)for(const i of S)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class O{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}function L(e){return Math.sqrt(e*(4/Math.PI))}export{f as I3SIndex,M as selectErrorMetric};
5
+ import{isSome as e,isNone as t,unwrap as i}from"../../../../core/maybe.js";import s from"../../../../core/PooledArray.js";import{isAbortError as r}from"../../../../core/promiseUtils.js";import{l as n}from"../../../../chunks/vec3.js";import{b as o}from"../../../../chunks/vec4f64.js";import{LodMetric as a,NodeBase as d,Node as l,NodeFilterImpact as h,NodeIMModificationImpact as u,NodeTraversalState as c}from"./I3SNode.js";import{addWraparound as g,invalidateMbs as _,invalidateObb as m}from"./I3SUtil.js";import{clone as f}from"../../support/orientedBoundingBox.js";class v{constructor(e,t,i,s,r){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this.ref=s,this.node=r,this.useAsHole=0,this.filterImpact=h.NotChecked}}class b{constructor(e,t,i,r,n,o,d,l,h,u,c,g,_,m){this.streamDataController=i,this.viewportQueries=r,this.logger=n,this.holeFilling=o,this._isLoaded=d,this._isReloading=l,this._isSelected=h,this._enable=u,this._needsUpdate=c,this._canRequest=g,this._computeVisibilityObb=_,this._computeNodeFiltering=m,this._dirty=!0,this._nodePages=[],this.nodeCount=0,this.nodesPerPage=0,this.rootIndex=0,this.lodMetric=a.None,this._lodConversion=e=>e,this.urlPrefix="",this._loading=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._nodeTraversalState=new Map,this._version=x(0),this._visibilityCacheVersion=x(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missing=new s({deallocator:null}),this._prefetch=new s({deallocator:null}),this._updates=new y(this._missing),this._imModificationUncategorized=new s({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=[],this.layerHasModifications=!1,this._layerHasFilter=!1,this.logLayer=e,e.serviceUpdateTimeStamp&&e.serviceUpdateTimeStamp.lastUpdate&&(this.lastUpdate=`${e.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this.viewportQueries?this.viewportQueries.maxLodLevel:1,this._init(t)}_init(e){if("page"===e.type){switch(this.urlPrefix=e.urlPrefix,this.nodesPerPage=e.pageSize,this.rootIndex=e.rootIndex,e.lodMetric){case"maxScreenThreshold":this.lodMetric=a.MaxScreenThreshold;break;case"maxScreenThresholdSQ":this.lodMetric=a.MaxScreenThreshold,this._lodConversion=E}this._addPage(M(this.rootIndex,this.nodesPerPage),e.rootPage),this._updateParentsAndLevel()}else if("node"===e.type){this.urlPrefix=e.urlPrefix,this._nodePages.push({nodes:[],children:[],parents:[]}),this._makeRefNode(new d(e.rootNode.id,null),-1);const t=this._validateNode(e.rootNode.id,e.rootNode);t&&this._addNode(t,0)}}_loadPage(e){this._loading.add(e);const t=this.urlPrefix+e;this.streamDataController.request(t,"json").then((t=>{this._pageQueue.push({pageIndex:e,page:t})})).catch((t=>{this._loading.delete(e),r(t)||(this._failedPages.add(e),this.logger.error("#loadPage()",this.logLayer,`Error when loading page ${e}`,t))}))}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loading.delete(t),e.madeProgress()}this._updateParentsAndLevel()}_addPage(e,t){for(let n=this._nodePages.length;n<e;n++)this._nodePages[n]=null;const i=[],s=[],r=t.nodes.map(((t,r)=>{const a=i.length,d=t.children?t.children.length:0;s.push(-1);for(let e=0;e<d;e++)i.push(t.children[e]);const h=`${t.index}`,u=f(t.obb),c=o([u.center[0],u.center[1],u.center[2],n(u.halfSize)]),g=t.mesh&&t.mesh.attribute,_=t.mesh&&t.mesh.geometry,m=t.mesh&&t.mesh.material,b={hasSharedResource:!1,hasFeatureData:!!_,attributes:g&&null!=g.resource?`${g.resource}`:null,geometry:_&&null!=_.resource?`${_.resource}`:null,texture:m&&null!=m.resource?`${m.resource}`:null,geometryDefinition:_?_.definition:-1,materialDefinition:m?m.definition:-1},p=new l(h,e*this.nodesPerPage+r,c,d,0,b,this.lastUpdate,this.lodMetric,this._lodConversion(t.lodThreshold),_?_.featureCount:null);return p.serviceObb=u,p.visibilityObb=this._computeVisibilityObb(p),p.vertexCount=_?_.vertexCount:0,new v(a,d,N(this._visibilityCacheVersion),null,p)}));this._nodePages[e]={nodes:r,children:i,parents:s},this.nodeCount+=r.length}_updateParentsAndLevel(){const t=new Array,i=(i,s,r)=>{const n=this._getPage(i);if(e(n)){const o=S(i,this.nodesPerPage);n.parents[o]=s;const a=n.nodes[o].node;e(a)&&(a.level=r,t.push(i))}};for(i(this.rootIndex,-1,0);t.length;){const s=t.pop(),r=this.getNode(s);if(e(r))for(let e=0;e<r.childCount;e++){i(this.getChildIndex(r,e),s,r.level+1),this._maxLevel=Math.max(this._maxLevel,r.level+1)}}}_getPage(e){return this._nodePages[M(e,this.nodesPerPage)]}_getNodeInternal(e){const i=this._getPage(e);return t(i)?null:i.nodes[S(e,this.nodesPerPage)]}_addNode(t,s){null!=t.children&&this.populateChildren(s,t.children);const r=this.getParent(s),n=e(r)?r.level+1:0;this._maxLevel=Math.max(this._maxLevel,t.children?n+1:n);const{lodMetric:a,maxError:d}=O(t.lodSelection),h=i(this._getNodeInternal(s));return h.node=new l(t.id,s,o(t.mbs),h.childCount,n,t.resources,t.version,a,d,t.numFeatures),t.obb&&(h.node.serviceObb=f(t.obb)),h.node.visibilityObb=this._computeVisibilityObb(h.node),e(h.ref)&&(null==h.ref.mbs&&(h.ref.mbs=t.mbs),h.node.renderMbs=h.ref.renderMbs,h.node.serviceObbInRenderSR=h.ref.serviceObbInRenderSR,h.ref.visibilityObb=h.node.visibilityObb),h.node}_makeRefNode(e,t){const i=this._nodePages[0],s=i.nodes.length;return i.nodes.push(new v(0,0,N(this._visibilityCacheVersion),e,null)),this.nodeCount++,i.parents.push(t),_(e.renderMbs),m(e.serviceObbInRenderSR),s}populateChildren(e,t){const s=i(this._getNodeInternal(e)),r=i(this._getPage(e));s.childOffset=r.children.length,s.childCount=t.length;for(let i=0;i<t.length;i++){const s=this._makeRefNode(t[i],e);r.children.push(s)}}getNode(t){const i=this._getNodeInternal(t);return e(i)?i.node:null}getIndexById(t){let i;return this._forAllNodes(((s,r)=>{(e(s.node)&&s.node.id===t||e(s.ref)&&s.ref.id===t)&&(i=r)})),i}getNodeById(e){const t=this.getIndexById(e);return t>=0?this.getNode(t):null}getChildIndex(e,i){const s=this._getPage(e.index);if(t(s))return-1;const r=s.nodes[S(e.index,this.nodesPerPage)];return s.children[r.childOffset+i]}getParentIndex(t){const i=this._getPage(t);return e(i)?i.parents[S(t,this.nodesPerPage)]:-1}getParent(e){return(e=this.getParentIndex(e))>=0?this.getNode(e):null}isLeaf(t){const i=this._getNodeInternal(t);return e(i)&&0===i.childCount}get rootNode(){return this.getNode(this.rootIndex)}get size(){return this.nodeCount}removeAllGeometryObbs(){this._forAllNodes((t=>{e(t.node)&&(t.node.geometryObb=null)}))}invalidateVisibilityCache(){this._visibilityCacheVersion=x(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(t){const i=this._getNodeInternal(t);e(i)&&this.invalidateNodeVisibilityCacheInternal(i)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=N(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(t){const i=this._getNodeInternal(t);e(i)&&(P(i),this.invalidateNodeVisibilityCacheInternal(i))}invalidateGeometryVisibility(t){const i=this._getNodeInternal(t);e(i)&&e(i.node)&&(i.node.geometryObb=null,_(i.node.renderMbs),m(i.node.serviceObbInRenderSR))}invalidateVisibilityObbs(){t(this.rootNode)||this.traverse(this.rootNode,(e=>(e.visibilityObb=this._computeVisibilityObb(e),e.geometryObb=null,!0)))}isNodeVisible(i){const s=this._getNodeInternal(i);if(t(s)||e(s.ref)&&!s.ref.mbs)return!0;if(!C(s.visibilityCache,this._visibilityCacheVersion)){const i=s.node,r=e(i)&&(t(s.ref)||e(i.visibilityObb))?i:e(s.ref)?s.ref:null;if(this._layerHasFilter&&this._computeNodeFiltering&&(e(i)||e(s.ref))&&s.filterImpact===h.NotChecked){const t=e(i)?i.mbs:e(s.ref)?s.ref.mbs:null;s.filterImpact=null!=t?this._computeNodeFiltering(t):h.Unmodified}const n=e(i)&&s.filterImpact===h.Culled,o=!(e(i)&&i.imModificationImpact===u.Culled)&&(!r||this.viewportQueries.isNodeVisible(r))&&!n;return s.visibilityCache=I(o,this._visibilityCacheVersion),o}return w(s.visibilityCache)}isGeometryVisible(t){if(!this.isNodeVisible(t))return!1;const i=this._getNodeInternal(t);return!(e(i)&&e(i.node)&&e(i.node.geometryObb)&&(!this.layerHasModifications||i.node.imModificationImpact!==u.NotChecked))||this.viewportQueries.isGeometryVisible(i.node)}_traverseCoverage(s,r,n,o,a){const d=this._getPage(s);if(t(d)||0===r.childCount)return;const l=r.childOffset+r.childCount,h=new Array;for(let t=r.childOffset;t<l;++t){const i=d.children[t],s=this._getNodeInternal(i);e(s)&&e(s.node)&&this.isGeometryVisible(i)&&h.push(s)}o/=h.length;for(const e of h){const t=i(e.node).index;this._isLoaded(t)||this._isReloading(t)?(a.delta=Math.max(a.delta,n),a.coverage+=o):this._traverseCoverage(t,e,n+1,o,a)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const i=this._getNodeInternal(e);if(t(i))return!1;if("always"===this.holeFilling)return!0;if(C(i.useAsHole,this._version))return w(i.useAsHole);const s={delta:0,coverage:0};this._traverseCoverage(e,i,0,1,s);const r=s.delta*s.coverage<=.5;return i.useAsHole=I(r,this._version),r}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.add.prune(),this._updates.update.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=x(this._version)}imModificationsChanged(t){this.layerHasModifications=t,this._forAllNodes((({node:t})=>{e(t)&&(t.imModificationImpact=u.NotChecked,t.visibilityObb=this._computeVisibilityObb(t),t.hasModifications&&this.invalidateGeometryVisibility(t.index))})),this.invalidateVisibilityCache()}layerFilterChanged(t){this._layerHasFilter=t,this._forAllNodes((t=>{if(e(t)){t.filterImpact=h.NotChecked;const i=t.node;e(i)&&this.invalidateNodeVisibilityCache(i.index)}})),this.invalidateVisibilityCache()}update(s,r,n){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(r),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missing.clear(),this._prefetch.clear(),this._updates.reset(s),p.clear();let o=!0;const a=new V,d=new V,l=this._imModificationUncategorized;l.clear();const h=new Set,c=(c,g,_)=>{if(t(g)){let e=this._entryPriority(c);e===1/0&&(e=this._entryPriority(_));const t=M(c,this.nodesPerPage);return p.set(t,Math.max(e,p.get(t)||0)),this._loading.has(t)||this._failedPages.has(t)||this._missing.push(t),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const m=g.node;if(this._updateNodeFeatureEstimate(m,d),t(m)){const e=this._entryPriority(c);return this._loading.has(c)||this._failedNodes.has(c)||(this._missing.push(c),p.set(c,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const f=i(this._getPage(c));if(0===this._missing.length&&0===this.nodesPerPage)for(let t=0;t<g.childCount;t++){const i=f.children[g.childOffset+t],s=this._getNodeInternal(i);!e(s)||s.node||this._loading.has(i)||this._failedNodes.has(i)||(p.set(i,this._entryPriority(i)),this._prefetch.push(i))}if(m.failed||!m.resources.hasFeatureData)return void(o&&g.childCount>0&&this._isSelected(m)&&(o=!1));if(h.add(m.id),this._isLoaded(c)){if(a.known+=m.memory,++a.knownNodes,this._isSelected(m)?g.childCount>0&&(o=!1):(a.unremoved+=m.memory,o=!1),this._needsUpdate(m)){const e=this._entryPriority(c);p.set(c,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(c)}return}if(m.memory&&(a.known+=m.memory,++a.knownNodes),!this._isSelected(m))return void(this._isReloading(c)&&this._updates.remove.push(c));if(g.childCount>0&&(o=!1),m.memory?(a.missing+=m.memory,a.known+=m.memory,++a.knownNodes):++a.missingNodes,s.includes(m.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(c)),void(this._updates.cancel=this._updates.cancel.filter((e=>e!==m.index)));if(!r.done&&this._enable(m))return void r.madeProgress();const v=this._entryPriority(c);p.set(c,v),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,v),this._updates.add.push(c),this.layerHasModifications&&n&&e(m)&&m.imModificationImpact===u.NotChecked&&l.push(c)};this.traverseVisible(c);const g=this._updates.add;g.length>0&&this.layerHasModifications&&(l.length>0&&n(l),g.filterInPlace((e=>{const i=this._getNodeInternal(e),s=t(i)||t(i.node)||i.node.imModificationImpact!==u.Culled;return s||this.invalidateNodeVisibilityCache(e),s}))),this._unloadedMemoryEstimate=a.missing-a.unremoved,a.knownNodes>3&&a.missingNodes>0&&(this._unloadedMemoryEstimate+=a.known/a.knownNodes*a.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(d),this._featureEstimate.leavesReached=o,this._missing.sort(((e,t)=>e-t)),this._missing.filterInPlace(((e,t)=>t<1||this._missing.data[t-1]!==e)),this._missing.sort(((e,t)=>p.get(e)-p.get(t))),this._missing.length>0&&(this._maxUnloadedPrio=p.get(this._missing.back()),this._prefetch.clear()),this._updates.add.filterInPlace((e=>p.get(e)>=this._maxUnloadedPrio)).sort(((e,t)=>p.get(e)-p.get(t))),this._updates.update.sort(((e,t)=>p.get(e)-p.get(t))),this._indexMissing=this._loading.size+this._missing.length,this._dirty=this._indexMissing>0,p.clear()}checkFeatureTarget(e,t){const i=this.viewportQueries.updateScreenSpaceErrorBias(t);let s=t,r=t,n=i,o=10;for(;o--;){const i=new V;this._updateFeatureEstimate(s,i);if(this._computeFeatureEstimate(i)<=e){if(s>=t||i.missingNodes>0||0===o)break;n=s,s=.5*(s+r)}else r=s,s=.5*(s+n)}return this._version=x(this._version),this.viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,s)}_updateFeatureEstimate(t,i){this._version=x(this._version),this.viewportQueries.updateScreenSpaceErrorBias(t),this.traverseVisible(((t,s)=>this._updateNodeFeatureEstimate(e(s)&&s.node,i)))}_updateNodeFeatureEstimate(i,s){if(!(t(i)||i.failed||t(i.numFeatures)))return this._isLoaded(i.index)?(s.known+=i.numFeatures,++s.knownNodes,void(this._isSelected(i)||(s.unremoved+=i.numFeatures))):void(this._isSelected(i)&&(e(i.numFeatures)?(s.missing+=i.numFeatures,s.known+=i.numFeatures,++s.knownNodes):++s.missingNodes))}_computeFeatureEstimate(e){let t=e.known-e.unremoved;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.known/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missing)}prefetch(){return this._prefetch.sort(((e,t)=>p.get(e)-p.get(t))),this._load(this._prefetch)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();)0===this.nodesPerPage?this._loadNode(e.pop()):this._loadPage(e.pop());return!0}isLoading(){return this._indexMissing>0}getIndexLoading(){return this._loading.size}getIndexMissing(){return this._indexMissing}getUnloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}nodeTraversalState(e){if(t(e))return null;let i=this._nodeTraversalState.get(e.index);if(i&&C(i.version,this._version))return i;const s=this.viewportQueries.getLodLevel(e),r=this.viewportQueries.hasLOD(e);let n=!0;if(r){const t=this.getParentIndex(e.index);if(t>=0){const e=this._nodeTraversalState.get(t);n=e&&s>e.lodLevel}else n=s>0}else n=0===e.childCount;return i?(i.lodLevel=s,i.isChosen=n,i.version=I(!0,this._version),i):(i=new c(r,n,s,I(!0,this._version)),this._nodeTraversalState.set(e.index,i),i)}_loadNode(e){this._loading.add(e);const s=i(this._getNodeInternal(e)).ref;if(t(s))return void this._failedNodes.add(e);const n=s.id,o=this.urlPrefix+n,a=()=>{this._loading.delete(e),0===this._missing.length&&0===this._loading.size&&this.requestUpdate()};this.streamDataController.request(o,"json").then((t=>{a();const i=this._validateNode(n,t);if(null==i)return;i.obb&&this.invalidateNodeVisibilityCache(e);const s=this._addNode(i,e);this.nodeTraversalState(s)}),(t=>{a(),r(t)||(this.logger.error("#loadNode()",this.logLayer,"Error loading node: "+o),this._failedNodes.add(e))}))}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this.logger.error("#validateNode()",this.logLayer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this.logger.error("#validateNode()",this.logLayer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this.logger.warn("#validateNode()",this.logLayer,`Invalid shared resource href on node "${e}"`),null==t.geometryData||Array.isArray(t.geometryData)&&1===t.geometryData.length&&"./geometries/0"===t.geometryData[0].href||this.logger.warn("#validateNode()",this.logLayer,`Invalid geometry data on node "${e}"`),null==t.attributeData||Array.isArray(t.attributeData)&&!t.attributeData.some(((e,t)=>e.href!==`./attributes/f_${t}/0`))||this.logger.warn("#validateNode()",this.logLayer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this.logger.warn("#validateNode()",this.logLayer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const i=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:null,s=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:null,r=t=>{if(null==t)return null;const i=t=>this.logger.error("#validateNode()",this.logLayer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this.logger.error("#validateNode()",this.logLayer,`Invalid node href on node "${e}"`);const s=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:null,r=new d(`${t.id}`,t.mbs);return r.serviceObb=s,r.visibilityObb=this._computeVisibilityObb(r),r},n=Array.isArray(t.children)?t.children.map(r).filter((e=>null!=e)):null;return{id:e,mbs:t.mbs,obb:i,children:n,resources:{hasFeatureData:t.featureData&&t.featureData.length>0,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:null,texture:t.textureData&&t.textureData.length>0?e:null,geometry:null!=t.geometryData?e:null},version:"string"==typeof t.version?t.version:null,lodSelection:Array.isArray(t.lodSelection)?t.lodSelection:null,numFeatures:s}}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes((t=>{e(t.node)&&(t.node.failed=!1)}))}_entryPriority(i){const s=this._getNodeInternal(i),r=this.getParentIndex(i);if(t(s)||r<0&&null==s.node)return r<0?1/0:this._entryPriority(r);let n=0;if(s.node&&r>=0){const e=this._nodeTraversalState.get(r);null!=e&&(n=e.lodLevel)}let o=this.progressiveLoadPenalty;for(let e=i;e>=0;e=this.getParentIndex(e))if(this._isLoaded(e)){o=0;break}const a=e(s.ref)?this.viewportQueries.distToPOI(s.ref):e(s.node)?this.viewportQueries.distToPOI(s.node):0;return-a-n*(a+this.progressiveLoadPenalty)+o}traverseVisible(e){const i=this._getNodeInternal(this.rootIndex);t(i)?e(this.rootIndex,null,null):this._traverseVisible(this.rootIndex,-1,i,e)}_traverseVisible(t,s,r,n){if(r.node&&0===r.childCount)return void(this.isGeometryVisible(t)&&n(t,r,s));if(!this.isNodeVisible(t))return;if(n(t,r,s),null==r.node)return;const o=this.nodeTraversalState(r.node);if(o.nodeHasLOD&&o.lodLevel===this._maxLodLevel)return;const a=i(this._getPage(t));for(let i=0;i<r.childCount;i++){const s=a.children[r.childOffset+i],o=this._getNodeInternal(s);e(o)?this._traverseVisible(s,t,o,n):n(s,null,t)}}traverse(e,t){t(e)&&this.traverseChildren(e,t)}traverseChildren(t,i){const s=t.index,r=this._getNodeInternal(s);e(r)&&this._traverseChildren(s,r,i)}_traverseChildren(i,s,r){const n=this._getPage(i);if(t(n))return;const o=s.childOffset+s.childCount;for(let t=s.childOffset;t<o;++t){const i=n.children[t],s=this._getNodeInternal(i);e(s)&&e(s.node)&&r(s.node)&&this._traverseChildren(i,s,r)}}updateChildrenLoaded(t,i){let s=this.getNode(t);for(;e(s);)s.childrenLoaded+=i,s=this.getParent(s.index)}checkChildrenLoadedInvariant(){if(t(this.rootNode))return!0;const e=[],i=t=>{let s=this._isLoaded(t.index)||this._isReloading(t.index)?1:0;return this.traverseChildren(t,(e=>(s+=i(e),!1))),t.childrenLoaded!==s&&e.push(t.index),s};return i(this.rootNode),e.length&&this.logger.error("childrenLoaded invariant broken at following nodes: "+e.join(",")),e.length>0}updateStats(e){if(this._updates.add.length>0&&(e.nodes+=" + "+this._updates.add.length),(this._indexMissing||this._prefetch.length>0)&&(e.index+=" + "+this._indexMissing||this._prefetch.length),e.prio=this._maxProcessingPrio,this._featureEstimate.estimate){const t=this._featureEstimate.estimate-e.features;t>0?e.features+=" + "+t:t<0&&(e.features+=" - "+-t)}}getPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}updateElevationInfo(e){this._forAllNodes(P),this.viewportQueries.updateElevationInfo(e)}_forAllNodes(e){for(let t=0;t<this._nodePages.length;t++){const i=this._nodePages[t];if(i){const s=t*this.nodesPerPage;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],s+t)}}}get test(){return{addNode:(e,t)=>this._addNode(e,t)}}}const p=new Map;class y{constructor(e){this.missing=e,this.update=new s({deallocator:null}),this.add=new s({deallocator:null}),this.remove=new s({deallocator:null}),this.cancel=[]}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function P(t){e(t.node)&&(_(t.node.renderMbs),m(t.node.serviceObbInRenderSR)),e(t.ref)&&(_(t.ref.renderMbs),m(t.ref.serviceObbInRenderSR))}function N(e){return g(e,-2)}function x(e){return g(e,2)}function I(e,t){return t+(e?1:0)}function C(e,t){return(-2&e)===t}function w(e){return 1==(1&e)}function M(e,t){return 0===t?0:e/t|0}function S(e,t){return 0===t?e:e%t}const L=[["maxScreenThreshold",a.MaxScreenThreshold],["screenSpaceRelative",a.ScreenSpaceRelative],["removedFeatureDiameter",a.RemovedFeatureDiameter],["distanceRangeFromDefaultCamera",a.DistanceRangeFromDefaultCamera]];function O(e){if(e)for(let t=0;t<e.length;t++)for(const i of L)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:a.None,maxError:0}}class V{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}function E(e){return Math.sqrt(e*(4/Math.PI))}export{b as I3SIndex,O as selectErrorMetric};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.24/esri/copyright.txt for details.
4
4
  */
5
- import{isSome as e,isNone as t}from"../../../../core/maybe.js";import{ViewingMode as i}from"../../../ViewingMode.js";import{intersectLine as r}from"../../support/orientedBoundingBox.js";import{newIntersectorResult as s}from"../../webgl-engine/lib/Intersector.js";import{IntersectorType as n,StoreResults as o}from"../../webgl-engine/lib/IntersectorInterfaces.js";import{getVerticalOffsetI3S as l}from"../../webgl-engine/lib/verticalOffsetUtils.js";class a{constructor(e){this.type=n.I3S,this._needVerticalOffset=!1,this.layerUid=e.layerUid,this.sublayerUid=e.sublayerUid,this.collection=e.collection,this.traverseNodeHierarchy=e.traverseNodeHierarchy,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isGround=e.isGround}updateElevationAlignState(e,t){this._needVerticalOffset=e&&t===i.Global}intersect(i,n,a,c){const b=i.results,f=i.options.store===o.ALL,u=i.ray.direction,m=i.tolerance;let h=e=>e,p=e=>e;const y=l(e(i.verticalOffset)?i.verticalOffset:this._needVerticalOffset?0:null);e(i.verticalOffset)&&e(y)&&(h=e=>y.applyToMbs(e),p=e=>y.applyToObb(e)),this.traverseNodeHierarchy(((o,l)=>!(e(o.serviceObbInRenderSR)&&!r(p(o.serviceObbInRenderSR),a,u,m))&&(l&&(t(o.geometryObb)||r(p(o.geometryObb),a,u,m))&&(e(o.serviceObbInRenderSR)||d(h(o.renderMbs),a,u,m))&&this.collection.intersect(l,a,c,m,y,((e,t,r,l)=>{if(t>=0){if(null!=n&&!n(a,c,t))return;const d=i=>{const s={layerUid:this.layerUid,sublayerUid:this.sublayerUid,nodeIndex:o.index,componentIndex:e,triangleNr:l};i.set(this.type,s,t,r)};if(this.isGround&&(null==b.ground.dist||t<b.ground.dist)&&d(b.ground),i.options.isFiltered)return;if((null==b.min.dist||t<b.min.dist)&&d(b.min),(null==b.max.dist||t>b.max.dist)&&d(b.max),f){const e=s(i.ray);d(e),i.results.all.push(e)}}})),!0)))}}function d(e,t,i,r=0){const s=e[3]+r,n=t[0]-e[0],o=t[1]-e[1],l=t[2]-e[2],a=i[0],d=i[1],c=i[2],b=a*n+d*o+c*l;return b*b-(a*a+d*d+c*c)*(n*n+o*o+l*l-s*s)>=0}export{a as I3SIntersectionHandler};
5
+ import{isSome as e,isNone as t}from"../../../../core/maybe.js";import{ViewingMode as r}from"../../../ViewingMode.js";import{isValidObb as i,isValidMbs as s}from"./I3SUtil.js";import{intersectLine as n}from"../../support/orientedBoundingBox.js";import{newIntersectorResult as o}from"../../webgl-engine/lib/Intersector.js";import{IntersectorType as l,StoreResults as d}from"../../webgl-engine/lib/IntersectorInterfaces.js";import{getVerticalOffsetI3S as a}from"../../webgl-engine/lib/verticalOffsetUtils.js";class c{constructor(e){this.type=l.I3S,this._needVerticalOffset=!1,this.layerUid=e.layerUid,this.sublayerUid=e.sublayerUid,this.collection=e.collection,this.traverseNodeHierarchy=e.traverseNodeHierarchy,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isGround=e.isGround}updateElevationAlignState(e,t){this._needVerticalOffset=e&&t===r.Global}intersect(r,l,c,u){const f=r.results,m=r.options.store===d.ALL,h=r.ray.direction,p=r.tolerance;let y=e=>e,g=e=>e;const O=a(e(r.verticalOffset)?r.verticalOffset:this._needVerticalOffset?0:null);e(r.verticalOffset)&&e(O)&&(y=e=>O.applyToMbs(e),g=e=>O.applyToObb(e)),this.traverseNodeHierarchy(((d,a)=>{if(0===d.childrenLoaded)return!1;const v=e(d.serviceObbInRenderSR)&&i(d.serviceObbInRenderSR)?d.serviceObbInRenderSR:null;return!(e(v)&&!n(g(v),c,h,p))&&(a&&(e(v)||!s(d.renderMbs)||b(y(d.renderMbs),c,h,p))&&(t(d.geometryObb)||n(g(d.geometryObb),c,h,p))&&this.collection.intersect(a,c,u,p,O,((e,t,i,s)=>{if(t>=0){if(null!=l&&!l(c,u,t))return;const n=r=>{const n={layerUid:this.layerUid,sublayerUid:this.sublayerUid,nodeIndex:d.index,componentIndex:e,triangleNr:s};r.set(this.type,n,t,i)};if(this.isGround&&(null==f.ground.dist||t<f.ground.dist)&&n(f.ground),r.options.isFiltered)return;if((null==f.min.dist||t<f.min.dist)&&n(f.min),(null==f.max.dist||t>f.max.dist)&&n(f.max),m){const e=o(r.ray);n(e),r.results.all.push(e)}}})),!0)}))}}function b(e,t,r,i=0){const s=e[3]+i,n=t[0]-e[0],o=t[1]-e[1],l=t[2]-e[2],d=r[0],a=r[1],c=r[2],b=d*n+a*o+c*l;return b*b-(d*d+a*a+c*c)*(n*n+o*o+l*l-s*s)>=0}export{c as I3SIntersectionHandler};