@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.6 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../request.js";import t from"../core/Collection.js";import i from"../core/Error.js";import{loadAll as s}from"../core/loadAll.js";import{MultiOriginJSONSupportMixin as o}from"../core/MultiOriginJSONSupport.js";import{debounce as a,throwIfAbortError as p,isAbortError as n}from"../core/promiseUtils.js";import{getMetersPerUnitForSR as m,inchesPerMeter as l}from"../core/units.js";import{property as c,subclass as u}from"../core/accessorSupport/decorators.js";import{Integer as y}from"../core/accessorSupport/ensureType.js";import{nameToId as d}from"../core/accessorSupport/PropertyOrigin.js";import h 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 x}from"./mixins/ArcGISMapService.js";import{ArcGISService as j}from"./mixins/ArcGISService.js";import{BlendLayer as S}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 P}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as L}from"./mixins/ScaleRangeLayer.js";import{SublayersOwner as T}from"./mixins/SublayersOwner.js";import{TemporalLayer as U}from"./mixins/TemporalLayer.js";import{url as E}from"./support/commonProperties.js";import{ExportImageParameters as M}from"./support/ExportImageParameters.js";import{createBitmap as F}from"./support/imageBitmapUtils.js";import R from"./support/Sublayer.js";import{shouldWriteSublayerStructure as _}from"./support/sublayerUtils.js";import{serviceSupportsSpatialReference as A}from"./support/versionUtils.js";import N from"../symbols/support/ElevationInfo.js";import J from"../time/TimeExtent.js";import{timeZoneProperty as q}from"../time/timeZoneUtils.js";import{reader as k}from"../core/accessorSupport/decorators/reader.js";import{writer as V}from"../core/accessorSupport/decorators/writer.js";let B=class extends(S(U(L(T(x(j(w(O(o(P(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=a(async(e,r,t)=>{const{save:i,saveAs:s}=await import("./save/mapImageLayerUtils.js");switch(e){case 0:return i(this,r);case 1:return s(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(p).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"}get loaded(){return super.loaded}get portalItem(){return super.portalItem}set portalItem(e){super.portalItem=e}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=d(i.origin);let p;if(this.capabilities?.operations.supportsExportMap&&this.capabilities?.exportMap?.supportsDynamicLayers)if(3===a){const e=this.createSublayersForOrigin("service").sublayers;o=_(s,e,2)}else if(a>3){const e=this.createSublayersForOrigin("portal-item");o=_(s,e.sublayers,d(e.origin)),p=e.originWithPartialOverrides}const n=[],m={writeSublayerStructure:o,...i,minimumWritableOrigin:p};let l=o||this.hasVisibleLayersForOrigin(a);s.forEach(e=>{const r=e.write({},m);n.push(r),l=l||"user"===e.originOf("visible")});n.some(e=>Object.keys(e).length>1)&&(r.layers=n),l&&(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=i?.scale||f({extent:e,width:r})*s;const o=this._exportImageParameters.toJSON(),a=!i?.rotation||this.version<10.3?{}:{rotation:-i.rotation},p=e?.spatialReference,n=g(p);if(i?.scale&&e){const t=e.width/r*(m(e?.spatialReference)*l);o.dpi=i.scale/t}o.dpi*=s;const c={};if(i?.timeExtent){const{start:e,end:r}=i.timeExtent.toJSON();c.time=e&&r&&e===r?""+e:`${e??"null"},${r??"null"}`}else this.timeInfo&&!this.timeInfo.hasLiveData&&(c.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,...c}}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 F(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&&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(0,e)}async saveAs(e,r){return this._debouncedSaveOperations(1,r,e)}serviceSupportsSpatialReference(e){return A(this,e)}async _fetchImage(e,t,s,o,a){const p={responseType:e,signal:a?.signal??null,query:{...this.parsedUrl.query,...this.createExportImageParameters(t,s,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 i("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 i("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([c(q("dateFieldsTimeReference"))],B.prototype,"dateFieldsTimeZone",void 0),e([c({type:Boolean})],B.prototype,"datesInUnknownTimezone",void 0),e([c()],B.prototype,"dpi",void 0),e([c()],B.prototype,"elevationInfo",void 0),e([c()],B.prototype,"gdbVersion",void 0),e([c()],B.prototype,"imageFormat",void 0),e([k("imageFormat",["supportedImageFormatTypes"])],B.prototype,"readImageFormat",null),e([c({json:{origins:{service:{read:{source:"maxImageHeight"}}}}})],B.prototype,"imageMaxHeight",void 0),e([c({json:{origins:{service:{read:{source:"maxImageWidth"}}}}})],B.prototype,"imageMaxWidth",void 0),e([c()],B.prototype,"imageTransparency",void 0),e([c({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],B.prototype,"isReference",void 0),e([c({json:{read:!1,write:!1}})],B.prototype,"labelsVisible",void 0),e([c({type:["ArcGISMapServiceLayer"]})],B.prototype,"operationalLayerType",void 0),e([c({json:{read:!1,write:!1}})],B.prototype,"popupEnabled",void 0),e([c(q("preferredTimeReference"))],B.prototype,"preferredTimeZone",void 0),e([c()],B.prototype,"sourceJSON",void 0),e([c({type:t.ofType(R),json:{write:{ignoreOrigin:!0}}})],B.prototype,"sublayers",void 0),e([V("sublayers",{layers:{type:[R]},visibleLayers:{type:[y]}})],B.prototype,"writeSublayers",null),e([c({type:["show","hide","hide-children"],json:{origins:{"portal-item":{read:!1,write:!1}}}})],B.prototype,"listMode",void 0),e([c({json:{read:!1},readOnly:!0,value:"map-image"})],B.prototype,"type",void 0),e([c(E)],B.prototype,"url",void 0),B=e([u("esri.layers.MapImageLayer")],B);const G=B;export{G as default};