UNPKG

@arcgis/core

Version:

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

5 lines • 79.3 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 e}from"../../chunks/tslib.es6.js";import t from"../../Graphic.js";import{equals as a,isSome as i}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import s from"../../core/Collection.js";import{deprecatedProperty as o}from"../../core/deprecate.js";import n from"../../core/Error.js";import l from"../../core/Evented.js";import{makeHandle as c}from"../../core/handleUtils.js";import{equalsShallow as u}from"../../core/lang.js";import h from"../../core/Logger.js";import{clamp as m}from"../../core/mathUtils.js";import{abortMaybe as d,destroyMaybe as p}from"../../core/maybe.js";import g from"../../core/Promise.js";import{isAbortError as y,throwIfAborted as v,waitTick as f}from"../../core/promiseUtils.js";import w from"../../core/ReactiveMap.js";import{whenOnce as F,on as b,watch as M,syncAndInitial as _,initial as P}from"../../core/reactiveUtils.js";import{sqlAnd as I}from"../../core/sql.js";import{getMetersPerUnitForSR as V}from"../../core/unitUtils.js";import{property as k}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as S}from"../../core/accessorSupport/decorators/subclass.js";import{distance as A}from"../../core/libs/gl-matrix-2/math/vec2.js";import{isSerializable as C}from"../../core/support/jsonUtils.js";import{UpdatingHandles as L}from"../../core/support/UpdatingHandles.js";import G from"../../geometry/Extent.js";import{union as R}from"../../geometry/geometryEngineAsync.js";import O from"../../geometry/Multipoint.js";import T from"../../geometry/Point.js";import j from"../../geometry/Polygon.js";import B from"../../geometry/Polyline.js";import{projectWithZConversion as x}from"../../geometry/projectionUtils.js";import E from"../../geometry/SpatialReference.js";import{isClockwise as H}from"../../geometry/support/coordsUtils.js";import{normalizeMapX as z}from"../../geometry/support/normalizeUtils.js";import{geographicToWebMercator as D}from"../../geometry/support/webMercatorUtils.js";import U from"../../layers/GraphicsLayer.js";import N from"../../layers/MediaLayer.js";import{searchImages as W,getSortedLayerFeatures as q}from"../../layers/orientedImagery/queries.js";import{calculateSuitabilities as $}from"../../layers/orientedImagery/core/bestImageUtils.js";import{createCoveragePolygon as J,computePolygonForInspection as Z,resizePolygon as K,checkIfPolygonContainsSelectedPoint as Q}from"../../layers/orientedImagery/core/coverageUtils.js";import{isElevationSource as X}from"../../layers/orientedImagery/core/ElevationSourceDefinitions.js";import{convertGeographicToWebMercator as Y}from"../../layers/orientedImagery/core/utils.js";import{imageToWorld as ee,imageToWorldPanoramic as te}from"../../layers/orientedImagery/transformations/imageToWorld.js";import ae from"../../layers/orientedImagery/transformations/updateElevation.js";import{getElevationSampler as ie}from"../../layers/orientedImagery/transformations/updateElevationUtils.js";import{or as re,getInitialAngle as se,convertPixelToHeadingPitch as oe,convertHeadingPitchToSphereVertex as ne,getImageToWorldProperties as le,getUpdateElevationProps as ce,isElevationSampler as ue,getImageToWorldPanoramicProperties as he,pointToArray as me,transformGraphicCoordinatesToPixel as de,getWorldToImageProperties as pe}from"../../layers/orientedImagery/transformations/utils.js";import{worldToImage as ge,worldToImagePanoramic as ye}from"../../layers/orientedImagery/transformations/worldToImage.js";import ve from"../../layers/support/ExtentAndRotationGeoreference.js";import{getFloorFilterClause as fe}from"../../layers/support/floorFilterUtils.js";import we from"../../layers/support/VideoElement.js";import Fe from"../../symbols/SimpleLineSymbol.js";import be from"../../views/MapView.js";import Me from"../../views/draw/Draw.js";import{scale as _e}from"../../views/draw/support/drawUtils.js";import{ViewEventPriorities as Pe}from"../../views/input/InputManager.js";import Ie from"../PanoramicViewer.js";import{defaultAngleThresholdInDegrees as Ve,videoExtent as ke,invalidCameraHeading as Se,sectorsInOrder as Ae,sampleExtent as Ce,sectorsRadii as Le}from"./constants.js";import{configureSketchTool as Ge,extractFieldsFromDataCaptureLayer as Re,isValidDataCaptureLayer as Oe,constructGraphicFromImageGeometry as Te}from"./dataCaptureUtils.js";import{isFeatureAttachment as je,getImageSourceFromAttachment as Be}from"./galleryUtils.js";import{formatPixels as xe,heightMeasurementPanoramic as Ee,heightMeasurement2D as He,calculateHeightAccuracyPanoramic as ze,calculateHeightAccuracy as De,pixelAreaMeasurement2D as Ue,pixelAreaMeasurementPanoramic as Ne,pixelDistanceMeasurement2D as We,pixelDistanceMeasurementPanoramic as qe,generateCombinations as $e,getRootOfSumOfSquaredErrors as Je,generateCombinationsPanoramic as Ze,calculateLocationAccuracyFromDeviations as Ke,calculateReferenceImagePointPanoramic as Qe,calculateAnglePano as Xe,calculateTempImagePoint as Ye,calculateAngle as et,computeTriangulatedAreaMeasurement as tt,computeTriangulatedDistanceMeasurement as at,getModeCorrectedPoint as it,calculateCorrectedPixel as rt,getUnitRateFromSpatialReference as st,calculateHeightFromTemporaryDistance as ot,computeTriangulatedVector as nt,computeTriangulatedPoint as lt}from"./imageMeasurementUtils.js";import{crossSymbol as ct,crossSymbol3D as ut,measurementPolygonSymbol as ht,polylineSymbolPanoramic as mt,measurementPolylineSymbol as dt,sourcePointSymbol as pt,diamondSymbol as gt,diamondSymbol3D as yt,locationSymbol as vt,locationSymbol3D as ft,activeSourcePointSymbol as wt}from"./symbols.js";import{isNoAttachmentError as Ft,getContentType as bt,isTifOrMrf as Mt,filterOILLayerView as _t,assignElevationSampleToFeatures as Pt,calculateDirection as It,calculateSegment as Vt,isSceneView as kt,isGraphic as St}from"./utils.js";import{disableVideoZoomAndPan as At}from"./videoViewerUtils.js";import Ct from"./components/ImageViewer.js";import Lt from"./components/NavigationNode.js";import Gt from"./components/OrientedImageryVideoViewModel.js";import{NoActiveViewerError as Rt,NoFeatureFoundWithObjectIdError as Ot}from"./navigation/errors.js";import{queryFeatureByObjectIds as Tt}from"./navigation/queries.js";import jt from"../Sketch/SketchViewModel.js";const Bt={click:"view-click",imageClick:"image-click",triangularImageClick:"triangular-click",interactionHandles:"interaction-handles",hittestHandles:"hittest-handles",videoPlayerHandles:"video-handles"},xt=new Set(["JPG","JPEG"]),Et=/\.(\w+)$/,Ht=()=>new n("orientedimageryviewer:sketch-not-initialized","Sketch property is not initialized, call loadSketch first");let zt=class extends(l.EventedMixin(g)){constructor(e){super(e),this.additionalFeatures=new s,this.additionalCameraLocations=new s,this.additionalFootprints=new s,this.areaMeasurementResult=0,this.areaMeasurementAccuracy=0,this.allLayerFeatures=[],this.bestFeatureAngle=0,this.bestFeatureCurrentFootprint=null,this.bestFeatureFootprint=null,this.cameraHeadingThreshold=Ve,this.cameraPitchThreshold=Ve,this.clickAction="hittest",this.videoViewModel=null,this.collectionId=null,this.conversionProps=null,this.coverageFrustums=new s,this.coveragePolygons=new s,this.currentBestFeature=null,this.currentBestFeatureMeasurementImage=null,this.currentBestFeatureLocation=null,this.currentCoverageVisible=!0,this.navigationNodes=new s,this.determineWorkflowForFeature=async(e,t,a)=>{const{currentBestFeature:i,selectedPoint:r,view:s}=this;if(s?.closePopup(),i&&r){this._initialCurrentCoverageUpdate=!0,this._updateGroundElevation=!0;try{await this._updatePointsAndPolygons(a),await this._loadImage(a)}catch(o){y(o)||(this.loadImageError(o),h.getLogger(this).error("#loadIImage()","error occured while loading image",o))}}},this.determineWorkflowForTriangularMeasurement=async(e,t,a)=>{if(this.view?.closePopup(),this.currentBestFeatureMeasurementImage&&this.selectedPoint)try{await this._loadMeasurementViewerImage(a)}catch(i){y(i)||(this.loadImageError(i),h.getLogger(this).error("#loadIImage()","error occured while loading image",i))}},this.disabled=!1,this.displayMessage={key:"onLoadMessage",type:"info"},this.displayNewMeasurementButton=!0,this.distanceMeasurementResult=0,this.distanceAccuracyArray=[],this.dataCaptureLayer=null,this.features=new s,this.groundCoordinates=null,this.groundCoordinatesAccuracy=null,this.heightMeasurementPixels=[],this.heightGraphic=null,this.heightMeasurementResult=0,this.heightMeasurementAccuracy=0,this.measurementAngle=null,this.tempDistance=null,this.imageGeometryField=null,this.imageLocationToolState=!1,this.imageMeasurementViewer=new Ct,this.isAdditionalCoverageVisible=!1,this.isAdditionalPointSourcesVisible=!1,this.measurementVectors=[],this.layer=null,this.localPort=null,this.mapImageConversionToolState=!1,this.measureType=null,this.measurementGraphic=null,this.navigatorCurrentBestFeature=null,this.oiObjectIdField=null,this.overlayedCameraLocations=new s,this.overlayedMapFeatures=new w,this.pixelCoordinates=null,this.preserveAngle="none",this.pointSources=new s,this.previousFeatureAngle=0,this.selectedPoint=null,this.shouldShowSelectedImage=!1,this.sketch=null,this.sketchTriangular=null,this.sketchTriangularGraphicsLayer=null,this.draw=null,this.sketchAdapter=null,this.triangularMeasurementActive=!1,this.triangulatedDistanceMeasurement=null,this.triangulatedDistanceAccuracy=null,this.triangulatedAreaMeasurement=null,this.triangulatedAreaAccuracy=0,this.triangulatedMeasurementGraphic=null,this.triangulatedPoint=null,this.triangulatedMeasurementAdapter=null,this.updateFootprint=async(e,t)=>{"default"===this.mode&&"image-loaded"!==this.state||"video"===this.mode&&!this.videoElement?.content||await(this._adapter?.updateFootprint(e,t))},this.updateFootprintPanorama=async(e,t)=>{await(this._adapter?.updateFootprintPanorama(e,t))},this.updatingTriangularMeasurementState=!1,this.videoElement=null,this.videoLayer=null,this.videoMapView=new be({map:new Map}),this._adapter=null,this._highlightedFeatureHandle=null,this._imageViewer=new Ct,this._initialCurrentCoverageUpdate=!0,this._locationPointOnImage=null,this._correctedLocationPointOnImage=null,this._overlays=new U({listMode:"hide",internal:!0,elevationInfo:{mode:"absolute-height"}}),this._panoramicViewer=new Ie,this._previousCursor=null,this._referencePointOnGround=null,this._referencePointOnImage=null,this._sectorData=null,this._featureToSector=null,this._updatingHandles=new L,this._clickTask=null,this._crossSymbol=null,this.footprintExtent=null,this._featureChangedTask=null,this._openPopupTask=null,this._suitabilities=null,this._transformController=new AbortController,this._updateFootprintTask=null,this._updateGroundElevation=!1,this.addUpdatingPromise=e=>this._updatingHandles.addPromise(e),this.hideImageGeometry=e=>{},this.highlight=e=>{if(!this._overlaysView)return;this.removeHighlight();const t=this.additionalFootprints.find((({attributes:{imageID:t}})=>t===Number(e)));this._highlightedFeatureHandle=t?this._overlaysView?.highlight(t):null},this.loadDataCaptureAdapter=async e=>{await this.loadSketch(e);const t=import("./adapters/sketch/DataCaptureAdapter.js"),{default:a}=await t;return v(e),this.sketchAdapter=new a({viewModel:this}),this.sketchAdapter},this.loadImageFromSource=async(e,t)=>this._updatingHandles.addPromise(this._loadImageFromSourceInternal(e,t)),this.storeImageMeasurementViewer=e=>{this.imageMeasurementViewer=e},this.loadImageViewer=e=>{this._imageViewer?.destroy(),this._imageViewer=e},this.loadPanoramicViewer=e=>{this._panoramicViewer?.destroy(),this._panoramicViewer=e},this.loadVideoViewer=e=>{this.videoMapView.container=e},this.showImageByObjectId=async(e,t)=>{const a=this.additionalFeatures.find((({attributes:t})=>t.objectId===e));if(a)this.currentBestFeature=a;else{const{layer:a,layerFloorFilterClause:r}=this;if(!a)return void this.setMessage("noLayerSelected","info");this.beforeLoad();const s=this._updatingHandles.addPromise(this._queryAndLoadByObjectId(a,e,r,t));try{await s,await this.selectBestFeature(e,t)}catch(i){y(i)||(h.getLogger(this).error("oriented-imagery-viewer:show-image",i),"NoFeatureFoundWithObjectIdError"===i.name?this.setMessage("noFeatureFoundWithObjectId","error","",{objectId:e}):this.setMessage("imageLoadError","error",i.message))}}},this.imageToImageTransform=async(e,t,a)=>{const{updateElevationProps:i,...r}=t,{updateElevationProps:s,...o}=a,n=await ee(e,r,i);return ge(n,o)},this.getSectorFeatureById=e=>this._suitabilities?.find((({feature:{attributes:{objectId:t}}})=>t===e)),this.getFeatureSectorById=e=>this._featureToSector?.[`${e}`],this.navigate=async(e,t)=>{const{activeViewer:a}=this;if(!a)throw new Rt;return await a.navigate(e,t)},this.removeHighlight=()=>this._highlightedFeatureHandle?.remove(),this.revealImageGeometry=e=>{},this.selectBestFeature=async(e,t)=>(v(t),this.currentBestFeature=this.features?.find((({attributes:t})=>`${t.objectId}`==`${e}`)),F((()=>"image-loaded"===this.state),t)),this.toggleImageAttributes=()=>{d(this._openPopupTask),this._openPopupTask=r((async e=>{const{currentBestFeature:a,popupEnabled:i,layer:r,view:s}=this;if(s?.closePopup(),!(s&&a&&i&&r))return;const{attributes:o,geometry:n}=a,l=new t({geometry:n,attributes:o.toJSON(),layer:r,sourceLayer:r});v(e),await s.openPopup({features:[l],location:o.location.clone()})}))},this.updateSuitabilities=(e,t=!0)=>{e.sort(((e,t)=>e.suitability-t.suitability)),this._suitabilities=e;const a=this._suitabilities.map((({feature:e})=>e));this._initialCurrentCoverageUpdate=!0,this._updateFeatures(a,t),this._groupFeaturesBySectors()},this._createViewClickHandle=()=>{if(this.removeHandles(Bt.click),"disabled"===this.state||null==this.view)return;const e=this.mapImageConversionToolState&&"image-loaded"===this.state?this._mapImageConversionToolViewClickHandler:this._viewClickHandler;this.addHandles(this.view.on("click",e,Pe.WIDGET),Bt.click)},this._createImageClickHandle=()=>{this.removeHandles(Bt.imageClick);const{mapImageConversionToolState:e,mode:t,activeViewer:a,currentBestFeature:i,footprintExtent:s}=this,o=a?.imageSize;if(!(e&&"none"!==t&&o&&s&&i))return;const n=a.clickAction;this.clickAction="pixel-location";const l=c((()=>{this.clickAction=n}));let u=null;const h=b((()=>a),"pixel-location",(e=>{this.plotReferencePointOnImage(e),u?.abort(),u=r((async a=>{if(!e)return;const r=await this.getMapPoint(e,{feature:i,imageSize:o,mode:t}).then((e=>{const t=this.view?.spatialReference;return re(!t,e.spatialReference.equals(t))?e:x(e,t)}));v(a),this.plotReferencePointOnGround(r)}))}));this.addHandles([h,l],Bt.imageClick)},this._createTriangularImageClickHandle=()=>{this.removeHandles(Bt.triangularImageClick);const e=this.imageMeasurementViewer?.imageSize;this.triangularMeasurementActive&&"none"!==this.mode&&e&&this.currentBestFeature&&this.addHandles(this.imageMeasurementViewer.imageRenderer.on("double-click",this._measurementImageClickHandler),Bt.triangularImageClick)},this._createTriangularImageLocationHandle=()=>{this.removeHandles(Bt.triangularImageClick);const{imageLocationToolState:e,mode:t,imageMeasurementViewer:a}=this,i=a?.imageSize;if(!e||"none"===t||!i)return;this.clickAction="pixel-location";let s=null;const o=b((()=>a),"pixel-location",(e=>{1===this.measurementVectors.length&&(this.plotLocationPointOnImage(e,!0),s?.abort(),s=r((async a=>{if(!e||this.triangulatedPoint||2===this.measurementVectors?.length||!this.currentBestFeatureMeasurementImage)return;let r=await this.getMapPoint(e,{feature:this.currentBestFeatureMeasurementImage,imageSize:i,mode:t});v(a);const s=this.currentBestFeatureMeasurementImage.geometry.spatialReference;s&&!r.spatialReference.equals(s)&&(r=await x(r,s),v(a)),await this._calculateTriangulatedPointFromGroundPoint(r,{signal:a}),v(a)})))}));this.addHandles(o,Bt.triangularImageClick)},this._createImageLocationHandle=()=>{this.removeHandles(Bt.imageClick);const{imageLocationToolState:e,mode:t,activeViewer:a,currentBestFeature:i,footprintExtent:s}=this,o=a?.imageSize;if(!(e&&"none"!==t&&o&&s&&i))return;this.clickAction="pixel-location";let n=null;const l=b((()=>a),"pixel-location",(e=>{const{currentBestFeatureMeasurementImage:a,triangularMeasurementActive:s,imageMeasurementViewer:l}=this;this.pixelCoordinates=e;const c=null!=a&&!l.state.includes("loading");re(!s,c)&&this.plotLocationPointOnImage(e),n?.abort(),n=r((async a=>{if(!e)return;let r=await this.getMapPoint(e,{feature:i,imageSize:o,mode:t});v(a);const n=this.view?.spatialReference;n&&!r.spatialReference.equals(n)&&(r=await x(r,n),v(a)),this.groundCoordinates=r,s&&r&&c&&await this.triangulatedLocationWorkflow(r,a);const l=await this.calculateLocationAccuracy(e,r,t,a);v(a),l&&(this.groundCoordinatesAccuracy=l)}))}));this.addHandles(l,Bt.imageClick)},this._handleImageHitTestResponse=async e=>{const{layer:t,overlayedCameraLocations:a}=this;if(!t)return;const i=e.results.find((({graphic:e,graphic:{attributes:i}})=>a.includes(e)&&i&&!i[t.imageReferenceField]&&!i[t.imageGeometryField]));if(!i)return;const r=i.graphic.attributes[t.objectIdField];await this.showImageByObjectId(r)},this._loadImage=async e=>{const{currentBestFeature:t,layer:a,mode:i}=this;if(this.clearGraphics(),!a||!t||"none"===i||"video"===i)return;const{attributes:r}=t,{imagePath:s,imageRotation:o,cameraHeading:n,cameraRoll:l,cameraPitch:c,objectId:u,cameraOrientation:m,location:d}=r,p=(l??0)+(o??0),g=d.spatialReference.isWGS84&&4!==m?.type?D(d):new T(d);let f=s;if(je(s))try{f=await Be(a,u,e)}catch(w){if(y(w))return;return Ft(w)?(h.getLogger(this).error(w),void this.setMessage("noAttachment","error",`${a.objectIdField}: ${u}`)):(h.getLogger(this).error(w,{[a.objectIdField]:u,layer:a}),void this.setMessage("imageLoadError","error",`query-attachments-failed:${a.objectIdField} ${u}`))}try{await this.loadImageFromSource(f,{imageRotation:p,options:e,pitch:c,yaw:n,mode:i,cameraLocation:g}),v(e),await this.transformAndPlotSelectedLocation(e)}catch(w){y(w)||this.loadImageError(w)}},this._loadImageFromSourceInternal=async(e,t)=>{const{mode:a,imageRotation:i,options:r}=t,s="string"==typeof e,o=s?e:e.url,{pathname:n,searchParams:l}=new URL(o);let c=s?n.match(Et)?.[1]:e.datasetFormat;if(!c)try{c=await bt(o,{...t.options})}catch(u){y(u)||h.getLogger(this).error("#getContentType()",u)}switch(c??="UNKNOWN FORMAT",a){case"default":this.triangularMeasurementActive?await this._setImageSource(this.imageMeasurementViewer,c,o,l,i,r):await this._setImageSource(this._imageViewer,c,o,l,i,r);break;case"panoramic":if(xt.has(c.toUpperCase())){const{selectedPoint:e}=this,{pitch:a,yaw:i,cameraLocation:s,viewAngle:n}=t;this._panoramicViewer.imageSource=o;let l=i??0;"number"==typeof n?l=n-l:s&&e&&(l=await se(s,e)-l),this._panoramicViewer.pitch=a??0,this._panoramicViewer.yaw=l,await this._panoramicViewer.loadImage(r)}else this.setMessage("unsupportedPanoramicImageryError","error",void 0,{datasetFormat:c});break}},this._loadMeasurementViewerImage=async e=>{const{currentBestFeatureMeasurementImage:t,layer:a,mode:i}=this;if(this.imageMeasurementViewer.clearGraphics(),!a||!t||"none"===i||"video"===i)return;const{attributes:r}=t,{imagePath:s,imageRotation:o,cameraHeading:n,cameraRoll:l,cameraPitch:c,objectId:u,cameraOrientation:m,location:d}=r,p=(l??0)+(o??0),g=d.spatialReference.isWGS84&&4!==m?.type?D(d):new T(d);let f=s;if(je(s))try{f=await Be(a,u,e)}catch(w){if(y(w))return;return Ft(w)?(h.getLogger(this).error(w),void this.setMessage("noAttachment","error",`${a.objectIdField}: ${u}`)):(h.getLogger(this).error(w,{[a.objectIdField]:u,layer:a}),void this.setMessage("imageLoadError","error",`query-attachments-failed:${a.objectIdField} ${u}`))}try{await this.loadImageFromSource(f,{imageRotation:p,options:e,pitch:c,yaw:n,mode:i,cameraLocation:g}),v(e)}catch(w){y(w)||this.loadImageError(w)}},this._loadViewAdapter=async e=>{const{view:t}=this;if(t)switch(t.type){case"2d":{const{default:t}=await import("./adapters/view/MapViewAdapter.js");v(e),this._adapter=new t(this);break}case"3d":{const{default:t}=await import("./adapters/view/SceneViewAdapter.js");v(e),this._adapter=new t(this);break}}else this._adapter=null},this._mapImageConversionToolViewClickHandler=e=>{e.stopPropagation(),e.preventDefault(),e.mapPoint&&this.plotMapPoint(e.mapPoint)},this._measurementImageClickHandler=e=>{e.stopPropagation(),e.preventDefault();const{sketchTriangular:t,triangularMeasurementActive:a,currentBestFeatureMeasurementImage:i,triangulatedMeasurementGraphic:r}=this;t&&a&&i&&r&&"active"!==t.state&&(t.update([r],{tool:"reshape"}),this.updatingTriangularMeasurementState=!0)},this._viewClickHandler=e=>{this._clickTask?.abort(),this._clickTask=r((async t=>{const{pointerType:a,button:i,mapPoint:r}=e;if(("mouse"!==a||0===i)&&r)return e.stopPropagation(),e.preventDefault(),this._updatingHandles.addPromise(this.loadBestImage(r,{signal:t}))}))},this.plotSelectedPointOnImage=async(e,a)=>{if(await f(a),!e)return;const i=new T({...C(e)?e.toJSON():e});if("default"===this.mode)i.x-=.5,i.y=.5-i.y,i.spatialReference=this._imageViewer.imageRenderer.spatialReference.clone(),this._crossSymbol=new t({geometry:i,symbol:ct}),this._imageViewer.addGraphic(this._crossSymbol,0);else if("panoramic"===this.mode){const{imageSize:a}=this._panoramicViewer;if(!a)return;const[i,r]=a,{heading:s,pitch:o}=oe(e,i,r),n=ne(s,o);this._crossSymbol=new t({geometry:new T(n,E.WebMercator),symbol:ut}),this._panoramicViewer.addGraphic(this._crossSymbol,0)}},this.handleSectorClick=this.handleSectorClick.bind(this),this.searchBestImage=this.searchBestImage.bind(this),this.transformAndPlotReferencePointOnImage=this.transformAndPlotReferencePointOnImage.bind(this)}initialize(){this.addHandles([M((()=>this.view),(()=>{this.load()}),_),M((()=>this.view?.map),((e,t)=>{t?.layers.remove(this._overlays),e?.layers.add(this._overlays)}),P),M((()=>this.view?.map?.allLayers?.length),(e=>{e&&this.view?.map?.layers.reorder(this._overlays,e-1)}),P),M((()=>[this.state,this.mapImageConversionToolState,this.view]),(()=>{this._createViewClickHandle(),this._createImageClickHandle()}),_),M((()=>[this.triangularMeasurementActive,this.currentBestFeatureMeasurementImage]),(()=>{this._createTriangularImageClickHandle()}),_),M((()=>[this.state,this.imageLocationToolState,this.view]),((e,t)=>{if(this._createImageLocationHandle(),!this.imageLocationToolState)return this.clearPreviousGroundLocation(),void this._resetCursor();e[1]!==t?.[1]&&this._setMeasurementCursor()}),_),M((()=>this.measureType),(()=>{this.clearPreviousMeasurements()}),_),M((()=>this.bestFeatureAngle),((e,t)=>{this.previousFeatureAngle=t??0}),_),M((()=>this.currentBestFeature),(async(e,t)=>{d(this._featureChangedTask),this._featureChangedTask=r((async a=>this.determineWorkflowForFeature.apply(this,[e,t,{signal:a}]))),await this._featureChangedTask.promise}),{sync:!0}),M((()=>this.currentBestFeatureMeasurementImage),(async(e,t)=>{d(this._featureChangedTask),t&&e!==t&&(this.measurementVectors=[],this.triangulatedPoint=null,this.sketchTriangularGraphicsLayer?.graphics.destroyAll()),this._featureChangedTask=r((async a=>{await this.determineWorkflowForTriangularMeasurement(e,t,{signal:a}),v(a),this._reorderTriangularSketchLayer()}))}),_),M((()=>this.triangularMeasurementActive),(async(e,t)=>{t&&!e&&(this.measurementVectors=[],this.currentBestFeatureMeasurementImage=null,this.triangulatedDistanceMeasurement=null,this.triangulatedMeasurementGraphic=null,this.triangulatedPoint=null,this.updatingTriangularMeasurementState=!1,this.triangulatedAreaMeasurement=null,this.triangulatedDistanceAccuracy=null,this.triangulatedAreaAccuracy=0,this.sketchTriangularGraphicsLayer?.graphics.destroyAll(),this.clearReferencePointOnImage(),this.imageMeasurementViewer.clearImage(),this.imageMeasurementViewer.clearGraphics())})),M((()=>this.mode),(e=>{switch(this.removeHandles(Bt.interactionHandles),e){case"default":this.addHandles(M((()=>{const{state:e}=this;return"image-loaded"===e?this._imageViewer.imagePointsInView:null}),(e=>{e&&(d(this._updateFootprintTask),this._updateFootprintTask=r((async t=>{await this.updateFootprint(e,{signal:t})})))}),{..._,equals:(e,t)=>a(e,t,u)}),Bt.interactionHandles);break;case"video":this.addHandles(M((()=>{const{footprintExtent:e}=this;if(e)return ke}),(e=>{e&&(d(this._updateFootprintTask),this._updateFootprintTask=r((async t=>{await this.updateFootprint(e,{signal:t})})))}),{..._,equals:(e,t)=>a(e,t,u)}),Bt.interactionHandles);break;case"panoramic":this.addHandles(M((()=>{const{currentBestFeature:e,state:t,_panoramicViewer:a}=this,{imageSize:i,vfov:r,hfov:s,pitch:o,yaw:n}=a;return e&&i&&!t.includes("loading")&&null!=r&&null!=s&&null!=o&&null!=n?[r,s,n,o]:null}),(e=>{if(!e||this.state.includes("loading"))return;const[t,a,i,s]=e;this.currentNode&&(this.currentNode.currentHeading=i+(this.currentNode.heading??0),this.currentNode.currentPitch=s+(this.currentNode.pitch??0)),d(this._updateFootprintTask),this._updateFootprintTask=r((async e=>{await this.updateFootprintPanorama({verticalFieldOfView:t,horizontalFieldOfView:a,yaw:i,pitch:s},{signal:e}),this._updateFootprintTask=null}))}),{equals:(e,t)=>a(e,t,u)}),Bt.interactionHandles)}}),_),M((()=>[this.brightness,this.contrast,this.sharpness]),(()=>{const{_imageViewer:e,brightness:t,contrast:a,mode:i,sharpness:r}=this;"default"===i&&(e.brightness=t,e.contrast=a,e.sharpness=r)}),_),M((()=>this.activeViewer?.imageRenderer),(()=>{this.sketch&&(this.sketch.view=this.activeViewer?.imageRenderer)})),M((()=>this.activeViewer),(e=>{this.removeHandles(Bt.hittestHandles),e&&this.addHandles(b((()=>e),"hittest-response",this._handleImageHitTestResponse),Bt.hittestHandles)}))]),this.when().finally((()=>{this.notifyChange("state")}))}destroy(){this.currentBestFeature=null,this._updateFootprintTask=d(this._updateFootprintTask),this._clickTask=d(this._clickTask),this.coverageFrustums.destroy(),this.coveragePolygons.destroy(),this.pointSources.destroy(),this.additionalFootprints.destroy(),this.additionalCameraLocations.destroy(),this.bestFeatureFootprint=p(this.bestFeatureFootprint),this.bestFeatureCurrentFootprint=p(this.bestFeatureCurrentFootprint),this.videoViewModel=p(this.videoViewModel),this._crossSymbol=p(this._crossSymbol),this._referencePointOnGround=p(this._referencePointOnGround),this._referencePointOnImage=p(this._referencePointOnImage),this._locationPointOnImage=p(this._locationPointOnImage),this._overlays&&this.view?.map?.remove(this._overlays),this._overlays.destroy(),this._imageViewer.destroy(),this.imageMeasurementViewer.destroy(),this._panoramicViewer.destroy()}get activeLayer(){return o(h.getLogger(this),"activeLayer",{replacement:"layer"}),this.layer}set activeLayer(e){o(h.getLogger(this),"activeLayer",{replacement:"layer"}),this.layer=e}get activeViewer(){const{_imageViewer:e,_panoramicViewer:t,mode:a}=this;switch(a){case"default":return e;case"panoramic":return t;default:return null}}get accuracyParametersMissing(){return this.layer?.orientationAccuracy?.every((e=>0===e))??!0}get brightness(){return this._get("brightness")??0}set brightness(e){this._set("brightness",m(e,-10,10))}get contrast(){return this._get("contrast")??0}set contrast(e){this._set("contrast",m(e,-10,10))}get currentNode(){const{currentBestFeature:e,navigationNodes:t}=this;return t.find((t=>t.id===e?.attributes.objectId))}get featureCount(){return this.features?.length??0}get imageGalleryEnabled(){const{currentBestFeature:e}=this;if(!e)return!1;const t=e.attributes.imagePath?.trim();return Mt(t)||je(t)}get imageLoaded(){return o(h.getLogger(this),"imageLoaded",{replacement:'Use OrientedImageryViewer.state === "image-loaded"',version:"4.29",warnOnce:!0}),"image-loaded"===this.state}get invalidCameraHeading(){return this.currentBestFeature?.attributes?.cameraHeading===Se}get imagePointsInView(){const{mode:e,_imageViewer:t}=this;return"default"===e?t.imagePointsInView:null}get layerView(){const{layer:e,view:t}=this;if(e&&t)return t.allLayerViews.find(_t(e))}get layerFloorFilterClause(){const{layerView:e}=this;return e?fe(e):null}get mode(){const e=this.currentBestFeature?.attributes;if(!e)return"none";if(e.orientedImageryType?.includes("video"))return"video";const{horizontalFieldOfView:t,isSpherical:a}=e;return 360===t||a?"panoramic":"default"}get popupEnabled(){return!0===this.layer?.popupEnabled}get referencePoint(){return this._referencePointOnGround?.geometry}get sectorData(){const{_sectorData:e}=this;return e?Ae.map((t=>e[t])):null}get sharpness(){return this._get("sharpness")??0}set sharpness(e){this._set("sharpness",m(e,0,1))}get sketchGraphicsLayer(){return this.sketch?.layer}get state(){const{mode:e,disabled:t,_updatingHandles:{updating:a},_featureChangedTask:i}=this;if(t)return"disabled";if(!this.isFulfilled()||a||!1===i?.finished)return"loading";if(this.isRejected())return"error";if("error"===this.displayMessage?.type)return"image-load-error";switch(e){case"default":return this._imageViewer.state;case"panoramic":return this._panoramicViewer.state;case"video":return this.videoElement?.loaded?"video-loaded":"video-not-loaded"}return"ready"}get thumbnails(){const{features:e}=this;return e?new s(e.map((({attributes:{imagePath:e,objectId:t,cameraRoll:a,imageRotation:i}})=>{const r=e?.trim();return Mt(r)||je(r)?{url:r,objectId:t,rotation:(a??0)+(i??0)}:null})).filter(i)):null}set view(e){this._set("view",e)}get _sketchGraphicsLayer(){const{mode:e}=this;switch(e){case"panoramic":return new U({elevationInfo:{mode:"absolute-height"}});case"default":return new U;default:return}}get _overlaysView(){return this.view?.layerViews.find((({layer:e})=>e===this._overlays))}beforeLoad(){this.view?.closePopup(),this.displayMessage=null,this.clearPreviousGroundLocation(),this.triangularMeasurementActive=!1,this.currentBestFeatureMeasurementImage=null,this.measureType=null,this.imageLocationToolState=!1,this.features.removeAll(),this.currentBestFeature=null,this.additionalFeatures.removeAll(),this.additionalFootprints.removeAll(),this.additionalCameraLocations.removeAll(),this.bestFeatureCurrentFootprint=p(this.bestFeatureCurrentFootprint),this._overlays?.removeAll()}async computeHeight(e,t,a=!0){const{currentBestFeature:i,activeViewer:r,layer:s,footprintExtent:o}=this,n=r?.imageSize,l=i?.attributes,c=s?.orientationAccuracy;if(!l||!n||!e||e.length<2||!c)return;const u="panoramic"===t?await this.getMeasurementPropertiesPanoramic():le(l,n[0],n[1]),h=e.at(0),m=e.at(-1);if(!(u&&h&&m&&c&&o))return;const d=[m,h],p=xe(d,!1),g="panoramic"===t?await Ee(d,u,c,i,!0,!1):await He(d,u,c,!0,a);if(!g)return;const y="panoramic"===t?await ze(c,p,u,g,i,!0):await De(c,p,u,g,!0);return y?{value:g,accuracy:y}:{value:g}}async calculateAreaMeasurement(e,t,a){if(e.length<3||!this.currentBestFeature||!this.activeViewer?.imageSize||"none"===t)return null;const i="default"===t?await this.getMeasurementProperties():await this.getMeasurementPropertiesPanoramic();return v(a),i?"default"===t?await Ue(e,i,!0):await Ne(e,i,!0,a):null}async calculateDistanceMeasurement(e,t,a){const{currentBestFeature:i,activeViewer:r}=this;if(e.length<2||!i||!r?.imageSize||"none"===t)return null;const s="default"===t?await this.getMeasurementProperties():await this.getMeasurementPropertiesPanoramic();return v(a),s?"default"===t?await We([e.at(0),e.at(-1)],s,!0):await qe([e.at(0),e.at(-1)],s,!0):null}async calculateAccuracy(e,t,a){const{layer:i,currentBestFeature:r,activeViewer:s}=this,o=i?.orientationAccuracy,n=o?.every((e=>0===e))||!o?.length;if("area"===t&&e.length<3||"distance"===t&&e.length<2||!r||!s?.imageSize||n)return null;let l=null;if(this.triangularMeasurementActive&&this.currentBestFeatureMeasurementImage&&this.imageMeasurementViewer?l=await this.getMeasurementProperties(this.currentBestFeatureMeasurementImage,this.imageMeasurementViewer):(l=await this.getMeasurementProperties(),v(a)),!l)return null;const c="area"===t?await Ue(e,l,!0):await We([e.at(0),e.at(-1)],l,!0);v(a);const{updateElevationProps:u,...h}=l,m=$e(h,o);if(!m?.length)return null;const d=m.map((e=>({...e,updateElevationProps:u}))).map((async i=>{const r="area"===t?await Ue(e,i,!0):await We([e.at(0),e.at(-1)],i,!0);if(v(a),r&&c){if("area"===t){const e="number"!=typeof r?r.area:null;return e?Math.abs(e-c.area):null}return Math.abs(r-c)}return null})),p=await Promise.all(d);v(a);const g=p.filter((e=>null!==e));return 0===g.length?null:Je(g)}async calculateLocationAccuracy(e,t,a="default",i){const{layer:r,currentBestFeature:s}=this,o=r?.orientationAccuracy,n=this.view?.spatialReference,l=o?.every((e=>0===e))||!o?.length;if(!s||l)return null;const c="default"===a?await this.getMeasurementProperties():await this.getMeasurementPropertiesPanoramic();if(v(i),!c)return null;const{updateElevationProps:u,...h}=c,m="default"===a?$e(h,o):Ze(h,o);if(!m?.length)return null;const d=m.map((e=>({...e,updateElevationProps:u}))).map((async r=>{const{updateElevationProps:s,...o}=r;let l="default"===a?await ee(e,o,s):await te(e,o,s);return v(i),n&&!l.spatialReference.equals(n)&&(l=await x(l,n),v(i)),l&&t?[Math.abs(l.x-t.x),Math.abs(l.y-t.y),l.z&&t.z?Math.abs(l.z-t.z):0]:null})),p=await Promise.all(d);if(v(i),!p?.length)return null;const g=p.map((e=>[e?.[0]??0,e?.[1]??0,e?.[2]??0])),[y,f,w]=Ke(g);return{x:y,y:f,z:w}}async calculateAccuracyPanoramic(e,t,a){const{layer:i,currentBestFeature:r,activeViewer:s,mode:o}=this,n=i?.orientationAccuracy,l=n?.every((e=>0===e))||!n?.length;if("area"===t&&e.length<3||"distance"===t&&e.length<2||!r||!s?.imageSize||l||"panoramic"!==o)return null;const c=await this.getMeasurementPropertiesPanoramic();if(v(a),!c)return null;const u="area"===t?await Ne(e,c,!0):await qe([e.at(0),e.at(-1)],c,!0);v(a);const{updateElevationProps:h,...m}=c,d=Ze(m,n);if(!d?.length)return null;const p=d.map((e=>({...e,updateElevationProps:h}))).map((async i=>{const r="area"===t?await Ne(e,i,!0):await qe([e.at(0),e.at(-1)],i,!0);if(v(a),r&&u){if("area"===t){const e="number"!=typeof r?r.area:null;return e?Math.abs(e-u.area):null}return Math.abs(r-u)}return null})),g=await Promise.all(p);v(a);const y=g.filter((e=>null!==e));return 0===y.length?null:Je(y)}async calculateHeightMeasurementInfo(e,t,a){const{currentBestFeature:i,activeViewer:r}=this,s=r?.imageSize;if(!i||!r||!s?.length||"none"===t)return;const{attributes:o}=i,[n]=xe([e],"panoramic"!==t),l="panoramic"===t?await this.getMeasurementPropertiesPanoramic():le(o,s[0],s[1]);if("panoramic"===t){if(!l)return;const e=await Qe(n,l,i,a);if(!e)return;e?.heading>180&&(e.heading-=360);const t=Xe(n,e),r=A([n.x,n.y],[e.x,e.y]);if(!t||!r)return;return{measurementAngle:t,tempDistance:r}}const c=await Ye(n,l,a);if(!c)return;const u=et(n,c),h=A([n.x,n.y],[c.x,c.y]);return u&&h?{measurementAngle:u,tempDistance:h}:void 0}async calculateTriangulatedMeasurements(e){switch(this.measureType){case"distance":{this.triangulatedDistanceMeasurement=await at(this.measurementVectors);const t=await this.calculateAccuracy(e,"distance");if(t&&this.triangulatedDistanceMeasurement?.distance){const e=Math.atan(t/this.triangulatedDistanceMeasurement.distance);this.triangulatedDistanceAccuracy={distanceAccuracy:t,angleAccuracy:e}}break}case"area":if(this.currentBestFeatureMeasurementImage?.geometry.spatialReference){const t=await tt(this.measurementVectors,this.currentBestFeatureMeasurementImage.geometry.spatialReference);this.triangulatedAreaMeasurement=t,this.triangulatedAreaAccuracy=await this.calculateAccuracy(e,"area")??this.triangulatedAreaAccuracy}}}clearPreviousMeasurements(){this.clearMeasurementGraphics(),this.resetMeasurementData(),this.stopMeasurement()}clearPreviousGroundLocation(){this.groundCoordinates=null,this.groundCoordinatesAccuracy=null,this.pixelCoordinates=null,this.clearLocationPointOnImage()}clearMeasurementGraphics(){this.measurementGraphic&&(this.activeViewer?.removeGraphic(this.measurementGraphic),this.measurementGraphic=null),this.heightGraphic&&(this.activeViewer?.removeGraphic(this.heightGraphic),this.heightGraphic=null),this.triangularMeasurementActive&&this.sketchTriangularGraphicsLayer?.graphics.destroyAll()}digitizeCancel(){return this.sketch?.cancel()}digitizeCanRedo(){return this.sketch?.canRedo()??!1}digitizeCanUndo(){return this.sketch?.canUndo()??!1}digitizeComplete(){return this.sketch?.complete()}async digitizeCreate(e,t){const{sketch:a,dataCaptureLayer:i}=this;if(!a)throw Ht();Ge(i,e,a),await a.create(e,{...t,defaultZ:0})}async digitizeDelete(){if(!this.sketch)throw Ht();return this.sketch.delete()}digitizeDuplicate(){if(!this.sketch)throw Ht();return this.sketch.duplicate()}digitizePlace(e,t){if(!this.sketch)throw Ht();return this.sketch.place(e,t)}digitizeRedo(){if(!this.sketch)throw Ht();return this.sketch.redo()}digitizeUndo(){if(!this.sketch)throw Ht();return this.sketch.undo()}digitizeUpdate(e,t){if(!this.sketch)throw Ht();return this.sketch.update(e,t)}async displayHeightResults(){const{currentBestFeature:e,activeViewer:t,heightMeasurementPixels:a,mode:i}=this,r=t?.imageSize,s=e?.attributes;if(!s||!r)return;const o=await this.computeHeight(a,i);o?.value&&o?.accuracy&&(this.heightMeasurementResult=o.value,this.heightMeasurementAccuracy=o.accuracy)}filterByFootprints(e,t,a=!1){const i=[],r=[],s=[];return e.forEach((e=>{const{layer:{coveragePercent:o},attributes:n}=e;let l;const{polygon:c,frustum:u}=J(n);if(l=c.clone(),n.isInspection&&(l=Z(n)),o&&(l=K(l,o)),a||!t||Q(l,t)){s.push(e);const{geometry:t,objectId:a,cameraHeight:o,cameraHeading:l}=n,h=t.clone();h.z=o,h.imageID=a,this.pointSources.push(h),l!==Se&&(i.push(c),u&&r.push(u))}})),{features:s,polygons:i,frustums:r}}getMeasurementProperties(e=this.currentBestFeature,t=this.activeViewer){if(!e||!t?.imageSize)return;const{elevationSample:a,attributes:i}=e,{elevationSource:r,cameraHeight:s}=i,o=le(i,t.imageSize[0],t.imageSize[1]);let n=o.cameraLocation;return(n.spatialReference.isGeographic?x(n,E.WebMercator):Promise.resolve(n)).then((e=>(n=e,ce(n.spatialReference,n.z??0,s,{elevationSample:a,elevationSource:r,extent:this.footprintExtent})))).then((t=>("elevationSample"in t&&ue(t.elevationSample)&&(e.elevationSample=t.elevationSample),{...o,cameraLocation:n,updateElevationProps:t})))}getMeasurementPropertiesPanoramic(){const{currentBestFeature:e,activeViewer:t}=this;if(!e||!t?.imageSize)return;const{elevationSample:a,attributes:i}=e,{elevationSource:r,cameraHeight:s}=i,o=he(i,t.imageSize[0],t.imageSize[1]);let n=o.cameraLocation;return(n.spatialReference.isGeographic?x(n,E.WebMercator):Promise.resolve(n)).then((e=>(n=e,ce(n.spatialReference,n.z??0,s,{elevationSample:a,elevationSource:r,extent:this.footprintExtent})))).then((t=>("elevationSample"in t&&ue(t.elevationSample)&&(e.elevationSample=t.elevationSample),{...o,cameraLocation:n,updateElevationProps:t})))}async deleteDataCaptureFeatures(e){const{dataCaptureLayer:t}=this;if(!t)throw new n("orientedimagery","Data capture layer is not available");return t.queryFeatures({objectIds:e}).then((({features:e})=>t.applyEdits({deleteFeatures:e})))}handleSectorClick(e){if(isNaN(e))return;const t=this._sectorData?.[Ae[e]],a=t?.at(0);a&&(this.triangularMeasurementActive&&this.currentBestFeature?this._updateImageMeasurementBestFeature(a):this._updateCurrentBestFeature(a))}handleFeatureClick(e){const{sector:t,featureIndexInSector:a}=e;if(isNaN(a))return;const i=this._sectorData?.[t],r=i?.at(a);r&&(this.triangularMeasurementActive&&this.currentBestFeature?this._updateImageMeasurementBestFeature(r):this._updateCurrentBestFeature(r))}handleDrawCursorUpdateEvents(e){const{measurementAngle:t,tempDistance:a,heightMeasurementPixels:i,mode:r,activeViewer:s,currentBestFeature:o}=this,n=s?.imageSize;if(!e.vertices||!n||!o)return;const l=it(e.vertices.at(-1),r,n);if(i.length<1||!l||!a||!t||"none"===r)return;const c=rt(i[0],l,t);if(!c?.length)return;this.heightMeasurementPixels.push(c),"panoramic"===r?this.createPolylineGraphicPano():this.createPolylineGraphic();const u=st(o.attributes.location.spatialReference),h=ot(this.heightMeasurementPixels,a,u);h&&(this.heightMeasurementResult=h)}async handleDrawVertexAddEvents(e,t){const{currentBestFeature:a,activeViewer:i,heightMeasurementPixels:r,mode:s}=this;if(!a||!i||!e.vertices?.length||"none"===s)return;const o=i?.imageSize;if(!r.length&&o){const a=it(e.vertices.at(-1),s,o);this.heightMeasurementPixels.push(a);const i=await this.calculateHeightMeasurementInfo(a,s,t);if(!i?.measurementAngle||!i?.tempDistance)return;this.measurementAngle=i.measurementAngle,this.tempDistance=i.tempDistance}}async load(e){return this.addResolvingPromise(this._loadViewAdapter(e).catch((e=>{if(!y(e))throw e}))),this}async loadBestImage(e,t){return this.selectedPoint=Y(e),this.beforeLoad(),this._fetchFeaturesWithController(e,t)}loadImageError(e){h.getLogger(this).error("oriented-imagery-viewer:load-image",e),this.setMessage("imageLoadError","error",e.message)}async loadSketch(e){if(!this.sketch){const t=import("../Sketch/SketchViewModel.js"),{default:a}=await t;v(e),this.sketch=new a({layer:this._sketchGraphicsLayer,view:this.activeViewer?.imageRenderer,updateOnGraphicClick:!1,defaultUpdateOptions:{reshapeOptions:{edgeOperation:"none",shapeOperation:"none",vertexOperation:void 0},enableMoveAllGraphics:!1,enableRotation:!1,enableScaling:!1,multipleSelectionEnabled:!1,toggleToolOnClick:!1,tool:"transform"}})}return this.sketch}async loadMeasurementAdapter(e){if(!this.sketchAdapter){const t=import("./adapters/sketch/MeasurementAdapter.js"),{default:a}=await t;if(v(e),this.sketchAdapter=new a({viewModel:this}),!this.sketchAdapter.viewModel.isResolved())return}return this.sketchAdapter}async loadTriangulatedMeasurementAdapter(e){if(!this.triangulatedMeasurementAdapter){const t=import("./adapters/sketch/TriangulatedMeasurementAdapter.js"),{default:a}=await t;if(v(e),this.triangulatedMeasurementAdapter=new a({viewModel:this}),!this.triangulatedMeasurementAdapter.viewModel.isResolved())return}return this.triangulatedMeasurementAdapter}async processFeatureResponse(e,t,a){const{features:i}=e;if(this._clearFeatureGeometries(),!this._checkFeatures(i))return;const{features:r,polygons:s,frustums:o}=this.filterByFootprints(i,t,a?.skipFilter);if(!this._checkFeatures(r))return;this.coveragePolygons.addMany(s),this.coverageFrustums.addMany(o);const n=await this.processElevationSample(s,r,a);v(a),await this._updateElevationOfSelectedPointAndLocations(r,t,n),v(a),Pt(r,n);const l=this._processSuitableFeatures(r,t);this.updateSuitabilities(l,a?.loadBestImage)}async startMeasurement(e,t){this.sketch||await this.loadSketch(t),await this.loadMeasurementAdapter(t);const{sketch:a,sketchAdapter:i,activeViewer:r,mode:s}=this;if(!a||!i||!r||"none"===s)return;if(this.displayNewMeasurementButton=!1,"panoramic"===s&&(a.defaultCreateOptions.defaultZ=0),await a.create(e),"panoramic"===s){const{drawOperation:e}=a.view.activeTool;e.constraintsEnabled=!1,e._set("elevationDrawSurface",null)}const o=this.activeViewer?.imageRenderer.effectiveTheme.accentColor;o&&this.sketch&&(this.sketch.polygonSymbol=ht(o),this.sketch.polylineSymbol="panoramic"===s?mt:dt(o,2.5))}startHeightMeasurement(){this.heightMeasurementPixels=[],this.displayNewMeasurementButton=!1,this.draw??=new Me({view:this.activeViewer?.imageRenderer});this.draw.create("polyline").on(["cursor-update","vertex-add","draw-complete"],(e=>this.handleDrawEvents(e)))}createPolylineGraphic(){const e=[this.heightMeasurementPixels[0],this.heightMeasurementPixels.at(-1)],a=this.activeViewer?.imageRenderer.spatialReference;if(this.heightGraphic)this.heightGraphic.geometry=new B({paths:[e],spatialReference:a});else{const i=new B({paths:[e],spatialReference:a}),r=this.activeViewer?.imageRenderer.effectiveTheme.accentColor;this.heightGraphic=new t({geometry:i,symbol:dt(r,2.5)}),this.activeViewer?.addGraphic(this.heightGraphic)}}createPolylineGraphicPano(){const e=this.activeViewer?.imageRenderer.spatialReference,a=this.activeViewer?.imageSize;if(!a)return;const i={x:this.heightMeasurementPixels[0][0],y:this.heightMeasurementPixels[0][1]},r={x:this.heightMeasurementPixels.at(-1)[0],y:this.heightMeasurementPixels.at(-1)[1]},{heading:s,pitch:o}=oe(i,a[0],a[1]),{heading:n,pitch:l}=oe(r,a[0],a[1]),c=[[...ne(s,o)],[...ne(n,l)]];if(this.heightGraphic)this.heightGraphic.geometry=new B({paths:[c],spatialReference:e});else{const a=new B({paths:[c],spatialReference:e});this.heightGraphic=new t({geometry:a,symbol:mt}),this._panoramicViewer.addGraphic(this.heightGraphic,0)}}async editOverlayedGraphics(e){this.sketchTriangularGraphicsLayer||this._initializeSketchTriangularGraphicsLayer(),this.sketchTriangularGraphicsLayer?.destroyed&&this._handleDestroyedTriangularSketchLayer(),this.sketchTriangularGraphicsLayer.add(e),this.sketchTriangular||(this._initializeSketchTriangular(),await this.loadTriangulatedMeasurementAdapter()),this.updateOverlayedGeometry(e)}updateOverlayedGeometry(e){this.sketchTriangular?.update([e],{tool:"reshape"})}async processMeasurementVectors(e){this.triangularMeasurementActive&&this.currentBestFeature&&(this.measurementVectors?.length<2&&await this.updateMeasurementVectorsArray(e),2===this.measurementVectors.length&&await this.calculateTriangulatedMeasurements(e))}async updateMeasurementVectorsArray(e){const t=this.measurementVectors.length?this.currentBestFeatureMeasurementImage:this.currentBestFeature;if(t){const a=await this.computeMeasurementVector(e,t);a&&this.measurementVectors.push(a)}}async computeMeasurementVector(e,t){const{activeViewer:a,mode:i}=this,r=a?.imageSize;if(!e||!t||!r)return;const s=e.map((e=>[e[0]-.5,-.5-e[1]])),o=this.view?.spatialReference,n=[];for(let l=0;l<s.length;l++){const e={x:s[l][0],y:s[l][1]};let a=await this.getMapPoint(e,{feature:t,imageSize:r,mode:i});o&&!a.spatialReference.equals(o)&&(a=await x(a,o)),n.push(a)}return nt(n,t)}async handleDrawEvents(e,t){if(this.draw)switch(e.type){case"cursor-update":this.handleDrawCursorUpdateEvents(e);break;case"vertex-add":this.handleDrawVertexAddEvents(e,t);break;case"draw-complete":await this.displayHeightResults()}}initializeMeasurement(e){switch(this.clearMeasurementGraphics(),this.resetMeasurementData(),e){case"distance":this.startMeasurement("polyline");break;case"area":this.startMeasurement("polygon");break;case"height":this.startHeightMeasurement()}}async overlayCameraLocations(e){const{activeViewer:a,currentBestFeature:i,overlayedCameraLocations:r,layer:s,mode:o,state:n,layerFloorFilterClause:l}=this,c=a?.imageSize;if(!c||!i||!s||"none"===o||n.includes("loading"))return;const{polygon:u}=J(i.attributes);if(a.removeManyGraphics(r.toArray()),r.removeAll(),e){const{features:e}=await s.queryFeatures({where:I(`${s.objectIdField} <> ${i.attributes.objectId}`,I(s.definitionExpression,l)),geometry:u,returnGeometry:!0,outFields:[s.objectIdField]}),n=await Promise.all(e.map((async e=>{const{attributes:a,geometry:r}=e,s=await this.getPixels(r,{feature:i,imageSize:c,mode:o}),n=pt.clone();return n.outline=new Fe({color:[0,0,0],width:1}),new t({attributes:a,symbol:n,geometry:s})})));r.addMany(n),a.addManyGraphics(r.toArray())}}overlayGraphicsOnImage(e,t){this.removeOverlayedGraphicsOnImage(e),this.overlayedMapFeatures.set(e,t),this.activeViewer?.addManyGraphics(t.toArray())}async overlayMapFeatures(e,a=!1){const{activeViewer:r,currentBestFeature:o,mode:n,state:l,layer:c}=this,u=r?.imageSize;if(!u||!o||"none"===n||"video"===n||l.includes("loading")||!c)return;const{polygon:m}=J(o.attributes);try{const{imageGeometryField:t,oiObjectIdField:a}=Re(e,c.imageGeometryField,c.imageReferenceField);this.imageGeometryField=t.name,this.oiObjectIdField=a.name}catch(g){h.getLogger(this).warn("oriented-imagery-viewer:overlay-map-features",g)}const{features:d}=await e.queryFeatures({geometry:m,returnGeometry:!0,outFields:["*"]}),p=new s((await Promise.all(d.map((async i=>{const r=i.symbol?.clone()??e.renderer?.getSymbol(i)?.clone(),{attributes:s,geometry:l}=i,c=l,{imageGeometryField:m,oiObjectIdField:d}=this;if(m&&d&&Oe(e,m,d)&&`${s[d]}`==`${o.attributes.objectId}`)try{return Te(s,m,e,a,u,n,r)}catch(g){h.getLogger(this).warn("oriented-imagery-viewer:overlay-map-features","couldn't create graphic from attributes, geometry will be used",{error:g,feature:i,layer:e,imageGeometryField:this.imageGeometryField,imageReferenceField:this.oiObjectIdField})}switch(c?.type){case"point":{const i=await this.getPixels(c,{feature:o,imageSize:u,mode:n});return new t({attributes:s,layer:e,symbol:r,geometry:i,visible:e.visible&&a})}case"polygon":{const{rings:i,spatialReference:l}=c,h=i.map((e=>e.map((([e,t,a])=>new T({x:e,y:t,z:a,spatialReference:l}))))),m=await Promise.all(h.map((async e=>this.getPixels(e,{feature:o,imageSize:u,mode:n}).then((e=>e.map(me))))));return new t({attributes:s,layer:e,symbol:r,geometry:new j({rings:m,spatialReference:E.WebMercator}),visible:e.visible&&a})}case"polyline":{const{paths:i,spatialReference:l}=c,h=i.map((e=>e.map((([e,t,a])=>new T({x:e,y:t,z:a,spatialReference:l}))))),m=await Promise.all(h.map((async e=>this.getPixels(e,{feature:o,imageSize:u,mode:n}).then((e=>e.map(me))))));return new t({attributes:s,layer:e,symbol:r,geometry:new B({paths:m,spatialReference:E.WebMercator}),visible:e.visible&&a})}case"multipoint":{const{points:i,spatialReference:l}=c,h=i.map((([e,t,a])=>new T({x:e,y:t,z:a,spatialReference:l}))),m=await this.getPixels(h,{feature:o,imageSize:u,mode:n}).then((e=>e.map(me)));return new t({attributes:s,layer:e,symbol:r,geometry:new O({points:m,spatialReference:E.WebMercator}),visible:e.visible&&a})}}return null})))).filter(i));this.overlayGraphicsOnImage(`${e.id}`,p)}async getPixels(e,t){const{imageSize:a,mode:i,feature:r}=t,s=(await this.worldToImage(Array.isArray(e)?e:[e],r)).map((e=>{if("default"===i)return new T({x:e.x-.5,y:.5-e.y,spatialReference:E.WebMercator});const[t,r]=a,{heading:s,pitch:o}=oe(e,t,r),n=ne(s,o);return new T(n,E.WebMercator)}));return Array.isArray(e)?s:s[0]}async getMapPoint(e,t){const{feature:a,mode:i,imageSize:r}=t,{elevationSample:s,attributes:o}=a,{elevationSource:n,location:l,cameraHeight:c}=o;let u=l.clone();u.spatialReference.isGeographic&&(u=aw