UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.65 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 i from"../../../core/Logger.js";import{throwIfAborted as o,isAbortError as s}from"../../../core/promiseUtils.js";import{watch as r,syncAndInitial as d}from"../../../core/reactiveUtils.js";import{property as n,subclass as a}from"../../../core/accessorSupport/decorators.js";import{fixedImageSize as h}from"../constants.js";let l=class extends t{constructor(e){super(e),this.closestFeature=null,this.currentTime=0,this.videoBrightness=1,this.videoContrast=1,this.videoDuration=void 0,this.videoPaused=null,this.videoScale=void 0,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=>{i.getLogger(this).error("error playing video",e)}):e.pause())},this.rewindVideoHandler=()=>{const e=this.oiViewModel.videoElement?.content;e&&(e.currentTime=0,e.play().catch(e=>{i.getLogger(this).error("error playing video",e)}))},this.resetVideoHandler=()=>{const{videoElement:e,videoMapView:t,videoLayer:i}=this.oiViewModel;e?.content&&i&&t&&(e.content.pause(),t.map.layers.remove(i),i.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.resetVideoScale=()=>{this.videoScale&&(this.oiViewModel.videoMapView.scale=this.videoScale)},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([r(()=>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))}},d),r(()=>this.oiViewModel.layer,(e,t)=>{t&&e&&e.uid!==t.uid&&this.oiViewModel.resetVideo()},d)])}destroy(){this.resetVideoHandler()}_pauseVideoHandler(e){this._updateVideoIcon(e.paused)}_setVideoInfo(){const{videoElement:e,videoMapView:t}=this.oiViewModel;e?.content&&(this.videoDuration=e.content.duration,this.videoScale=t.scale)}_startVideo(){try{this.enableAudio(),this._setVideoInfo();const e=this.oiViewModel.currentBestFeature;e&&this.playVideoFromSelectedLocation(e)}catch(e){i.getLogger(this).error("oriented-imagery-viewer:video-load",e)}}async _updateVideoFootprintWithGivenFeature(e,t,r){const{activeViewer:d,mode:n,footprintExtent:a}=this.oiViewModel;if(t&&("video"===n?h:d?.imageSize)&&a)try{const i={points:e,feature:t,undefined:void 0,options:r};await this.oiViewModel.updateVideoFootprint(i),o(r)}catch(l){s(l)||i.getLogger(this).error("update-footprint",l)}else this.oiViewModel.updateCurrentCoveragePolygon(null)}async _updateVidFootprint(e){const t=this.oiViewModel.featureCache.find(t=>t.attributes.offsetFromStart===Math.floor(e));t?.attributes.offsetFromStart&&this.closestFeature!==t&&(this.closestFeature=t,await this._updateVideoFootprintWithGivenFeature(this.oiViewModel.videoExtentPoints,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){this.resetVideoScale();const e=this.oiViewModel.videoElement?.content;e&&(e.currentTime=t,e.play().catch(e=>{i.getLogger(this).error("error playing video",e)}))}}};e([n()],l.prototype,"closestFeature",void 0),e([n()],l.prototype,"currentTime",void 0),e([n()],l.prototype,"oiViewModel",void 0),e([n({type:Number})],l.prototype,"videoBrightness",void 0),e([n({type:Number})],l.prototype,"videoContrast",void 0),e([n()],l.prototype,"videoDuration",void 0),e([n()],l.prototype,"videoPaused",void 0),e([n()],l.prototype,"videoScale",void 0),e([n()],l.prototype,"videoMuted",void 0),l=e([a("esri.widgets.OrientedImageryViewer.components.OrientedImageryVideoViewModel")],l);const c=l;export{c as default};