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"../../core/Accessor.js";import{isNone as r}from"../../core/maybe.js";import{createScreenPoint as s}from"../../core/screenUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import{isSupported as n,geodesicLengths as a}from"../../geometry/support/geodesicUtils.js";import{straightLineDensify as c}from"../../geometry/support/normalizeUtils.js";import{getInfo as m}from"../../geometry/support/spatialReferenceUtils.js";import{webMercatorToGeographic as l}from"../../geometry/support/webMercatorUtils.js";import p from"../../geometry/support/WKIDUnitConversion.js";import u from"../../geometry/SpatialReference.js";import d from"../../geometry/Polyline.js";import f from"../../geometry/Point.js";function g(e){const{wkid:t}=e;if(null!=p[t])return p.values[p[t]];const{wkt:r}=e,s=r.lastIndexOf(",")+1,o=r.lastIndexOf("]]");return parseFloat(r.substring(s,o))}function h(e,t){return e&&e.includes(t)}function w(e,t){const{x:r,y:s}="decimal-degrees"===e?l(t,!0):t;return[r,s]}function y({state:{paddedViewState:e},spatialReference:t,width:r}){return t.isWrappable&&e.worldScreenWidth<r}let S=class extends t{constructor(e){super(e),this.scaleComputedFrom=s(),this.view=null}get state(){return this.get("view.ready")&&"2d"===this.get("view.type")?"ready":"disabled"}getScaleBarProperties(e,t){if("disabled"===this.state||isNaN(e)||!t)return null;const s=this._getDistanceInKm(this.view,this.scaleComputedFrom);if(r(s))return null;if("metric"===t)return this._getScaleBarProps(e,s,"metric");const o=s/1.609;return this._getScaleBarProps(e,o,"non-metric")}_getLocationUnit(){const e=this.get("view.spatialReference"),{isWebMercator:t,wkid:r,wkt:s}=e;return t||h(s,"WGS_1984_Web_Mercator")?"decimal-degrees":null!=p[r]||h(s,"PROJCS")?"linear-unit":"unknown"}_getDistanceInKm(e,t){const{state:r,spatialReference:s}=e,o=this._getLocationUnit();if("linear-unit"===o){const e=1e3;return r.extent.width*g(s)/e}const[i,m]=this._getScaleMeasuringPoints(e,t),l="decimal-degrees"===o||s.isGeographic&&!n(s)?u.WGS84:s,p=new d({paths:[[w(o,i),w(o,m)]],spatialReference:l}),f=c(p,10);let h;try{[h]=a([f],"kilometers")}catch{return null}return h}_getScaleMeasuringPoints(e,t){const{width:r,height:o,position:i,spatialReference:n}=e;if(y(e)){const{valid:e}=m(n);return[new f(e[0],0,n),new f(e[1],0,n)]}let a=t.y-i[1];a>o?a=o:a<0&&(a=0);const c=s(0,a),l=s(r,a);return[e.toMap(c),e.toMap(l)]}_getScaleBarProps(e,t,r){const{view:s}=this;let o=e*t/(y(s)?s.state.paddedViewState.worldScreenWidth:s.width),i="metric"===r?"km":"mi";if(o<.1)if("mi"===i){o*=5280,i="ft"}else if("km"===i){o*=1e3,i="m"}let n=0;for(;o>=1;)o/=10,n++;const a=this._getConstraints(o);if(!a)return null;const{min:c,max:m}=a,l=m/o>=o/c?c:m;return{length:e*(l/o),value:10**n*l,unit:i}}_getConstraints(e){return e>.5?{min:.5,max:1}:e>.3?{min:.3,max:.5}:e>.2?{min:.2,max:.3}:e>.15?{min:.15,max:.2}:e>=.1?{min:.15,max:.1}:void 0}};e([o()],S.prototype,"scaleComputedFrom",void 0),e([o({readOnly:!0})],S.prototype,"state",null),e([o()],S.prototype,"view",void 0),S=e([i("esri.widgets.Scalebar.ScaleBarViewModel")],S);const j=S;export{j as default};
|