import{M as L,V as b,q as m,b as n,l as T,n as M}from"./TileImage-B-0PORC6.js";import{W as R,a as P,X as d}from"./WMTS-C6QUHVX3.js";import{T as _}from"./TileWMS-Wnr0cw94.js";import{at as j,by as v,bq as G,cr as u,bs as I,an as W,bi as V,_ as Y}from"./index-BVAEVuZQ.js";const h=j({__name:"LayerPreview",props:{url:{},params:{},type:{},bbox:{}},setup(f,{expose:y}){const e=f,p=v();let r;G(()=>{r=new L({target:p.value,view:new b({zoom:1,center:[0,0],projection:"EPSG:3857"})}),i(),e.bbox&&setTimeout(()=>{r.getView().fit(m(e.bbox,"EPSG:4326","EPSG:3857"),{padding:[10,10,10,10]})},0)}),u(()=>({prams:e.params,type:e.type,url:e.url}),()=>{r.getLayers().clear(),i()},{deep:!0,immediate:!1}),u(()=>e.bbox,a=>{a&&V(()=>{r.getView().fit(m(e.bbox,"EPSG:4326","EPSG:3857"),{padding:[10,10,10,10]})})});const S=()=>{if(!e.params.LAYERS||!e.url)return;const a=new _({url:e.url,params:{...e.params,LAYERS:e.params.LAYERS,FORMAT:e.params.FORMAT||"image/png",VERSION:e.params.VERSION||"1.3.0",STYLES:e.params.STYLES||"default"},projection:"EPSG:3857"});r.addLayer(new n({source:a})),r.on("click",t=>{console.log(a.getFeatureInfoUrl(t.coordinate,r.getView().getResolution(),r.getView().getProjection(),{}))})},w=()=>{if(!e.params.crs||!e.url||!e.params.layer)return;const t=T(e.params.crs).getExtent(),o=M(t)/256,c=new Array(22),l=new Array(22);for(let s=0;s<22;s++)c[s]=o/Math.pow(2,s),l[s]=s;const x=new n({source:new R({url:e.url,layer:e.params.layer,format:e.params.format||"image/png",style:e.params.style||"default",matrixSet:e.params.crs,tileGrid:new P({resolutions:c,matrixIds:e.params.matrixIds?e.params.matrixIds.split(","):l,origin:[t[0],t[3]]})})});r.addLayer(x)},g=()=>{const a=new URL(e.url);for(const[t,o]of Object.entries(e.params))a.searchParams.set(t,o);r.addLayer(new n({source:new d({url:decodeURIComponent(a.toString()),projection:"EPSG:3857"})}))},E=()=>{const a=new URL(e.url.replace("{y}","{-y}"));for(const[t,o]of Object.entries(e.params))a.searchParams.set(t,o);r.addLayer(new n({source:new d({url:decodeURIComponent(a.toString()),projection:"EPSG:3857"})}))},i=()=>{e.type=="WMS"?S():e.type=="WMTS"?w():e.type=="XYZ"?g():e.type=="TMS"&&E()};return y({refresh:()=>{r.getLayers().clear(),i()}}),(a,t)=>(I(),W("div",{class:"layer-preview-container",ref_key:"mapRef",ref:p},null,512))}}),X=Y(h,[["__scopeId","data-v-1fe74362"]]);export{X as L};
