@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.85 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as i}from"tslib";import t from"../../../Graphic.js";import{isSome as e}from"../../../core/arrayUtils.js";import s from"../../../core/Collection.js";import{makeHandle as r}from"../../../core/handleUtils.js";import has from"../../../core/has.js";import{QueueProcessor as h}from"../../../core/QueueProcessor.js";import{watch as a,sync as o}from"../../../core/reactiveUtils.js";import{property as n,subclass as l}from"../../../core/accessorSupport/decorators.js";import{convertGeometryToMask as g}from"../../../layers/raster/functions/clipUtils.js";import{GraphicsCollection as p}from"../../../support/GraphicsCollection.js";import d from"../engine/flow/FlowView2D.js";import{LayerView2D as c}from"./LayerView2D.js";import u from"./graphics/GraphicsView2D.js";import m from"./graphics/HighlightGraphicContainer.js";import w from"./imagery/ImageryView2D.js";import y from"./imagery/VectorFieldView2D.js";import f from"../../layers/ImageryLayerView.js";import{RefreshableLayerView as v}from"../../layers/RefreshableLayerView.js";import{isPixelHighlightTarget as b,isEmptyPixelRanges as _}from"../../layers/support/highlightUtils.js";import{defaultColor as x}from"../../support/HighlightDefaults.js";import{getHighlightName as H}from"../../support/highlightOptionsUtils.js";let V=class extends(v(c(f))){constructor(){super(...arguments),this._exportImageVersion=-1,this._highlightGraphics=new p,this._highlightView=void 0,this._pixelHighlights=[],this.layer=null,this.subview=null}get pixelData(){const{subview:i}=this;return this.updating||!i?null:"getPixelData"in i?i.getPixelData():null}update(i){this.subview?.update(i)}attach(){this.layer.increaseRasterJobHandlerUsage(),this._setSubView(),this.view&&(this._highlightView=new u({view:this.view,graphics:this._highlightGraphics,requestUpdateCallback:()=>this.requestUpdate(),container:new m(this.view.featuresTilingScheme)}),this.container.addChild(this._highlightView.container)),this.addAttachHandles([a(()=>this.layer.exportImageServiceParameters.version,i=>{i&&this._exportImageVersion!==i&&(this._exportImageVersion=i,this.requestUpdate())},o),a(()=>this.timeExtent,i=>{const{subview:t}=this;t&&(t.timeExtent=i,"redraw"in t?this.requestUpdate():t.redrawOrRefetch())},o),this.layer.on("redraw",()=>{const{subview:i}=this;i&&("redraw"in i?i.redraw():i.redrawOrRefetch())}),a(()=>this.layer.renderer,()=>this._setSubView()),a(()=>this.view.highlights.items.map(({name:i,color:t})=>({name:i,color:t})),()=>this._updateHighlightOptions(this.subview))])}detach(){this.layer.decreaseRasterJobHandlerUsage(),this.container.removeAllChildren(),this._detachSubview(this.subview),this.subview?.destroy(),this.subview=null,this._highlightView?.destroy(),this._exportImageVersion=-1}viewChange(){}moveEnd(){this.requestUpdate()}highlight(i,h){if(b(i))return _(i)?r():this._highlightPixels(i,h);if("number"==typeof i||"string"==typeof i)return this._highlightByImageIds([i],h);const a=Array.isArray(i)||s.isCollection(i)?i.at(0):i;if("number"==typeof a||"string"==typeof a)return this._highlightByImageIds(i,h);if(!(a instanceof t))return r();let o=[];Array.isArray(i)||s.isCollection(i)?o=i.map(i=>i.clone()):i instanceof t&&(o=[i.clone()]);const n=o?.filter(e);if(!n?.length)return r();const l=H(h);return this._addHighlightGraphics(o,l),r(()=>!this.destroyed&&this._removeHighlightGraphics(o,l))}_highlightByImageIds(i,t){const e=H(t),s=new AbortController,{signal:a}=s,o=this.layer.sourceJSON.maxRecordCount??1e3,n=Math.ceil(i.length/o),l=[],g=[],p=new h({concurrency:4,process:i=>this.layer.queryFeatures({objectIds:i.ids,returnGeometry:!0,outSpatialReference:this.view.spatialReference},{signal:a}).then(i=>g.push(...i.features)).catch(()=>{})});for(let r=0;r<n;r++)l.push(p.push({ids:i.slice(r*o,(r+1)*o)}));return Promise.allSettled(l).then(()=>{g.length&&!a.aborted&&(this._addHighlightGraphics(g,e),a.addEventListener("abort",()=>{this._removeHighlightGraphics(g,e)}))}),r(()=>s.abort())}_highlightPixels(i,t){const e={target:i,options:t};return this._pixelHighlights.push(e),this._updateHighlightOptions(this.subview),r(()=>{const i=this._pixelHighlights.indexOf(e);i>-1&&(this._pixelHighlights.splice(i,1),this._updateHighlightOptions(this.subview))})}_addHighlightGraphics(i,t){this._highlightGraphics.addMany(i),this._addHighlights(i.map(i=>i.uid),t)}_removeHighlightGraphics(i,t){this._highlightGraphics.removeMany(i),this._removeHighlights(i.map(i=>i.uid),t)}async doRefresh(){this.requestUpdate()}isUpdating(){const i=!this.subview||this.subview.updating||!!this._highlightView?.updating;return has("esri-2d-log-updating")&&console.log(`Updating ImageryLayerView2D (${this.layer.id}): ${i}\n-> subview ${!this.subview||this.subview.updating}\n-> higlightView ${this._highlightView?.updating}\n`),i}_processHighlight(){const i=this._getHighlights();this._highlightView?.setHighlight(i)}_setSubView(){if(!this.view)return;const i=this.layer.renderer?.type;let t="imagery";if("vector-field"===i?t="imageryVF":"flow"===i&&(t="flow"),this.subview){const{type:i}=this.subview;if(i===t)return this._attachSubview(this.subview),void("flow"===i?this.subview.redrawOrRefetch():"imagery"===i&&"lerc"===this.layer.format?this.subview.redraw():this.requestUpdate());this._detachSubview(this.subview),this.subview?.destroy()}"imagery"===t?(this.subview=new w({layer:this.layer,view:this.view,timeExtent:this.timeExtent}),this._updateHighlightOptions(this.subview)):this.subview="imageryVF"===t?new y({layer:this.layer,view:this.view,timeExtent:this.timeExtent}):new d({layer:this.layer,layerView:this}),this._attachSubview(this.subview),this.requestUpdate()}_attachSubview(i){i&&!i.attached&&(i.attach(),i.attached=!0,this.container.addChildAt(i.container,0))}_detachSubview(i){i?.attached&&(this.container.removeChild(i.container),i.detach(),i.attached=!1)}_updateHighlightOptions(i){const t=this.view.highlights;this._pixelHighlights.sort((i,e)=>t.findIndex(({name:i})=>i===H(e.options))-t.findIndex(({name:t})=>t===H(i.options)));const s=this._pixelHighlights.map(({target:i,options:e})=>I(i,t,e)).filter(e);"imagery"===i?.type&&(i.pixelHighlights=s,i.attached&&("lerc"===this.layer.format?i.redraw():this.requestUpdate()))}};function I(i,t,e){const s=H(e),r=(t.find(i=>i.name===s)?.color??x).toArray(),{pixelRanges:h}=i;if(Array.isArray(h))return{ranges:h,bandId:i.bandId??0,color:r};const a="extent"===h.type?h:h.extent;if(!a)return;const o=[a.xmin,a.xmax],n=[a.ymin,a.ymax],{xBandId:l,yBandId:p}=i,d=1024,c=1024;return{xBandId:l,yBandId:p,xBandRange:o,yBandRange:n,color:r,width:d,height:c,xyMask:"polygon"===h.type?g({srcExtent:a,geometry:h,size:[d,c]}):void 0}}i([n()],V.prototype,"pixelData",null),i([n()],V.prototype,"subview",void 0),V=i([l("esri.views.2d.layers.ImageryLayerView2D")],V);const j=V;export{j as default};