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 r from"../../core/Handles.js";import{destroyMaybe as s}from"../../core/maybe.js";import{watch as i,initial as o}from"../../core/reactiveUtils.js";import{formatDecimal as a,formatImperialArea as n,formatMetricArea as l,formatImperialLength as m,formatMetricLength as c}from"../../core/unitFormatUtils.js";import{convertUnit as h}from"../../core/unitUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{geodesicDensify as d,planarLength as y,simplify as f,geodesicLength as v,geodesicArea as _,planarArea as w}from"../../geometry/geometryEngine.js";import{isLoaded as g,project as b}from"../../geometry/projection.js";import{isSupported as j,geodesicDensify as L,geodesicLengths as S,geodesicAreas as A}from"../../geometry/support/geodesicUtils.js";import G from"../../layers/GraphicsLayer.js";import{ViewingMode as k}from"../../views/ViewingMode.js";import q from"../../views/draw/Draw.js";import{createManipulatorDragEventPipeline as x,screenToMap as M,dragGraphic as W}from"../../views/interactive/dragEventPipeline.js";import{GraphicManipulator as I}from"../../views/interactive/GraphicManipulator.js";import{InteractiveToolBase as R}from"../../views/interactive/InteractiveToolBase.js";import{fetchMessageBundle as T}from"../../intl/messages.js";import{onLocaleChange as D}from"../../intl/locale.js";import U from"../../geometry/Point.js";import C from"../../symbols/SimpleFillSymbol.js";import z from"../../symbols/SimpleLineSymbol.js";import E from"../../symbols/TextSymbol.js";import O from"../../symbols/Font.js";import P from"../../symbols/SimpleMarkerSymbol.js";import F from"../../geometry/Polyline.js";import B from"../../geometry/SpatialReference.js";import H from"../../geometry/Polygon.js";const N=1e5;let V=class extends R{constructor(e){super(e),this._drawActive=!1,this._handles=new r,this._measurementLayer=new G({internal:!0,listMode:"hide",visible:!1}),this._manipulatorLayer=new G({internal:!0,listMode:"hide",visible:!1}),this._vertices=[],this.geodesicDistanceThreshold=1e5,this.measurement=null,this.measurementLabel=null}initialize(){T("esri/core/t9n/Units").then((e=>{this.messages=e})),this._handles.add(D((async()=>{this.messages=await T("esri/core/t9n/Units")})));const e=this.view;this._draw=new q({view:e}),e.map.addMany([this._measurementLayer,this._manipulatorLayer]),e.focus(),this._handles.add([i((()=>[this.unit,this.geodesicDistanceThreshold,this.palette,this.messages]),(()=>{this._vertices.length>0&&this._updateGraphics()}),o)])}destroy(){const{map:e}=this.view;this._draw.view=null,this._draw=s(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=s(this._handles),this._measurementLayer=s(this._measurementLayer),this._manipulatorLayer=s(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(){if(this._vertices.length<3)return this.reset(),void this._startSketch();this.manipulators.forEach((e=>{e.manipulator.interactive=!0})),this._drawActive=!1,this.finishToolCreation()}_updateSketch(e){if(X(this.view.spatialReference)&&!g())return;if(e.length<2)return this._vertices=[],this.manipulators.removeAll(),void this._measurementLayer.removeAll();const t=this.view.spatialReference;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[r,s]=e[n],i=J(new U({x:r,y:s,spatialReference:t}),this.view,this._manipulatorLayer,this.palette),o=this.manipulators.add(i);x(i,((e,t)=>{t.next(M(this.view)).next(W(e.graphic,k.Local)).next((()=>{const t=e.graphic.geometry;this._vertices[n].coord=[t.x,t.y],this._updateGraphics()}))})),this._vertices.push({manipulatorId:o,coord:[r,s]})}const r=this._vertices.length-1,s=this._vertices[r],[i,o]=e[r];if(s.coord[0]!==i||s.coord[1]!==o){s.coord=[i,o];const e=new U({x:i,y:o,spatialReference:t});this.manipulators.findById(s.manipulatorId).graphic.geometry=e}const a=this._drawActive?this._vertices[r].manipulatorId:null;this.manipulators.forEach((e=>{e.manipulator.interactive=null==a||e.id!==a})),this._updateGraphics()}_updateGraphics(){const e=K(this._vertices.map((e=>e.coord)),this.view.spatialReference,this.geodesicDistanceThreshold);if(!e)return;const{measurement:r,fillGeometry:s,outlineGeometry:i}=e;this._set("measurement",r);const o=r?Y(this.messages,r,this.unit):null;if(this._set("measurementLabel",o),!s&&!i)return;let a,n,l;const{graphics:m}=this._measurementLayer;if(3===m.length)a=m.getItemAt(0),n=m.getItemAt(1),l=m.getItemAt(2);else{const{fillColor:e,pathColor:r,pathWidth:s}=this.palette;a=new t({symbol:new C({color:e,outline:null})}),n=new t({symbol:new z({color:r,width:s})}),l=new t({symbol:new E({color:[255,255,255,1],font:new O({size:14,family:"sans-serif"}),haloColor:[0,0,0,.5],haloSize:2})}),m.removeAll(),m.addMany([a,n,l])}a.geometry=s,n.geometry=i,l.geometry=s?.centroid,l.symbol.text=o?.area}};function J(e,r,s,i){const o=new P({style:"circle",color:i.handleColor,size:i.handleWidth,outline:{type:"simple-line",width:0}}),a=new P({style:"circle",color:i.handleColor,size:1.5*i.handleWidth,outline:{type:"simple-line",width:0}}),n=new t({geometry:e,symbol:o});return new I({view:r,layer:s,graphic:n,focusedSymbol:a})}function K(e,t,r){if(2===e.length){const s=new F({paths:e,spatialReference:t});let i;if(t.isGeographic)if(j(t))i=L(s,N);else{const e=b(s,B.WGS84),r=L(e,N);i=b(r,t)}else if(t.isWebMercator)i=d(s,N,"meters");else{if(y(s,"meters")>=r){const e=b(s,B.WGS84),r=L(e,N);i=b(r,t)}else i=s}return{measurement:null,fillGeometry:null,outlineGeometry:i}}e.push(e[0]);const s=new F({paths:[e],spatialReference:t}),i=new H({rings:[e],spatialReference:t});let o,a,n=null,l=null;if(t.isGeographic)if(j(t)){if(n=L(s,N),l=L(i,N),l=f(l),!l)return null;o=S([s],"meters")[0],a=A([l],"square-meters")[0]}else{const e=B.WGS84,r=b(s,e),m=b(i,e);if(n=L(r,N),l=L(m,N),l=f(l),!l)return null;o=S([r],"meters")[0],a=A([l],"square-meters")[0],n=b(n,t),l=b(l,t)}else if(t.isWebMercator){if(n=d(s,N,"meters"),l=d(i,N,"meters"),l=f(l),!l)return null;o=v(s,"meters"),a=_(l,"square-meters")}else{const e=y(s,"meters");if(e>=r){const e=B.WGS84,r=b(s,e),m=b(i,e);if(n=L(r,N),l=L(m,N),l=f(l),!l)return null;o=S([r],"meters")[0],a=A([l],"square-meters")[0],n=b(n,t),l=b(l,t)}else{if(n=s,l=f(i),!l)return null;o=e,a=w(l,"square-meters")}}return{measurement:{geometry:l,area:a,perimeter:o},fillGeometry:l,outlineGeometry:n}}function Q(e){return null!=e}function X(e){if(!e)return!1;const{isGeographic:t,isWebMercator:r,isWGS84:s}=e;return t&&!s&&!j(e)||!t&&!r}function Y(e,t,r){if(!t||!e)return null;const s={area:null,perimeter:null},{area:i,perimeter:o}=t;switch(r){case"metric":s.area=l(e,i,"square-meters");break;case"imperial":s.area=n(e,i,"square-meters");break;default:{const t=h(i,"square-meters",r);s.area=a(e,t,r);break}}const u=Z(r);if(u)switch(u){case"metric":s.perimeter=c(e,o,"meters");break;case"imperial":s.perimeter=m(e,o,"meters");break;default:{const t=h(o,"meters",u);s.perimeter=a(e,t,u);break}}else s.perimeter="";return s}function Z(e){switch(e){case"metric":case"ares":case"hectares":return"metric";case"imperial":case"acres":return"imperial";case"square-inches":return"inches";case"square-feet":return"feet";case"square-yards":return"yards";case"square-miles":return"miles";case"square-us-feet":return"us-feet";case"square-meters":return"meters";case"square-kilometers":return"kilometers";case"square-millimeters":return"millimeters";case"square-centimeters":return"centimeters";case"square-decimeters":return"decimeters";default:return null}}e([u()],V.prototype,"_drawActive",void 0),e([u({readOnly:!0})],V.prototype,"cursor",null),e([u({value:!0})],V.prototype,"editable",null),e([u({type:Number})],V.prototype,"geodesicDistanceThreshold",void 0),e([u({readOnly:!0})],V.prototype,"measurement",void 0),e([u({readOnly:!0})],V.prototype,"measurementLabel",void 0),e([u()],V.prototype,"messages",void 0),e([u()],V.prototype,"palette",void 0),e([u()],V.prototype,"unit",void 0),e([u({constructOnly:!0})],V.prototype,"view",void 0),V=e([p("esri.widgets.AreaMeasurement2D.AreaMeasurement2DTool")],V);export{V as AreaMeasurement2DTool,K as createAreaMeasurementInfo2D,Y as createAreaMeasurementLabel,X as isProjectionEngineRequired,Q as isSupported};
|