UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.01 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{createScreenPoint as e}from"../../core/screenUtils.js";import{nameToId as t,OriginId as n}from"../../core/accessorSupport/PropertyOrigin.js";import o from"../../geometry/Extent.js";import r from"../../geometry/Point.js";import{getInfo as i}from"../../geometry/support/spatialReferenceUtils.js";import s from"./ControlPointsGeoreference.js";import a from"./CornersGeoreference.js";import c from"./ExtentAndRotationGeoreference.js";import p from"./GeoreferenceBase.js";const l=100,y=.5;async function m(e,t){e.loaded||await e.load();const{contentWidth:n,contentHeight:a}=e,{spatialReference:c}=t,p=i(c);let m=!1;if(p){const e=p.valid[1]-p.valid[0];t.width>e&&(t=new o({xmin:p.valid[0],ymin:t.ymin,xmax:p.valid[1],ymax:t.ymax,spatialReference:t.spatialReference}),m=!0)}const f=t.expand(y),{center:u,width:P,height:d}=f,x=n/a,w=m||x>1,g=w?l:l*x,h=w?l/x:l,R=w?P:d*x,j=w?P/x:d,v=u.x-R/2,O=u.x+R/2,b=u.y+j/2,G=u.y-j/2;return new s({controlPoints:[{sourcePoint:{x:g,y:a-h},mapPoint:new r({x:v,y:G,spatialReference:c})},{sourcePoint:{x:g,y:h},mapPoint:new r({x:v,y:b,spatialReference:c})},{sourcePoint:{x:n-g,y:h},mapPoint:new r({x:O,y:b,spatialReference:c})},{sourcePoint:{x:n-g,y:a-h},mapPoint:new r({x:O,y:G,spatialReference:c})}],width:n,height:a})}function f(e){const t=e.georeference;if("control-points"!==t.type)return null;const n={wkid:0},{width:o,height:i}=t,a=t.controlPoints;return new s({controlPoints:a.map((e=>{const{x:t,y:o}=e.sourcePoint;return{sourcePoint:{x:t,y:o},mapPoint:new r({x:t,y:i-o,spatialReference:n})}})),width:o,height:i})}function u(e){return"media"===e?.type}function P(e,o){const r=t(o);return u(e)&&!!e.portalItem&&null!=r&&r>n.PORTAL_ITEM}function d(t,n,o){if(!t||"control-points"===t.type)return t;const{coords:i}=t;if(5!==i?.rings[0]?.length)return null;const[a,c,p,l]=i.rings[0],{spatialReference:y}=i;return new s({controlPoints:[{mapPoint:new r({x:a[0],y:a[1],spatialReference:y}),sourcePoint:e(0,o)},{mapPoint:new r({x:c[0],y:c[1],spatialReference:y}),sourcePoint:e(0,0)},{mapPoint:new r({x:p[0],y:p[1],spatialReference:y}),sourcePoint:e(n,0)},{mapPoint:new r({x:l[0],y:l[1],spatialReference:y}),sourcePoint:e(n,o)}],width:n,height:o})}function x(e,t,n){return{enabled:!P(n?.layer,n?.origin),ignoreOrigin:!0}}const w={json:{name:"url",type:String,write:{overridePolicy:x}}},g={readOnly:!0,json:{read:!1,write:{target:"mediaType",overridePolicy:x}}},h={types:{key:"type",base:p,typeMap:{"control-points":s,corners:a,"extent-and-rotation":c}},json:{types:{key:"type",base:p,typeMap:{"control-points":s}},write:{overridePolicy:()=>({enabled:!0,ignoreOrigin:!0})}}};export{m as createDefaultControlPointsGeoreference,f as createLocalModeControlPointsGeoreference,P as isWritingLayerFromItemToWebDocument,w as mediaElementUrlProperty,h as mediaGeoreferenceProperty,g as mediaTypeProperty,d as toControlPointsGeoreference};