UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import t from"../../core/Collection.js";var a;!function(t){t[t.WhenToolEditable=0]="WhenToolEditable",t[t.WhenToolNotEditable=1]="WhenToolNotEditable",t[t.Always=2]="Always"}(a||(a={}));class i{constructor(){this._isToolEditable=!0,this._manipulators=new t,this._resourceContexts={manipulator3D:{}},this._attached=!1}set isToolEditable(t){this._isToolEditable=t}get length(){return this._manipulators.length}add(t,i=a.WhenToolEditable){this.addMany([t],i)}addMany(t,i=a.WhenToolEditable){for(const a of t){const t={manipulator:a,visibilityPredicate:i,attached:!1};this._manipulators.add(t),this._attached&&this._updateManipulatorAttachment(t)}}remove(t){for(let a=0;a<this._manipulators.length;a++)if(this._manipulators.at(a).manipulator===t){const t=this._manipulators.splice(a,1)[0];this._detachManipulator(t);break}}removeAll(){this._manipulators.forEach((t=>{this._detachManipulator(t)})),this._manipulators.removeAll()}attach(){this._manipulators.forEach((t=>{this._updateManipulatorAttachment(t)})),this._attached=!0}detach(){this._manipulators.forEach((t=>{this._detachManipulator(t)})),this._attached=!1}destroy(){this.detach(),this._manipulators.forEach((({manipulator:t})=>t.destroy())),this._manipulators.destroy(),this._resourceContexts=null}on(t,a){return this._manipulators.on(t,(t=>{a(t)}))}forEach(t){for(const a of this._manipulators.items)t(a)}some(t){return this._manipulators.items.some(t)}toArray(){const t=[];return this.forEach((a=>t.push(a.manipulator))),t}intersect(t,a){let i=null,e=Number.MAX_VALUE;return this._manipulators.forEach((({manipulator:o,attached:s})=>{if(!s||!o.interactive)return;const r=o.intersectionDistance(t,a);null!=r&&r<e&&(e=r,i=o)})),i}_updateManipulatorAttachment(t){this._isManipulatorItemVisible(t)?this._attachManipulator(t):this._detachManipulator(t)}_attachManipulator(t){t.attached||(t.manipulator.attach&&t.manipulator.attach(this._resourceContexts),t.attached=!0)}_detachManipulator(t){if(!t.attached)return;const a=t.manipulator;a.grabbing=!1,a.dragging=!1,a.hovering=!1,a.selected=!1,a.detach&&a.detach(this._resourceContexts),t.attached=!1}_isManipulatorItemVisible(t){return t.visibilityPredicate===a.Always||(this._isToolEditable?t.visibilityPredicate===a.WhenToolEditable:t.visibilityPredicate===a.WhenToolNotEditable)}}export{i as ManipulatorCollection,a as ManipulatorVisibilityPredicate};