UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 7 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";import r from"../../../geometry/Multipoint.js";import s from"../../../geometry/Point.js";import n from"../../../geometry/Polygon.js";import m from"../../../geometry/Polyline.js";import{projectAsync as p}from"../../../geometry/projectionUtils.js";import l from"../../../geometry/SpatialReference.js";import{imageToWorld as c,imageToWorldPanoramic as y}from"../../../layers/orientedImagery/transformations/imageToWorld.js";import h from"../../../layers/orientedImagery/transformations/updateElevation.js";import{getUpdateElevationProps as g,getImageToWorldProperties as u,getImageToWorldPanoramicProperties as f,pointToArray as d}from"../../../layers/orientedImagery/transformations/utils.js";import{worldToImagePanoramic as w,worldToImage as T}from"../../../layers/orientedImagery/transformations/worldToImage.js";import{imageSpaceToPoint as P,pointToImageSpace as x}from"../support/geometryUtils.js";let z=class extends t{constructor(e){super(e),this.mode="default"}get horizonAngles(){if("panoramic"!==this.mode)return;const{horizonPitch:e,horizonRoll:t,horizonYaw:a}=this.imageToWorldProperties;return[e,t,a]}async pixelToMapPoint(e,t){const{imageToWorldProperties:o,updateElevationProps:i,mode:r}=this,s=Array.isArray(e)?e:[e];await(this.depthImageService?.load(t)),a(t);const n=await Promise.all(s.map(async e=>{e.depth=await(this.depthImageService?.depthAt(e,{width:this.imageSize?.[0]??0,height:this.imageSize?.[1]??0}))}));if(await Promise.all(n),a(t),"default"===r){const r=await c(s,o,i);return a(t),Array.isArray(e)?r:r[0]}const m=await y(s,o,i);return a(t),Array.isArray(e)?m:m[0]}async pixelToMapPointForFeature(e,t,o){const{feature:i,mode:r,imageSize:s,footprintExtent:n}=t,{elevationSample:m,attributes:h}=i,{elevationSource:d,location:w,cameraHeight:T}=h;let P=w.clone();P.spatialReference.isGeographic&&(P=await p(P,l.WebMercator));const x=await g(w.spatialReference,w.z??0,T,{elevationSample:m,elevationSource:d,extent:n});let z;"elevationSample"in x&&(i.elevationSample=x.elevationSample);const S=Array.isArray(e)?e:[e];await(this.depthImageService?.load(o)),a(o);const G=await Promise.all(S.map(async e=>{e.depth=this.depthImageService?.depthAt(e,{width:s?.[0]??0,height:s?.[1]??0})}));if(await Promise.all(G),a(o),"default"===r||"video"===r){const e=u(h,s[0],s[1]);z=await c(S,{...e,cameraLocation:P},x)}else{const e=f(h,s[0],s[1]);z=await y(S,{...e,cameraLocation:P},x)}return Array.isArray(e)?z:z[0]}async pointToPixel(e,t){const{imageToWorldProperties:o,updateElevationProps:i,mode:r}=this;if(!i||!o)throw new Error("updateElevationProps and imageToWorldProperties are required to perform pointToPixel operation.");const s=Array.isArray(e)?e:[e],{spatialReference:n}=o.cameraLocation,m=await Promise.all(s.map(async e=>{let o=e;return e.hasZ||(o=await h(e,i,t)),o.spatialReference.equals(n)||(o=await p(o,n,t)),a(t),o}));let l;return a(t),l="panoramic"===r?w(m,o):T(m,o),a(t),Array.isArray(e)?l:l[0]}async pointToImageGeometry(e,t){const o=await this.pointToPixel(e,t);return a(t),P(o,this.mode,this.imageSize,this.horizonAngles)}async polygonToImageGeometry(e,t){const o=await Promise.all(e.rings.map(async o=>{const i=o.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})),r=await this.pointToPixel(i,t);return a(t),r.map(e=>d(P(e,this.mode,this.imageSize,this.horizonAngles)))}));return a(t),n.fromJSON({rings:o,spatialReference:l.WebMercator})}async polylineToImageGeometry(e,t){const o=await Promise.all(e.paths.map(async o=>{const i=o.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})),r=await this.pointToPixel(i,t);return a(t),r.map(e=>d(P(e,this.mode,this.imageSize,this.horizonAngles)))}));return a(t),m.fromJSON({paths:o,spatialReference:l.WebMercator})}async multipointToImageGeometry(e,t){const o=e.points.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})),i=await this.pointToPixel(o,t);a(t);const n=i.map(e=>d(P(e,this.mode,this.imageSize,this.horizonAngles)));return a(t),r.fromJSON({points:n,spatialReference:l.WebMercator})}async extentToImageGeometry(e,t){const o=n.fromExtent(e),i=await this.polygonToImageGeometry(o,t);return a(t),i.extent}async geometryToImageGeometry(e,t){switch(e.type){case"point":return await this.pointToImageGeometry(e,t);case"polygon":return await this.polygonToImageGeometry(e,t);case"polyline":return await this.polylineToImageGeometry(e,t);case"multipoint":return await this.multipointToImageGeometry(e,t);case"extent":return await this.extentToImageGeometry(e,t);default:return null}}async imagePointToMapGeometry(e,t){const o=x(e,this.mode,this.imageSize,this.horizonAngles),i=await this.pixelToMapPoint(o,t);return a(t),i}async imagePolygonToMapGeometry(e,t){const o=await Promise.all(e.rings.map(async a=>{const o=a.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})).map(e=>x(e,this.mode,this.imageSize,this.horizonAngles));return await this.pixelToMapPoint(o,t)}));return a(t),new n({rings:o.map(e=>e.map(d)),spatialReference:o[0][0].spatialReference})}async imagePolylineToMapGeometry(e,t){const o=await Promise.all(e.paths.map(async a=>{const o=a.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})).map(e=>x(e,this.mode,this.imageSize,this.horizonAngles));return await this.pixelToMapPoint(o,t)}));return a(t),new m({paths:o.map(e=>e.map(d)),spatialReference:o[0][0].spatialReference})}async imageMultipointToMapGeometry(e,t){const o=e.points.map(t=>new s({x:t[0],y:t[1],z:t[2],spatialReference:e.spatialReference})).map(e=>x(e,this.mode,this.imageSize,this.horizonAngles)),i=await this.pixelToMapPoint(o,t);return a(t),new r({points:i.map(e=>d(e)),spatialReference:i[0].spatialReference})}async imageExtentToMapGeometry(e,t){const o=n.fromExtent(e),i=await this.imagePolygonToMapGeometry(o,t);a(t);const r=await this.imageGeometryToMapGeometry(i,t);return a(t),r.extent}async imageGeometryToMapGeometry(e,t){switch(e.type){case"point":return await this.imagePointToMapGeometry(e,t);case"polygon":return await this.imagePolygonToMapGeometry(e,t);case"polyline":return await this.imagePolylineToMapGeometry(e,t);case"multipoint":return await this.imageMultipointToMapGeometry(e,t);case"extent":return await this.imageExtentToMapGeometry(e,t);default:return null}}};e([o()],z.prototype,"mode",void 0),e([o()],z.prototype,"imageToWorldProperties",void 0),e([o()],z.prototype,"updateElevationProps",void 0),e([o()],z.prototype,"depthImageService",void 0),e([o()],z.prototype,"imageSize",void 0),e([o()],z.prototype,"horizonAngles",null),z=e([i("esri.widgets.OrientedImageryViewer.services.TransformationService")],z);const S=z;export{S as default};