import{r as T,n as I,m as A,c as O,a as p,f as y,l as F,t as G,e as L,d as R,p as M,o as U}from"./TileImage-B-0PORC6.js";function P(u,e){const r=(""+u).split("."),n=(""+e).split(".");for(let t=0;t<Math.max(r.length,n.length);t++){const s=parseInt(r[t]||"0",10),i=parseInt(n[t]||"0",10);if(s>i)return 1;if(i>s)return-1}return 0}const S=4,f="1.3.0";function v(u,e,r,n,t){t.WIDTH=r[0],t.HEIGHT=r[1];const s=n.getAxisOrientation(),i=P(t.VERSION,"1.3")>=0;t[i?"CRS":"SRS"]=n.getCode();const a=i&&s.startsWith("ne")?[e[1],e[0],e[3],e[2]]:e;return t.BBOX=a.join(","),O(u,t)}function C(u,e,r,n,t,s,i){s=Object.assign({REQUEST:"GetMap"},s);const a=e/r,o=[T(I(u)/a,S),T(A(u)/a,S)];if(r!=1)switch(i){case"geoserver":const l=90*r+.5|0;"FORMAT_OPTIONS"in s?s.FORMAT_OPTIONS+=";dpi:"+l:s.FORMAT_OPTIONS="dpi:"+l;break;case"mapserver":s.MAP_RESOLUTION=90*r;break;case"carmentaserver":case"qgis":s.DPI=90*r;break;default:throw new Error("Unknown `serverType` configured")}return v(t,u,o,n,s)}function m(u,e){return Object.assign({REQUEST:e,SERVICE:"WMS",VERSION:f,FORMAT:"image/png",STYLES:"",TRANSPARENT:"TRUE"},u)}class V extends p{constructor(e){e=e||{};const r=Object.assign({},e.params);super({attributions:e.attributions,attributionsCollapsible:e.attributionsCollapsible,cacheSize:e.cacheSize,crossOrigin:e.crossOrigin,interpolate:e.interpolate,projection:e.projection,reprojectionErrorThreshold:e.reprojectionErrorThreshold,tileClass:e.tileClass,tileGrid:e.tileGrid,tileLoadFunction:e.tileLoadFunction,url:e.url,urls:e.urls,wrapX:e.wrapX!==void 0?e.wrapX:!0,transition:e.transition,zDirection:e.zDirection}),this.gutter_=e.gutter!==void 0?e.gutter:0,this.params_=r,this.v13_=!0,this.serverType_=e.serverType,this.hidpi_=e.hidpi!==void 0?e.hidpi:!0,this.tmpExtent_=y(),this.updateV13_(),this.setKey(this.getKeyForParams_())}getFeatureInfoUrl(e,r,n,t){const s=F(n),i=this.getProjection()||s;let a=this.getTileGrid();a||(a=this.getTileGridForProjection(i));const o=G(e,s,i),_=L(i,s,e,r),l=a.getZForResolution(_,this.zDirection),g=a.getResolution(l),d=a.getTileCoordForCoordAndZ(o,l);if(a.getResolutions().length<=d[0])return;let c=a.getTileCoordExtent(d,this.tmpExtent_);const E=this.gutter_;E!==0&&(c=R(c,g*E,c));const h={QUERY_LAYERS:this.params_.LAYERS};Object.assign(h,m(this.params_,"GetFeatureInfo"),t);const b=Math.floor((o[0]-c[0])/g),j=Math.floor((c[3]-o[1])/g);return h[this.v13_?"I":"X"]=b,h[this.v13_?"J":"Y"]=j,this.getRequestUrl_(d,c,1,i||s,h)}getLegendUrl(e,r){if(this.urls[0]===void 0)return;const n={SERVICE:"WMS",VERSION:f,REQUEST:"GetLegendGraphic",FORMAT:"image/png"};if(r===void 0||r.LAYER===void 0){const t=this.params_.LAYERS;if(!(!Array.isArray(t)||t.length===1))return;n.LAYER=t}if(e!==void 0){const t=this.getProjection()?this.getProjection().getMetersPerUnit():1,s=28e-5;n.SCALE=e*t/s}return Object.assign(n,r),O(this.urls[0],n)}getGutter(){return this.gutter_}getParams(){return this.params_}getRequestUrl_(e,r,n,t,s){const i=this.urls;if(!i)return;let a;if(i.length==1)a=i[0];else{const o=M(U(e),i.length);a=i[o]}return C(r,(this.tileGrid||this.getTileGridForProjection(t)).getResolution(e[0]),n,t,a,s,this.serverType_)}getTilePixelRatio(e){return!this.hidpi_||this.serverType_===void 0?1:e}getKeyForParams_(){let e=0;const r=[];for(const n in this.params_)r[e++]=n+"-"+this.params_[n];return r.join("/")}setParams_(e){this.params_=e,this.updateV13_(),this.setKey(this.getKeyForParams_())}setParams(e){this.setParams_(Object.assign({},e))}updateParams(e){this.setParams_(Object.assign(this.params_,e))}updateV13_(){const e=this.params_.VERSION||f;this.v13_=P(e,"1.3")>=0}tileUrlFunction(e,r,n){let t=this.getTileGrid();if(t||(t=this.getTileGridForProjection(n)),t.getResolutions().length<=e[0])return;r!=1&&(!this.hidpi_||this.serverType_===void 0)&&(r=1);const s=t.getResolution(e[0]);let i=t.getTileCoordExtent(e,this.tmpExtent_);const a=this.gutter_;a!==0&&(i=R(i,s*a,i));const o=Object.assign({},m(this.params_,"GetMap"));return this.getRequestUrl_(e,i,r,n,o)}}export{V as T};
