@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.97 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/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 i}from"../core/loadAll.js";import{MultiOriginJSONMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as o,isAbortError as a}from"../core/promiseUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import{Integer as n}from"../core/accessorSupport/ensureType.js";import"../core/has.js";import"../core/RandomLCG.js";import{reader as m}from"../core/accessorSupport/decorators/reader.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import{writer as c}from"../core/accessorSupport/decorators/writer.js";import{nameToId as u,OriginId as y}from"../core/accessorSupport/PropertyOrigin.js";import h from"../geometry/Extent.js";import{getScale as d}from"../geometry/support/scaleUtils.js";import{srToRESTValue as f}from"../geometry/support/spatialReferenceUtils.js";import g from"./Layer.js";import{APIKeyMixin as b}from"./mixins/APIKeyMixin.js";import{ArcGISMapService as x}from"./mixins/ArcGISMapService.js";import{ArcGISService as v}from"./mixins/ArcGISService.js";import{BlendLayer as j}from"./mixins/BlendLayer.js";import{CustomParametersMixin as S}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as I}from"./mixins/OperationalLayer.js";import{PortalLayer as w}from"./mixins/PortalLayer.js";import{RefreshableLayer as O}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 E}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 F}from"./support/sublayerUtils.js";import{serviceSupportsSpatialReference as _}from"./support/versionUtils.js";import A from"../time/TimeExtent.js";import{timeZoneProperty as N}from"../time/timeZoneUtils.js";let J=class extends(j(T(L(P(x(v(I(w(s(O(b(S(g))))))))))))){constructor(...e){super(...e),this._exportImageParameters=new M({layer:this}),this.dateFieldsTimeZone=null,this.datesInUnknownTimezone=!1,this.dpi=96,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}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(o).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,i){if(!this.loaded||!e)return;const s=e.slice().reverse().flatten((({sublayers:e})=>e&&e.toArray().reverse())).toArray();let o=!1;const a=u(i.origin);if(this.capabilities?.operations.supportsExportMap&&this.capabilities?.exportMap?.supportsDynamicLayers)if(a===y.PORTAL_ITEM){const e=this.createSublayersForOrigin("service").sublayers;o=F(s,e,y.SERVICE)}else if(a>y.PORTAL_ITEM){const e=this.createSublayersForOrigin("portal-item");o=F(s,e.sublayers,u(e.origin))}const p=[],n={writeSublayerStructure:o,...i};let m=o||this.hasVisibleLayersForOrigin(a);s.forEach((e=>{const r=e.write({},n);p.push(r),m=m||"user"===e.originOf("visible")}));p.some((e=>Object.keys(e).length>1))&&(r.layers=p),m&&(r.visibleLayers=s.filter((e=>e.visible)).map((e=>e.id)))}createExportImageParameters(e,r,t,i){const s=i?.pixelRatio||1;e&&this.version>=10&&(e=e.clone().shiftCentralMeridian()),this._exportImageParameters.floors=i?.floors??null,this._exportImageParameters.scale=d({extent:e,width:r})*s;const o=this._exportImageParameters.toJSON(),a=!i?.rotation||this.version<10.3?{}:{rotation:-i.rotation},p=e?.spatialReference,n=f(p);o.dpi*=s;const m={};if(i?.timeExtent){const{start:e,end:r}=i.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:n,imageSR:n,size:r+","+t,...o,...a,...m}}async fetchImage(e,r,t,i){const{data:s}=await this._fetchImage("image",e,r,t,i);return s}async fetchImageBitmap(e,r,t,i){const{data:s,url:o}=await this._fetchImage("blob",e,r,t,i);return R(s,o,i?.signal)}async fetchRecomputedExtents(e={}){const t={...e,query:{returnUpdates:!0,f:"json",...this.customParameters,token:this.apiKey}},{data:i}=await r(this.url,t),{extent:s,fullExtent:o,timeExtent:a}=i,p=s||o;return{fullExtent:p&&h.fromJSON(p),timeExtent:a&&A.fromJSON({start:a[0],end:a[1]})}}loadAll(){return i(this,(e=>{e(this.allSublayers),e(this.subtables)}))}serviceSupportsSpatialReference(e){return _(this,e)}async _fetchImage(e,i,s,o,p){const n={responseType:e,signal:p?.signal??null,query:{...this.parsedUrl.query,...this.createExportImageParameters(i,s,o,p),f:"image",...this.refreshParameters,...this.customParameters,token:this.apiKey}},m=this.parsedUrl.path+"/export";if(null!=n.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:n.query});try{const{data:e}=await r(m,n);return{data:e,url:m}}catch(l){if(a(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:i}=await r(this.parsedUrl.path,{query:{f:"json",...this.parsedUrl.query,...this.customParameters,token:this.apiKey},signal:e});i&&(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(N("dateFieldsTimeReference"))],J.prototype,"dateFieldsTimeZone",void 0),e([p({type:Boolean})],J.prototype,"datesInUnknownTimezone",void 0),e([p()],J.prototype,"dpi",void 0),e([p()],J.prototype,"gdbVersion",void 0),e([p()],J.prototype,"imageFormat",void 0),e([m("imageFormat",["supportedImageFormatTypes"])],J.prototype,"readImageFormat",null),e([p({json:{origins:{service:{read:{source:"maxImageHeight"}}}}})],J.prototype,"imageMaxHeight",void 0),e([p({json:{origins:{service:{read:{source:"maxImageWidth"}}}}})],J.prototype,"imageMaxWidth",void 0),e([p()],J.prototype,"imageTransparency",void 0),e([p({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],J.prototype,"isReference",void 0),e([p({json:{read:!1,write:!1}})],J.prototype,"labelsVisible",void 0),e([p({type:["ArcGISMapServiceLayer"]})],J.prototype,"operationalLayerType",void 0),e([p({json:{read:!1,write:!1}})],J.prototype,"popupEnabled",void 0),e([p(N("preferredTimeReference"))],J.prototype,"preferredTimeZone",void 0),e([p()],J.prototype,"sourceJSON",void 0),e([p({json:{write:{ignoreOrigin:!0}}})],J.prototype,"sublayers",void 0),e([c("sublayers",{layers:{type:[U]},visibleLayers:{type:[n]}})],J.prototype,"writeSublayers",null),e([p({type:["show","hide","hide-children"]})],J.prototype,"listMode",void 0),e([p({json:{read:!1},readOnly:!0,value:"map-image"})],J.prototype,"type",void 0),e([p(E)],J.prototype,"url",void 0),J=e([l("esri.layers.MapImageLayer")],J);const q=J;export{q as default};