// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../core/arrayUtils ../../core/Error ../../geometry/ellipsoidUtils ../../geometry/Extent ../../geometry/Point ../../geometry/support/WKIDUnitConversion ../ogc/crsUtils ../ogc/xmlUtils ./LOD ./TileInfo".split(" "),function(w,P,G,Q,H,I,C,D,J,R,S){function p(b,a){for(let d=0;dc.textContent).filter(P.isSome)}function l(b,a){b.split("\x3e").forEach(d=>{a&&=p(d,a)});return a&&a.textContent}function y(b,a,d,c){let f;Array.prototype.slice.call(c.childNodes).some(e=>{if(e.nodeName.includes(b)){const k=p(a,e)?.textContent;if(k===d||d.split(":")&&d.split(":")[1]=== k)return f=e,!0}return!1});return f}function K(b,a){const d=[];var c=b.layerMap?.get(a);if(!c)return null;const f=v("ResourceURL",c);c=v("Dimension",c);let e,k,h,m;c.length&&(e=l("Identifier",c[0]),k=x("Default",c[0])||x("Value",c[0]));1{let g=q.getAttribute("template");if("tile"===q.getAttribute("resourceType")){if(e&&k.length)if(g.includes("{"+e+"}"))g=g.replace("{"+ e+"}","{dimensionValue}");else{var n=g.toLowerCase().indexOf("{"+e.toLowerCase()+"}");-1c.format=== d);return(a?.length?a:b)??[]}function T(b){const a=[];J.visitXML(b,{BoundingBox:d=>{if(d.getAttribute("crs")){var c=d.getAttribute("crs").toLowerCase(),f=E(c),e=c.includes("epsg")&&D.isAxesOrderReversedForWkid(f.wkid),k,h,m,q;J.visitXML(d,{LowerCorner:g=>{[k,h]=g.textContent.split(" ").map(n=>Number.parseFloat(n));e&&([k,h]=[h,k])},UpperCorner:g=>{[m,q]=g.textContent.split(" ").map(n=>Number.parseFloat(n));e&&([m,q]=[q,m])}});a.push({xmin:k,ymin:h,xmax:m,ymax:q,spatialReference:f})}}});return a}function U(b, a){return v("Style",b).map(d=>{var c=p("LegendURL",d),f=p("Keywords",d);f=f?x("Keyword",f):[];c=c?.getAttribute("xlink:href");a&&(c=c?.replace(/^http:/i,"https:"));return{abstract:l("Abstract",d),id:l("Identifier",d),isDefault:"true"===d.getAttribute("isDefault"),keywords:f,legendUrl:c,title:l("Title",d)}})}function V(b,a,d){return v("TileMatrixSetLink",a).map(c=>W(b,c,d))}function W(b,a,d){const c=p("TileMatrixSet",a).textContent;var f=x("TileMatrix",a);const e=d.find(g=>{g=p("Identifier",g)?.textContent; return g===c||c.split(":")&&c.split(":")[1]===g?!0:!1});a=(a=p("TileMatrixSetLimits",a))&&v("TileMatrixLimits",a);const k=new Map;if(a?.length)for(var h of a){a=p("TileMatrix",h).textContent;d=+p("MinTileRow",h).textContent;const g=+p("MaxTileRow",h).textContent,n=+p("MinTileCol",h).textContent,z=+p("MaxTileCol",h).textContent;k.set(a,{minCol:n,maxCol:z,minRow:d,maxRow:g})}const m=l("SupportedCRS",e).toLowerCase();h=X(e,m);a=h.spatialReference;d=p("TileMatrix",e);d=[parseInt(l("TileWidth",d),10), parseInt(l("TileHeight",d),10)];const q=[];f.length?f.forEach((g,n)=>{g=y("TileMatrix","Identifier",g,e);q.push(M(g,m,n,c,k))}):v("TileMatrix",e).forEach((g,n)=>{q.push(M(g,m,n,c,k))});b=Y(b,e,h,d,q[0]).toJSON();f=(new S({dpi:96,spatialReference:a,size:d,origin:h,lods:q})).toJSON();return{id:c,fullExtent:b,tileInfo:f}}function E(b){b=b.toLowerCase();let a=parseInt(b.split(":").pop(),10);if(900913===a||3857===a)a=102100;b=b.includes("crs84")||b.includes("crs:84")?A.CRS84:b.includes("crs83")||b.includes("crs:83")? A.CRS83:b.includes("crs27")||b.includes("crs:27")?A.CRS27:null;null!=b&&(a=b);return{wkid:a}}function X(b,a){b=p("TileMatrix",b);return N(b,a)}function N(b,a){const d=E(a),[c,f]=l("TopLeftCorner",b).split(" ").map(e=>parseFloat(e));return a.includes("epsg")&&D.isAxesOrderReversedForWkid(d.wkid)?new I({x:f,y:c,spatialReference:d}):new I({x:c,y:f,spatialReference:d})}function Y(b,a,d,c,f){var e=p("BoundingBox",a);if(e){var k=l("LowerCorner",e).split(" ");var h=l("UpperCorner",e).split(" ")}k&&1d.x&&-90<=d.y?new H(a,c,k,h,d.spatialReference):new H(c,a,h,k,d.spatialReference)}function M(b,a,d,c,f){var e=E(a);const k=l("Identifier",b);let h= parseFloat(l("ScaleDenominator",b));c=O(e.wkid,h,c);h*=1.058267716535433;e=+l("MatrixWidth",b);const m=+l("MatrixHeight",b),{maxCol:q=e-1,maxRow:g=m-1,minCol:n=0,minRow:z=0}=f.get(k)??{},{x:F,y:r}=N(b,a);return new R({cols:[n,q],level:d,levelValue:k,origin:[F,r],scale:h,resolution:c,rows:[z,g]})}function O(b,a,d){b=C.hasOwnProperty(""+b)?C.values[C[b]]:"default028mm"===d?6370997*Math.PI/180:Q.getReferenceEllipsoidFromWKID(b).metersPerDegree;return 7*a/25E3/b}var A;(function(b){b[b.CRS84=4326]="CRS84"; b[b.CRS83=4269]="CRS83";b[b.CRS27=4267]="CRS27"})(A||={});w.getTileUrlFromResourceUrls=function(b,a,d,c,f,e,k,h){c=L(b,a,c);if(!(0{const t=p("Constraint",r);if(!t||y("AllowedValues","Value",m,t))return g=r.attributes[0].nodeValue,!0;if(!t||y("AllowedValues","Value","RESTful",t)||y("AllowedValues","Value","REST",t))n=r.attributes[0].nodeValue;else if(!t||y("AllowedValues","Value","KVP",t))q=r.attributes[0].nodeValue;return!1});g||(n?(g=n,m="RESTful"):q?(g=q,m="KVP"):g=p("ServiceMetadataURL",d)?.getAttribute("xlink:href"));a=g.indexOf("1.0.0/");-1===a&&"RESTful"===m?g+="/":-1{const t=l("Identifier",r);c.set(t,r);const Z=l("Abstract",r),aa=x("Format",r);var u=p("WGS84BoundingBox",r);var B=u?l("LowerCorner",u).split(" "):["-180","-90"];u=u?l("UpperCorner",u).split(" "):["180","90"];B={xmin:parseFloat(B[0]),ymin:parseFloat(B[1]),xmax:parseFloat(u[0]), ymax:parseFloat(u[1]),spatialReference:{wkid:4326}};u=T(r);const ba=U(r,h),ca=l("Title",r);r=V(z,r,F);return{id:t,fullExtent:B,fullExtents:u,description:Z,formats:aa,styles:ba,title:ca,tileMatrixSets:r}});return{copyright:a,dimensionMap:b,layerMap:c,layers:f,serviceMode:m,tileUrl:g}};w.parseResourceInfo=function(b){b.layers.forEach(a=>{a.tileMatrixSets?.forEach(d=>{const c=d.tileInfo;c&&96!==c.dpi&&(c.lods?.forEach(f=>{f.scale=96*f.scale/c.dpi;f.resolution=O(c.spatialReference?.wkid,90.71428571428571* f.scale/96,d.id)}),c.dpi=96)})});return b};w.validateCapabilities=function(b){var a=b.replaceAll(/ows:/gi,"");a=(new DOMParser).parseFromString(a,"text/xml").documentElement;if(!p("Contents",a))throw new G("wmtslayer:wmts-capabilities-xml-is-not-valid","the wmts get capabilities response is not compliant",{text:b});};Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});