UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 13.1 kB
import{_ as t}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import e from"../../../../Graphic.js";import"../../../../symbols.js";import{getAccentColor as i,getContrastColor as s}from"../../../../core/analysisThemeUtils.js";import{destroyMaybe as o,isSome as r,unwrap as a}from"../../../../core/maybe.js";import{watch as n}from"../../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as h}from"../../../../core/unitUtils.js";import{property as c}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as p}from"../../../../core/accessorSupport/decorators/subclass.js";import{a as l,f as _}from"../../../../chunks/vec2.js";import{a as m,U as d}from"../../../../chunks/vec2f64.js";import{g as y,l as u,n as g,a as f,h as v,b as G}from"../../../../chunks/vec3.js";import{c as w}from"../../../../chunks/vec3f64.js";import{project as R,initializeProjection as b}from"../../../../geometry/projection.js";import{a as k,c as j}from"../../../../chunks/boundedPlane.js";import{equals as P}from"../../../../geometry/support/spatialReferenceUtils.js";import A from"../../../../layers/GraphicsLayer.js";import{ViewingMode as C}from"../../../ViewingMode.js";import{DragManipulation as S}from"./manipulations/DragManipulation.js";import{RotateManipulation as M}from"./manipulations/RotateManipulation.js";import{ScaleManipulation as T}from"./manipulations/ScaleManipulation.js";import{PreserveAspectRatio as O,SnapRotation as U}from"./manipulations/utils.js";import{primaryKey as D}from"../../../input/keys.js";import{InteractiveToolBase as x}from"../../../interactive/InteractiveToolBase.js";import{EditGeometry as E}from"../../../interactive/editGeometry/EditGeometry.js";import{EditGeometryOperations as L}from"../../../interactive/editGeometry/EditGeometryOperations.js";import{AccumulationBehaviour as B}from"../../../interactive/editGeometry/interfaces.js";import{AccumulationType as H}from"../../../interactive/editGeometry/operations/UpdateVertices.js";import{calculateOrientedBounds as V}from"../../../interactive/editGeometry/support/editPlaneUtils.js";import{findFirstGraphicHit as I}from"../../../support/hitTestSelectUtils.js";import{createScreenPointFromEvent as z}from"../../../support/screenUtils.js";import K from"../../../../geometry/Polygon.js";import N from"../../../../geometry/Point.js";import W from"../../../../symbols/SimpleFillSymbol.js";import q from"../../../../symbols/SimpleMarkerSymbol.js";const F={up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",plus:"+",minus:"-",toggleOpacity:"t",shift:"Shift",primaryKey:D},J=80,Q=10,X=30,Y=[[1,1],[1,-1],[-1,-1],[-1,1],[1,0],[0,-1],[-1,0],[0,1]],Z=1,$=10;let tt=class extends x{constructor(t){super(t),this._initialControlPoints=null,this._initialGeometry=null,this._graphic=null,this._planeCache=k(),this._displayPlaneCache=k(),this._mainAxisCache=m(),this._rotationHandleCache=w(),this._cornerA=w(),this._cornerB=w(),this._cornerC=w(),this._cornerD=w(),this._avgAB=w(),this._avgBC=w(),this._avgCD=w(),this._avgDA=w(),this._preserveAspectRatio=new O,this._snapRotation=new U,this._graphicsLayer=new A({internal:!0,listMode:"hide",visible:!1}),this._sharedUndoStack=[],this._sharedRedoStack=[],this._isOpacityToggled=!1,this._isModifierActive=!1,this._factor=1,this.preserveAspectRatio=null,this.snapRotation=null}initialize(){this._initialize()}destroy(){const{map:t}=this.view;this._dragManipulation.destroy(),this._rotateManipulation.destroy(),this._scaleManipulations.forEach((t=>t.destroy())),this._editGeometryOperations.destroy(),t.removeMany([this._graphicsLayer]),this._graphicsLayer.removeAll(),this._graphicsLayer=o(this._graphicsLayer),this._initialControlPoints=null,this._initialGeometry=null,this._graphic=null,this._preserveAspectRatio=null,this._snapRotation=null,this._planeCache=null,this._displayPlaneCache=null,this._rotationHandleCache=null,this._mainAxisCache=null,this._cornerA=null,this._cornerB=null,this._cornerC=null,this._cornerD=null,this._avgAB=null,this._avgBC=null,this._avgCD=null,this._avgDA=null,this._sharedUndoStack=null,this._sharedRedoStack=null}get _plane(){const t=this._graphic.geometry;if(!r(t))return null;const e=this._editGeometryOperations.data,i=e.components[0].edges[0],s=l(this._mainAxisCache,i.leftVertex.pos,i.rightVertex.pos);_(s,s);let o=J*this.view.resolution;const a=this.view.spatialReference;return P(a,t.spatialReference)&&(o*=h(a)/h(t.spatialReference)),V(s,e,o,this._planeCache)}get _displayPlane(){const t=this._plane;if(!t)return null;const e=this._displayPlaneCache;j(t,e);const i=Q*this.view.resolution;return y(e.basis1,e.basis1,1+i/u(e.basis1)),y(e.basis2,e.basis2,1+i/u(e.basis2)),e}get _backgroundGraphicGeometry(){const t=this._displayPlane;if(!t)return null;const e=this.view.spatialReference;return this._updateDisplayPlaneConrers(t),new K({spatialReference:e,rings:[[this._cornerA,this._cornerB,this._cornerC,this._cornerD,this._cornerA]]})}get _rotateGraphicGeometry(){const t=this._plane;if(!t)return null;const e=this._rotationHandleCache;return g(e,t.basis1),y(e,e,X*this.view.resolution),f(e,e,t.origin),f(e,e,t.basis1),new N({x:e[0],y:e[1],spatialReference:this.view.spatialReference})}get _scaleGraphicGeometries(){const t=this._displayPlane;if(!t)return[];const e=this.view.spatialReference;this._updateDisplayPlaneConrers(t);const{_cornerA:i,_cornerB:s,_cornerC:o,_cornerD:r}=this,a=v(this._avgAB,i,s,.5),n=v(this._avgBC,s,o,.5),h=v(this._avgCD,o,r,.5),c=v(this._avgDA,r,i,.5);return[new N({x:i[0],y:i[1],spatialReference:e}),new N({x:s[0],y:s[1],spatialReference:e}),new N({x:o[0],y:o[1],spatialReference:e}),new N({x:r[0],y:r[1],spatialReference:e}),new N({x:a[0],y:a[1],spatialReference:e}),new N({x:n[0],y:n[1],spatialReference:e}),new N({x:h[0],y:h[1],spatialReference:e}),new N({x:c[0],y:c[1],spatialReference:e})]}onActivate(){this.visible=!0}onDeactivate(){this.visible=!1}onShow(){this._graphicsLayer.visible=!0}onHide(){this._graphicsLayer.visible=!1}canUndo(){return this._editGeometryOperations.canUndo}canRedo(){return this._editGeometryOperations.canRedo}undo(){this._editGeometryOperations.undo(),this.updateGraphics()}redo(){this._editGeometryOperations.redo(),this.updateGraphics()}refresh(){const{view:t,target:e}=this,i="georeference"in e?a(a(e.georeference).coords):e.geometry,s=this._editGeometryOperations,o=s.data.components[0].vertices,r=E.fromGeometry(R(i,t.spatialReference),C.Local).components[0].vertices;o.forEach(((t,e)=>{s.setVertexPosition(t,r[e].pos)})),this.updateGraphics()}reset(){const{target:t}=this;if("georeference"in t){const e=a(t.georeference);"control-points"===e.type&&(e.controlPoints=this._initialControlPoints)}else t.geometry=this._initialGeometry;this.refresh(),this._sharedUndoStack.length=0,this._sharedRedoStack.length=0}updateGraphics(){const t=this._editGeometryOperations.data.geometry;if("georeference"in this.target){a(this.target.georeference).coords=t}this._graphic.geometry=t,this._backgroundGraphic.geometry=this._backgroundGraphicGeometry,this._rotateGraphic.geometry=this._rotateGraphicGeometry,this._scaleGraphicGeometries.forEach(((t,e)=>{this._scaleGraphics[e].geometry=t}))}setSharedUndoStack(t){this._sharedUndoStack=t}setSharedRedoStack(t){this._sharedRedoStack=t}async _initialize(){const{view:t,target:o}=this;if("georeference"in o){const t=a(o.georeference);this._graphic=new e({geometry:a(t.coords)}),this._initialControlPoints="control-points"===t.type?t.controlPoints:null}else this._graphic=o,this._initialGeometry=a(o.geometry);t.map.addMany([this._graphicsLayer]),t.focus(),this.visible=!1,this.finishToolCreation(),await this._loadProjectionEngine(),this._editGeometryOperations=L.fromGeometry(R(this._graphic.geometry,t.spatialReference),C.Local),this._backgroundGraphic=new e({symbol:new W({color:"transparent",outline:{type:"simple-line",color:i(),width:2}}),geometry:this._backgroundGraphicGeometry}),this._rotateGraphic=new e({symbol:new q({color:s(),outline:{type:"simple-line",color:i(),width:1}}),geometry:this._rotateGraphicGeometry}),this._scaleGraphics=this._scaleGraphicGeometries.map((t=>new e({symbol:new q({size:6,style:"square",color:s(),outline:{type:"simple-line",color:i(),width:1}}),geometry:t}))),this._graphicsLayer.graphics.addMany([this._backgroundGraphic,this._rotateGraphic,...this._scaleGraphics]),this._dragManipulation=new S({tool:this,view:t,graphic:this._graphic}),this._rotateManipulation=new M({tool:this,view:t,graphic:this._rotateGraphic,snapRotation:this._snapRotation}),this._scaleManipulations=this._scaleGraphics.map(((e,i)=>new T({tool:this,view:t,graphic:e,direction:Y[i],preserveAspectRatio:this._preserveAspectRatio}))),this.addHandles([this._dragManipulation.createDragPipeline(this._getInfo.bind(this),this._updateGraphics.bind(this)),this._rotateManipulation.createDragPipeline(this._getInfo.bind(this),this._updateGraphics.bind(this)),...this._scaleManipulations.map((t=>t.createDragPipeline(this._getInfo.bind(this),this._updateGraphics.bind(this)))),n((()=>this.view.scale),(()=>this.active?this.updateGraphics():null)),t.on("click",(async e=>{if(null!=t.activeTool&&t.activeTool!==this)return;const i=z(e),s=[];t.map.allLayers.forEach((t=>{"vector-tile"!==t.type&&"imagery"!==t.type||s.push(t)}));const a=await this.view.hitTest(i,{exclude:s}),n=a.results;if(0===n.length)t.activeTool=null;else{const e=I(a.results),i="georeference"in o,s=n.map((t=>"media"===t.type?t.element:null)).filter(Boolean),h=[...this._graphicsLayer.graphics,i?null:o].filter(Boolean);i&&s.includes(o)||r(e)&&h.includes(e.graphic)?null==t.activeTool&&(t.activeTool=this):t.activeTool=null}}))]);const h=t=>{this.addHandles(t.events.on("grab-changed",(t=>{"georeference"in o&&("start"===t.action?o.opacity*=.5:"end"===t.action&&(o.opacity*=2))})))};this._dragManipulation.forEachManipulator(h),this._rotateManipulation.forEachManipulator(h),this._scaleManipulations.forEach((t=>t.forEachManipulator(h))),this.addHandles([t.on("key-down",(e=>{t.activeTool===this&&(e.key!==F.shift||e.repeat||(null==this.preserveAspectRatio&&(this._preserveAspectRatio.enabled=!this._preserveAspectRatio.enabled),null==this.snapRotation&&(this._snapRotation.enabled=!this._snapRotation.enabled),this._isModifierActive=!0,e.stopPropagation()),e.key!==F.toggleOpacity||e.repeat||("georeference"in o&&(o.opacity*=this._isOpacityToggled?2:.5,this._isOpacityToggled=!this._isOpacityToggled),e.stopPropagation()),e.key!==F.primaryKey||e.repeat||(this._factor=$,e.stopPropagation()),this._isModifierActive&&(e.key===F.plus&&(this._scale(this._factor),e.stopPropagation()),e.key===F.minus&&(this._scale(-this._factor),e.stopPropagation()),e.key===F.up&&(this._move(0,this._factor),e.stopPropagation()),e.key===F.down&&(this._move(0,-this._factor),e.stopPropagation()),e.key===F.left&&(this._move(-this._factor,0),e.stopPropagation()),e.key===F.right&&(this._move(this._factor,0),e.stopPropagation())))})),t.on("key-up",(e=>{t.activeTool===this&&(e.key===F.shift&&(null==this.preserveAspectRatio&&(this._preserveAspectRatio.enabled=!this._preserveAspectRatio.enabled),null==this.snapRotation&&(this._snapRotation.enabled=!this._snapRotation.enabled),this._isModifierActive=!1,e.stopPropagation()),e.key===F.primaryKey&&(this._factor=Z,e.stopPropagation()))}))])}async _loadProjectionEngine(){const t=a(this._graphic.geometry);return b(t.spatialReference,this.view.spatialReference)}_updateDisplayPlaneConrers(t){const{basis1:e,basis2:i,origin:s}=t,o=this._cornerA;f(o,s,e),f(o,o,i);const r=this._cornerB;f(r,s,e),G(r,r,i);const a=this._cornerC;G(a,s,e),G(a,a,i);const n=this._cornerD;G(n,s,e),f(n,n,i)}_getInfo(){return{editGeometryOperations:this._editGeometryOperations,plane:this._plane,displayPlane:this._displayPlane}}_updateGraphics(t,e){"start"===t.action&&(this._sharedUndoStack.push({tool:this,operation:e}),this._sharedRedoStack.length=0),this.updateGraphics()}_scale(t){const e=this._editGeometryOperations,i=[];for(const a of e.data.components)i.push(...a.vertices);const s=e.data.geometry.extent?.width,o=(s+t*this.view.resolution)/s,r=e.scaleVertices(i,this._plane.origin,d,o,o,B.NEW_STEP,H.REPLACE);this._sharedUndoStack.push({tool:this,operation:r}),this._sharedRedoStack.length=0,this.updateGraphics()}_move(t,e){const i=this._editGeometryOperations,s=[];for(const r of i.data.components)s.push(...r.vertices);const o=i.moveVertices(s,t*this.view.resolution,e*this.view.resolution,0,B.NEW_STEP);this._sharedUndoStack.push({tool:this,operation:o}),this._sharedRedoStack.length=0,this.updateGraphics()}};t([c()],tt.prototype,"_plane",null),t([c()],tt.prototype,"_backgroundGraphicGeometry",null),t([c()],tt.prototype,"_rotateGraphicGeometry",null),t([c()],tt.prototype,"_scaleGraphicGeometries",null),t([c()],tt.prototype,"preserveAspectRatio",void 0),t([c()],tt.prototype,"snapRotation",void 0),t([c({constructOnly:!0,nonNullable:!0})],tt.prototype,"target",void 0),t([c({constructOnly:!0})],tt.prototype,"view",void 0),tt=t([p("esri.views.2d.interactive.editingTools.TransformTool")],tt);export{F as KEYS,tt as TransformTool};