UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 7.31 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import o from"../../core/Clonable.js";import e from"../../core/Error.js";import r from"../../core/JSONSupport.js";import n from"../../core/Logger.js";import{transformProjective as i,getProjectiveTransform as s}from"../../core/perspectiveUtils.js";import{createScreenPoint as l}from"../../core/screenUtils.js";import{property as c}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{reader as a}from"../../core/accessorSupport/decorators/reader.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{writer as u}from"../../core/accessorSupport/decorators/writer.js";import{invert as m}from"../../core/libs/gl-matrix-2/math/mat3.js";import{fromValues as f,create as P}from"../../core/libs/gl-matrix-2/factories/mat3f64.js";import{set as h,lerp as d,rotate as y}from"../../core/libs/gl-matrix-2/math/vec2.js";import{create as g,fromValues as j}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import w from"../../geometry/Point.js";import R from"../../geometry/Polygon.js";import{projectOrLoad as x}from"../../geometry/projectionUtils.js";import v from"../../geometry/SpatialReference.js";import b from"./GeoreferenceBase.js";const S=P(),C=g();let N=class extends r{};t([c({type:Number,json:{write:{isRequired:!0}}})],N.prototype,"x",void 0),t([c({type:Number,json:{write:{isRequired:!0}}})],N.prototype,"y",void 0),N=t([p("esri.layers.support.ControlPointsGeoreference.ControlPointJSONType")],N);let q=class extends o{constructor(){super(...arguments),this.sourcePoint=null,this.mapPoint=null}};t([c()],q.prototype,"sourcePoint",void 0),t([c({type:w})],q.prototype,"mapPoint",void 0),q=t([p("esri.layers.support.ControlPointsGeoreference.ControlPoint")],q);let O=class extends(r.JSONSupportMixin(b)){constructor(t){super(t),this.controlPoints=null,this.height=0,this.type="control-points",this.width=0}readControlPoints(t,o){const e=v.fromJSON(o.spatialReference),r=f(...o.coefficients,1);return t.map((t=>(h(C,t.x,t.y),i(C,C,r),{sourcePoint:t,mapPoint:new w({x:C[0],y:C[1],spatialReference:e})})))}writeControlPoints(t,o,r,i){if(null!=this.transform)null!=t&&T(t[0])&&(o.controlPoints=t.map((t=>{const o=t.sourcePoint;return{x:o.x,y:o.y}})),o.spatialReference=t[0].mapPoint.spatialReference.toJSON(),o.coefficients=this.transform.slice(0,8));else{const t=new e("web-document-write:invalid-georeference","Invalid 'controlPoints', 'width', 'height' configuration. Make sure the parent media element is loaded i.e. the ImageElement or VideoElement set as 'MediaLayer.source'.",{layer:i?.layer,georeference:this});i?.messages?i.messages.push(t):n.getLogger(this).error(t.name,t.message)}}get coords(){if(null==this.controlPoints)return null;const t=this._updateTransform(S);if(null==t||!T(this.controlPoints[0]))return null;const o=this.controlPoints[0].mapPoint.spatialReference;return K(t,this.width,this.height,o)}set coords(t){if(null==this.controlPoints||!T(this.controlPoints[0]))return;const o=this.controlPoints[0].mapPoint.spatialReference;if(null==(t=this.projectOrWarn(t,o)))return;const{width:e,height:r}=this,{rings:[[n,s,c,a]]}=t,p={sourcePoint:l(0,r),mapPoint:new w({x:n[0],y:n[1],spatialReference:o})},u={sourcePoint:l(0,0),mapPoint:new w({x:s[0],y:s[1],spatialReference:o})},m={sourcePoint:l(e,0),mapPoint:new w({x:c[0],y:c[1],spatialReference:o})},f={sourcePoint:l(e,r),mapPoint:new w({x:a[0],y:a[1],spatialReference:o})};T(p)&&T(u)&&T(m)&&T(f)&&(B(S,p,u,m,f),this.controlPoints=this.controlPoints.map((({sourcePoint:t})=>(h(C,t.x,t.y),i(C,C,S),{sourcePoint:t,mapPoint:new w({x:C[0],y:C[1],spatialReference:o})}))))}get inverseTransform(){return null==this.transform?null:m(P(),this.transform)}get transform(){return this._updateTransform()}toMap(t){if(null==t||null==this.transform||null==this.controlPoints||!T(this.controlPoints[0]))return null;h(C,t.x,t.y);const o=this.controlPoints[0].mapPoint.spatialReference;return i(C,C,this.transform),new w({x:C[0],y:C[1],spatialReference:o})}toSource(t){if(null==t||null==this.inverseTransform||null==this.controlPoints||!T(this.controlPoints[0]))return null;const o=this.controlPoints[0].mapPoint.spatialReference;return t=t.normalize(),null==(t=x(t,o).geometry)?null:(h(C,t.x,t.y),i(C,C,this.inverseTransform),l(C[0],C[1]))}toSourceNormalized(t){const o=this.toSource(t);return null!=o&&(o.x/=this.width,o.y/=this.height),o}_updateTransform(t){const{controlPoints:o,width:e,height:r}=this;if(!(null!=o&&e>0&&r>0))return null;const[n,i,s,l]=o;if(!T(n))return null;const c=n.mapPoint.spatialReference,a=this._projectControlPoint(i,c),p=this._projectControlPoint(s,c),u=this._projectControlPoint(l,c);if(!a.valid||!p.valid||!u.valid)return null;if(!T(a.controlPoint))return null;null==t&&(t=P());let m=null;return m=T(p.controlPoint)&&T(u.controlPoint)?B(t,n,a.controlPoint,p.controlPoint,u.controlPoint):T(p.controlPoint)?V(t,n,a.controlPoint,p.controlPoint):A(t,n,a.controlPoint),m.every((t=>0===t))?null:m}_projectControlPoint(t,o){if(!T(t))return{valid:!0,controlPoint:t};const{sourcePoint:e,mapPoint:r}=t,{geometry:i,pending:s}=x(r,o);return s?{valid:!1,controlPoint:null}:s||i?{valid:!0,controlPoint:{sourcePoint:e,mapPoint:i}}:(n.getLogger(this).warn("map point could not be projected to the spatial reference",{georeference:this,controlPoint:t,sourceSpatialReference:r.spatialReference,targetSpatialReference:o}),{valid:!1,controlPoint:null})}};function T(t){return null!=t?.sourcePoint&&null!=t.mapPoint}t([c({type:[q],json:{write:{allowNull:!1,isRequired:!0,target:{controlPoints:{type:[N],isRequired:!0},coefficients:{type:[Number],isRequired:!0},spatialReference:{type:v,isRequired:!0}}}}})],O.prototype,"controlPoints",void 0),t([a("controlPoints")],O.prototype,"readControlPoints",null),t([u("controlPoints")],O.prototype,"writeControlPoints",null),t([c({clonable:!1})],O.prototype,"coords",null),t([c({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}})],O.prototype,"height",void 0),t([c({readOnly:!0})],O.prototype,"inverseTransform",null),t([c({readOnly:!0})],O.prototype,"transform",null),t([c({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}})],O.prototype,"width",void 0),O=t([p("esri.layers.support.ControlPointsGeoreference")],O);const _=g(),M=g(),G=g(),I=g(),J=g(),L=g(),E=g(),U=g(),k=Math.PI/2;function z(t,o,e){h(t,e.sourcePoint.x,e.sourcePoint.y),h(o,e.mapPoint.x,e.mapPoint.y)}function A(t,o,e){return z(_,J,o),z(M,L,e),y(G,M,_,k),y(I,_,M,k),y(E,L,J,-k),y(U,J,L,-k),H(t,_,M,G,I,J,L,E,U)}function V(t,o,e,r){return z(_,J,o),z(M,L,e),z(G,E,r),d(I,_,M,.5),y(I,G,I,Math.PI),d(U,J,L,.5),y(U,E,U,Math.PI),H(t,_,M,G,I,J,L,E,U)}function B(t,o,e,r,n){return z(_,J,o),z(M,L,e),z(G,E,r),z(I,U,n),H(t,_,M,G,I,J,L,E,U)}const W=new Array(8).fill(0),D=new Array(8).fill(0);function F(t,o,e,r,n){return t[0]=o[0],t[1]=o[1],t[2]=e[0],t[3]=e[1],t[4]=r[0],t[5]=r[1],t[6]=n[0],t[7]=n[1],t}function H(t,o,e,r,n,i,l,c,a){return s(t,F(W,o,e,r,n),F(D,i,l,c,a))}function K(t,o,e,r){const n=j(0,e),s=j(0,0),l=j(o,0),c=j(o,e);return i(n,n,t),i(s,s,t),i(l,l,t),i(c,c,t),new R({rings:[[n,s,l,c,n]],spatialReference:r})}export{O as default};