@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.07 kB
JavaScript
/*
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 o from"../../../core/Accessor.js";import{isSome as i}from"../../../core/arrayUtils.js";import r from"../../../core/Logger.js";import{throwIfAborted as s,isAbortError as d}from"../../../core/promiseUtils.js";import{watch as n,syncAndInitial as a}from"../../../core/reactiveUtils.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import h from"../../../geometry/Polygon.js";import{fixedImageSize as p,videoExtent as u}from"../constants.js";import{activePolygonSymbol as m}from"../symbols.js";let v=class extends o{constructor(e){super(e),this.closestFeature=null,this.currentTime=0,this.videoBrightness=1,this.videoContrast=1,this.videoDuration=void 0,this.videoPaused=null,this.videoMuted=null,this.enableAudio=()=>{const{videoElement:e}=this.oiViewModel;e?.content&&(e.content.muted=!1,this.videoMuted=!1)},this.playVideoHandler=()=>{const e=this.oiViewModel.videoElement?.content;e&&(e.paused?e.play().catch((e=>{console.error("Error playing video:",e)})):e.pause())},this.rewindVideoHandler=()=>{const e=this.oiViewModel.videoElement?.content;e&&(e.currentTime=0,e.play().catch((e=>{console.error("Error playing video:",e)})))},this.resetVideoHandler=()=>{const{videoElement:e,videoMapView:t,videoLayer:o}=this.oiViewModel;e?.content&&o&&t&&(e.content.pause(),t.map.layers.remove(o),o.destroy(),this.oiViewModel.videoElement=null)},this.resetVideoEnhancementTools=()=>{this.oiViewModel?.videoLayer&&(this.videoBrightness=1,this.videoContrast=1,this.oiViewModel.videoLayer.effect=`brightness(${this.videoBrightness}) contrast(${this.videoContrast})`)},this.toggleAudio=()=>{const{videoElement:e}=this.oiViewModel;if(e?.content){const t=e.content.muted;e.content.muted=!t,this.videoMuted=!t}}}initialize(){this.addHandles([n((()=>this.oiViewModel.videoElement?.content),(e=>{if(e instanceof HTMLVideoElement){this._startVideo();const t=async()=>{this.currentTime=Number(e.currentTime.toFixed(2)),e.currentTime&&await this._updateVidFootprint(e.currentTime)};e.addEventListener("timeupdate",t),e.addEventListener("play",(()=>this._updateVideoIcon(e.paused))),e.addEventListener("pause",(()=>this._pauseVideoHandler(e)))}}),a),n((()=>this.oiViewModel.layer),((e,t)=>{t&&e&&e.uid!==t.uid&&this.oiViewModel.resetVideo()}),a)])}destroy(){this.resetVideoHandler()}_pauseVideoHandler(e){this._updateVideoIcon(e.paused)}_setVideoDuration(){const{videoElement:e}=this.oiViewModel;e?.content&&(this.videoDuration=e.content.duration)}_startVideo(){try{this.enableAudio(),this._setVideoDuration();const e=this.oiViewModel.currentBestFeature;e&&this.playVideoFromSelectedLocation(e)}catch(e){r.getLogger(this).error("oriented-imagery-viewer:video-load",e)}}async _updateVideoFootprintWithGivenFeature(e,o,n){const{activeViewer:a,mode:c,currentCoverageVisible:l,footprintExtent:u}=this.oiViewModel,v="video"===c?p:a?.imageSize;if(o&&v&&u)try{const r=await this.oiViewModel.getMapPoint(e,{feature:o,mode:"default",imageSize:v});s(n);const d=r.filter(i);if(!d.length)return;const a=[d.map((({x:e,y:t})=>[e,t,1]))];a[0].push(a[0][0]);const c=new h({rings:a,spatialReference:d[0].spatialReference});this.oiViewModel.updateCurrentCoveragePolygon(new t({geometry:c,attributes:{imageID:o.attributes.objectId},symbol:m,visible:l}))}catch(V){d(V)||r.getLogger(this).error("update-footprint",V)}else this.oiViewModel.updateCurrentCoveragePolygon(null)}async _updateVidFootprint(e){const t=this.oiViewModel.allLayerFeatures.find((t=>t.attributes.offsetFromStart===Math.floor(e)));t?.attributes.offsetFromStart&&(this.closestFeature=t,await this._updateVideoFootprintWithGivenFeature(u,t))}_updateVideoIcon(e){this.videoPaused=!!e}handleVideoBrightnessChange(e){this.oiViewModel?.videoLayer&&(this.videoBrightness=e??0,this.oiViewModel.videoLayer.effect=`brightness(${this.videoBrightness}) contrast(${this.videoContrast})`)}handleVideoContrastChange(e){this.oiViewModel?.videoLayer&&(this.videoContrast=e??0,this.oiViewModel.videoLayer.effect=`brightness(${this.videoBrightness}) contrast(${this.videoContrast})`)}playVideoFromSelectedLocation(e){const t=e.attributes.offsetFromStart;if(t){const e=this.oiViewModel.videoElement?.content;e&&(e.currentTime=t,e.play().catch((e=>{console.error("Error playing video:",e)})))}}};e([c()],v.prototype,"closestFeature",void 0),e([c()],v.prototype,"currentTime",void 0),e([c()],v.prototype,"oiViewModel",void 0),e([c({type:Number})],v.prototype,"videoBrightness",void 0),e([c({type:Number})],v.prototype,"videoContrast",void 0),e([c()],v.prototype,"videoDuration",void 0),e([c()],v.prototype,"videoPaused",void 0),e([c()],v.prototype,"videoMuted",void 0),v=e([l("esri.widgets.OrientedImageryViewer.components.OrientedImageryVideoViewModel")],v);const V=v;export{V as default};