UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.84 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{throwIfAborted as r}from"../../../core/promiseUtils.js";import{property as o,subclass as i}from"../../../core/accessorSupport/decorators.js";import s from"../../../geometry/Point.js";import{polygonCentroidPoint as n}from"../../../geometry/support/centroid.js";import{createCoveragePolygon as a}from"../../../layers/orientedImagery/core/coverageUtils.js";import l from"../../../layers/orientedImagery/core/ExposurePoint.js";import{NoSequenceFoundError as d,NoImageInSequenceError as u,InvalidDirectionError as c}from"./errors.js";import{queryNextLocationFeatures as g,querySequenceCount as w,queryAfterSequenceField as p,querySequenceFeaturesAroundPoint as f,queryOffsetSequenceFeatures as v}from"./queries.js";import{shouldQueryAndNavigateSequentially as y,sortStringOrNumber as h,shouldQueryAndNavigate as m}from"./utils.js";let M=class extends t{constructor(e){super(e),this.viewModel=null}get currentNode(){return this.viewModel.currentNode}get layer(){return this.viewModel.layer}get navigationNodes(){return this.viewModel.navigationNodes}async _queryAndHandleFeatureResponse(e,t,o,i,s){const{error:n,nextLocation:a,response:l}=await g(e,t,o,i,s);if(r(s),n)throw n;this.viewModel.selectedPoint=a,await this.viewModel.processFeatureResponse(l,a,{signal:s?.signal,loadBestImage:!1})}async afterNavigate(e,t,r){return await this.viewModel.selectBestFeature(t.id,r),t}async navigate(e,t){let r;if("direction"in t?r=await this.navigateInDirection(e,t):("step"in t||"goTo"in t)&&(r=await this.navigateInSequence(e,t)),!r)throw new Error("No next node found");return await this.afterNavigate(e,r,t)}async navigateBySkippingSteps(e,t){const{step:r}=t,{layer:o}=this,{layerFloorFilterClause:i,layerTimeExtent:c,preloadMediaSize:g}=this.viewModel;if(!o)throw new Error("Layer is not defined");const v=e.attributes.sequenceOrder;if(0===await w(o,i??void 0,c,{signal:t.signal})||!v)throw new d;const m=r>0?e.next:e.previous;if(!y(m))return m;const{response:M,error:N}=await p(o,v,r,g,i??void 0,c,{signal:t.signal});if(N)throw new Error("Error querying sequence features");const S=M?.features[0];if(!S)throw new u(r>0?"end":"start");const b=l.fromJSON({...S.toJSON(),layer:o}),{polygon:q}=a(b),E=s.fromJSON(n(q)),{response:j,error:I,nextLocation:x}=await f(o,E,i??void 0,c,{signal:t.signal});if(I)throw new Error("Error querying sequence features");const O=new Set(j.features.map(e=>e.attributes.objectId)),F=[...M.features.filter(e=>!O.has(e.attributes.objectId)),...j.features],P=new Set(F.map(e=>e.attributes.objectId));j.features=F,this.viewModel.selectedPoint=x;const T=S.attributes.objectId;await this.viewModel.processFeatureResponse(j,x,{signal:t.signal,loadBestImage:!1});const B=this.viewModel.navigationNodes.filter((e,t)=>null!=e.attributes.sequenceOrder&&P.has(e.attributes.objectId)&&t===this.viewModel.navigationNodes.indexOf(e)).items.toSorted((e,t)=>h(e.attributes.sequenceOrder,t.attributes.sequenceOrder)),J=B.length;for(let s=0;s<J;s++){const e=B[s];e.previous=s>0?B[s-1]:null,e.next=s<J-1?B[s+1]:null}return this.viewModel.selectedPoint=x,this.viewModel.navigationNodes.find(e=>e.id===T)}async navigateInDirection(e,t){const{viewModel:r}=this,{layer:o,layerFloorFilterClause:i,layerTimeExtent:s}=r,{direction:n,signal:a}=t,l=e?.[n];if(!l)throw new c(n);return m(l,n)&&await this._queryAndHandleFeatureResponse(o,l,i??void 0,s,{signal:a}),l}async navigateInSequence(e,t){return"step"in t?this.navigateBySkippingSteps(e,t):this.navigateTo(t)}async navigateTo(e){const{goTo:t}=e,{layer:r}=this,{layerFloorFilterClause:o,layerTimeExtent:i}=this.viewModel;if(!r)throw new Error("Layer is not defined");const d="number"==typeof t?t:1,u=this.viewModel.navigationNodes.find(e=>e.id===d);if(u)return u;const{response:c,error:g}=await v(r,d,1,"end"===t?"DESC":"ASC",o??void 0,i,{signal:e.signal});if(g)throw new Error("Error querying sequence features");const w=c?.features[0];if(!w)throw new Error("No next node found");const p=l.fromJSON({...w.toJSON(),layer:r}),{polygon:y}=a(p),h=s.fromJSON(n(y)),{response:m,error:M,nextLocation:N}=await f(r,h,o??void 0,i,{signal:e.signal});if(M)throw new Error("Error querying sequence features");const S=[...m.features];S.push(w),m.features=S,this.viewModel.selectedPoint=N;const b=w.attributes.objectId;return await this.viewModel.processFeatureResponse(m,N,{signal:e.signal,loadBestImage:!1}),this.viewModel.selectedPoint=N,this.viewModel.navigationNodes.find(e=>e.id===b)}};e([o()],M.prototype,"currentNode",null),e([o()],M.prototype,"layer",null),e([o()],M.prototype,"navigationNodes",null),e([o({constructOnly:!0})],M.prototype,"viewModel",void 0),M=e([i("esri.widgets.OrientedImageryViewer.navigation.NavigationManager")],M);export{M as default};