12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import t from"../../Graphic.js";import"../../intl.js";import"../../symbols.js";import s from"../../core/Handles.js";import{destroyMaybe as i}from"../../core/maybe.js";import{watch as r,initial as o}from"../../core/reactiveUtils.js";import{formatDecimal as a,formatImperialLength as n,formatMetricLength as l}from"../../core/unitFormatUtils.js";import{convertUnit as m}from"../../core/unitUtils.js";import{property as h}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import{geodesicLength as p,geodesicDensify as d,planarLength as u}from"../../geometry/geometryEngine.js";import{project as y}from"../../geometry/projection.js";import{isSupported as v,geodesicLengths as _,geodesicDensify as f}from"../../geometry/support/geodesicUtils.js";import w from"../../layers/GraphicsLayer.js";import{ViewingMode as g}from"../../views/ViewingMode.js";import b from"../../views/draw/Draw.js";import{createManipulatorDragEventPipeline as j,screenToMap as S,dragGraphic as L}from"../../views/interactive/dragEventPipeline.js";import{GraphicManipulator as A}from"../../views/interactive/GraphicManipulator.js";import{InteractiveToolBase as M}from"../../views/interactive/InteractiveToolBase.js";import{fetchMessageBundle as x}from"../../intl/messages.js";import{onLocaleChange as I}from"../../intl/locale.js";import C from"../../geometry/Point.js";import k from"../../symbols/CIMSymbol.js";import D from"../../symbols/TextSymbol.js";import G from"../../symbols/Font.js";import T from"../../symbols/SimpleMarkerSymbol.js";import P from"../../geometry/Polyline.js";import R from"../../geometry/SpatialReference.js";const W=1e5;let E=class extends M{constructor(e){super(e),this._drawActive=!1,this._handles=new s,this._measurementLayer=new w({internal:!0,listMode:"hide",visible:!1}),this._manipulatorLayer=new w({internal:!0,listMode:"hide",visible:!1}),this._vertices=[],this.geodesicDistanceThreshold=1e5,this.measurement=null,this.measurementLabel=null}initialize(){x("esri/core/t9n/Units").then((e=>{this.messages=e})),this._handles.add(I((async()=>{this.messages=await x("esri/core/t9n/Units")})));const e=this.view;this._draw=new b({view:e}),e.map.addMany([this._measurementLayer,this._manipulatorLayer]),e.focus(),this._handles.add([r((()=>[this.unit,this.geodesicDistanceThreshold,this.palette,this.messages]),(()=>{this._vertices.length>0&&this._updatePolylines()}),o)])}destroy(){const{map:e}=this.view;this._draw.view=null,this._draw=i(this._draw),e.removeMany([this._measurementLayer,this._manipulatorLayer]),this._handles.removeAll(),this._measurementLayer.removeAll(),this._manipulatorLayer.removeAll(),this._set("measurement",null),this._set("measurementLabel",null),this._handles=i(this._handles),this._measurementLayer=i(this._measurementLayer),this._manipulatorLayer=i(this._manipulatorLayer)}get cursor(){return this._drawActive?"crosshair":null}set editable(e){this._set("editable",e),e||this._draw.reset()}onActivate(){this._drawActive||0!==this._vertices.length||this._startSketch()}onShow(){this._measurementLayer.visible=!0,this._manipulatorLayer.visible=!0}onHide(){this._measurementLayer.visible=!1,this._manipulatorLayer.visible=!1}reset(){this._vertices=[],this._measurementLayer.removeAll(),this._set("measurement",null),this._set("measurementLabel",null),this._draw.reset(),this._drawActive=!1,this._updateSketch([])}_startSketch(){this._drawActive=!0;const e=this._draw.create("polyline",{mode:"click"});e.on(["vertex-add","vertex-update","vertex-remove","cursor-update","undo","redo"],(e=>this._updateSketch(e.vertices))),e.on("draw-complete",(()=>{this._stopSketch()}))}_stopSketch(){this.manipulators.forEach((e=>{e.manipulator.interactive=!0})),this._drawActive=!1,this.finishToolCreation()}_updateSketch(e){if(e.length<2)return this._vertices=[],this.manipulators.removeAll(),void this._measurementLayer.removeAll();const{spatialReference:t}=this.view;for(;this._vertices.length>e.length;){const{manipulatorId:e}=this._vertices.pop();this.manipulators.remove(e)}for(let n=this._vertices.length;n<e.length;n++){const[s,i]=e[n],r=U(new C({x:s,y:i,spatialReference:t}),this.view,this._manipulatorLayer,this.palette),o=this.manipulators.add(r);j(r,((e,t)=>{t.next(S(this.view)).next(L(e.graphic,g.Local)).next((()=>{const t=e.graphic.geometry;this._vertices[n].coord=[t.x,t.y],this._updatePolylines()}))})),this._vertices.push({manipulatorId:o,coord:[s,i]})}const s=this._vertices.length-1,i=this._vertices[s],[r,o]=e[s];if(i.coord[0]!==r||i.coord[1]!==o){i.coord=[r,o];const e=new C({x:r,y:o,spatialReference:t});this.manipulators.findById(i.manipulatorId).graphic.geometry=e}const a=this._drawActive?this._vertices[s].manipulatorId:null;this.manipulators.forEach((e=>{e.manipulator.interactive=null==a||e.id!==a})),this._updatePolylines()}_updatePolylines(){const e=this._vertices.map((e=>e.coord)),{measurement:s,drawing:i,original:r}=z(e,this.view.spatialReference,this.geodesicDistanceThreshold);this._set("measurement",s);const o=F(this.messages,s,this.unit);let a,n;this._set("measurementLabel",o);const{graphics:l}=this._measurementLayer;if(2===l.length)a=l.getItemAt(0),n=l.getItemAt(1);else{const{pathPrimaryColor:e,pathSecondaryColor:s,pathWidth:i}=this.palette;a=new t({symbol:new k({data:{type:"CIMSymbolReference",symbol:{type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",effects:[{type:"CIMGeometricEffectDashes",dashTemplate:[14,12],lineDashEnding:"FullGap",controlPointEnding:"NoConstraint"}],enable:!0,capStyle:"Butt",joinStyle:"Round",width:i-1.5,color:s},{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",width:i,color:e}]}}})}),n=new t({symbol:new D({color:[255,255,255,1],haloColor:[0,0,0,.5],haloSize:2,font:new G({size:14,family:"sans-serif"})})}),l.removeAll(),l.addMany([a,n])}a.geometry=i,n.geometry=r.extent.center,n.symbol.text=o}};function U(e,s,i,r){const o=new T({style:"circle",color:r.handleColor,size:r.handleWidth,outline:{type:"simple-line",width:0}}),a=new T({style:"circle",color:r.handleColor,size:1.5*r.handleWidth,outline:{type:"simple-line",width:0}}),n=new t({geometry:e,symbol:o});return new A({view:s,layer:i,graphic:n,focusedSymbol:a})}function z(e,t,s){const i=new P({paths:[e],spatialReference:t});let r,o;if(t.isGeographic)if(v(t))r=_([i],"meters")[0],o=f(i,W);else{const e=y(i,R.WGS84),s=f(e,W);r=_([e],"meters")[0],o=y(s,t)}else if(t.isWebMercator)r=p(i,"meters"),o=d(i,W,"meters");else{const e=u(i,"meters");if(e>=s){const e=y(i,R.WGS84),s=f(e,W);r=_([e],"meters")[0],o=y(s,t)}else r=e,o=i}return{measurement:{geometry:o,length:r},original:i,drawing:o}}function B(e){return null!=e}function O(e){if(!e)return!1;const{isGeographic:t,isWebMercator:s,isWGS84:i}=e;return t&&!i&&!v(e)||!t&&!s}function F(e,t,s){if(!t||!e)return null;switch(s){case"metric":return l(e,t.length,"meters");case"imperial":return n(e,t.length,"meters");default:return a(e,m(t.length,"meters",s),s)}}e([h()],E.prototype,"_drawActive",void 0),e([h({readOnly:!0})],E.prototype,"cursor",null),e([h({value:!0})],E.prototype,"editable",null),e([h({type:Number})],E.prototype,"geodesicDistanceThreshold",void 0),e([h({readOnly:!0})],E.prototype,"measurement",void 0),e([h({readOnly:!0})],E.prototype,"measurementLabel",void 0),e([h()],E.prototype,"messages",void 0),e([h()],E.prototype,"palette",void 0),e([h()],E.prototype,"unit",void 0),e([h({constructOnly:!0})],E.prototype,"view",void 0),E=e([c("esri.widgets.DistanceMeasurement2D.DistanceMeasurement2DTool")],E);export{E as DistanceMeasurement2DTool,z as createDistanceMeasurementInfo2D,F as createDistanceMeasurementLabel,O as isProjectionEngineRequired,B as isSupported};
|