12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/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{getContrastColor as s,getAccentColor as r,getTextColor as i,getTextHaloColor as o}from"../../core/analysisThemeUtils.js";import{destroyMaybe as a,isNone as n}from"../../core/maybe.js";import{watch as l,initial as m}from"../../core/reactiveUtils.js";import{formatDecimal as c,formatImperialLength as h,formatMetricLength as p}from"../../core/unitFormatUtils.js";import{convertUnit as u}from"../../core/unitUtils.js";import{property as d}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as y}from"../../core/accessorSupport/decorators/subclass.js";import{geodesicLength as v,geodesicDensify as _,planarLength as f}from"../../geometry/geometryEngine.js";import{project as w}from"../../geometry/projection.js";import{isSupported as g,geodesicLengths as b,geodesicDensify as j}from"../../geometry/support/geodesicUtils.js";import S from"../../layers/GraphicsLayer.js";import{ViewingMode as L}from"../../views/ViewingMode.js";import M from"../../views/draw/Draw.js";import{createManipulatorDragEventPipeline as A,screenToMap as x,dragGraphic as k}from"../../views/interactive/dragEventPipeline.js";import{GraphicManipulator as D}from"../../views/interactive/GraphicManipulator.js";import{InteractiveToolBase as T}from"../../views/interactive/InteractiveToolBase.js";import{fetchMessageBundle as G}from"../../intl/messages.js";import{onLocaleChange as C}from"../../intl/locale.js";import R from"../../geometry/Point.js";import P from"../../symbols/CIMSymbol.js";import U from"../../symbols/TextSymbol.js";import E from"../../symbols/Font.js";import I from"../../symbols/SimpleMarkerSymbol.js";import z from"../../geometry/Polyline.js";import W from"../../geometry/SpatialReference.js";const O=1e5;let V=class extends T{constructor(e){super(e),this._drawActive=!1,this._measurementLayer=new S({internal:!0,listMode:"hide",visible:!1}),this._manipulatorLayer=new S({internal:!0,listMode:"hide",visible:!1}),this._vertices=[],this.geodesicDistanceThreshold=1e5,this.measurement=null,this.measurementLabel=null}initialize(){G("esri/core/t9n/Units").then((e=>{this.messages=e})),this.addHandles(C((async()=>{this.messages=await G("esri/core/t9n/Units")})));const e=this.view;this._draw=new M({view:e}),e.map.addMany([this._measurementLayer,this._manipulatorLayer]),e.focus(),this.addHandles(l((()=>[this.unit,this.geodesicDistanceThreshold,this.messages]),(()=>{this._updatePolylines()}),m))}destroy(){const{map:e}=this.view;this._draw.view=null,this._draw=a(this._draw),e.removeMany([this._measurementLayer,this._manipulatorLayer]),this._measurementLayer.removeAll(),this._manipulatorLayer.removeAll(),this._set("measurement",null),this._set("measurementLabel",null),this._measurementLayer=a(this._measurementLayer),this._manipulatorLayer=a(this._manipulatorLayer),this._resetVertices()}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._resetVertices(),this._measurementLayer.removeAll(),this._set("measurement",null),this._set("measurementLabel",null),this._draw.reset(),this._drawActive=!1,this._updateSketch([])}_resetVertices(){for(const{handle:e}of this._vertices)e.remove();this._vertices=[]}_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((({manipulator:e})=>{e.interactive=!0})),this._drawActive=!1,this.finishToolCreation()}_updateSketch(e){const{spatialReference:t}=this.view;for(;this._vertices.length>e.length;){const{handle:e,manipulator:t}=this._vertices.pop();e.remove(),this.manipulators.remove(t)}for(let n=this._vertices.length;n<e.length;n++){const[s,r]=e[n],i=B(new R({x:s,y:r,spatialReference:t}),this.view,this._manipulatorLayer);this.manipulators.add(i);const o=A(i,((e,t)=>{t.next(x(this.view)).next(k(e.graphic,L.Local)).next((()=>{const t=e.graphic.geometry;this._vertices[n].coord=[t.x,t.y],this._updatePolylines()}))}));this._vertices.push({manipulator:i,coord:[s,r],handle:o})}const s=this._vertices.length-1,r=this._vertices[s],[i,o]=e[s];r.coord[0]===i&&r.coord[1]===o||(r.coord=[i,o],r.manipulator.graphic.geometry=new R({x:i,y:o,spatialReference:t}));const a=this._drawActive?this._vertices[s].manipulator:null;this.manipulators.forEach((({manipulator:e})=>{e.interactive=n(a)||e!==a})),this._updatePolylines()}_updatePolylines(){if(this._vertices.length<2)return void this._measurementLayer.removeAll();const e=this._vertices.map((({coord:e})=>e)),{measurement:a,drawing:n,original:l}=F(e,this.view.spatialReference,this.geodesicDistanceThreshold);this._set("measurement",a);const m=q(this.messages,a,this.unit);let c,h;this._set("measurementLabel",m);const{graphics:p}=this._measurementLayer;2===p.length?(c=p.at(0),h=p.at(1)):(c=new t({symbol:new P({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:3.5,color:s().toArray()},{type:"CIMSolidStroke",enable:!0,capStyle:"Butt",joinStyle:"Round",width:5,color:r().toArray()}]}}})}),h=new t({symbol:new U({color:i(),haloColor:o(.5),haloSize:2,font:new E({size:14,family:"sans-serif"})})}),p.removeAll(),p.addMany([c,h])),c.geometry=n,h.geometry=l.extent.center,h.symbol.text=m}};function B(e,s,i){const o=r(.5),a={type:"simple-line",width:0},n=8,l=new I({style:"circle",color:o,size:n,outline:a}),m=new I({style:"circle",color:o,size:1.5*n,outline:a}),c=new t({geometry:e,symbol:l});return new D({view:s,layer:i,graphic:c,focusedSymbol:m})}function F(e,t,s){const r=new z({paths:[e],spatialReference:t});let i,o;if(t.isGeographic)if(g(t))i=b([r],"meters")[0],o=j(r,O);else{const e=w(r,W.WGS84),s=j(e,O);i=b([e],"meters")[0],o=w(s,t)}else if(t.isWebMercator)i=v(r,"meters"),o=_(r,O,"meters");else{const e=f(r,"meters");if(e>=s){const e=w(r,W.WGS84),s=j(e,O);i=b([e],"meters")[0],o=w(s,t)}else i=e,o=r}return{measurement:{geometry:o,length:i},original:r,drawing:o}}function H(e){return null!=e}function N(e){if(!e)return!1;const{isGeographic:t,isWebMercator:s,isWGS84:r}=e;return t&&!r&&!g(e)||!t&&!s}function q(e,t,s){if(!t||!e)return null;switch(s){case"metric":return p(e,t.length,"meters");case"imperial":return h(e,t.length,"meters");default:return c(e,u(t.length,"meters",s),s)}}e([d()],V.prototype,"_drawActive",void 0),e([d({readOnly:!0})],V.prototype,"cursor",null),e([d({value:!0})],V.prototype,"editable",null),e([d({type:Number})],V.prototype,"geodesicDistanceThreshold",void 0),e([d({readOnly:!0})],V.prototype,"measurement",void 0),e([d({readOnly:!0})],V.prototype,"measurementLabel",void 0),e([d()],V.prototype,"messages",void 0),e([d()],V.prototype,"unit",void 0),e([d({constructOnly:!0})],V.prototype,"view",void 0),V=e([y("esri.widgets.DistanceMeasurement2D.DistanceMeasurement2DTool")],V);export{V as DistanceMeasurement2DTool,F as createDistanceMeasurementInfo2D,q as createDistanceMeasurementLabel,N as isProjectionEngineRequired,H as isSupported};
|