UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.33 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import e from"../../../Graphic.js";import{makeHandle as t}from"../../../core/handleUtils.js";import{px2pt as r}from"../../../core/screenUtils.js";import{ensureClass as i}from"../../../core/accessorSupport/ensureType.js";import{subtract as n,cross as o}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{create as l}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import s from"../../../geometry/Point.js";import c from"../../../geometry/Polyline.js";import m from"../../../geometry/SpatialReference.js";import p from"../../../symbols/CIMSymbol.js";import y from"../../../symbols/SimpleLineSymbol.js";import g from"../../../symbols/SimpleMarkerSymbol.js";import{asVec2 as h}from"../../interactive/sketch/normalizedPoint.js";import{defaults as b}from"../../interactive/snapping/Settings.js";import{SnappingVisualizer as S}from"../../interactive/snapping/SnappingVisualizer.js";class f extends S{constructor(e){super(),this._graphicsAdapter=e,this._symbolPairingsByType=new Map}visualizeIntersectionPoint(e,t){return this._visualizeSnappingIndicator(new s({x:e.intersectionPoint[0],y:e.intersectionPoint[1],spatialReference:t.spatialReference}),this._getOrCreateSymbol("intersectionPoint",t.view.effectiveTheme.accentColor))}visualizePoint(e,t){return this._visualizeSnappingIndicator(new s({x:e.point[0],y:e.point[1],spatialReference:t.spatialReference}),this._getOrCreateSymbol("point",t.view.effectiveTheme.accentColor))}visualizeLine(e,t){return this._visualizeSnappingIndicator(new c({paths:[[[...e.lineStart],[...e.lineEnd]]],spatialReference:i(m,t.spatialReference)}),this._getOrCreateSymbol("line",t.view.effectiveTheme.accentColor))}visualizeCurve(e,t){return this._visualizeSnappingIndicator(new c({curvePaths:[[[...e.start],e.curve]],spatialReference:i(m,t.spatialReference)}),this._getOrCreateSymbol("line",t.view.effectiveTheme.accentColor))}visualizeParallelSign(e,t){return this._visualizeSnappingIndicator(new c({paths:[[[...e.lineStart],[...e.lineEnd]]],spatialReference:i(m,t.spatialReference)}),this._getOrCreateSymbol("parallelSign",t.view.effectiveTheme.accentColor))}visualizeRightAngleQuad(e,t){const r=a(),s=a(),p=l();n(r,h(e.centerVertex),h(e.previousVertex)),n(s,h(e.nextVertex),h(e.previousVertex)),o(p,r,s);const y=`rightAngleQuad${p[2]<0?45:225}`;return this._visualizeSnappingIndicator(new c({paths:[[[...e.previousVertex],[...e.centerVertex],[...e.nextVertex]]],spatialReference:i(m,t.spatialReference)}),this._getOrCreateSymbol(y,t.view.effectiveTheme.accentColor))}_visualizeSnappingIndicator(r,i){const n=new e({geometry:r,symbol:i});return this._graphicsAdapter.add(n),t(()=>{this._graphicsAdapter.remove(n)})}_getOrCreateSymbol(e,t){const r=this._symbolPairingsByType;return r.get(e)?.color!==t&&r.set(e,{color:t,symbol:u(e,t)}),r.get(e).symbol}}function u(e,t){const i=[...t.toRgb(),255*t.a];switch(e){case"point":return new g({outline:{width:.5,color:[0,0,0,1]},size:10,color:t});case"intersectionPoint":return new g({outline:new y({width:1.5,color:t}),size:15,color:[0,0,0,0]});case"line":return new p({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",miterLimit:10,width:r(b.lineHintWidthTarget),color:i}]}}});case"parallelSign":return new p({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:!0,anchorPoint:{x:0,y:-1,z:0},anchorPointUnits:"Relative",size:5,markerPlacement:{type:"CIMMarkerPlacementOnLine",placePerPart:!0,angleToLine:!0,relativeTo:"LineMiddle"},frame:{xmin:-5,ymin:-1.5,xmax:5,ymax:1.5},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{rings:[[[7,0],[-7,0],[-7,1.5],[7,1.5]]]},symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:i}]}}],scaleSymbolsProportionally:!0,respectFrame:!0},{type:"CIMVectorMarker",enable:!0,anchorPoint:{x:0,y:1,z:0},anchorPointUnits:"Relative",size:5,markerPlacement:{type:"CIMMarkerPlacementOnLine",placePerPart:!0,angleToLine:!0,relativeTo:"LineMiddle"},frame:{xmin:-5,ymin:-1.5,xmax:5,ymax:1.5},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{rings:[[[7,0],[-7,0],[-7,-1.5],[7,-1.5]]]},symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:i}]}}],scaleSymbolsProportionally:!0,respectFrame:!0}]}}});case"rightAngleQuad45":case"rightAngleQuad225":{const n="rightAngleQuad45"===e?45:225;return new p({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:!0,anchorPoint:{x:.5,y:.5,z:0},anchorPointUnits:"Relative",size:r(b.rightAngleHintSize),rotation:n,markerPlacement:{type:"CIMMarkerPlacementOnVertices",placePerPart:!0,angleToLine:!0,placeOnEndPoints:!1},frame:{xmin:-5,ymin:-5,xmax:5,ymax:5},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{paths:[[[5,-5],[-5,-5],[-5,5],[5,5],[5,-5]]]},symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",miterLimit:10,width:r(b.rightAngleHintOutlineSize),color:i},{type:"CIMSolidFill",enable:!0,color:[...t.toRgb(),255*t.a*.4]}]}}],scaleSymbolsProportionally:!0,respectFrame:!0}]}}})}}}export{f as SnappingVisualizer2D};