WMSLayer.js 11 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import r from"../config.js";import t from"../Graphic.js";import s from"../PopupTemplate.js";import o from"../request.js";import i from"../core/Collection.js";import a from"../core/CollectionFlattener.js";import{HandleOwnerMixin as n}from"../core/HandleOwner.js";import{JSONMap as p}from"../core/jsonMap.js";import{clone as l}from"../core/lang.js";import{isSome as m}from"../core/maybe.js";import{MultiOriginJSONMixin as u}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as c}from"../core/promiseUtils.js";import{watch as y,sync as d}from"../core/reactiveUtils.js";import{addQueryParameters as f,Url as h}from"../core/urlUtils.js";import{property as g}from"../core/accessorSupport/decorators/property.js";import{Integer as b}from"../core/accessorSupport/ensureType.js";import{reader as w}from"../core/accessorSupport/decorators/reader.js";import{subclass as x}from"../core/accessorSupport/decorators/subclass.js";import{writer as v}from"../core/accessorSupport/decorators/writer.js";import{willPropertyWrite as j}from"../core/accessorSupport/write.js";import S from"../geometry/Extent.js";import I from"../geometry/SpatialReference.js";import{getScale as R}from"../geometry/support/scaleUtils.js";import{equals as E}from"../geometry/support/spatialReferenceUtils.js";import U from"./Layer.js";import{BlendLayer as O}from"./mixins/BlendLayer.js";import{OperationalLayer as P}from"./mixins/OperationalLayer.js";import{PortalLayer as F}from"./mixins/PortalLayer.js";import{RefreshableLayer as L}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as q}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as M}from"./mixins/TemporalLayer.js";import{isAxesOrderReversedForWkid as T}from"./ogc/crsUtils.js";import{isWmsServer as C}from"./support/arcgisLayerUrl.js";import{legendEnabled as W,url as $}from"./support/commonProperties.js";import{ExportWMSImageParameters as N}from"./support/ExportWMSImageParameters.js";import _ from"./support/WMSSublayer.js";import{normalizeWKID as H,toISOString as k,getPopupLayers as A,parseCapabilities as B}from"./support/wmsUtils.js";const D=new p({bmp:"image/bmp",gif:"image/gif",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml"},{ignoreUnknown:!1});let G=class extends(n(O(M(L(q(P(F(u(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.featureInfoFormat=null,this.featureInfoUrl=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;const r="wms-sublayer";this.own(y((()=>this.sublayers),((e,t)=>{if(t){for(const e of t)e.layer=null;this.handles.remove(r)}if(e){for(const r of e)r.parent=this,r.layer=this;this.handles.add([e.on("after-add",(({item:e})=>{e.parent=this,e.layer=this})),e.on("after-remove",(({item:e})=>{e.parent=null,e.layer=null}))],r)}}),d))}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}load(e){const r=m(e)?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["WMS"]},e).catch(c).then((()=>this._fetchService(r)))),Promise.resolve(this)}readFullExtentFromItemOrMap(e,r){const t=r.extent;return new S({xmin:t[0][0],ymin:t[0][1],xmax:t[1][0],ymax:t[1][1]})}writeFullExtent(e,r){r.extent=[[e.xmin,e.ymin],[e.xmax,e.ymax]]}readImageFormat(e,r){const t=r.supportedImageFormatTypes;return t&&t.includes("image/png")?"image/png":t&&t[0]}readSpatialReferenceFromItemOrDocument(e,r){return new I(r.spatialReferences[0])}writeSpatialReferences(e,r){const t=this.spatialReference&&this.spatialReference.wkid;e&&t?(r.spatialReferences=e.filter((e=>e!==t)),r.spatialReferences.unshift(t)):r.spatialReferences=e}readSublayersFromItemOrMap(e,r,t){return V(r.layers,t,r.visibleLayers)}readSublayers(e,r,t){return V(r.layers,t)}writeSublayers(e,r,t,s){r.layers=[];const o=new Map,i=e.flatten((({sublayers:e})=>e&&e.toArray())).toArray();i.forEach((e=>{"number"==typeof e.parent.id&&(o.has(e.parent.id)?o.get(e.parent.id).push(e.id):o.set(e.parent.id,[e.id]))})),i.forEach((e=>{const t={sublayer:e,...s},i=e.write({parentLayerId:"number"==typeof e.parent.id?e.parent.id:-1},t);if(o.has(e.id)&&(i.sublayerIds=o.get(e.id)),!e.sublayers&&e.name){const s=e.write({},t);delete s.id,r.layers.push(s)}})),r.visibleLayers=i.filter((e=>e.visible&&!e.sublayers)).map((e=>e.name))}createExportImageParameters(e,r,t,s){const o=s&&s.pixelRatio||1,i=R({extent:e,width:r})*o,a=new N({layer:this,scale:i}),{xmin:n,ymin:p,xmax:l,ymax:m,spatialReference:u}=e,c=H(u,this.spatialReferences),y="1.3.0"===this.version&&T(c)?`${p},${n},${m},${l}`:`${n},${p},${l},${m}`,d=a.toJSON();return{bbox:y,["1.3.0"===this.version?"crs":"srs"]:isNaN(c)?void 0:"EPSG:"+c,...d}}async fetchImage(e,r,t,s){const i=this.mapUrl,a=this.createExportImageParameters(e,r,t,s);if(!a.layers){const e=document.createElement("canvas");return e.width=r,e.height=t,e}const n=s?.timeExtent?.start,p=s?.timeExtent?.end,l=m(n)&&m(p)?n.getTime()===p.getTime()?k(n):`${k(n)}/${k(p)}`:void 0,u={responseType:"image",query:this._mixCustomParameters({width:r,height:t,...a,time:l,...this.refreshParameters}),signal:s?.signal};return o(i,u).then((e=>e.data))}fetchFeatureInfo(e,r,o,i,a){const n=R({extent:e,width:r}),p=new N({layer:this,scale:n}),l=A(p.visibleSublayers);if(!this.featureInfoUrl||!l)return null;const m="1.3.0"===this.version?{I:i,J:a}:{x:i,y:a},u={query_layers:l,request:"GetFeatureInfo",info_format:this.featureInfoFormat,feature_count:25,width:r,height:o,...m},c={...this.createExportImageParameters(e,r,o),...u},y=this._mixCustomParameters(c),d=f(this.featureInfoUrl,y),h=document.createElement("iframe");h.src=d,h.style.border="none",h.style.margin="0",h.style.width="100%",h.setAttribute("sandbox","");const g=new s({title:this.title,content:h});return new t({sourceLayer:this,popupTemplate:g})}findSublayerById(e){return this.allSublayers.find((r=>r.id===e))}findSublayerByName(e){return this.allSublayers.find((r=>r.name===e))}serviceSupportsSpatialReference(e){return C(this.url)||this.spatialReferences.some((r=>{const t=900913===r?I.WebMercator:new I({wkid:r});return E(t,e)}))}async _fetchService(e){if(!this.resourceInfo){this.parsedUrl.query&&this.parsedUrl.query.service&&(this.parsedUrl.query.SERVICE=this.parsedUrl.query.service,delete this.parsedUrl.query.service),this.parsedUrl.query&&this.parsedUrl.query.request&&(this.parsedUrl.query.REQUEST=this.parsedUrl.query.request,delete this.parsedUrl.query.request);const r=await o(this.parsedUrl.path,{query:{SERVICE:"WMS",REQUEST:"GetCapabilities",...this.parsedUrl.query,...this.customParameters},responseType:"xml",signal:e});this.resourceInfo=B(r.data)}if(this.parsedUrl){const e=new h(this.parsedUrl.path);"https"!==e.scheme||e.port&&"443"!==e.port||r.request.httpsDomains.includes(e.host)||r.request.httpsDomains.push(e.host)}this.read(this.resourceInfo,{origin:"service"})}_mixCustomParameters(e){if(!this.customLayerParameters&&!this.customParameters)return e;const r={...this.customParameters,...this.customLayerParameters};for(const t in r)e[t.toLowerCase()]=r[t];return e}};function J(e,r){return e.some((e=>{for(const t in e)if(j(e,t,null,r))return!0;return!1}))}function V(e,r,t){const s=new Map;e.every((e=>null==e.id))&&(e=l(e)).forEach(((e,r)=>e.id=r));for(const i of e){const e=new _;e.read(i,r),-1===t?.indexOf(e.name)&&(e.visible=!1),s.set(e.id,e)}const o=[];for(const a of e){const e=s.get(a.id);if(null!=a.parentLayerId&&a.parentLayerId>=0){const r=s.get(a.parentLayerId);r.sublayers||(r.sublayers=new i),r.sublayers.unshift(e)}else o.unshift(e)}return o}e([g({readOnly:!0})],G.prototype,"allSublayers",void 0),e([g({json:{type:Object,write:!0}})],G.prototype,"customParameters",void 0),e([g({json:{type:Object,write:!0}})],G.prototype,"customLayerParameters",void 0),e([g({type:String,json:{write:!0}})],G.prototype,"copyright",void 0),e([g()],G.prototype,"description",void 0),e([g({readOnly:!0})],G.prototype,"dimensions",void 0),e([g({json:{type:[[Number]],read:{source:"extent"},write:{target:"extent"},origins:{"web-document":{write:{ignoreOrigin:!0}},"portal-item":{write:{ignoreOrigin:!0}}}}})],G.prototype,"fullExtent",void 0),e([w(["web-document","portal-item"],"fullExtent",["extent"])],G.prototype,"readFullExtentFromItemOrMap",null),e([v(["web-document","portal-item"],"fullExtent",{extent:{type:[[Number]]}})],G.prototype,"writeFullExtent",null),e([g()],G.prototype,"fullExtents",void 0),e([g({type:String,json:{write:{ignoreOrigin:!0}}})],G.prototype,"featureInfoFormat",void 0),e([g({type:String,json:{write:{ignoreOrigin:!0}}})],G.prototype,"featureInfoUrl",void 0),e([g({type:String,json:{origins:{"web-document":{default:"image/png",type:D.jsonValues,read:{reader:D.read,source:"format"},write:{writer:D.write,target:"format"}}}}})],G.prototype,"imageFormat",void 0),e([w("imageFormat",["supportedImageFormatTypes"])],G.prototype,"readImageFormat",null),e([g({type:Number,json:{read:{source:"maxHeight"},write:{target:"maxHeight"}}})],G.prototype,"imageMaxHeight",void 0),e([g({type:Number,json:{read:{source:"maxWidth"},write:{target:"maxWidth"}}})],G.prototype,"imageMaxWidth",void 0),e([g()],G.prototype,"imageTransparency",void 0),e([g(W)],G.prototype,"legendEnabled",void 0),e([g({type:["show","hide","hide-children"]})],G.prototype,"listMode",void 0),e([g({type:String,json:{write:{ignoreOrigin:!0}}})],G.prototype,"mapUrl",void 0),e([g({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],G.prototype,"isReference",void 0),e([g({type:["WMS"]})],G.prototype,"operationalLayerType",void 0),e([g()],G.prototype,"resourceInfo",void 0),e([g({type:I,json:{origins:{service:{read:{source:"extent.spatialReference"}}},write:!1}})],G.prototype,"spatialReference",void 0),e([w(["web-document","portal-item"],"spatialReference",["spatialReferences"])],G.prototype,"readSpatialReferenceFromItemOrDocument",null),e([g({type:[b],json:{read:!1,origins:{service:{read:!0},"web-document":{read:!1,write:{ignoreOrigin:!0}},"portal-item":{read:!1,write:{ignoreOrigin:!0}}}}})],G.prototype,"spatialReferences",void 0),e([v(["web-document","portal-item"],"spatialReferences")],G.prototype,"writeSpatialReferences",null),e([g({type:i.ofType(_),json:{write:{target:"layers",overridePolicy(e,r,t){if(J(this.allSublayers,t))return{ignoreOrigin:!0}}}}})],G.prototype,"sublayers",void 0),e([w(["web-document","portal-item"],"sublayers",["layers","visibleLayers"])],G.prototype,"readSublayersFromItemOrMap",null),e([w("service","sublayers",["layers"])],G.prototype,"readSublayers",null),e([v("sublayers",{layers:{type:[_]},visibleLayers:{type:[String]}})],G.prototype,"writeSublayers",null),e([g({json:{read:!1},readOnly:!0,value:"wms"})],G.prototype,"type",void 0),e([g($)],G.prototype,"url",void 0),e([g({type:String,json:{write:{ignoreOrigin:!0}}})],G.prototype,"version",void 0),G=e([x("esri.layers.WMSLayer")],G);const Q=G;export{Q as default};