UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 9.99 kB
import{_ as i}from"../../../chunks/tslib.es6.js";import"../../../symbols.js";import t from"../../../core/Evented.js";import e from"../../../core/Handles.js";import{clone as s}from"../../../core/lang.js";import{destroyMaybe as r,isSome as h,isNone as a}from"../../../core/maybe.js";import{watch as o,when as c}from"../../../core/reactiveUtils.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import p from"../../../layers/GraphicsLayer.js";import{cloneMove as d}from"./drawUtils.js";import v from"./HighlightHelper.js";import{addUniqueLayer as g,findLayerView as _}from"./layerUtils.js";import{GraphicClickEvent as m,GraphicDoubleClickEvent as y,GraphicPointerDownEvent as u,GraphicPointerUpEvent as f,GraphicPointerOutEvent as w,GraphicMoveStartEvent as G,GraphicMoveEvent as b,GraphicMoveStopEvent as k,GraphicPointerOverEvent as O}from"./input/GraphicMoverEvents.js";import{ViewEventPriorities as H}from"../../input/InputManager.js";import{GraphicManipulator as M}from"../../interactive/GraphicManipulator.js";import{createScreenPointFromEvent as x}from"../../support/screenUtils.js";import E from"../../../symbols/SimpleMarkerSymbol.js";import j from"../../../symbols/SimpleLineSymbol.js";import U from"../../../symbols/SimpleFillSymbol.js";const P="indicator-symbols";let S=class extends t.EventedAccessor{constructor(i){super(i),this._activeGraphic=null,this._dragEvent=null,this._handles=new e,this._hoverGraphic=null,this._indicators=[],this._initialDragGeometry=null,this._viewHandles=new e,this._manipulators=[],this._layerViews=null,this.type="graphic-mover",this.callbacks={onGraphicClick(){},onGraphicDoubleClick(){},onGraphicMoveStart(){},onGraphicMove(){},onGraphicMoveStop(){},onGraphicPointerOver(){},onGraphicPointerOut(){},onGraphicPointerDown(){},onGraphicPointerUp(){}},this.enableMoveAllGraphics=!1,this.graphics=[],this.indicatorsEnabled=!1,this.layer=new p({listMode:"hide",internal:!0,title:"GraphicMover highlight layer"}),this.view=null}initialize(){g(this.view,this.layer),this._highlightHelper=new v({view:this.view}),this.refresh(),this._handles.add([o((()=>[this.graphics,this.graphics?.length]),(()=>this.refresh())),c((()=>this.view?.ready),(()=>{this._viewHandles.add([this.view.on("immediate-click",(i=>this._clickHandler(i)),H.TOOL),this.view.on("double-click",(i=>this._doubleClickHandler(i)),H.TOOL),this.view.on("pointer-down",(i=>this._pointerDownHandler(i)),H.TOOL),this.view.on("pointer-move",(i=>this._pointerMoveHandler(i)),H.TOOL),this.view.on("pointer-up",(i=>this._pointerUpHandler(i)),H.TOOL),this.view.on("drag",(i=>this._dragHandler(i)),H.TOOL),this.view.on("key-down",(i=>this._keyDownHandler(i)),H.TOOL)])}),{once:!0,initial:!0}),o((()=>this.view),(i=>{this._highlightHelper.removeAll(),this._highlightHelper.view=i}))])}destroy(){this._removeIndicators(),this.view.map?.remove(this.layer),this.layer.destroy(),this.reset(),this._manipulators.forEach((i=>i.destroy())),this._manipulators=null,this._handles=r(this._handles),this._viewHandles=r(this._viewHandles)}set highlightsEnabled(i){this._highlightHelper?.removeAll(),this._set("highlightsEnabled",i),i&&this._highlightHelper?.add(this.graphics)}get state(){const i=!!this.get("view.ready"),t=!!this.get("graphics.length"),e=this._activeGraphic;return i&&t?e?"moving":"active":i?"ready":"disabled"}refresh(){this.reset(),this._setup()}reset(){this._activeGraphic=null,this._hoverGraphic=null,this._dragEvent=null,this._highlightHelper.removeAll()}updateGeometry(i,t){const e=this.graphics[i];e&&(e.set("geometry",t),this._setUpIndicators())}_setup(){this._setUpHighlights(),this._setUpIndicators(),this._setUpManipulators(),this._syncLayerViews()}_clickHandler(i){const t=this._findTargetGraphic(x(i));if(t){const e=new m(t,this.graphics.indexOf(t),i.x,i.y,i);this.emit("graphic-click",e),this.callbacks.onGraphicClick&&this.callbacks.onGraphicClick(e)}}_doubleClickHandler(i){const t=this._findTargetGraphic(x(i));if(t){const e=new y(t,this.graphics.indexOf(t),i.x,i.y,i);this.emit("graphic-double-click",e),this.callbacks.onGraphicDoubleClick&&this.callbacks.onGraphicDoubleClick(e)}}_pointerDownHandler(i){const t=this._findTargetGraphic(x(i));if(t){this._activeGraphic=t;const{x:e,y:s}=i,r=new u(t,this.graphics.indexOf(t),e,s,i);this.emit("graphic-pointer-down",r),this.callbacks.onGraphicPointerDown&&this.callbacks.onGraphicPointerDown(r)}else this._activeGraphic=null}_pointerUpHandler(i){if(this._activeGraphic){const{x:t,y:e}=i,s=this.graphics.indexOf(this._activeGraphic),r=new f(this._activeGraphic,s,t,e,i);this.emit("graphic-pointer-up",r),this.callbacks.onGraphicPointerUp&&this.callbacks.onGraphicPointerUp(r)}}_pointerMoveHandler(i){if(this._dragEvent)return;const t=this._findTargetGraphic(x(i));if(t){const{x:e,y:s}=i;if(this._hoverGraphic){if(this._hoverGraphic===t)return;const r=this.graphics.indexOf(this._hoverGraphic),h=new w(this.graphics[r],r,e,s,i);this._hoverGraphic=null,this.emit("graphic-pointer-out",h),this.callbacks.onGraphicPointerOut&&this.callbacks.onGraphicPointerOut(h)}const r=this.graphics.indexOf(t),h=new O(t,r,e,s,i);return this._hoverGraphic=t,this.emit("graphic-pointer-over",h),void(this.callbacks.onGraphicPointerOver&&this.callbacks.onGraphicPointerOver(h))}if(this._hoverGraphic){const{x:t,y:e}=i,s=this.graphics.indexOf(this._hoverGraphic),r=new w(this.graphics[s],s,t,e,i);this._hoverGraphic=null,this.emit("graphic-pointer-out",r),this.callbacks.onGraphicPointerOut&&this.callbacks.onGraphicPointerOut(r)}}_dragHandler(i){if("start"!==i.action&&!this._dragEvent||!this._activeGraphic||!this._activeGraphic.geometry)return;"start"===i.action&&this._removeIndicators(),i.stopPropagation();const{action:t,x:e,y:r}=i,h=this.graphics.indexOf(this._activeGraphic),a=this._dragEvent?e-this._dragEvent.x:0,o=this._dragEvent?r-this._dragEvent.y:0,c=e-i.origin.x,n=r-i.origin.y,l="start"===t?this._activeGraphic.geometry:this._initialDragGeometry,p=d(l,c,n,this.view);if(this._activeGraphic.geometry=p,this.enableMoveAllGraphics&&this.graphics.forEach((i=>{i!==this._activeGraphic&&(i.geometry=d(i.geometry,a,o,this.view))})),this._dragEvent=i,"start"===t){this._initialDragGeometry=s(l);const t=new G(this._activeGraphic,this.graphics,h,e,r,a,o,c,n,i);this.emit("graphic-move-start",t),this.callbacks.onGraphicMoveStart&&this.callbacks.onGraphicMoveStart(t),t.defaultPrevented&&this._activeGraphic.set("geometry",l)}else if("update"===t){const t=new b(this._activeGraphic,this.graphics,h,e,r,a,o,c,n,i);this.emit("graphic-move",t),this.callbacks.onGraphicMove&&this.callbacks.onGraphicMove(t),t.defaultPrevented&&(this._activeGraphic.geometry=l)}else{const t=new k(this._activeGraphic,this.graphics,h,e,r,a,o,c,n,i);this._dragEvent=null,this._activeGraphic=null,this._setUpIndicators(),this.emit("graphic-move-stop",t),this.callbacks.onGraphicMoveStop&&this.callbacks.onGraphicMoveStop(t),t.defaultPrevented&&(this.graphics[h].set("geometry",this._initialDragGeometry),this._setUpIndicators()),this._initialDragGeometry=null}}_keyDownHandler(i){"a"!==i.key&&"d"!==i.key&&"n"!==i.key||"moving"!==this.state||i.stopPropagation()}_findTargetGraphic(i){const t=this.view.toMap(i);let e=null,s=Number.MAX_VALUE;this._syncLayerViews();const r=this._layerViews.flatMap((i=>"graphicsViews"in i?Array.from(i.graphicsViews(),(i=>i.hitTest(t))).flat():i.graphicsView.hitTest(t))).filter((i=>this.graphics.includes(i)));return r.length?r[0]:(this._manipulators.forEach((t=>{const r=t.intersectionDistance(i);h(r)&&r<s&&(s=r,e=t.graphic)})),e)}_syncLayerViews(){this._layerViews=[];const i=new Set;for(const t of this.graphics){const e=_(this.view,t.layer);e&&i.add(e)}this._layerViews=[...i]}_setUpManipulators(){const{graphics:i,view:t}=this;this._manipulators.forEach((i=>i.destroy())),this._manipulators=i?.length?i.map((i=>new M({graphic:i,view:t}))):[]}_setUpHighlights(){this.highlightsEnabled&&this._highlightHelper.add(this.graphics)}_setUpIndicators(){if(this._removeIndicators(),this.indicatorsEnabled){for(const i of this.graphics){const t=i.clone();t.symbol=this._getSymbolForIndicator(i),this._indicators.push(t),this._handles.add(o((()=>i.symbol),(()=>this._setUpIndicators())),P)}this.layer.addMany(this._indicators)}}_removeIndicators(){this._handles.remove(P),this._indicators.length&&(this.layer.removeMany(this._indicators),this._indicators.forEach((i=>i.destroy())),this._indicators=[])}_getSymbolForIndicator(i){const t=12;if(a(i.symbol))return null;switch(i.symbol.type){case"cim":return new E({style:"circle",size:t,color:[0,0,0,0],outline:{color:[255,127,0,1],width:1}});case"picture-marker":{const{xoffset:t,yoffset:e,height:s,width:r}=i.symbol,h=s===r?r:Math.max(s,r);return new E({xoffset:t,yoffset:e,size:h,style:"square",color:[0,0,0,0],outline:{color:[255,127,0,1],width:1}})}case"simple-marker":{const{xoffset:t,yoffset:e,size:s,style:r}=i.symbol;return new E({xoffset:t,yoffset:e,style:"circle"===r?"circle":"square",size:s+2,color:[0,0,0,0],outline:{color:[255,127,0,1],width:1}})}case"simple-fill":return new U({color:[0,0,0,0],outline:{style:"dash",color:[255,127,0,1],width:1}});case"simple-line":return new j({color:[255,127,0,1],style:"dash",width:1});case"text":{const{xoffset:e,yoffset:s}=i.symbol;return new E({xoffset:e,yoffset:s,size:t,color:[0,0,0,0],outline:{color:[255,127,0,1],width:1}})}default:return null}}};i([n()],S.prototype,"_activeGraphic",void 0),i([n({readOnly:!0})],S.prototype,"type",void 0),i([n()],S.prototype,"callbacks",void 0),i([n()],S.prototype,"enableMoveAllGraphics",void 0),i([n()],S.prototype,"graphics",void 0),i([n({value:!1})],S.prototype,"highlightsEnabled",null),i([n()],S.prototype,"indicatorsEnabled",void 0),i([n()],S.prototype,"layer",void 0),i([n({readOnly:!0})],S.prototype,"state",null),i([n()],S.prototype,"view",void 0),S=i([l("esri.views.draw.support.GraphicMover")],S);const D=S;export{D as default};