12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/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{JSONMap as n}from"../core/jsonMap.js";import{clone as l}from"../core/lang.js";import{isSome as p,isNone as m}from"../core/maybe.js";import{MultiOriginJSONMixin as u}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as c}from"../core/promiseUtils.js";import{on as f,watch as y,sync as d}from"../core/reactiveUtils.js";import{addQueryParameters as h,addProxy as g,Url as b}from"../core/urlUtils.js";import{property as v}from"../core/accessorSupport/decorators/property.js";import{Integer as w}from"../core/accessorSupport/ensureType.js";import{reader as x}from"../core/accessorSupport/decorators/reader.js";import{subclass as j}from"../core/accessorSupport/decorators/subclass.js";import{writer as I}from"../core/accessorSupport/decorators/writer.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 R}from"../geometry/support/scaleUtils.js";import{equals as P}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 $}from"./support/arcgisLayerUrl.js";import{legendEnabled as q,url as N}from"./support/commonProperties.js";import{ExportWMSImageParameters as B}from"./support/ExportWMSImageParameters.js";import H from"./support/WMSSublayer.js";import{normalizeWKID as k,toISOString as G,getPopupLayers as A,parseCapabilities as D}from"./support/wmsUtils.js";const J=new n({bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"},{ignoreUnknown:!1});function V(e){return"text/html"===e}function Q(e){return"text/plain"===e}let z=class extends(L(C(T(_(U(M(u(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.url=null,this.version=null,this.addHandles([f((()=>this.sublayers),"after-add",(({item:e})=>{e.parent=e.layer=this}),d),f((()=>this.sublayers),"after-remove",(({item:e})=>{e.layer=e.parent=null}),d),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}),d)])}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}load(e){const t=p(e)?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["WMS"]},e).catch(c).then((()=>this._fetchService(t)))),Promise.resolve(this)}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 m(this.featureInfoFormats)?null:this.featureInfoFormats.find(V)??this.featureInfoFormats.find(Q)??null}set featureInfoFormat(e){p(e)?(V(e)||Q(e))&&this._override("featureInfoFormat",e):(this.revert("featureInfoFormat","service"),this._clearOverride("featureInfoFormat"))}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 X(t.layers,r,t.visibleLayers)}readSublayers(e,t,r){return X(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()}createExportImageParameters(e,t,r,o){const s=o?.pixelRatio??1,i=R({extent:e,width:t})*s,a=new B({layer:this,scale:i}),{xmin:n,ymin:l,xmax:p,ymax:m,spatialReference:u}=e,c=k(u,this.spatialReferences),f="1.3.0"===this.version&&W(c)?`${l},${n},${m},${p}`:`${n},${l},${p},${m}`,y=a.toJSON();return{bbox:f,["1.3.0"===this.version?"crs":"srs"]:isNaN(c)?void 0:"EPSG:"+c,...y}}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=o?.timeExtent?.start,l=o?.timeExtent?.end,m=p(n)&&p(l)?n.getTime()===l.getTime()?G(n):`${G(n)}/${G(l)}`:void 0,u={responseType:"image",query:this._mixCustomParameters({width:t,height:r,...a,time:m,...this.refreshParameters}),signal:o?.signal};return s(i??"",u).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=o?.timeExtent?.start,l=o?.timeExtent?.end,m=p(n)&&p(l)?n.getTime()===l.getTime()?G(n):`${G(n)}/${G(l)}`:void 0,u={responseType:"blob",query:this._mixCustomParameters({width:t,height:r,...a,time:m,...this.refreshParameters}),signal:o?.signal},c=await s(i??"",u).then((e=>e.data));return createImageBitmap(c)}fetchFeatureInfo(e,t,r,o,s){const i=R({extent:e,width:t}),a=new B({layer:this,scale:i}),n=A(a.visibleSublayers);if(m(this.featureInfoUrl)||m(n))return Promise.resolve([]);if(m(this.fetchFeatureInfoFunction)&&m(this.featureInfoFormat))return Promise.resolve([]);const l="1.3.0"===this.version?{I:o,J:s}:{x:o,y:s},u={query_layers:n,request:"GetFeatureInfo",info_format:this.featureInfoFormat,feature_count:25,width:t,height:r,...l},c={...this.createExportImageParameters(e,t,r),...u},f=this._mixCustomParameters(c);return p(this.fetchFeatureInfoFunction)?this.fetchFeatureInfoFunction(f):this._defaultFetchFeatureInfoFunction(h(this.featureInfoUrl,f))}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 P(r,e)}))}_defaultFetchFeatureInfoFunction(e){const t=document.createElement("iframe");t.src=g(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){const{path:t,query:r}=this.parsedUrl??{};r?.service&&(r.SERVICE=r.service,delete r.service),r?.request&&(r.REQUEST=r.request,delete r.request);const{data:o}=await s(t??"",{query:{SERVICE:"WMS",REQUEST:"GetCapabilities",...r,...this.customParameters},responseType:"xml",signal:e});this.resourceInfo=D(o)}if(this.parsedUrl){const e=new b(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"})}_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 K(e,t){return e.some((e=>{for(const r in e)if(S(e,r,null,t))return!0;return!1}))}function X(e,t,r){e=e??[];const o=new Map;e.every((e=>null==e.id))&&(e=l(e)).forEach(((e,t)=>e.id=t));for(const i of e){const e=new H;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([v({readOnly:!0})],z.prototype,"allSublayers",void 0),e([v({json:{type:Object,write:!0}})],z.prototype,"customParameters",void 0),e([v({json:{type:Object,write:!0}})],z.prototype,"customLayerParameters",void 0),e([v({type:String,json:{write:!0}})],z.prototype,"copyright",void 0),e([v()],z.prototype,"description",void 0),e([v({readOnly:!0})],z.prototype,"dimensions",void 0),e([v({json:{type:[[Number]],read:{source:"extent"},write:{target:"extent"},origins:{"web-document":{write:{ignoreOrigin:!0}},"portal-item":{write:{ignoreOrigin:!0}}}}})],z.prototype,"fullExtent",void 0),e([x(["web-document","portal-item"],"fullExtent",["extent"])],z.prototype,"readFullExtentFromItemOrMap",null),e([I(["web-document","portal-item"],"fullExtent",{extent:{type:[[Number]]}})],z.prototype,"writeFullExtent",null),e([v()],z.prototype,"fullExtents",void 0),e([v({type:String,json:{write:{ignoreOrigin:!0}}})],z.prototype,"featureInfoFormat",null),e([v({type:[String],readOnly:!0})],z.prototype,"featureInfoFormats",void 0),e([v({type:String,json:{write:{ignoreOrigin:!0}}})],z.prototype,"featureInfoUrl",void 0),e([v()],z.prototype,"fetchFeatureInfoFunction",void 0),e([v({type:String,json:{origins:{"web-document":{default:"image/png",type:J.jsonValues,read:{reader:J.read,source:"format"},write:{writer:J.write,target:"format"}}}}})],z.prototype,"imageFormat",void 0),e([x("imageFormat",["supportedImageFormatTypes"])],z.prototype,"readImageFormat",null),e([v({type:Number,json:{read:{source:"maxHeight"},write:{target:"maxHeight"}}})],z.prototype,"imageMaxHeight",void 0),e([v({type:Number,json:{read:{source:"maxWidth"},write:{target:"maxWidth"}}})],z.prototype,"imageMaxWidth",void 0),e([v()],z.prototype,"imageTransparency",void 0),e([v(q)],z.prototype,"legendEnabled",void 0),e([v({type:["show","hide","hide-children"]})],z.prototype,"listMode",void 0),e([v({type:String,json:{write:{ignoreOrigin:!0}}})],z.prototype,"mapUrl",void 0),e([v({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],z.prototype,"isReference",void 0),e([v({type:["WMS"]})],z.prototype,"operationalLayerType",void 0),e([v()],z.prototype,"resourceInfo",void 0),e([v({type:E,json:{origins:{service:{read:{source:"extent.spatialReference"}}},write:!1}})],z.prototype,"spatialReference",void 0),e([x(["web-document","portal-item"],"spatialReference",["spatialReferences"])],z.prototype,"readSpatialReferenceFromItemOrDocument",null),e([v({type:[w],json:{read:!1,origins:{service:{read:!0},"web-document":{read:!1,write:{ignoreOrigin:!0}},"portal-item":{read:!1,write:{ignoreOrigin:!0}}}}})],z.prototype,"spatialReferences",void 0),e([I(["web-document","portal-item"],"spatialReferences")],z.prototype,"writeSpatialReferences",null),e([v({type:i.ofType(H),json:{write:{target:"layers",overridePolicy(e,t,r){if(K(this.allSublayers,r))return{ignoreOrigin:!0}}}}})],z.prototype,"sublayers",void 0),e([x(["web-document","portal-item"],"sublayers",["layers","visibleLayers"])],z.prototype,"readSublayersFromItemOrMap",null),e([x("service","sublayers",["layers"])],z.prototype,"readSublayers",null),e([I("sublayers",{layers:{type:[H]},visibleLayers:{type:[String]}})],z.prototype,"writeSublayers",null),e([v({json:{read:!1},readOnly:!0,value:"wms"})],z.prototype,"type",void 0),e([v(N)],z.prototype,"url",void 0),e([v({type:String,json:{write:{ignoreOrigin:!0}}})],z.prototype,"version",void 0),z=e([j("esri.layers.WMSLayer")],z);const Y=z;export{Y as default};
|