UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 13 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../config.js";import r from"../Graphic.js";import o from"../PopupTemplate.js";import i from"../request.js";import s from"../core/Collection.js";import a from"../core/CollectionFlattener.js";import n from"../core/Error.js";import{JSONMap as l}from"../core/jsonMap.js";import{clone as p}from"../core/lang.js";import{MultiOriginJSONSupportMixin as m}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as u}from"../core/promiseUtils.js";import{on as c,sync as f,watch as y}from"../core/reactiveUtils.js";import{renderingSanitizer as d}from"../core/sanitizerUtils.js";import{urlToObject as h,addQueryParameters as g,addProxy as b,makeAbsolute as w,Url as v}from"../core/urlUtils.js";import{property as x,subclass as j}from"../core/accessorSupport/decorators.js";import{Integer as I}from"../core/accessorSupport/ensureType.js";import{willPropertyWrite as S}from"../core/accessorSupport/write.js";import F from"../geometry/Extent.js";import E from"../geometry/SpatialReference.js";import{getScale as P}from"../geometry/support/scaleUtils.js";import{equals as R}from"../geometry/support/spatialReferenceUtils.js";import O from"./Layer.js";import{BlendLayer as L}from"./mixins/BlendLayer.js";import{OperationalLayer as U}from"./mixins/OperationalLayer.js";import{PortalLayer as M}from"./mixins/PortalLayer.js";import{RefreshableLayer as T}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as _}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as C}from"./mixins/TemporalLayer.js";import{isAxesOrderReversedForWkid as W}from"./ogc/crsUtils.js";import{isWmsServer as q}from"./support/arcgisLayerUrl.js";import{legendEnabled as N,url as $}from"./support/commonProperties.js";import{ExportWMSImageParameters as B}from"./support/ExportWMSImageParameters.js";import{createBitmap as k}from"./support/imageBitmapUtils.js";import H from"./support/WMSSublayer.js";import{normalizeWKID as G,toTimeQueryParameter as V,getPopupLayers as z,parseCapabilities as A}from"./support/wmsUtils.js";import D from"../time/TimeExtent.js";import J from"../time/TimeInterval.js";import{reader as Q}from"../core/accessorSupport/decorators/reader.js";import{writer as K}from"../core/accessorSupport/decorators/writer.js";const X=new l({bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"},{ignoreUnknown:!1});function Y(e){return"text/html"===e}function Z(e){return"text/plain"===e}let ee=class extends(L(C(T(_(U(M(m(O)))))))){constructor(...e){super(...e),this.allSublayers=new a({getCollections:()=>[this.sublayers],getChildrenFunction:e=>e.sublayers}),this.customParameters=null,this.customLayerParameters=null,this.copyright=null,this.description=null,this.dimensions=null,this.fullExtent=null,this.fullExtents=null,this.featureInfoFormats=null,this.featureInfoUrl=null,this.fetchFeatureInfoFunction=null,this.imageFormat=null,this.imageMaxHeight=2048,this.imageMaxWidth=2048,this.imageTransparency=!0,this.legendEnabled=!0,this.mapUrl=null,this.isReference=null,this.operationalLayerType="WMS",this.spatialReference=null,this.spatialReferences=null,this.sublayers=null,this.type="wms",this.version=null,this.addHandles([c(()=>this.sublayers,"after-add",({item:e})=>{e.parent=e.layer=this},f),c(()=>this.sublayers,"after-remove",({item:e})=>{e.layer=e.parent=null},f),y(()=>this.sublayers,(e,t)=>{if(t)for(const r of t)r.layer=r.parent=null;if(e)for(const r of e)r.parent=r.layer=this},f)])}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}destroy(){this.allSublayers.destroy()}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["WMS"]},e).catch(u).then(()=>this._fetchService(t)).then(()=>this._checkLayerValidity())),Promise.resolve(this)}get timeInfo(){return super.timeInfo}set timeInfo(e){super.timeInfo=e}readFullExtentFromItemOrMap(e,t){const r=t.extent;return r?new F({xmin:r[0][0],ymin:r[0][1],xmax:r[1][0],ymax:r[1][1]}):null}writeFullExtent(e,t){t.extent=[[e.xmin,e.ymin],[e.xmax,e.ymax]]}get featureInfoFormat(){return null==this.featureInfoFormats?null:this.featureInfoFormats.find(Y)??this.featureInfoFormats.find(Z)??null}set featureInfoFormat(e){null==e?(this.revertToOrigin("featureInfoFormat","service"),this._clearOverride("featureInfoFormat")):(Y(e)||Z(e))&&this._override("featureInfoFormat",e)}readImageFormat(e,t){const r=t.supportedImageFormatTypes;return r&&r.includes("image/png")?"image/png":r&&r[0]}readSpatialReferenceFromItemOrDocument(e,t){return new E(t.spatialReferences[0])}writeSpatialReferences(e,t){const r=this.spatialReference?.wkid;e&&r?(t.spatialReferences=e.filter(e=>e!==r),t.spatialReferences.unshift(r)):t.spatialReferences=e}readSublayersFromItemOrMap(e,t,r){return re(t.layers,r,t.visibleLayers)}readSublayers(e,t,r){return re(t.layers,r)}writeSublayers(e,t,r,o){t.layers=[];const i=new Map,s=e.flatten(({sublayers:e})=>e??[]);for(const a of s)if("number"==typeof a.parent?.id){const e=i.get(a.parent.id);null!=e?e.push(a.id):i.set(a.parent.id,[a.id])}for(const a of s){const e={sublayer:a,...o},r=a.write({parentLayerId:"number"==typeof a.parent?.id?a.parent.id:-1},e);if(i.has(a.id)&&(r.sublayerIds=i.get(a.id)),!a.sublayers&&a.name){const r=a.write({},e);delete r.id,t.layers.push(r)}}t.visibleLayers=s.filter(({visible:e,sublayers:t})=>e&&!t).map(({name:e})=>e).toArray()}set url(e){if(!e)return void this._set("url",e);const{path:t,query:r}=h(e);for(const i in r)/^(request|service)$/i.test(i)&&delete r[i];const o=g(t,r??{});this._set("url",o)}createExportImageParameters(e,t,r,o){const i=o?.pixelRatio??1,s=P({extent:e,width:t})*i,a=new B({layer:this,scale:s}),{xmin:n,ymin:l,xmax:p,ymax:m,spatialReference:u}=e,c=G(u,this.spatialReferences),f="1.3.0"===this.version&&W(c)?`${l},${n},${m},${p}`:`${n},${l},${p},${m}`,y=a.toJSON(),d="1.3.0"===this.version?"crs":"srs";return{bbox:f,[d]:null==c||isNaN(c)?void 0:"EPSG:"+c,...y}}async fetchImage(e,t,r,o){const s=this.mapUrl,a=this.createExportImageParameters(e,t,r,o);if(!a.layers){const e=document.createElement("canvas");return e.width=t,e.height=r,e}const n=V(o?.timeExtent),l={responseType:"image",query:this._mixCustomParameters({width:t,height:r,...a,time:n,...this.refreshParameters}),signal:o?.signal};return i(s??"",l).then(e=>e.data)}async fetchImageBitmap(e,t,r,o){const s=this.mapUrl??"",a=this.createExportImageParameters(e,t,r,o);if(!a.layers){const e=document.createElement("canvas");return e.width=t,e.height=r,e}const n=V(o?.timeExtent),l={responseType:"blob",query:this._mixCustomParameters({width:t,height:r,...a,time:n,...this.refreshParameters}),signal:o?.signal},{data:p}=await i(s,l);return k(p,s,o?.signal)}fetchFeatureInfo(e,t,r,o,i){const s=P({extent:e,width:t}),a=new B({layer:this,scale:s}),n=z(a.visibleSublayers);if(null==this.featureInfoUrl||null==n)return Promise.resolve([]);if(null==this.fetchFeatureInfoFunction&&null==this.featureInfoFormat)return Promise.resolve([]);const l="1.3.0"===this.version?{I:o,J:i}:{x:o,y:i},p={query_layers:n,request:"GetFeatureInfo",info_format:this.featureInfoFormat,feature_count:25,width:t,height:r,...l},m={...this.createExportImageParameters(e,t,r),...p},u=this._mixCustomParameters(m);return null!=this.fetchFeatureInfoFunction?this.fetchFeatureInfoFunction(u):this._defaultFetchFeatureInfoFunction(g(this.featureInfoUrl,u))}findSublayerById(e){return this.allSublayers.find(t=>t.id===e)}findSublayerByName(e){return this.allSublayers.find(t=>t.name===e)}serviceSupportsSpatialReference(e){return q(this.url)||null!=this.spatialReferences&&this.spatialReferences.some(t=>{const r=900913===t?E.WebMercator:new E({wkid:t});return R(r,e)})}_defaultFetchFeatureInfoFunction(e){const t=document.createElement("iframe");t.src=b(d.sanitizeUrl(w(e))),t.style.border="none",t.style.margin="0",t.style.width="100%",t.setAttribute("sandbox","");const i=new o({title:this.title,content:t}),s=new r({sourceLayer:this,popupTemplate:i});return Promise.resolve([s])}async _fetchService(e){if(!this.resourceInfo&&this.parsedUrl?.path){const{path:t,query:r}=this.parsedUrl,{data:o}=await i(t,{query:{SERVICE:"WMS",REQUEST:"GetCapabilities",...r,...this.customParameters},responseType:"xml",signal:e});this.resourceInfo=A(o)}if(this.parsedUrl){const e=new v(this.parsedUrl.path),{httpsDomains:r}=t.request;"https"!==e.scheme||e.port&&"443"!==e.port||!e.host||r.includes(e.host)||r.push(e.host)}this.read(this.resourceInfo,{origin:"service"})}_checkLayerValidity(){if(!this.allSublayers.length)throw new n("wmslayer:empty-layer","The layer doesn't have any sublayer")}_mixCustomParameters(e){if(!this.customLayerParameters&&!this.customParameters)return e;const t={...this.customParameters,...this.customLayerParameters};for(const r in t)e[r.toLowerCase()]=t[r];return e}};function te(e,t){return e.some(e=>{for(const r in e)if(S(e,r,null,t))return!0;return!1})}function re(e,t,r){e=e??[];const o=new Map;e.every(e=>null==e.id)&&(e=p(e)).forEach((e,t)=>e.id=t);for(const s of e){const e=new H;e.read(s,t),r&&!r.includes(e.name)&&(e.visible=!1),o.set(e.id,e)}const i=[];for(const a of e){const e=null!=a.id?o.get(a.id):null;if(e)if(null!=a.parentLayerId&&a.parentLayerId>=0){const t=o.get(a.parentLayerId);if(!t)continue;t.sublayers||(t.sublayers=new s),t.sublayers.push(e)}else i.push(e)}return i}e([x({type:D})],ee.prototype,"timeExtent",void 0),e([x({type:J})],ee.prototype,"timeOffset",void 0),e([x({readOnly:!0})],ee.prototype,"allSublayers",void 0),e([x({json:{type:Object,write:!0}})],ee.prototype,"customParameters",void 0),e([x({json:{type:Object,write:!0}})],ee.prototype,"customLayerParameters",void 0),e([x({type:String,json:{write:!0}})],ee.prototype,"copyright",void 0),e([x()],ee.prototype,"description",void 0),e([x({readOnly:!0})],ee.prototype,"dimensions",void 0),e([x({json:{type:[[Number]],read:{source:"extent"},write:{target:"extent"},origins:{"web-document":{write:{ignoreOrigin:!0}},"portal-item":{write:{ignoreOrigin:!0}}}}})],ee.prototype,"fullExtent",void 0),e([Q(["web-document","portal-item"],"fullExtent",["extent"])],ee.prototype,"readFullExtentFromItemOrMap",null),e([K(["web-document","portal-item"],"fullExtent",{extent:{type:[[Number]]}})],ee.prototype,"writeFullExtent",null),e([x({type:[F]})],ee.prototype,"fullExtents",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],ee.prototype,"featureInfoFormat",null),e([x({type:[String],readOnly:!0})],ee.prototype,"featureInfoFormats",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],ee.prototype,"featureInfoUrl",void 0),e([x()],ee.prototype,"fetchFeatureInfoFunction",void 0),e([x({type:String,json:{origins:{"web-document":{default:"image/png",type:X.jsonValues,read:{reader:X.read,source:"format"},write:{writer:X.write,target:"format"}}}}})],ee.prototype,"imageFormat",void 0),e([Q("imageFormat",["supportedImageFormatTypes"])],ee.prototype,"readImageFormat",null),e([x({type:Number,json:{read:{source:"maxHeight"},write:{target:"maxHeight"}}})],ee.prototype,"imageMaxHeight",void 0),e([x({type:Number,json:{read:{source:"maxWidth"},write:{target:"maxWidth"}}})],ee.prototype,"imageMaxWidth",void 0),e([x()],ee.prototype,"imageTransparency",void 0),e([x(N)],ee.prototype,"legendEnabled",void 0),e([x({type:["show","hide","hide-children"]})],ee.prototype,"listMode",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],ee.prototype,"mapUrl",void 0),e([x({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],ee.prototype,"isReference",void 0),e([x({type:["WMS"]})],ee.prototype,"operationalLayerType",void 0),e([x()],ee.prototype,"resourceInfo",void 0),e([x({type:E,json:{origins:{service:{read:{source:"extent.spatialReference"}}},write:!1}})],ee.prototype,"spatialReference",void 0),e([Q(["web-document","portal-item"],"spatialReference",["spatialReferences"])],ee.prototype,"readSpatialReferenceFromItemOrDocument",null),e([x({type:[I],json:{read:!1,origins:{service:{read:!0},"web-document":{read:!1,write:{ignoreOrigin:!0}},"portal-item":{read:!1,write:{ignoreOrigin:!0}}}}})],ee.prototype,"spatialReferences",void 0),e([K(["web-document","portal-item"],"spatialReferences")],ee.prototype,"writeSpatialReferences",null),e([x({type:s.ofType(H),json:{write:{target:"layers",overridePolicy(e,t,r){if(te(this.allSublayers,r))return{ignoreOrigin:!0}}}}})],ee.prototype,"sublayers",void 0),e([Q(["web-document","portal-item"],"sublayers",["layers","visibleLayers"])],ee.prototype,"readSublayersFromItemOrMap",null),e([Q("service","sublayers",["layers"])],ee.prototype,"readSublayers",null),e([K("sublayers",{layers:{type:[H]},visibleLayers:{type:[String]}})],ee.prototype,"writeSublayers",null),e([x({json:{read:!1},readOnly:!0,value:"wms"})],ee.prototype,"type",void 0),e([x($)],ee.prototype,"url",null),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],ee.prototype,"version",void 0),ee=e([j("esri.layers.WMSLayer")],ee);const oe=ee;export{oe as default};