@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 8.63 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 r from"../request.js";import t from"../core/Error.js";import{loadAll as s}from"../core/loadAll.js";import{MultiOriginJSONMixin as i}from"../core/MultiOriginJSONSupport.js";import{debounce as o,throwIfAbortError as a,isAbortError as n}from"../core/promiseUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{Integer as m}from"../core/accessorSupport/ensureType.js";import"../core/has.js";import"../core/RandomLCG.js";import{reader as l}from"../core/accessorSupport/decorators/reader.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import{writer as u}from"../core/accessorSupport/decorators/writer.js";import{nameToId as y,OriginId as h}from"../core/accessorSupport/PropertyOrigin.js";import d from"../geometry/Extent.js";import{getScale as f}from"../geometry/support/scaleUtils.js";import{srToRESTValue as g}from"../geometry/support/spatialReferenceUtils.js";import v from"./Layer.js";import{APIKeyMixin as b}from"./mixins/APIKeyMixin.js";import{ArcGISMapService as S}from"./mixins/ArcGISMapService.js";import{ArcGISService as j}from"./mixins/ArcGISService.js";import{BlendLayer as x}from"./mixins/BlendLayer.js";import{CustomParametersMixin as I}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as w}from"./mixins/OperationalLayer.js";import{PortalLayer as O}from"./mixins/PortalLayer.js";import{RefreshableLayer as E}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as L}from"./mixins/ScaleRangeLayer.js";import{SublayersOwner as P}from"./mixins/SublayersOwner.js";import{TemporalLayer as T}from"./mixins/TemporalLayer.js";import{url as A}from"./support/commonProperties.js";import{ExportImageParameters as M}from"./support/ExportImageParameters.js";import{createBitmap as R}from"./support/imageBitmapUtils.js";import U from"./support/Sublayer.js";import{shouldWriteSublayerStructure as _}from"./support/sublayerUtils.js";import{serviceSupportsSpatialReference as F}from"./support/versionUtils.js";import N from"../symbols/support/ElevationInfo.js";import{T as J}from"../chunks/TimeExtent.js";import{timeZoneProperty as V}from"../time/timeZoneUtils.js";import{SaveOperationType as q}from"../webdoc/interfaces.js";let k=class extends(x(T(L(P(S(j(w(O(i(E(b(I(v))))))))))))){constructor(...e){super(...e),this._exportImageParameters=new M({layer:this}),this.dateFieldsTimeZone=null,this.datesInUnknownTimezone=!1,this.dpi=96,this.elevationInfo=new N({mode:"on-the-ground"}),this.gdbVersion=null,this.imageFormat="png24",this.imageMaxHeight=2048,this.imageMaxWidth=2048,this.imageTransparency=!0,this.isReference=null,this.labelsVisible=!1,this.operationalLayerType="ArcGISMapServiceLayer",this.preferredTimeZone=null,this.sourceJSON=null,this.sublayers=null,this.type="map-image",this.url=null,this._debouncedSaveOperations=o((async(e,r,t)=>{const{save:s,saveAs:i}=await import("./save/mapImageLayerUtils.js");switch(e){case q.SAVE:return s(this,r);case q.SAVE_AS: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:["Map Service"]},e).catch(a).then((()=>this._fetchService(r)))),Promise.resolve(this)}destroy(){this._exportImageParameters.destroy()}readImageFormat(e,r){const t=r.supportedImageFormatTypes;return t&&t.includes("PNG32")?"png32":"png24"}writeSublayers(e,r,t,s){if(!this.loaded||!e)return;const i=e.slice().reverse().flatten((({sublayers:e})=>e&&e.toArray().reverse())).toArray();let o=!1;const a=y(s.origin);let n;if(this.capabilities?.operations.supportsExportMap&&this.capabilities?.exportMap?.supportsDynamicLayers)if(a===h.PORTAL_ITEM){const e=this.createSublayersForOrigin("service").sublayers;o=_(i,e,h.SERVICE)}else if(a>h.PORTAL_ITEM){const e=this.createSublayersForOrigin("portal-item");o=_(i,e.sublayers,y(e.origin)),n=e.originWithPartialOverrides}const p=[],m={writeSublayerStructure:o,...s,minimumWritableOrigin:n};let l=o||this.hasVisibleLayersForOrigin(a);i.forEach((e=>{const r=e.write({},m);p.push(r),l=l||"user"===e.originOf("visible")}));p.some((e=>Object.keys(e).length>1))&&(r.layers=p),l&&(r.visibleLayers=i.filter((e=>e.visible)).map((e=>e.id)))}createExportImageParameters(e,r,t,s){const i=s?.pixelRatio||1;e&&this.version>=10&&(e=e.clone().shiftCentralMeridian()),this._exportImageParameters.floors=s?.floors??null,this._exportImageParameters.scale=f({extent:e,width:r})*i;const o=this._exportImageParameters.toJSON(),a=!s?.rotation||this.version<10.3?{}:{rotation:-s.rotation},n=e?.spatialReference,p=g(n);o.dpi*=i;const m={};if(s?.timeExtent){const{start:e,end:r}=s.timeExtent.toJSON();m.time=e&&r&&e===r?""+e:`${e??"null"},${r??"null"}`}else this.timeInfo&&!this.timeInfo.hasLiveData&&(m.time="null,null");return{bbox:e?e.xmin+","+e.ymin+","+e.xmax+","+e.ymax:void 0,bboxSR:p,imageSR:p,size:r+","+t,...o,...a,...m}}async fetchImage(e,r,t,s){const{data:i}=await this._fetchImage("image",e,r,t,s);return i}async fetchImageBitmap(e,r,t,s){const{data:i,url:o}=await this._fetchImage("blob",e,r,t,s);return R(i,o,s?.signal)}async fetchRecomputedExtents(e={}){const t={...e,query:{returnUpdates:!0,f:"json",...this.customParameters,token:this.apiKey}},{data:s}=await r(this.url,t),{extent:i,fullExtent:o,timeExtent:a}=s,n=i||o;return{fullExtent:n&&d.fromJSON(n),timeExtent:a&&J.fromJSON({start:a[0],end:a[1]})}}loadAll(){return s(this,(e=>{e(this.allSublayers),e(this.subtables)}))}async save(e){return this._debouncedSaveOperations(q.SAVE,e)}async saveAs(e,r){return this._debouncedSaveOperations(q.SAVE_AS,r,e)}serviceSupportsSpatialReference(e){return F(this,e)}async _fetchImage(e,s,i,o,a){const p={responseType:e,signal:a?.signal??null,query:{...this.parsedUrl.query,...this.createExportImageParameters(s,i,o,a),f:"image",...this.refreshParameters,...this.customParameters,token:this.apiKey}},m=this.parsedUrl.path+"/export";if(null!=p.query?.dynamicLayers&&!this.capabilities?.exportMap?.supportsDynamicLayers)throw new t("mapimagelayer:dynamiclayer-not-supported",`service ${this.url} doesn't support dynamic layers, which is required to be able to change the sublayer's order, rendering, labeling or source.`,{query:p.query});try{const{data:e}=await r(m,p);return{data:e,url:m}}catch(l){if(n(l))throw l;throw new t("mapimagelayer:image-fetch-error",`Unable to load image: ${m}`,{error:l})}}async _fetchService(e){if(this.sourceJSON)return void this.read(this.sourceJSON,{origin:"service",url:this.parsedUrl});const{data:t,ssl:s}=await r(this.parsedUrl.path,{query:{f:"json",...this.parsedUrl.query,...this.customParameters,token:this.apiKey},signal:e});s&&(this.url=this.url.replace(/^http:/i,"https:")),this.sourceJSON=t,this.read(t,{origin:"service",url:this.parsedUrl})}hasVisibleLayersForOrigin(e){return!(null==e||!this.sublayersSourceJSON[e]?.visibleLayers)}};e([p(V("dateFieldsTimeReference"))],k.prototype,"dateFieldsTimeZone",void 0),e([p({type:Boolean})],k.prototype,"datesInUnknownTimezone",void 0),e([p()],k.prototype,"dpi",void 0),e([p()],k.prototype,"elevationInfo",void 0),e([p()],k.prototype,"gdbVersion",void 0),e([p()],k.prototype,"imageFormat",void 0),e([l("imageFormat",["supportedImageFormatTypes"])],k.prototype,"readImageFormat",null),e([p({json:{origins:{service:{read:{source:"maxImageHeight"}}}}})],k.prototype,"imageMaxHeight",void 0),e([p({json:{origins:{service:{read:{source:"maxImageWidth"}}}}})],k.prototype,"imageMaxWidth",void 0),e([p()],k.prototype,"imageTransparency",void 0),e([p({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],k.prototype,"isReference",void 0),e([p({json:{read:!1,write:!1}})],k.prototype,"labelsVisible",void 0),e([p({type:["ArcGISMapServiceLayer"]})],k.prototype,"operationalLayerType",void 0),e([p({json:{read:!1,write:!1}})],k.prototype,"popupEnabled",void 0),e([p(V("preferredTimeReference"))],k.prototype,"preferredTimeZone",void 0),e([p()],k.prototype,"sourceJSON",void 0),e([p({json:{write:{ignoreOrigin:!0}}})],k.prototype,"sublayers",void 0),e([u("sublayers",{layers:{type:[U]},visibleLayers:{type:[m]}})],k.prototype,"writeSublayers",null),e([p({type:["show","hide","hide-children"],json:{origins:{"portal-item":{read:!1,write:!1}}}})],k.prototype,"listMode",void 0),e([p({json:{read:!1},readOnly:!0,value:"map-image"})],k.prototype,"type",void 0),e([p(A)],k.prototype,"url",void 0),k=e([c("esri.layers.MapImageLayer")],k);const G=k;export{G as default};