@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.35 kB
JavaScript
import"../../../geometry.js";import{equals as t}from"../../../core/arrayUtils.js";import{clone as e}from"../../../core/lang.js";import{filterNones as o,isSome as n,isNone as r}from"../../../core/maybe.js";import{getMetersPerUnitForSR as a}from"../../../core/unitUtils.js";import{h as s}from"../../../chunks/vec3.js";import{c as l}from"../../../chunks/vec3f64.js";import i from"../../../geometry/Circle.js";import{simplify as c,distance as y}from"../../../geometry/geometryEngine.js";import{unnormalizeGeometryOnDatelineCrossing as p,isClockwise as m,unnormalizeVerticesOnDatelineCrossing as x}from"../../../geometry/support/coordsUtils.js";import{isValid as u}from"../../../geometry/support/spatialReferenceUtils.js";import{makeSurfacePoint as f}from"./surfaceCoordinateSystems.js";import h from"../../../geometry/Point.js";import M from"../../../geometry/Multipoint.js";import g from"../../../geometry/Polyline.js";import d from"../../../geometry/Polygon.js";function R(t,e){const o=new h({x:t[0],y:t[1],spatialReference:e});return t.length>2&&(o.z=t[2]),o}function j(t,e){return new M({points:t,spatialReference:e})}function T(t,e,o){const n=new g({paths:t,spatialReference:e});return o&&p(n),n}function b(o,n,r,a=!0){const s=e(o);s.forEach((e=>{const o=e[0],n=e[e.length-1];t(o,n)&&1!==e.length||e.push(e[0])}));let l=new d({rings:s,spatialReference:n});return l.rings.forEach((t=>{m(t,!1,!1)||t.reverse()})),r&&p(l),a&&l.isSelfIntersecting&&u(n)&&(l=c(l)),l}function U(t,e,n){const r=e.mapToLocalMultiple(t),a=[],s={x:r[0].x,y:r[0].y},l={x:r[1].x,y:r[1].y},i=Math.round(l.x-s.x),c=Math.round(l.y-s.y),y=Math.max(Math.abs(i),Math.abs(c));if(n){const t={x:s.x+y,y:s.y+y},e={x:s.x-y,y:s.y-y};a.push(f(t.x,e.y),f(e.x,e.y),f(e.x,t.y),f(t.x,t.y))}else{const t={x:i>0?s.x+y:s.x-y,y:c>0?s.y+y:s.y-y};a.push(f(s.x,s.y),f(t.x,s.y),f(t.x,t.y),f(s.x,t.y))}return z(b([o(a.map((t=>e.localToMap(t))))],e.spatialReference,e.doUnnormalization,!0),a,e)}function P(t,e,n){let r=e.mapToLocalMultiple(t);if(1===r.length){const t=48,e=r[0];r=[f(e.x-t,e.y+t),f(e.x+t,e.y-t),f(e.x+t,e.y-t),f(e.x-t,e.y+t)]}const a=[],s={x:r[0].x,y:r[0].y},l={x:r[1].x,y:r[1].y};if(n){const t=Math.round(l.x-s.x),e=Math.round(l.y-s.y);a.push(f(s.x-t,s.y-e),f(l.x,s.y-e),f(l.x,l.y),f(s.x-t,l.y))}else a.push(f(s.x,s.y),f(l.x,s.y),f(l.x,l.y),f(s.x,l.y));return z(b([o(a.map((t=>e.localToMap(t))))],e.spatialReference,e.doUnnormalization,!0),a,e)}function z(t,e,o){const r=w(e[3],e[2],o),a=w(e[1],e[2],o),s=w(e[0],e[1],o),l=w(e[0],e[3],o);return{geometry:t,midpoints:n(r)&&n(a)&&n(s)&&n(l)?{top:r,right:a,bottom:s,left:l}:null}}function w(t,e,o){L[0]=t.x,L[1]=t.y,L[2]=0,v[0]=e.x,v[1]=e.y,v[2]=0,s(L,L,v,.5),I.x=L[0],I.y=v[1],I.z=v[2];const r=o.localToMap(I);return n(r)?R(r,o.spatialReference):null}const I=f(0,0,0),L=l(),v=l();function E(t,e,o,n){const s=e.mapToLocalMultiple(t);let l=null,c=null;if(o)l=s[0],c=s[1];else{const t=s[0],e=s[1],o=Math.round(e.x-t.x),n=Math.round(e.y-t.y),r=Math.max(Math.abs(o),Math.abs(n));l=f(o>0?t.x+r/2:t.x-r/2,n>0?t.y+r/2:t.y-r/2),c=f(Math.abs(o)>Math.abs(n)?l.x-r/2:l.x,Math.abs(o)>Math.abs(n)?l.y:l.y-r/2)}const p=e.localToMap(l),m=e.localToMap(c);if(r(p)||r(m))return null;e.doUnnormalization&&x([[p,m]],e.spatialReference);const h=R(p,e.spatialReference),M=R(m,e.spatialReference),g=a(e.spatialReference);let d=0;if(u(e.spatialReference))d=g*y(h,M,null);else{const t=l.x-c.x,e=l.y-c.y;d=g*Math.sqrt(t*t+e*e)*(n||1)}const j=new i({center:h,radius:d,radiusUnit:"meters",spatialReference:e.spatialReference});return{geometry:b(j.rings,j.spatialReference,!1),center:h,edge:M}}function k(t,e,r){const a=e.mapToLocalMultiple(t),s=a[0],l=a[1],i=Math.round(l.x-s.x),c=Math.round(l.y-s.y),y=f(r?s.x:s.x+i/2,r?s.y:s.y+c/2),p=r?i:i/2,m=r?c:c/2,x=60,u=[],h=2*Math.PI/x;function M(t){const e=Math.cos(t),o=Math.sin(t);return f(p*e+y.x,m*o+y.y)}for(let o=0;o<x;o++)u.push(M(o*h));u.push(u[0]);const{spatialReference:g,doUnnormalization:d}=e,j=b([o(u.map((t=>e.localToMap(t))))],g,d,!1),T=e.localToMap(M(Math.PI/2)),U=e.localToMap(M(0)),P=e.localToMap(M(-Math.PI/2)),z=e.localToMap(M(Math.PI));return{geometry:j,midpoints:n(T)&&n(U)&&n(P)&&n(z)?{top:R(T,g),right:R(U,g),bottom:R(P,g),left:R(z,g)}:null}}export{E as createCircle,k as createEllipse,j as createMultipoint,R as createPoint,b as createPolygon,T as createPolyline,P as createRectangle,U as createSquare};