@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 10.8 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../PopupTemplate.js";import{ClonableMixin as t}from"../core/Clonable.js";import s from"../core/Error.js";import i from"../core/Logger.js";import{MultiOriginJSONSupportMixin as o}from"../core/MultiOriginJSONSupport.js";import{debounce as a,throwIfAbortError as n}from"../core/promiseUtils.js";import{watch as p}from"../core/reactiveUtils.js";import{property as l,subclass as c}from"../core/accessorSupport/decorators.js";import{ensureClass as m}from"../core/accessorSupport/ensureType.js";import u from"../graphic/ImageryTileGraphicOrigin.js";import h from"./Layer.js";import{ArcGISService as d}from"./mixins/ArcGISService.js";import{BlendLayer as y}from"./mixins/BlendLayer.js";import{CustomParametersMixin as f}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as g}from"./mixins/OperationalLayer.js";import{PortalLayer as v}from"./mixins/PortalLayer.js";import{RasterJobHandlerMixin as R}from"./mixins/RasterJobHandlerMixin.js";import{RasterPresetRendererMixin as w}from"./mixins/RasterPresetRendererMixin.js";import{RefreshableLayer as S}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as I}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as j}from"./mixins/TemporalLayer.js";import{TiledImagery as O}from"./mixins/TiledImagery.js";import{isFunctionRaster as F,getPrimaryRasters as _}from"./raster/datasets/datasetUtils.js";import b from"./raster/datasets/FunctionRaster.js";import P from"./raster/datasets/RasterFactory.js";import{getPrimaryRasterUrls as N,create as T}from"./raster/functions/rasterFunctionHelper.js";import{legendEnabled as x,screenSizePerspectiveEnabled as J}from"./support/commonProperties.js";import L from"./support/Field.js";import{getServicePixelValueField as C,getRawServicePixelValueField as E,getRasterAttributeTableFields as M,getMagnitudeField as U,getDirectionField as W,getMultidimensionalFields as z,commonRasterFieldNames as B,setDefaultRasterFieldFormats as D}from"./support/rasterFieldUtils.js";import A from"./support/RasterFunction.js";import k from"./support/TileInfo.js";import{logInvalidElevationInfoWarning as G,elevationModeUnsupportedMessage as V,featureExpressionUnsupportedMessage as H}from"../support/elevationInfoUtils.js";import{createPopupTemplate as $}from"../support/popupUtils.js";import Y from"../symbols/support/ElevationInfo.js";import{addLayerUnsupportedError as q}from"../webdoc/support/unsupportedErrors.js";let K=class extends(y(I(g(v(w(f(O(R(j(d(S(o(t(h)))))))))))))){constructor(...e){super(...e),this._primaryRasters=[],this.graphicOrigin=new u(this),this.legendEnabled=!0,this.isReference=null,this.listMode="show",this.sourceJSON=null,this.version=null,this.type="imagery-tile",this.operationalLayerType="ArcGISTiledImageServiceLayer",this.popupEnabled=!0,this.popupTemplate=null,this.screenSizePerspectiveEnabled=!0,this.fields=null,this.source=void 0,this._debouncedSaveOperations=a(async(e,r,t)=>{const{save:s,saveAs:i}=await import("./save/imageryUtils.js");switch(e){case 0:return s(this,r);case 1:return i(this,t,r)}})}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}load(e){const r=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Image Service"]},e).catch(n).then(()=>this._openRaster(r))),Promise.resolve(this)}set elevationInfo(e){"relative-to-scene"!==e?.mode&&this._set("elevationInfo",e),this._validateElevationInfo(e)}get defaultPopupTemplate(){return this.createPopupTemplate()}get rasterFields(){const e=[C("Pixel Value"),E("Raw Pixel Value")],r=this.raster?.rasterInfo??this.serviceRasterInfo,t=r?.attributeTable;if(t){const r=M(t);e.push(...r)}const s=r?.dataType,i=r?.multidimensionalInfo;if(("vector-magdir"===s||"vector-uv"===s)&&null!=i){const r=i.variables[0].unit?.trim(),t=U(r),s=W();e.push(t,s)}if(i){const r=z(i);e.push(...r)}return e}get renderer(){return super.renderer}set renderer(e){super.renderer=e}createPopupTemplate(e){const{rasterFields:r}=this,t=e?.visibleFieldNames??new Set(r.map(({name:e})=>e).filter(e=>e!==B.rawServicePixelValue)),s=$({fields:r,title:this.title},{...e,visibleFieldNames:t}),{rasterInfo:i}=this.raster;return s?.fieldInfos&&i&&D(s.fieldInfos,i),s}async generateRasterInfo(e,r){const t=m(A,e);if(await this.load(),!t||"none"===t.functionName?.toLowerCase())return this.serviceRasterInfo;try{const{rasterInfo:e}=await this._openFunctionRaster(t,r);return e}catch(i){if(i instanceof s)throw i;throw new s("imagery-tile-layer","the given raster function is not supported")}}async save(e){return this._debouncedSaveOperations(0,e)}async saveAs(e,r){return this._debouncedSaveOperations(1,r,e)}supportsWrite(){const e=this._primaryRasters[0]??this.raster;return!!(this.loaded?"RasterTileServer"===e.datasetFormat&&("Raster"===e.tileType||"Map"===e.tileType):this.url&&/\/ImageServer(\/|\/?$)/i.test(this.url))}write(e,r){return this.supportsWrite()?super.write(e,r):(q(r,this),null)}async hasDataChanged(){try{const e=this._primaryRasters[0]??this.raster,{dataChanged:r,updates:t}=await e.refresh();return r&&(this.serviceRasterInfo!==e.rasterInfo&&this._set("serviceRasterInfo",e.rasterInfo),e.sourceJSON&&this.sourceJSON!==e.sourceJSON&&(this.sourceJSON=e.sourceJSON),t&&this.read(t,{origin:"service",url:this.parsedUrl,ignoreDefaults:!0})),r}catch{return!1}}async _openRaster(e){let r=!1;if(this.raster)await this._openFromRaster(this.raster,e),r=F(this.raster),!r&&this.rasterFunction&&(this._primaryRasters=[this.raster],await this._initializeWithFunctionRaster(this.rasterFunction));else{const{url:r,rasterFunction:t,source:i}=this;if(!r&&!i)throw new s("imagery-tile-layer:open","missing url or source parameter");i?await this._openFromSource(i,e):t?await this._openFromUrlWithRasterFunction(r,t,e):await this._openFromUrl(r,e)}const t=this.raster.rasterInfo;if(!t)throw new s("imagery-tile-layer:load","cannot load resources on "+this.url);if(this._set("serviceRasterInfo",r?t:this._primaryRasters[0].rasterInfo),this._set("spatialReference",t.spatialReference),this.sourceJSON=this.sourceJSON||this.raster.sourceJSON,null!=this.sourceJSON){const e="Map"===this.raster.tileType&&null!=this.sourceJSON.minLOD&&null!=this.sourceJSON.maxLOD?this.sourceJSON:{...this.sourceJSON,minScale:0,maxScale:0};this.read(e,{origin:"service"})}else this.read({tileInfo:this.serviceRasterInfo?.storageInfo.tileInfo.toJSON()},{origin:"service"});this.title||(this.title=this.raster.datasetName),"Map"===this.raster.tileType&&(this.popupEnabled=!1),this._configDefaultSettings(),this.addHandles(p(()=>this.customParameters,e=>{this.raster&&(this.raster.ioConfig.customFetchParameters=e)}))}async _openFromRaster(e,r){e.rasterInfo||await e.open({signal:r}),this._primaryRasters=_(e),this.url||(this.url=this._primaryRasters[0].url)}async _openFromUrlWithRasterFunction(e,r,t){const i=[e];r&&N(r.toJSON(),i);const o=await Promise.all(i.map(e=>P.open({url:e,sourceJSON:this.sourceJSON,ioConfig:{sampling:"closest",...this.ioConfig,customFetchParameters:this.customParameters},signal:t}))),a=o.findIndex(e=>null==e);if(a>-1)throw new s("imagery-tile-layer:open",`cannot open raster: ${i[a]}`);return this._primaryRasters=o,this._initializeWithFunctionRaster(r)}async _openFromUrl(e,r){const t=await P.open({url:e,sourceJSON:this.sourceJSON,ioConfig:{sampling:"closest",...this.ioConfig,customFetchParameters:this.customParameters},signal:r});if(null==t)throw new s("imagery-tile-layer:open",`cannot open raster: ${e}`);this._primaryRasters=[t],this.raster=t}async _openFromSource(e,r){const t="the tiled imagery data source is not supported",i="coverage"===e.type?.toLowerCase()?"CovJSON":e.extent&&e.pixelBlock?"MEMORY":null;if(!i)throw new s("imagery-tile-layer:open",t);"MEMORY"===i&&(e={...e,pixelBlock:void 0,pixelBlocks:[e.pixelBlock]});const o=await P.open({url:"",source:e,datasetFormat:i,ioConfig:{sampling:"closest",...this.ioConfig,customFetchParameters:this.customParameters},signal:r});if(null==o)throw new s("imagery-tile-layer:open",t);this._primaryRasters=[o],this.rasterFunction?await this._initializeWithFunctionRaster(this.rasterFunction):this.raster=o}async _openFunctionRaster(e,r){const t={raster:this._primaryRasters[0]};this._primaryRasters.length>1&&this._primaryRasters.forEach(e=>t[e.url]=e);const s=T(e.functionDefinition?.toJSON()??e.toJSON(),t),i=new b({rasterFunction:s});return await i.open(r),i}async _initializeWithFunctionRaster(e,r){try{this.raster=await this._openFunctionRaster(e,r)}catch(t){t instanceof s&&i.getLogger(this).error("imagery-tile-layer:open",t.message),i.getLogger(this).warn("imagery-tile-layer:open","the raster function cannot be applied and is removed"),this._set("rasterFunction",null),this.raster=this._primaryRasters[0]}}_validateElevationInfo(e){G(i.getLogger(this),V("ImageryTile layers","relative-to-scene",e)),G(i.getLogger(this),H("ImageryTile layers",e))}};e([l({clonable:!1})],K.prototype,"_primaryRasters",void 0),e([l({type:Y,value:null,json:{name:"layerDefinition.elevationInfo",write:!0,origins:{"portal-item":{read:!1,write:!1},"web-map":{read:!1,write:!1}}}})],K.prototype,"elevationInfo",null),e([l({type:k})],K.prototype,"tileInfo",void 0),e([l({readOnly:!0,clonable:!1})],K.prototype,"graphicOrigin",void 0),e([l(x)],K.prototype,"legendEnabled",void 0),e([l({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],K.prototype,"isReference",void 0),e([l({type:["show","hide"]})],K.prototype,"listMode",void 0),e([l({json:{read:!0,write:!0}})],K.prototype,"blendMode",void 0),e([l({type:A,json:{name:"renderingRule",write:!0}})],K.prototype,"rasterFunction",void 0),e([l()],K.prototype,"sourceJSON",void 0),e([l({readOnly:!0,json:{origins:{service:{read:{source:"currentVersion"}}}}})],K.prototype,"version",void 0),e([l({readOnly:!0,json:{read:!1}})],K.prototype,"type",void 0),e([l({type:["ArcGISTiledImageServiceLayer"]})],K.prototype,"operationalLayerType",void 0),e([l({type:Boolean,value:!0,json:{read:{source:"disablePopup",reader:(e,r)=>!r.disablePopup},write:{target:"disablePopup",overridePolicy(){return{enabled:!this.loaded||"Raster"===this.raster.tileType}},writer(e,r,t){r[t]=!e}}}})],K.prototype,"popupEnabled",void 0),e([l({type:r,json:{read:{source:"popupInfo"},write:{target:"popupInfo",overridePolicy(){return{enabled:!this.loaded||"Raster"===this.raster.tileType}}}}})],K.prototype,"popupTemplate",void 0),e([l({readOnly:!0})],K.prototype,"defaultPopupTemplate",null),e([l(J)],K.prototype,"screenSizePerspectiveEnabled",void 0),e([l({readOnly:!0,type:[L]})],K.prototype,"fields",void 0),e([l({readOnly:!0,type:[L]})],K.prototype,"rasterFields",null),e([l({constructOnly:!0})],K.prototype,"source",void 0),K=e([c("esri.layers.ImageryTileLayer")],K);const Q=K;export{Q as default};