text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.10/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../../core/tsSupport/declareExtendsHelper ../../../../../core/tsSupport/decorateHelper ../../../../../core/Handles ../../../../../geometry/ScreenPoint ./AreaMeasurement3DView".split(" "),function(k,l,m,n,f,d,h){function e(c){return"mouse"!==c.pointerType||0===c.button}return function(){function c(a,b){this._dragVertices={};this._handles=new f;this._viewEventHandles=new f;this._tempPickRequest=new h.PickRequest;this._ignoreClickEventId=null;this.model=a;this.view=b;
  this.model.reset()}c.prototype.destroy=function(){this._handles.destroy();this._handles=null;this._viewEventHandles.destroy();this._viewEventHandles=null};c.prototype.install=function(){var a=this;if(!(0<this._viewEventHandles.size)){var b=this.model.sceneView;this._viewEventHandles.add([b.on("immediate-click",function(b){return a._handleImmediateClick(b)}),b.on("click",function(b){return a._handleClick(b)}),b.on("double-click",function(b){return a._handleDoubleClick(b)}),b.on("drag",function(b){return a._handleDrag(b)}),
  b.on("pointer-move",function(b){return a._handlePointerMove(b)}),b.on("pointer-down",function(b){return a._handlePointerDown(b)}),b.on("pointer-up",function(b){return a._handlePointerUp(b)}),b.on("pointer-drag",function(b){return a._handlePointerDrag(b)}),b.on("key-down",function(b){return a._handleKeyDown(b)})])}};c.prototype.uninstall=function(){this._viewEventHandles.removeAll()};c.prototype._handleDrag=function(a){0!==this.model.draggedVertices.length&&a.stopPropagation()};c.prototype._handlePointerMove=
  function(a){var b=new d({x:a.x,y:a.y});"mouse"===a.pointerType&&this._hoverAt(b,a.pointerType)};c.prototype._handlePointerDown=function(a){if(e(a)&&this.model.editable){var b=new d({x:a.x,y:a.y}),b=this.view.vertexHandleAt(b,a.pointerType);null==b||b in this._dragVertices||(this._dragVertices[a.pointerId]=b,this.model.draggedVertices.push(b));0<this.model.draggedVertices.length&&"measured"===this.model.state&&(this.model.state="editing");"mouse"!==a.pointerType&&this._removeHover();null!=b&&a.stopPropagation()}};
  c.prototype._handlePointerUp=function(a){if(e(a)){var b=this._dragVertices[a.pointerId];null!=b&&(delete this._dragVertices[a.pointerId],this.model.draggedVertices.remove(b));0===this.model.draggedVertices.length&&"editing"===this.model.state&&(this.model.state="measured")}};c.prototype._handlePointerDrag=function(a){if(e(a)){var b=new d({x:a.x,y:a.y}),c=this._dragVertices[a.pointerId];if(null!=c){switch(a.action){case "update":this._moveVertexTo(c,b,a.pointerType);break;case "end":delete this._dragVertices[a.pointerId],
  this.model.draggedVertices.remove(c)}a.stopPropagation()}}};c.prototype._handleImmediateClick=function(a){if(e(a)){var b=new d({x:a.x,y:a.y}),c=!1;if(this.model.active)switch(this.model.state){case "initial":this._addVertexAt(b,a.pointerType)&&(this.model.state="drawing",c=!0);break;case "drawing":var g=this.view.vertexHandleAt(b,a.pointerType);if(null===g){if(this._addVertexAt(b,a.pointerType)){a.stopPropagation();return}}else 0===g&&(this._updateHoveredHandle(b,a.pointerType),this.model.finishMeasurement(),
  c=!0);break;case "measured":null===this.view.vertexHandleAt(b,a.pointerType)&&(this.model.clearMeasurement(),this._addVertexAt(b,a.pointerType)&&(this.model.state="drawing",c=!0))}c&&(a.stopPropagation(),this._ignoreClickEventId=a.eventId);"mouse"===a.pointerType&&this._hoverAt(b,a.pointerType)}};c.prototype._handleClick=function(a){e(a)&&(this.model.active||this._ignoreClickEventId===a.eventId)&&a.stopPropagation()};c.prototype._handleDoubleClick=function(a){if(e(a)){var b=new d({x:a.x,y:a.y});"drawing"===
  this.model.state&&null!=this.view.vertexHandleAt(b,a.pointerType)?(this.model.finishMeasurement(),a.stopPropagation()):(this.model.active||this._ignoreClickEventId===a.eventId)&&a.stopPropagation()}};c.prototype._handleKeyDown=function(a){"Escape"===a.key&&"drawing"===this.model.state&&(this.model.clearMeasurement(),a.stopPropagation());"Enter"===a.key&&"drawing"===this.model.state&&(this.model.finishMeasurement(),a.stopPropagation())};c.prototype._hoverAt=function(a,b){this._updateHoveredHandle(a,
  "mouse");this.view.requiresCursorPoint?(a=this._pick(a),a.mapPoint&&(this.model.cursorPoint=a.mapPoint)):this.model.cursorPoint=null};c.prototype._removeHover=function(){this.model.cursorPoint=null;this.model.hoveredVertexHandle=null};c.prototype._addVertexAt=function(a,b){var c=this._pick(a);if(c.mapPoint)return this.model.path.add(c.mapPoint),this.model.hoveredVertexHandle="touch"!==b?this.model.path.length-1:null,!0;this._updateHoveredHandle(a,b);return!1};c.prototype._moveVertexTo=function(a,
  b,c){b=this._clipToScreen(b);if(null!=a){var d=this._pick(b);if(d.mapPoint&&!this.view.overlapsAnyHandles(d.mapPoint,[a]))return this.model.path.update(a,d.mapPoint),this.model.hoveredVertexHandle="touch"!==c?a:null,!0}this._updateHoveredHandle(b,c);return!1};c.prototype._pick=function(a){var b=this._tempPickRequest;b.screenPoint=a;return this.view.pick(b)};c.prototype._clipToScreen=function(a){return new d({x:Math.max(0,Math.min(this.model.sceneView.width,a.x)),y:Math.max(0,Math.min(this.model.sceneView.height,
  a.y))})};c.prototype._updateHoveredHandle=function(a,b){this.model.hoveredVertexHandle="touch"!==b?this.view.vertexHandleAt(a,b):null};return c}()});