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