UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 12.9 kB
/* 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 t from"../config.js";import r from"../Graphic.js";import o from"../PopupTemplate.js";import s from"../request.js";import i 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{MultiOriginJSONMixin as m}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as u}from"../core/promiseUtils.js";import{on as c,watch as y,sync as f}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}from"../core/accessorSupport/decorators/property.js";import{Integer as j}from"../core/accessorSupport/ensureType.js";import{reader as I}from"../core/accessorSupport/decorators/reader.js";import{subclass as S}from"../core/accessorSupport/decorators/subclass.js";import{writer as F}from"../core/accessorSupport/decorators/writer.js";import{willPropertyWrite as P}from"../core/accessorSupport/write.js";import R from"../geometry/Extent.js";import E from"../geometry/SpatialReference.js";import{getScale as L}from"../geometry/support/scaleUtils.js";import{equals as O}from"../geometry/support/spatialReferenceUtils.js";import U from"./Layer.js";import{BlendLayer as M}from"./mixins/BlendLayer.js";import{OperationalLayer as _}from"./mixins/OperationalLayer.js";import{PortalLayer as T}from"./mixins/PortalLayer.js";import{RefreshableLayer as C}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as W}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as q}from"./mixins/TemporalLayer.js";import{isAxesOrderReversedForWkid as N}from"./ogc/crsUtils.js";import{isWmsServer as $}from"./support/arcgisLayerUrl.js";import{legendEnabled as k,url as B}from"./support/commonProperties.js";import{ExportWMSImageParameters as H}from"./support/ExportWMSImageParameters.js";import{createBitmap as G}from"./support/imageBitmapUtils.js";import V from"./support/WMSSublayer.js";import{normalizeWKID as z,toTimeQueryParameter as A,getPopupLayers as D,parseCapabilities as J}from"./support/wmsUtils.js";const Q=new l({bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"},{ignoreUnknown:!1});function K(e){return"text/html"===e}function X(e){return"text/plain"===e}let Y=class extends(M(q(C(W(_(T(m(U)))))))){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)}readFullExtentFromItemOrMap(e,t){const r=t.extent;return r?new R({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(K)??this.featureInfoFormats.find(X)??null}set featureInfoFormat(e){null==e?(this.revert("featureInfoFormat","service"),this._clearOverride("featureInfoFormat")):(K(e)||X(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 ee(t.layers,r,t.visibleLayers)}readSublayers(e,t,r){return ee(t.layers,r)}writeSublayers(e,t,r,o){t.layers=[];const s=new Map,i=e.flatten((({sublayers:e})=>e??[]));for(const a of i)if("number"==typeof a.parent?.id){const e=s.get(a.parent.id);null!=e?e.push(a.id):s.set(a.parent.id,[a.id])}for(const a of i){const e={sublayer:a,...o},r=a.write({parentLayerId:"number"==typeof a.parent?.id?a.parent.id:-1},e);if(s.has(a.id)&&(r.sublayerIds=s.get(a.id)),!a.sublayers&&a.name){const r=a.write({},e);delete r.id,t.layers.push(r)}}t.visibleLayers=i.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 s in r)/^(request|service)$/i.test(s)&&delete r[s];const o=g(t,r??{});this._set("url",o)}createExportImageParameters(e,t,r,o){const s=o?.pixelRatio??1,i=L({extent:e,width:t})*s,a=new H({layer:this,scale:i}),{xmin:n,ymin:l,xmax:p,ymax:m,spatialReference:u}=e,c=z(u,this.spatialReferences),y="1.3.0"===this.version&&N(c)?`${l},${n},${m},${p}`:`${n},${l},${p},${m}`,f=a.toJSON(),d="1.3.0"===this.version?"crs":"srs";return{bbox:y,[d]:null==c||isNaN(c)?void 0:"EPSG:"+c,...f}}async fetchImage(e,t,r,o){const i=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=A(o?.timeExtent),l={responseType:"image",query:this._mixCustomParameters({width:t,height:r,...a,time:n,...this.refreshParameters}),signal:o?.signal};return s(i??"",l).then((e=>e.data))}async fetchImageBitmap(e,t,r,o){const i=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=A(o?.timeExtent),l={responseType:"blob",query:this._mixCustomParameters({width:t,height:r,...a,time:n,...this.refreshParameters}),signal:o?.signal},{data:p}=await s(i,l);return G(p,i,o?.signal)}fetchFeatureInfo(e,t,r,o,s){const i=L({extent:e,width:t}),a=new H({layer:this,scale:i}),n=D(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:s}:{x:o,y:s},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 $(this.url)||null!=this.spatialReferences&&this.spatialReferences.some((t=>{const r=900913===t?E.WebMercator:new E({wkid:t});return O(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 s=new o({title:this.title,content:t}),i=new r({sourceLayer:this,popupTemplate:s});return Promise.resolve([i])}async _fetchService(e){if(!this.resourceInfo&&this.parsedUrl?.path){const{path:t,query:r}=this.parsedUrl,{data:o}=await s(t,{query:{SERVICE:"WMS",REQUEST:"GetCapabilities",...r,...this.customParameters},responseType:"xml",signal:e});this.resourceInfo=J(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 Z(e,t){return e.some((e=>{for(const r in e)if(P(e,r,null,t))return!0;return!1}))}function ee(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 i of e){const e=new V;e.read(i,t),r&&!r.includes(e.name)&&(e.visible=!1),o.set(e.id,e)}const s=[];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 i),t.sublayers.push(e)}else s.push(e)}return s}e([x({readOnly:!0})],Y.prototype,"allSublayers",void 0),e([x({json:{type:Object,write:!0}})],Y.prototype,"customParameters",void 0),e([x({json:{type:Object,write:!0}})],Y.prototype,"customLayerParameters",void 0),e([x({type:String,json:{write:!0}})],Y.prototype,"copyright",void 0),e([x()],Y.prototype,"description",void 0),e([x({readOnly:!0})],Y.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}}}}})],Y.prototype,"fullExtent",void 0),e([I(["web-document","portal-item"],"fullExtent",["extent"])],Y.prototype,"readFullExtentFromItemOrMap",null),e([F(["web-document","portal-item"],"fullExtent",{extent:{type:[[Number]]}})],Y.prototype,"writeFullExtent",null),e([x({type:[R]})],Y.prototype,"fullExtents",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],Y.prototype,"featureInfoFormat",null),e([x({type:[String],readOnly:!0})],Y.prototype,"featureInfoFormats",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],Y.prototype,"featureInfoUrl",void 0),e([x()],Y.prototype,"fetchFeatureInfoFunction",void 0),e([x({type:String,json:{origins:{"web-document":{default:"image/png",type:Q.jsonValues,read:{reader:Q.read,source:"format"},write:{writer:Q.write,target:"format"}}}}})],Y.prototype,"imageFormat",void 0),e([I("imageFormat",["supportedImageFormatTypes"])],Y.prototype,"readImageFormat",null),e([x({type:Number,json:{read:{source:"maxHeight"},write:{target:"maxHeight"}}})],Y.prototype,"imageMaxHeight",void 0),e([x({type:Number,json:{read:{source:"maxWidth"},write:{target:"maxWidth"}}})],Y.prototype,"imageMaxWidth",void 0),e([x()],Y.prototype,"imageTransparency",void 0),e([x(k)],Y.prototype,"legendEnabled",void 0),e([x({type:["show","hide","hide-children"]})],Y.prototype,"listMode",void 0),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],Y.prototype,"mapUrl",void 0),e([x({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],Y.prototype,"isReference",void 0),e([x({type:["WMS"]})],Y.prototype,"operationalLayerType",void 0),e([x()],Y.prototype,"resourceInfo",void 0),e([x({type:E,json:{origins:{service:{read:{source:"extent.spatialReference"}}},write:!1}})],Y.prototype,"spatialReference",void 0),e([I(["web-document","portal-item"],"spatialReference",["spatialReferences"])],Y.prototype,"readSpatialReferenceFromItemOrDocument",null),e([x({type:[j],json:{read:!1,origins:{service:{read:!0},"web-document":{read:!1,write:{ignoreOrigin:!0}},"portal-item":{read:!1,write:{ignoreOrigin:!0}}}}})],Y.prototype,"spatialReferences",void 0),e([F(["web-document","portal-item"],"spatialReferences")],Y.prototype,"writeSpatialReferences",null),e([x({type:i.ofType(V),json:{write:{target:"layers",overridePolicy(e,t,r){if(Z(this.allSublayers,r))return{ignoreOrigin:!0}}}}})],Y.prototype,"sublayers",void 0),e([I(["web-document","portal-item"],"sublayers",["layers","visibleLayers"])],Y.prototype,"readSublayersFromItemOrMap",null),e([I("service","sublayers",["layers"])],Y.prototype,"readSublayers",null),e([F("sublayers",{layers:{type:[V]},visibleLayers:{type:[String]}})],Y.prototype,"writeSublayers",null),e([x({json:{read:!1},readOnly:!0,value:"wms"})],Y.prototype,"type",void 0),e([x(B)],Y.prototype,"url",null),e([x({type:String,json:{write:{ignoreOrigin:!0}}})],Y.prototype,"version",void 0),Y=e([S("esri.layers.WMSLayer")],Y);const te=Y;export{te as default};